/* Shared dashboard styling. Matches the v1 phone-frame aesthetic:
   teal #0097b9 accent, soft cream card bg, rounded 8-22px frames.
   The phone-frame layout (.page.phone-frame) is used by /user; admin pages
   use .page or .page.narrow for wider table views. */

:root {
  --primary: var(--brand, #0097b9);           /* inherits theme brand colour */
  --primary-dark: var(--brand-deep, #007a96);
  --primary-soft: var(--chip-green, #e0f2f7);
  --text: #333;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --bg: #f8f8f8;
  --card-bg: #fff;
  --card-bg-soft: #fdfcfb;     /* matches --bg-panel in main.css */
  --border: #e5e7eb;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 8px 20px rgba(0, 0, 0, 0.1);
  --transition: 0.25s ease;
  --radius: 8px;
  --radius-frame: 22px;         /* phone-frame radius */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Montserrat', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.4;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Top bar — light, matches home */
.topbar {
  background: var(--card-bg);
  color: var(--text);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Small Paro logo used inside dashboard h1 headers */
.paro-logo-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
  display: inline-block;
  vertical-align: middle;
}
.phone-frame .phone-header h1 .paro-logo-icon { width: 18px; height: 18px; }
.topbar a, .topbar button {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
  margin-left: 16px;
  background: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  transition: color var(--transition);
}
.topbar a:hover, .topbar button:hover { color: var(--primary-dark); }

/* Azure TTS config status dot in the admin topbar. Filled green dot
   when AZURE_SPEECH_KEY + AZURE_SPEECH_REGION are set; hollow grey
   circle when not — visual nudge for the admin to set up Azure if
   they want Irma / Fabiola / Fiamma etc voices. */
.azure-status {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.6rem;
  line-height: 1;
  vertical-align: middle;
}
.azure-status.azure-ok { color: #16a34a; }       /* green — configured */
.azure-status.azure-missing { color: #9ca3af; }  /* grey — not set */

/* Page container */
.page {
  /* match /home width (.homepage-container is 760px) so all top-level
     pages share a consistent column on desktop. */
  max-width: 760px;
  margin: 0 auto;
  padding: 24px;
}
.page.narrow { max-width: 960px; }

/* Phone-frame layout — mirrors v1 chat UI. Use for /user dashboard. */
.page.phone-frame {
  max-width: 460px;
  margin: 18px auto;
  padding: 0;
  background: var(--card-bg);
  border: 2px solid var(--primary);
  border-radius: var(--radius-frame);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.phone-frame .phone-inner {
  padding: 16px;
}
.phone-frame .phone-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.phone-frame .phone-header h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: 0.3px;
}
.phone-frame .phone-header a,
.phone-frame .phone-header button {
  font-size: 0.8rem;
  color: var(--primary);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  margin-left: 12px;
}
.phone-frame .phone-header a:hover,
.phone-frame .phone-header button:hover { color: var(--primary-dark); }

/* "Back to lesson" — red so it reads as the primary nav-back action,
   not a peer to Logout. (Default phone-header link color was blue
   like everything else, which made the user not realise it was the
   action to return to lessons.) */
.phone-frame .phone-header a.back-to-lesson-link {
  color: #c0392b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid currentColor;
  vertical-align: middle;
  text-decoration: none;
  margin-left: 0;
  flex: 0 0 auto;
}
.phone-frame .phone-header a.back-to-lesson-link svg { width: 20px; height: 20px; display: block; }
.phone-frame .phone-header a.back-to-lesson-link:hover { color: #962d22; background: rgba(192, 57, 43, 0.06); }

/* Mobile: let phone frame become edge-to-edge on small screens */
@media (max-width: 520px) {
  .page.phone-frame {
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    /* iOS Safari: prefer dvh, fall back to vh on ancient browsers. */
    min-height: 100vh;
    min-height: 100dvh;
  }
  .page { padding: 14px; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 1.5rem; }
  .card { padding: 14px 16px; }
  .profile-card { padding: 16px; gap: 14px; }
  .avatar-xl { width: 52px; height: 52px; font-size: 26px; }
  .profile-card h2 { font-size: 1.15rem; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 1rem; }
  table { font-size: 0.8rem; }
  th, td { padding: 8px 10px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 6px; }
}

/* KPI cards grid */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}
.kpi:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}
.kpi .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 500;
}
.kpi .value {
  font-size: 1.8rem;
  font-weight: 600;
  margin-top: 6px;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.kpi .value.plain { color: var(--text); }
.kpi .hint, .kpi .sub {
  font-size: 0.8rem;
  color: var(--text-faint);
  margin-top: 4px;
}
.kpi .delta { font-size: 0.8rem; margin-top: 2px; }
.delta-up { color: #16a34a; }
.delta-down { color: #dc2626; }

/* PLAN / TRIAL bars use the .kpi container shell but render inline
   "LABEL: value" instead of stacked big-number style. Value sits on
   ONE line ("PLAN: Plus") so the bar reads as info, not a metric.
   Hint stays on its own line below at the .kpi default styling. */
.plan-inline-kpi .value {
  font-size: 1.05rem;     /* much smaller than the big 1.8rem KPI number */
  font-weight: 600;
  margin-top: 0;          /* no gap above — there's no .label row above it */
  color: var(--text);     /* darker than the primary-blue KPI value;
                             reads as "info text" not "metric" */
}

/* Card — white block with soft shadow */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}
.card.compact { padding: 16px 20px; }
.card h3 {
  margin: 0 0 14px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Profile header card */
.profile-card {
  display: flex;
  gap: 20px;
  align-items: center;
  background: var(--card-bg);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.avatar-xl {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--primary-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; overflow: hidden; flex-shrink: 0;
}
.avatar-xl img { width: 100%; height: 100%; object-fit: cover; }
.profile-card h2 { margin: 0 0 4px; font-size: 1.4rem; font-weight: 600; color: var(--text); }
.profile-card .sub { color: var(--text-muted); font-size: 0.85rem; }

/* Plan badges */
.plan-badge {
  display: inline-block;
  font-size: 0.7rem; font-weight: 700;
  padding: 3px 10px; border-radius: 999px;
  letter-spacing: 0.5px;
  vertical-align: middle; margin-left: 8px;
}
.plan-free { background: #e5e7eb; color: #374151; }
.plan-core { background: #d1fae5; color: #065f46; }  /* green — entry paid (Core) */
.plan-plus { background: #fde68a; color: #92400e; }  /* gold — AI Plus */
.plan-biz  { background: #c7d2fe; color: #312e81; }  /* indigo — Business English */
.plan-trial { background: #fef3c7; color: #92400e; }
.plan-pro { background: #fde68a; color: #92400e; }   /* legacy alias — keep for old rows */
.plan-comp { background: #ddd6fe; color: #4c1d95; }
.plan-admin { background: #fbcfe8; color: #9d174d; }

/* Toolbar (search + chips) */
.toolbar {
  display: flex; gap: 10px; align-items: center;
  flex-wrap: wrap; margin-bottom: 16px;
}
.search {
  flex: 1; min-width: 220px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  background: var(--card-bg);
  transition: border-color var(--transition);
}
.search:focus { outline: none; border-color: var(--primary); }

.chip {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
  transition: all var(--transition);
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.chip .count { font-size: 0.7rem; opacity: 0.75; margin-left: 6px; }

/* Tables inside cards / panels */
.panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-title {
  padding: 18px 24px 10px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}

table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 12px 20px;
  text-align: left;
  border-bottom: 1px solid #f3f4f6;
  font-size: 0.85rem;
  vertical-align: middle;
}
th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  font-weight: 600;
  background: #fafbfc;
  cursor: pointer;
  user-select: none;
}
th:hover { background: #f3f4f6; color: var(--primary); }
tr:hover td { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.num-hot { color: #c2410c; font-weight: 600; }

/* User cell in admin table */
.user-cell { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary-soft);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; overflow: hidden;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-meta strong { font-weight: 600; display: block; color: var(--text); }
.user-meta .email { color: var(--text-muted); font-size: 0.75rem; }

.muted { color: var(--text-faint); }
.ip { font-family: ui-monospace, monospace; font-size: 0.75rem; color: var(--text-muted); }
.lang-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  background: var(--primary-soft);
  color: var(--primary-dark);
  margin-right: 4px;
}

a.row-link { color: var(--text); text-decoration: none; }
a.row-link:hover { color: var(--primary); }

.empty { text-align: center; color: var(--text-faint); padding: 40px 24px; }

/* Week cells (user dashboard) */
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.week-cell {
  text-align: center;
  padding: 12px 4px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid transparent;
  transition: transform var(--transition);
}
.week-cell.today { border-color: var(--primary); }
.week-cell:hover { transform: translateY(-2px); }
.week-cell .day { font-size: 0.7rem; color: var(--text-muted); font-weight: 500; }
.week-cell .count { font-size: 1.4rem; font-weight: 600; margin-top: 4px; color: var(--primary); }
.week-cell .date { font-size: 0.65rem; color: var(--text-faint); }
.week-cell.active { background: var(--primary-soft); }
.week-cell.hot { background: linear-gradient(180deg, #fef3c7, #fde68a); }
.week-cell.hot .count { color: #92400e; }

/* Quota progress bar */
.quota-bar { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.quota-bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #7ba6d1); transition: width var(--transition); }
.quota-bar-fill.hot { background: linear-gradient(90deg, #fb923c, #ef4444); }
.quota-bar-fill.unlimited { background: linear-gradient(90deg, #34d399, #10b981); }

/* Buttons / CTAs */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  transition: background var(--transition), transform var(--transition);
}
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary {
  background: var(--card-bg);
  color: var(--primary);
}
.btn-secondary:hover { background: var(--primary-soft); color: var(--primary-dark); }

/* Key-value list for detail cards */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 20px; font-size: 0.85rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text); font-family: ui-monospace, monospace; font-size: 0.8rem; word-break: break-all; }
.kv dd.plain { font-family: inherit; font-size: 0.85rem; }

/* Language progress list (user dashboard) */
.lang-list { list-style: none; padding: 0; margin: 0; }
.lang-list li {
  /* <details> handles its own block layout — drop flex so the open state can
     stack the summary + the expanded progress panel vertically. */
  padding: 12px 0;
  border-bottom: 1px solid #f3f4f6;
}
.lang-list li:last-child { border-bottom: 0; }
.lang-name { font-weight: 600; color: var(--text); }
.lang-meta { color: var(--text-muted); font-size: 0.8rem; }
/* Score inline pill rendered before the lessons/topics counts so the
   "Score by language" card delivers on its name — user sees scores
   at first glance, not only after click-to-expand. Slightly heavier
   weight to draw the eye. */
.lang-score-inline { color: var(--text); font-weight: 600; }
.lang-levels { display: flex; gap: 6px; }
.level-tag { padding: 2px 8px; background: var(--bg); border-radius: 4px; font-size: 0.7rem; color: var(--text-muted); }

/* Expandable language row: <summary> is the always-visible header (matches
   the old non-expandable row), <details> open reveals .lang-progress below. */
.lang-row { width: 100%; }
.lang-row > summary {
  list-style: none;          /* hide default triangle — we use the open-state rotation below */
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.lang-row > summary::-webkit-details-marker { display: none; }
/* Affordance chevron — rotates when expanded so the user knows the row is
   interactive without needing a separate explainer label. */
.lang-row > summary::after {
  content: '›';
  margin-left: 6px;
  font-size: 1rem;
  color: var(--text-muted);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.lang-row[open] > summary::after { transform: rotate(90deg); }
.lang-summary-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.lang-progress {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lang-progress-empty { color: var(--text-muted); font-size: 0.78rem; }
.level-row { display: flex; flex-direction: column; gap: 6px; }
.level-row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.level-row-title { font-weight: 600; font-size: 0.82rem; color: var(--text); }
.level-row-score { font-size: 0.78rem; color: var(--text-muted); }
.topic-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.topic-list li {
  display: flex;
  justify-content: space-between;
  padding: 2px 0 2px 14px;
  font-size: 0.76rem;
  color: var(--text-muted);
  border-bottom: none;
}
.topic-name { word-break: break-word; }
.topic-score { flex-shrink: 0; margin-left: 12px; }

/* Per-language delete: small ✕ button on the LEFT of each row. Subtle at
   rest, brightens on hover/focus. Same affordance on desktop + mobile —
   no swipe gesture needed. The wrap reserves space via padding-left so
   the language name doesn't shift when JS hides the button. */
.lang-row-wrap {
  position: relative;
}
.lang-delete-btn {
  /* Anchored to the TOP-left of the wrap (not center) so the button stays
     next to the language name even when the row expands — otherwise on an
     opened <details> the button drifts to the middle of the expanded
     panel, which looks wrong. */
  position: absolute;
  left: 0;
  top: 14px;
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  color: #b91c1c;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  opacity: 0.35;
  transition: opacity 0.15s ease, background 0.15s ease;
  z-index: 2;
}
.lang-delete-btn:hover,
.lang-delete-btn:focus-visible {
  opacity: 1;
  background: #fee2e2;
  outline: none;
}
/* Make room for the ✕ so the language name doesn't sit right under it. */
.lang-row-wrap > .lang-row > summary { padding-left: 28px; }

/* Streak */
.streak-fire { font-size: 1.3rem; }
