/* ── Tawfir Design System v2 ───────────────────────────────────────────── */

/* ── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  /* Brand */
  --brand:        #059669;
  --brand-dark:   #047857;
  --brand-light:  #d1fae5;

  /* Section accent palette */
  --c-home:        #059669;
  --c-accounts:    #2563eb;
  --c-goals:       #7c3aed;
  --c-budgets:     #f59e0b;
  --c-discussions: #db2777;
  --c-decisions:   #6366f1;
  --c-operations:  #0891b2;
  --c-privacy:     #dc2626;

  /* Neutral palette */
  --ink:      #0f172a;
  --ink-2:    #334155;
  --muted:    #64748b;
  --border:   #e2e8f0;
  --surface:  #ffffff;
  --bg:       #f1f5f9;
  --bg-warm:  #fafaf9;

  /* Elevation */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.04);
  --shadow-lg:  0 12px 40px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.06);
  --shadow-xl:  0 24px 60px rgba(0,0,0,.18);

  /* Radius */
  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 24px;
  --r-xl: 32px;

  /* Bottom nav */
  --nav-h:   68px;
}

/* ── Base Reset ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: 'Tajawal', 'IBM Plex Sans Arabic', 'Noto Sans Arabic', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ── Splash Screen (full-page initial load) ────────────────────────────── */
.splash-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #064e3b 0%, #1e1b4b 100%);
}

/* ── Inline loading indicator (used during re-render) ──────────────────── */
.loading-state {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--muted);
  font-size: 1rem;
}

.splash-loader {
  text-align: center;
  animation: splashPulse 1.4s ease-in-out infinite;
}

.splash-loader .splash-icon {
  font-size: 4rem;
  display: block;
  margin-bottom: 12px;
  animation: bounce 1s ease-in-out infinite alternate;
}

.splash-loader p {
  font-size: 2rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: 2px;
}

@keyframes splashPulse { 0%,100%{opacity:1} 50%{opacity:.7} }
@keyframes bounce { from{transform:translateY(0)} to{transform:translateY(-12px)} }

/* ── Onboarding / Auth Screen ──────────────────────────────────────────── */
.onboarding-bg {
  min-height: 100vh;
  background: linear-gradient(155deg, #064e3b 0%, #1e1b4b 55%, #7c3aed 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  position: relative;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Animated decorative blobs */
.onboarding-bg::before,
.onboarding-bg::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  opacity: .18;
  animation: float 7s ease-in-out infinite;
}
.onboarding-bg::before {
  width: 380px; height: 380px;
  background: radial-gradient(circle, #34d399, transparent);
  top: -80px; right: -100px;
}
.onboarding-bg::after {
  width: 260px; height: 260px;
  background: radial-gradient(circle, #a78bfa, transparent);
  top: 180px; left: -60px;
  animation-delay: 3.5s;
}

@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-28px)} }

.onboarding-brand {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 56px 28px 28px;
  text-align: center;
  color: #fff;
  z-index: 2;
}

.onboarding-brand .brand-emoji {
  font-size: 3.5rem;
  display: block;
  margin-bottom: 12px;
  filter: drop-shadow(0 4px 16px rgba(0,0,0,.3));
}

.onboarding-brand h1 {
  font-size: 2.8rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: -1px;
  line-height: 1.1;
}

.onboarding-brand .tagline {
  margin-top: 8px;
  font-size: 1.05rem;
  color: rgba(255,255,255,.72);
  font-weight: 400;
}

.onboarding-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 32px 24px 40px;
  z-index: 3;
  box-shadow: 0 -8px 40px rgba(0,0,0,.25);
  animation: slideUp .5s cubic-bezier(.16,1,.3,1);
}

@keyframes slideUp {
  from { transform: translateY(80px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.onboarding-sheet h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}

.onboarding-sheet .sheet-sub {
  font-size: .95rem;
  color: var(--muted);
  margin-bottom: 24px;
}

/* ── App Shell (main layout) ───────────────────────────────────────────── */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

/* ── Section accent helper (applied to app-shell by JS) ─────────────────── */
.app-shell[data-active-section="home"]         { --section-color: var(--c-home); }
.app-shell[data-active-section="accounts"]     { --section-color: var(--c-accounts); }
.app-shell[data-active-section="goals"]        { --section-color: var(--c-goals); }
.app-shell[data-active-section="budgets"]      { --section-color: var(--c-budgets); }
.app-shell[data-active-section="achievements"] { --section-color: #ca8a04; }
.app-shell[data-active-section="discussions"]  { --section-color: var(--c-discussions); }
.app-shell[data-active-section="decisions"]    { --section-color: var(--c-decisions); }
.app-shell[data-active-section="operations"]   { --section-color: var(--c-operations); }
.app-shell[data-active-section="privacy"]      { --section-color: var(--c-privacy); }
.app-shell { --section-color: var(--brand); }

/* ── Top Header ────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-brand-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--section-color, var(--brand)), color-mix(in srgb, var(--section-color, var(--brand)) 70%, #000));
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  transition: background .4s;
  color: #fff;
}
.header-brand-icon svg {
  width: 22px; height: 22px;
  display: block;
  color: #fff;
}

.header-family-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
}

.header-section-name {
  font-size: .78rem;
  color: var(--muted);
  font-weight: 400;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 1.1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, transform .1s;
}
.icon-btn:active { transform: scale(.92); }

/* ── Section Hero Banner ─────────────────────────────────────────────────── */
.section-hero {
  margin: 16px 16px 0;
  border-radius: var(--r-lg);
  padding: 20px 22px;
  background: linear-gradient(135deg, var(--section-color, var(--brand)), color-mix(in srgb, var(--section-color, var(--brand)) 80%, #fff 20%));
  color: #fff;
  box-shadow: 0 8px 32px color-mix(in srgb, var(--section-color, var(--brand)) 40%, transparent);
  transition: background .4s, box-shadow .4s;
  position: relative;
  overflow: hidden;
}

.section-hero-icon {
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  opacity: .13;
  pointer-events: none;
  color: #fff;
}
.section-hero-icon svg {
  display: block;
  width: 90px;
  height: 90px;
  color: #fff;
}

.section-hero h1 {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 4px;
}

.section-hero .hero-sub {
  font-size: .88rem;
  opacity: .85;
  font-weight: 400;
}

/* ── Metric Cards ──────────────────────────────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.metric {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.metric::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--section-color, var(--brand));
  border-radius: 0 4px 4px 0;
}

.metric span {
  display: block;
  font-size: .8rem;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 6px;
}

.metric strong {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
}

.metric--highlight {
  background: linear-gradient(135deg, color-mix(in srgb, var(--section-color, var(--brand)) 8%, #fff), #fff);
  border-color: color-mix(in srgb, var(--section-color, var(--brand)) 20%, transparent);
}

.metric--highlight::before {
  background: var(--section-color, var(--brand));
}

.metric--highlight strong {
  color: color-mix(in srgb, var(--section-color, var(--brand)) 80%, #000);
}

/* ── Content Area ──────────────────────────────────────────────────────── */
.app-content {
  flex: 1;
  padding: 0 0 16px;
}

.content-pane {
  padding: 16px;
  display: grid;
  gap: 12px;
}

/* ── More / Secondary Sections Grid ────────────────────────────────────── */
.more-grid { padding: 4px 0; }

.more-intro {
  font-size: .82rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 14px;
}

.more-tiles {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.more-tile {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px 8px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: transform .12s, box-shadow .12s, border-color .12s;
  border-top: 3px solid var(--tile-color, var(--brand));
  position: relative;
  overflow: hidden;
}
.more-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--tile-color, var(--brand));
  opacity: 0;
  transition: opacity .12s;
}
.more-tile:hover::before { opacity: .05; }
.more-tile:active { transform: scale(.94); box-shadow: none; }

.more-tile-icon {
  color: var(--tile-color, var(--brand));
  display: flex;
  position: relative;
}
.more-tile-icon svg { width: 28px; height: 28px; }

.more-tile-label {
  font-size: .78rem;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
  position: relative;
}

/* ── Bottom Navigation ─────────────────────────────────────────────────── */
.app-sidebar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 -4px 24px rgba(0,0,0,.08);
  display: flex;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.sidebar-brand { display: none; }

.sidebar-nav {
  display: flex;
  width: 100%;
  overflow-x: hidden;
  scrollbar-width: none;
  gap: 0;
  padding: 4px 4px;
  align-items: stretch;
}

.sidebar-nav::-webkit-scrollbar { display: none; }

.sidebar-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: .7rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .2s, transform .1s;
  white-space: nowrap;
}

.sidebar-link .nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  transition: transform .2s cubic-bezier(.34,1.56,.64,1);
}
.sidebar-link .nav-icon svg {
  width: 22px; height: 22px;
  display: block;
}

.sidebar-link .nav-label {
  display: block;
  font-size: .68rem;
}

.sidebar-link:active { transform: scale(.9); }

.sidebar-link.is-active {
  color: var(--section-color, var(--brand));
  background: color-mix(in srgb, var(--section-color, var(--brand)) 10%, transparent);
}

.sidebar-link.is-active .nav-icon {
  transform: scale(1.18) translateY(-2px);
}

/* ── Cards / Panels ────────────────────────────────────────────────────── */
.card, .panel {
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, transform .15s;
}

.card:hover { box-shadow: var(--shadow-md); }

.card-accent {
  border-right: 4px solid var(--section-color, var(--brand));
}

/* ── Alert Cards (AI Insights) ─────────────────────────────────────────── */
.alert-card {
  padding: 14px 16px;
}
.alert-card--warning { border-right-color: #f59e0b; }
.alert-card--info    { border-right-color: #3b82f6; }
.alert-card--positive { border-right-color: #10b981; }

.alert-card-inner {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.alert-card-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
  line-height: 1.2;
}
.alert-card-content {
  flex: 1;
  min-width: 0;
}
.alert-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.alert-card-top h3 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  flex: 1;
}
.alert-card-action {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 6px 0 0;
  padding: 4px 10px;
  background: var(--surface-alt, #f8fafc);
  border-radius: 6px;
  border-right: 2px solid var(--border);
}

/* ── AI Insights Section Header ────────────────────────────────────────── */
.ai-insights-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.ai-insights-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: #7c3aed;
  background: #ede9fe;
  border: 1px solid #c4b5fd;
  border-radius: 999px;
  padding: 3px 10px;
}
.ai-insights-refresh {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .2s;
}
.ai-insights-refresh:hover { background: var(--surface-alt); color: var(--text); }
.ai-insights-refresh:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── AI Insights Skeleton Loader ───────────────────────────────────────── */
.ai-insights-loading {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0 12px;
}
.ai-insights-pulse {
  height: 14px;
  width: 100%;
  background: linear-gradient(90deg, var(--border) 25%, #e2e8f0 50%, var(--border) 75%);
  background-size: 200% 100%;
  border-radius: 6px;
  animation: pulse-sweep 1.5s ease-in-out infinite;
}
@keyframes pulse-sweep {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Progress Bar ──────────────────────────────────────────────────────── */
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
  direction: ltr;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--section-color, var(--brand)), color-mix(in srgb, var(--section-color, var(--brand)) 60%, #fff));
  transition: width .6s cubic-bezier(.34,1,.64,1);
}

/* ── Section Heading ───────────────────────────────────────────────────── */
.workspace-stack {
  display: grid;
  gap: 24px;
}

.workspace-section {
  display: grid;
  gap: 10px;
}

.section-heading {
  padding: 0 4px;
}

.section-heading h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-heading h2::before {
  content: '';
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--section-color, var(--brand));
  flex-shrink: 0;
}

.section-heading h3 {
  font-size: 1rem;
  font-weight: 600;
}

.section-heading p, .subtitle, .helper {
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.6;
  margin-top: 4px;
}

.eyebrow {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--section-color, var(--brand));
  margin-bottom: 4px;
}

.eyebrow--ink { color: var(--muted); text-transform: none; letter-spacing: 0; }

.stack { display: grid; gap: 10px; }

/* ── Member & Privacy Headers ─────────────────────────────────────────── */
.member-header, .privacy-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.member-header h3, .privacy-header h3, .card h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}

/* ── Badges & Pills ────────────────────────────────────────────────────── */
.role-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: flex-start;
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--section-color, var(--brand)) 10%, transparent);
  color: color-mix(in srgb, var(--section-color, var(--brand)) 80%, #000);
  font-size: .75rem;
  font-weight: 600;
  border: 1px solid color-mix(in srgb, var(--section-color, var(--brand)) 20%, transparent);
}

.status-pill {
  padding: 4px 12px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  font-size: .75rem;
  font-weight: 600;
  border: 1px solid #fde68a;
  white-space: nowrap;
}

.status-pill--green  { background:#d1fae5; color:#065f46; border-color:#6ee7b7; }
.status-pill--red    { background:#fee2e2; color:#991b1b; border-color:#fca5a5; }
.status-pill--blue   { background:#dbeafe; color:#1e40af; border-color:#93c5fd; }
.status-pill--purple { background:#ede9fe; color:#5b21b6; border-color:#c4b5fd; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-panel {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span, .field label {
  font-size: .88rem;
  font-weight: 600;
  color: var(--ink-2);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-family: inherit;
  font-size: .95rem;
  color: var(--ink);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--section-color, var(--brand));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--section-color, var(--brand)) 15%, transparent);
}

.checkbox-group { display: grid; gap: 8px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.checkbox-row:hover {
  border-color: var(--section-color, var(--brand));
  background: var(--surface);
}

/* ── Buttons ───────────────────────────────────────────────────────────── */
.primary-button {
  border: none;
  border-radius: var(--r-sm);
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--section-color, var(--brand)), color-mix(in srgb, var(--section-color, var(--brand)) 70%, #000 30%));
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: opacity .15s, transform .12s, box-shadow .2s;
  box-shadow: 0 4px 16px color-mix(in srgb, var(--section-color, var(--brand)) 30%, transparent);
}

.primary-button:hover { opacity: .92; box-shadow: 0 6px 20px color-mix(in srgb, var(--section-color, var(--brand)) 40%, transparent); }
.primary-button:active { transform: scale(.97); opacity: .85; }
.primary-button:disabled { opacity: .5; cursor: not-allowed; }

.secondary-button {
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 11px 16px;
  background: var(--surface);
  color: var(--ink-2);
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .12s;
  text-align: center;
}

.secondary-button:hover {
  border-color: var(--section-color, var(--brand));
  background: color-mix(in srgb, var(--section-color, var(--brand)) 5%, #fff);
}

.secondary-button:active { transform: scale(.96); }

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* ── Feedback / Alerts ─────────────────────────────────────────────────── */
.feedback-region { min-height: 0; }

.feedback-banner {
  border-radius: var(--r-sm);
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  animation: fadeIn .3s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.feedback-banner p { margin: 0; font-size: .9rem; }

.feedback-banner--success { background:#d1fae5; border-color:#6ee7b7; color:#065f46; }
.feedback-banner--error   { background:#fee2e2; border-color:#fca5a5; color:#991b1b; }
.feedback-banner--warning { background:#fef3c7; border-color:#fde68a; color:#92400e; }
.feedback-banner--info    { background:#dbeafe; border-color:#93c5fd; color:#1e40af; }

/* ── Empty State ───────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 32px 20px;
  color: var(--muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  display: block;
  opacity: .6;
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: .88rem;
  color: var(--muted);
  line-height: 1.6;
}

/* ── Detail List ───────────────────────────────────────────────────────── */
.detail-list {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.detail-list h4 {
  font-size: .85rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 8px;
}

.mini-list {
  list-style: none;
  display: grid;
  gap: 8px;
}

.mini-list li { display: grid; gap: 2px; }

.mini-list span {
  color: var(--muted);
  font-size: .82rem;
}

/* ── Activation card ─────────────────────────────────────────────────── */
.activation-status-card {
  border-color: #fde68a;
  background: #fffbeb;
}

/* ── Account / institution specific ──────────────────────────────────── */
.account-balance {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--section-color, var(--brand));
  margin-top: 8px;
}

/* ── Code / monospace ────────────────────────────────────────────────── */
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: .88em;
  border: 1px solid var(--border);
}

/* ── Section-heading--tight ──────────────────────────────────────────── */
.section-heading--tight h3 { font-size: .95rem; }

/* ── Utility ─────────────────────────────────────────────────────────── */
.cards { display: grid; gap: 10px; }
.section { margin-top: 24px; }

/* ── Screen fallback (old layout) ────────────────────────────────────── */
.screen {
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 18px 48px;
}
.workspace { max-width: 640px; }

/* ════════════════════════════════════════════════════════════════════════
   GAMIFICATION SYSTEM STYLES
   ════════════════════════════════════════════════════════════════════════ */

/* ── Achievements view wrapper ───────────────────────────────────────── */
.achievements-view {
  display: grid;
  gap: 20px;
}

/* ── Level card ──────────────────────────────────────────────────────── */
.gam-level-card {
  border-width: 2px;
  padding: 20px;
}

.gam-level-header {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.gam-level-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border-radius: var(--r-md);
  padding: 14px 16px;
  flex-shrink: 0;
  min-width: 80px;
  box-shadow: var(--shadow-md);
}

.gam-level-emoji {
  font-size: 2rem;
  line-height: 1;
}

.gam-level-number {
  font-size: .72rem;
  font-weight: 700;
  color: rgba(255,255,255,.9);
  white-space: nowrap;
}

.gam-level-info {
  flex: 1;
}

.gam-level-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 4px;
}

.gam-level-xp {
  font-size: .9rem;
  color: var(--muted);
}

.gam-xp-progress { margin-top: 4px; }

.gam-xp-labels {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--muted);
}

.gam-next-title {
  margin-top: 8px;
  font-size: .82rem;
  color: var(--muted);
}

.gam-max-level {
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--section-color, #ca8a04);
  padding: 8px 0 4px;
}

/* ── Streak card ─────────────────────────────────────────────────────── */
.gam-streak-card {
  background: var(--surface);
  border-width: 2px;
  border-color: var(--border);
  transition: border-color .2s;
}

.gam-streak-active {
  border-color: #f59e0b;
  background: linear-gradient(135deg, #fffbeb, #fff);
}

.gam-streak-inner {
  display: flex;
  align-items: center;
  gap: 14px;
}

.gam-streak-icon {
  font-size: 2.4rem;
  flex-shrink: 0;
  animation: flamePulse 1.5s ease-in-out infinite alternate;
}

@keyframes flamePulse {
  from { transform: scale(1); }
  to   { transform: scale(1.15) rotate(-5deg); }
}

.gam-streak-count {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
}

.gam-streak-desc {
  font-size: .82rem;
  color: var(--muted);
  margin-top: 2px;
}

.gam-streak-best {
  margin-right: auto;
  text-align: center;
  padding: 8px 14px;
  background: var(--bg);
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.gam-streak-best-label {
  display: block;
  font-size: .68rem;
  color: var(--muted);
  font-weight: 500;
}

.gam-streak-best-count {
  display: block;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1;
  margin-top: 2px;
}

/* ── Challenges ──────────────────────────────────────────────────────── */
.gam-challenge {
  border: 1.5px solid var(--border);
  transition: border-color .2s, background .2s;
}

.gam-challenge-done {
  border-color: #6ee7b7;
  background: #f0fdf4;
}

.gam-challenge-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.gam-challenge-emoji {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.gam-challenge-info {
  flex: 1;
}

.gam-challenge-info h4 {
  font-size: .95rem;
  font-weight: 700;
  color: var(--ink);
}

.gam-challenge-info p {
  font-size: .8rem;
  color: var(--muted);
  margin-top: 2px;
}

.gam-challenge-reward {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  background: linear-gradient(135deg, var(--section-color, #ca8a04), #fbbf24);
  border-radius: 10px;
  padding: 6px 10px;
  flex-shrink: 0;
}

.gam-challenge-reward span:first-child {
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  line-height: 1;
}

.gam-xp-label {
  font-size: .65rem;
  font-weight: 700;
  color: rgba(255,255,255,.85);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── Leaderboard ─────────────────────────────────────────────────────── */
.gam-leaderboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  transition: box-shadow .2s, transform .15s;
}

.gam-leaderboard-first {
  border-color: #fde68a;
  background: linear-gradient(135deg, #fffbeb, #fff);
  box-shadow: 0 4px 20px rgba(202,138,4,.12);
}

.gam-rank-emoji {
  font-size: 1.8rem;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}

.gam-member-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.gam-member-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.gam-member-name {
  font-size: .9rem;
  font-weight: 600;
  color: var(--ink);
  display: block;
  direction: ltr;
  text-align: right;
}

.gam-member-points {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  flex-shrink: 0;
  background: var(--bg);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  border: 1px solid var(--border);
}

.gam-points-value {
  font-size: 1rem;
  font-weight: 800;
  color: var(--section-color, #ca8a04);
  line-height: 1;
}

.gam-member-points .gam-xp-label {
  font-size: .65rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

/* ── Badge grid ──────────────────────────────────────────────────────── */
.gam-badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
}

.gam-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  border-radius: var(--r-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: default;
  transition: transform .15s, box-shadow .15s;
}

.gam-badge:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.gam-badge-unlocked {
  border-color: color-mix(in srgb, var(--section-color, #ca8a04) 25%, transparent);
  background: color-mix(in srgb, var(--section-color, #ca8a04) 6%, #fff);
  animation: badgePop .4s cubic-bezier(.34,1.56,.64,1) both;
}

@keyframes badgePop {
  from { transform: scale(.8); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

.gam-badge-locked {
  opacity: .4;
  filter: grayscale(1);
}

.gam-badge-emoji {
  font-size: 1.9rem;
  line-height: 1;
}

.gam-badge-title {
  font-size: .68rem;
  font-weight: 600;
  color: var(--ink-2);
  text-align: center;
  line-height: 1.3;
}

/* ── XP breakdown ────────────────────────────────────────────────────── */
.gam-xp-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
  color: var(--ink-2);
}

.gam-xp-row:last-of-type { border-bottom: none; }

.gam-xp-amount {
  font-weight: 700;
  color: var(--section-color, #ca8a04);
}

.gam-xp-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 2px solid var(--border);
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
}

.gam-xp-total strong {
  color: var(--section-color, #ca8a04);
  font-size: 1.1rem;
}

/* ══════════════════════════════════════════════════════════════════════════
   AI ADVISOR (توفيق)
   ══════════════════════════════════════════════════════════════════════ */

/* Hero */
.advisor-hero {
  background: linear-gradient(135deg, #0284c7 0%, #0ea5e9 60%, #38bdf8 100%);
}

/* Container */
.advisor-container {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding-bottom: 100px;
  min-height: calc(100dvh - 220px);
}

/* Quick Tip Card */
.advisor-quick-tips {
  padding: 16px 16px 0;
}

.advisor-tip-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: linear-gradient(135deg, color-mix(in srgb, #0284c7 8%, white), color-mix(in srgb, #0ea5e9 5%, white));
  border: 1px solid color-mix(in srgb, #0284c7 20%, white);
  border-radius: 14px;
  padding: 14px 16px;
  position: relative;
}

.loading-tip .tip-text {
  flex: 1;
}

.skeleton-line {
  height: 12px;
  background: var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  animation: shimmer 1.5s infinite;
  background: linear-gradient(90deg, var(--border) 25%, color-mix(in srgb, var(--border) 60%, white) 50%, var(--border) 75%);
  background-size: 200% 100%;
}

.skeleton-line.short { width: 60%; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.tip-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.tip-text {
  flex: 1;
  font-size: .88rem;
  line-height: 1.6;
  color: var(--ink-2);
}

.tip-refresh {
  background: none;
  border: none;
  color: #0284c7;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
  opacity: .6;
  transition: opacity .2s, transform .3s;
}

.tip-refresh:hover {
  opacity: 1;
  transform: rotate(180deg);
}

/* Prompts */
.advisor-prompts-section {
  padding: 16px 16px 8px;
}

.advisor-prompts-label {
  font-size: .78rem;
  color: var(--ink-3);
  margin-bottom: 8px;
  font-weight: 500;
}

.advisor-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.advisor-chip {
  background: white;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: .8rem;
  font-family: 'Tajawal', sans-serif;
  color: var(--ink-2);
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}

.advisor-chip:hover, .advisor-chip:active {
  background: color-mix(in srgb, #0284c7 10%, white);
  border-color: #0284c7;
  color: #0284c7;
}

/* Messages */
.advisor-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
}

.advisor-message {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: fadeUp .3s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.user-message {
  flex-direction: row-reverse;
}

.message-avatar {
  font-size: 1.4rem;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.message-bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: .88rem;
  line-height: 1.65;
  position: relative;
}

.assistant-message .message-bubble {
  background: white;
  border: 1px solid var(--border);
  border-top-right-radius: 4px;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.user-message .message-bubble {
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  color: white;
  border-top-left-radius: 4px;
}

.message-bubble p {
  margin: 0 0 8px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble strong { font-weight: 700; }

.message-bubble ul {
  margin: 4px 0;
  padding-right: 20px;
}

.message-bubble li {
  margin-bottom: 4px;
}

/* Typing animation */
.typing-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  height: 20px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #0284c7;
  animation: bounce 1.2s infinite;
  display: inline-block;
}

.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40% { transform: translateY(-5px); opacity: 1; }
}

.cursor-blink {
  display: inline-block;
  width: 2px;
  background: currentColor;
  animation: blink .7s steps(1) infinite;
  margin-right: 2px;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Input Area */
.advisor-input-area {
  position: sticky;
  bottom: 72px;
  background: white;
  border-top: 1px solid var(--border);
  padding: 12px 16px 8px;
  z-index: 10;
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}

.advisor-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.advisor-textarea {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 10px 16px;
  font-family: 'Tajawal', sans-serif;
  font-size: .92rem;
  color: var(--ink);
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color .2s;
  background: var(--surface);
  line-height: 1.5;
}

.advisor-textarea:focus {
  border-color: #0284c7;
  background: white;
}

.advisor-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  border: none;
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, opacity .2s;
  box-shadow: 0 4px 12px rgba(2,132,199,.3);
}

.advisor-send-btn:hover { transform: scale(1.05); }
.advisor-send-btn:active { transform: scale(.95); }
.advisor-send-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.send-icon {
  transform: scaleX(-1);
  display: inline-block;
}

.advisor-disclaimer {
  font-size: .7rem;
  color: var(--ink-3);
  text-align: center;
  margin: 6px 0 0;
}

/* Section color for advisor */
.app-shell[data-active-section="advisor"] {
  --section-color: #0284c7;
}

/* ── Inline AI advisor tip banner ────────────────────────────────────── */
.advisor-inline-tip {
  margin: 0 0 0;
  animation: slideDown .35s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(-6px); height: 0; padding: 0; margin: 0; }
}

.advisor-inline-tip-inner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: color-mix(in srgb, var(--tip-color, #059669) 8%, white);
  border-bottom: 2px solid color-mix(in srgb, var(--tip-color, #059669) 30%, white);
  padding: 12px 16px;
}

.advisor-inline-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.advisor-inline-text {
  flex: 1;
  font-size: .83rem;
  line-height: 1.55;
  color: var(--ink-2);
  margin: 0;
}

.advisor-inline-close {
  background: none;
  border: none;
  color: var(--ink-3);
  cursor: pointer;
  font-size: .8rem;
  padding: 2px 4px;
  flex-shrink: 0;
  opacity: .6;
  transition: opacity .2s;
}

.advisor-inline-close:hover { opacity: 1; }

/* ══════════════════════════════════════════════════════════════════════════
   GAMIFICATION LEVEL STRIP (Home Screen)
   ══════════════════════════════════════════════════════════════════════ */

.gam-level-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px 14px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--lvl-color, #059669) 6%, white), color-mix(in srgb, var(--lvl-color, #059669) 3%, white));
  border: 1.5px solid color-mix(in srgb, var(--lvl-color, #059669) 22%, white);
  border-radius: 14px;
  text-decoration: none;
  cursor: pointer;
  transition: box-shadow .2s, transform .15s;
  user-select: none;
}

.gam-level-strip:active {
  transform: scale(.98);
  box-shadow: none;
}

.gam-level-strip-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  color: #fff;
  flex-shrink: 0;
  font-size: 1.3rem;
  line-height: 1;
  gap: 1px;
}

.gam-level-strip-num {
  font-size: .6rem;
  font-weight: 800;
  color: rgba(255,255,255,.9);
  letter-spacing: .5px;
}

.gam-level-strip-info {
  flex: 1;
  min-width: 0;
}

.gam-level-strip-title {
  display: block;
  font-size: .88rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gam-level-strip-bar {
  height: 5px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 5px;
}

.gam-level-strip-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .6s cubic-bezier(.16,1,.3,1);
  min-width: 4px;
}

.gam-level-strip-badges {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 10px;
  gap: 1px;
}

.gam-level-strip-badges span:first-child {
  font-size: .95rem;
  font-weight: 800;
  color: var(--lvl-color, #059669);
  line-height: 1;
}

.gam-level-strip-label {
  font-size: .6rem;
  color: var(--muted);
  font-weight: 600;
}

.gam-level-strip-arrow {
  font-size: 1rem;
  color: var(--muted);
  flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════════════════════════
   BADGE DESCRIPTIONS (inline, mobile-friendly)
   ══════════════════════════════════════════════════════════════════════ */

.gam-badge-grid {
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
}

.gam-badge-desc {
  display: block;
  font-size: .62rem;
  color: var(--muted);
  line-height: 1.3;
  margin-top: 3px;
  text-align: center;
}

.gam-badge-unlocked .gam-badge-desc {
  color: color-mix(in srgb, var(--badge-color, #059669) 80%, black);
}

.gam-badge-unlocked {
  border-color: var(--badge-color, #059669);
  background: linear-gradient(145deg, color-mix(in srgb, var(--badge-color, #059669) 8%, white) 0%, #fff 100%);
  box-shadow: 0 2px 12px color-mix(in srgb, var(--badge-color, #059669) 18%, transparent);
}

/* ══════════════════════════════════════════════════════════════════════════
   BADGE UNLOCK TOAST
   ══════════════════════════════════════════════════════════════════════ */

.gam-toast {
  position: fixed;
  bottom: 88px;
  right: 16px;
  left: 16px;
  z-index: 9999;
  transform: translateY(20px);
  opacity: 0;
  transition: transform .35s cubic-bezier(.16,1,.3,1), opacity .35s;
  pointer-events: none;
}

.gam-toast-visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.gam-toast-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  border: 1.5px solid rgba(255,255,255,.12);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.35);
  direction: rtl;
}

.gam-toast-emoji {
  font-size: 2rem;
  flex-shrink: 0;
}

.gam-toast-label {
  font-size: .7rem;
  font-weight: 600;
  color: #fbbf24;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.gam-toast-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  margin-top: 1px;
}

.gam-toast-close {
  margin-right: auto;
  background: none;
  border: none;
  color: rgba(255,255,255,.5);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}

.gam-toast-close:hover {
  color: #fff;
}
