/* Dashboard-specific styles */
body { background: var(--bg); }

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
aside.side {
  background: var(--bg-deep);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  display: flex; flex-direction: column; gap: 24px;
  position: sticky; top: 0; height: 100vh;
}
.side .brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: -0.02em; padding: 0 6px; }
.side .brand img { width: 26px; height: 26px; }

.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  color: var(--text-dim);
  font-size: 14px;
  border: 1px solid transparent;   /* reserved so .active doesn't shift layout */
  transition: background var(--dur) var(--ease), color var(--dur-fast), border-color var(--dur);
  white-space: nowrap;
}
.side nav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side nav a:hover { background: var(--surface); color: var(--text); }
.side nav a.active {
  background: var(--surface-2); color: var(--text);
  border-color: var(--border);
}
/* sliding left accent bar marks the active item */
.side nav a.active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  background: var(--blue); border-radius: 0 3px 3px 0;
}
.side nav a { position: relative; }
.side nav a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }
.side nav a.active svg { opacity: 1; color: var(--blue-bright); }

.side .group-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.18em; color: var(--text-faint); text-transform: uppercase; padding: 0 12px 6px; }

.side .user {
  margin-top: auto;
  padding: 14px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.avatar {
  width: 36px; height: 36px; border-radius: var(--r-sm);
  background: var(--blue);
  display: grid; place-items: center;
  color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.side .user .meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.side .user .name { font-size: 13px; font-weight: 600; }
.side .user .role { font-size: 11px; color: var(--text-dim); }

/* ===== Main ===== */
main {
  padding: 32px 40px 60px;
  display: flex; flex-direction: column; gap: 28px;
  min-width: 0;
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar .search {
  display: flex; align-items: center; gap: 10px;
  width: 360px;
  height: 40px; padding: 0 14px;
  border-radius: var(--r-pill);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
}
.topbar .actions { display: flex; gap: 10px; align-items: center; }
.icon-btn { width: 40px; height: 40px; border-radius: 999px; display:grid;place-items:center; background: var(--surface); border: 1px solid var(--border); cursor: pointer; transition: background var(--dur) var(--ease), border-color var(--dur), transform var(--dur) var(--ease); color: var(--text); }
.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.icon-btn:active { transform: scale(0.94); }

/* Greeting hero card */
.greeting {
  position: relative; overflow: hidden;
  border-radius: var(--r-lg);
  padding: 32px 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: end;
}
.greeting::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--blue);
}
.greeting h1 { font-family: var(--font-display); font-weight: 700; font-size: 34px; letter-spacing: -0.01em; margin: 0 0 6px; line-height: 1.12; }
.greeting p { color: var(--text-dim); font-size: 15px; margin: 0 0 22px; max-width: 520px; line-height: 1.55; }
.streak { display: flex; gap: 22px; align-items: center; }
.streak-num {
  font-family: var(--font-display);
  font-size: 54px; font-weight: 700; letter-spacing: -0.02em;
  color: var(--blue-bright);
  line-height: 1;
}
.streak-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.streak-days .day { width: 24px; height: 24px; border-radius: var(--r-xs); background: var(--surface-3); border: 1px solid var(--border); }
.streak-days .day.on { background: var(--blue); border-color: var(--blue); }
.streak-days .day.today { background: var(--blue-bright); border-color: var(--blue-bright); }

/* Stat cards row */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat {
  padding: 20px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.stat:hover { transform: translateY(-2px); border-color: var(--blue-line); }
.stat .lbl { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-faint); }
.stat .val { font-family: var(--font-display); font-size: 34px; font-weight: 700; letter-spacing: -0.01em; margin-top: 4px; line-height: 1; }
.stat .val .u { font-size: 14px; color: var(--text-dim); font-weight: 500; margin-left: 4px; }
.stat .delta { font-size: 12px; margin-top: 8px; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.stat .delta span { white-space: nowrap; }
.stat .delta.up { color: #6EE7B7; }
.stat .delta.down { color: #F0808F; }
.stat .spark { position: absolute; right: 12px; bottom: 12px; opacity: .6; }

/* Section title */
.sec-title { display: flex; align-items: baseline; justify-content: space-between; }
.sec-title h2 { font-family: var(--font-display); font-weight: 600; font-size: 22px; letter-spacing: -0.02em; margin: 0; }
.sec-title a { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.sec-title a:hover { color: var(--text); }

/* Scenario cards (continue / start) */
.scenarios-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.scenario {
  aspect-ratio: 3/4;
  border-radius: var(--r-lg);
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  cursor: pointer;
}
.scenario:hover { transform: translateY(-3px); border-color: var(--border-strong); box-shadow: var(--shadow-pop); }
.scenario .top { display: flex; justify-content: space-between; align-items: start; position: relative; z-index: 2; }
.scenario h3 { font-family: var(--font-display); font-weight: 600; font-size: 18px; letter-spacing: -0.02em; margin: 6px 0 4px; position: relative; z-index: 2; }
.scenario .sub { font-size: 12px; color: var(--text-dim); position: relative; z-index: 2; }
.scenario .bg { position: absolute; inset: 0; opacity: .8; pointer-events: none; }

/* Two-column section */
.cols-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.panel { padding: 24px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-card); }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.panel-head h3 { font-family: var(--font-display); font-weight: 600; font-size: 18px; letter-spacing: -0.02em; margin: 0; }
.panel-head .tabs { display: flex; gap: 4px; padding: 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.panel-head .tabs button { background: transparent; border: 0; color: var(--text-dim); font-size: 12px; padding: 6px 12px; border-radius: 999px; cursor: pointer; font-family: var(--font-body); }
.panel-head .tabs button.active { background: var(--surface-3); color: var(--text); }

/* Chart */
.chart { height: 240px; position: relative; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .y-lbl { font-family: var(--font-mono); font-size: 10px; fill: var(--text-faint); }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 2 4; }
.chart .x-lbl { font-family: var(--font-mono); font-size: 10px; fill: var(--text-faint); }

/* Sessions list */
.session-row {
  display: grid; grid-template-columns: 44px 1fr 100px 90px 24px;
  gap: 14px; align-items: center;
  padding: 14px 12px; margin: 0 -12px;
  border-radius: var(--r-sm);
  border-bottom: 1px solid var(--border);
  transition: background var(--dur) var(--ease);
}
.session-row:last-child { border-bottom: 0; }
.session-row:hover { background: var(--surface); }
.session-row .ic { width: 40px; height: 40px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; }
.session-row .title { font-size: 14px; font-weight: 500; }
.session-row .date { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.session-row .score { font-family: var(--font-display); font-size: 18px; font-weight: 600; letter-spacing: -0.02em; }
.score-high { color: #6EE7B7; }
.score-mid { color: #FFD27A; }
.score-low { color: #F0808F; }
.session-row .dur { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); }
.session-row .more { color: var(--text-faint); cursor: pointer; }

/* Goals */
.goal { display: flex; gap: 12px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--border); }
.goal:last-child { border-bottom: 0; }
.ring {
  position: relative;
  width: 40px; height: 40px; border-radius: 999px;
  background: conic-gradient(var(--violet) var(--p, 60%), var(--surface-3) 0);
  flex-shrink: 0;
}
.ring::after {
  content: ""; position: absolute; inset: 4px; border-radius: 999px;
  background: var(--bg-deep);
}
.ring .pct { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-mono); font-size: 10px; font-weight: 600; color: var(--text); z-index: 1; }
.ring.done { background: conic-gradient(#34D399 100%, transparent 0); }
.goal .text { font-size: 13px; line-height: 1.5; }
.goal .text .name { font-weight: 500; color: var(--text); }
.goal .text .meta { color: var(--text-dim); margin-top: 2px; font-size: 12px; }

/* Achievements */
.ach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ach { aspect-ratio: 1/1; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; }
.ach.locked { opacity: .4; }
.ach svg { width: 36px; height: 36px; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 72px 1fr; }
  .side .brand span, .side nav a span, .side .user .meta, .side .group-label { display: none; }
  .scenarios-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .cols-2 { grid-template-columns: 1fr; }
}

/* ===== Mobile: sidebar → bottom tab bar, single-column content (phones ≤640px) ===== */
@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }

  aside.side {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: auto; height: calc(60px + env(safe-area-inset-bottom));
    flex-direction: row; align-items: stretch; justify-content: space-around; gap: 0;
    padding: 0 4px env(safe-area-inset-bottom);
    border-right: 0; border-top: 1px solid var(--border);
    background: var(--bg-deep);
    z-index: 200;
  }
  .side .brand, .side .group-label, .side .user, .side > button[data-logout] { display: none; }
  /* promote both <nav>'s links (and their wrapper divs) into one even flex row */
  .side > div, .side nav { display: contents; }
  .side nav a {
    flex: 1 1 0; flex-direction: column; gap: 3px;
    align-items: center; justify-content: center;
    padding: 8px 2px; border: 0; border-radius: 12px;
  }
  .side nav a span { display: none; }
  .side nav a svg { width: 23px; height: 23px; opacity: .82; }
  .side nav a.active { background: none; box-shadow: none; border: 0; }
  .side nav a.active svg { opacity: 1; }

  main { padding: 16px 14px calc(80px + env(safe-area-inset-bottom)); gap: 18px; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar .search { width: 100%; order: 3; }
  .greeting { grid-template-columns: 1fr; padding: 22px; gap: 16px; }
  .greeting h1 { font-size: 26px; }
  .greeting p { font-size: 14px; margin-bottom: 14px; }
  .streak { gap: 16px; }
  .streak-num { font-size: 44px; }
  .stat-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 16px; }
  .stat .val { font-size: 26px; }
  .scenarios-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .cols-2 { grid-template-columns: 1fr; }
  .ach-grid { grid-template-columns: repeat(4, 1fr); }
}


/* ---- Header language / theme / color-blind toggles (shared across every app page).
   Previously lived only in dashboard.css, so pages that didn't load it (learn, etc.)
   rendered unstyled toggles. Centralized here so they look identical everywhere. ---- */
.nav-tools { display: flex; align-items: center; gap: 8px; }
.lang-seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-pill);
}
.lang-seg button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font-family: var(--font-display); font-weight: 600; font-size: 12px;
  color: var(--text-dim); padding: 5px 11px; border-radius: var(--r-pill);
  transition: color .15s, background .2s;
}
.lang-seg button:hover { color: var(--text); }
.lang-seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); }
.theme-toggle {
  appearance: none; cursor: pointer; width: 36px; height: 36px;
  display: grid; place-items: center; border-radius: var(--r-pill);
  background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--text); transition: background .2s;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .ico-sun { display: none; }
[data-theme="light"] .theme-toggle .ico-sun { display: block; }
[data-theme="light"] .theme-toggle .ico-moon { display: none; }
