/* ===========================================================================
   MindMate — modern dark theme.
   Deep layered surfaces, soft glows, glassmorphism, and a vivid blue accent.
   Class names are unchanged from the original so all templates/JS still work.
   =========================================================================== */
:root {
  /* Notch / home-indicator insets. app_base.html sets viewport-fit=cover, so
     the page paints UNDER the notch and home bar — every element sitting on a
     physical edge has to pad itself or the hardware covers it. env() resolves
     to 0 on devices without insets (and on desktop), so these are inert
     everywhere else and need no media query. */
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-right: env(safe-area-inset-right, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  --sa-left: env(safe-area-inset-left, 0px);

  /* Comfortable minimum for a finger. Applied to controls on touch devices
     only, so the desktop layout keeps its tighter proportions. */
  --tap: 44px;

  /* surfaces (dark, layered) */
  --bg: #0b0c12;
  --bg-soft: #11131c;
  --surface: #161823;
  --surface-2: #1c1f2e;
  --surface-3: #232739;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);

  /* text */
  --text: #e9ebf2;
  --muted: #9aa0b7;
  --faint: #6b7186;

  /* blue accent */
  --blue: #4f8cff;
  --blue-bright: #6ba0ff;
  --blue-dark: #3b74e6;
  --accent-grad: linear-gradient(135deg, #4f8cff 0%, #6c63ff 100%);
  --blue-soft: rgba(79, 140, 255, 0.14);
  --blue-glow: 0 6px 22px rgba(79, 140, 255, 0.35);

  --danger: #ff6b6b;
  --ok: #34d399;

  --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.55);
  --radius: 14px;

  /* layout */
  --sidebar-w: 282px;
  --glass-bg: rgba(11, 12, 18, 0.7); /* translucent bars (topbar, composer) */
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 500px at 12% -8%, rgba(79, 140, 255, 0.12), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(108, 99, 255, 0.10), transparent 55%);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;   /* dvh tracks the collapsing mobile URL bar; the vh
                           line above stays as the fallback for old browsers */
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

/* custom scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #2f344a; background-clip: content-box; }

/* ===================== BUTTONS ===================== */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  padding: 10px 16px;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  transition: transform .06s ease, background .18s ease, border-color .18s ease,
              box-shadow .18s ease, opacity .18s ease, filter .18s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--blue-glow);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); box-shadow: 0 8px 28px rgba(79, 140, 255, 0.5); }

.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); border-color: var(--border); }

.btn-block { width: 100%; }

/* loading state (spinner inside a button while a request is in flight) */
.btn.loading { cursor: progress; }
.spinner {
  display: inline-block; width: 15px; height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: #fff;
  border-radius: 50%; margin-right: 9px; vertical-align: -2px;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-icon {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
  font-size: 18px;
  padding: 9px 12px;
}
.btn-icon:hover { background: var(--blue-soft); border-color: var(--blue); color: var(--blue-bright); }
.btn-icon.recording { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,107,107,.45);} 50% { box-shadow: 0 0 0 9px rgba(255,107,107,0);} }

/* ===================== AUTH ===================== */
/* dvh so the card doesn't jump when the mobile URL bar collapses; the insets
   keep it clear of the notch on a landscape phone. */
.auth-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: calc(24px + var(--sa-top)) calc(24px + var(--sa-right))
           calc(24px + var(--sa-bottom)) calc(24px + var(--sa-left));
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 32px;
  position: relative;
  overflow: hidden;
}
.auth-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 2px;
  background: var(--accent-grad); opacity: .9;
}
.brand { text-align: center; margin-bottom: 22px; }
.brand-logo {
  display: block; width: 76px; height: 76px; object-fit: contain;
  padding: 12px; margin: 0 auto 8px; border-radius: 20px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
}
.brand-logo.small {
  display: inline-block; vertical-align: middle;
  width: 30px; height: 30px; padding: 0; margin: 0;
  border-radius: 8px; background: none; border: 0;
}
.brand h1 {
  margin: 8px 0 2px; font-size: 27px; letter-spacing: -.4px;
  background: linear-gradient(120deg, #fff, #b9c6ff);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.brand-tagline { margin: 0; color: var(--muted); font-size: 13px; }

.tabs {
  display: flex; background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 12px; padding: 4px; margin-bottom: 20px;
}
.tab {
  flex: 1; background: transparent; border: 0; color: var(--muted);
  font: inherit; font-weight: 600; padding: 10px; border-radius: 9px; cursor: pointer; transition: .18s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface-3); color: #fff; box-shadow: var(--shadow); }

.field { display: block; margin-bottom: 15px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; font-weight: 500; }
/* select is included so the register/profile dropdowns match the text inputs */
.field input,
.field select {
  width: 100%; padding: 12px 14px;
  background: var(--bg-soft); border: 1px solid var(--border-strong);
  border-radius: 11px; color: var(--text); font: inherit;
  transition: border-color .18s, box-shadow .18s;
}
.field input::placeholder { color: var(--faint); }
.field input:disabled { color: var(--muted); cursor: not-allowed; }

/* shared focus ring for text inputs (login fields + chat composer) */
.field input:focus,
.field select:focus,
#message:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }

.auth-msg { min-height: 18px; margin: 13px 0 0; font-size: 13px; text-align: center; color: var(--muted); }
.auth-msg.error { color: var(--danger); }
.auth-msg.ok { color: var(--ok); }

/* secondary link under the auth card's button (e.g. "Login as staff") */
.auth-alt { margin: 14px 0 0; text-align: center; font-size: 13px; }
.auth-alt a { color: var(--muted); font-weight: 600; }
.auth-alt a:hover { color: var(--blue-bright); text-decoration: none; }

/* agreement block */
.agreement-box { border: 1px solid var(--border); border-radius: 12px; background: var(--bg-soft); margin-bottom: 14px; overflow: hidden; }
.agreement-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px; font-size: 13px; font-weight: 600; color: var(--text);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.agreement-body { max-height: 180px; overflow-y: auto; padding: 14px; font-size: 12.5px; line-height: 1.6; color: var(--muted); white-space: pre-wrap; }
.agree-check { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; color: var(--text); margin-bottom: 15px; cursor: pointer; }
.agree-check input { margin-top: 2px; width: 16px; height: 16px; accent-color: var(--blue); }
.hidden { display: none !important; }

/* ===================== APP SHELL ===================== */
.app-wrap { display: flex; flex-direction: row; height: 100vh; height: 100dvh; overflow: hidden; }
.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ---- Sidebar (Claude-style nav drawer) ---- */
#sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: rgba(8, 9, 14, 0.78);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  backdrop-filter: blur(12px);
  transition: margin-left .26s cubic-bezier(.4,0,.2,1), transform .26s cubic-bezier(.4,0,.2,1);
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 14px 12px 10px;
}
.sidebar-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; color: var(--text); }
.sidebar-brand:hover { text-decoration: none; opacity: .9; }
.sidebar-brand span { font-size: 16px; letter-spacing: -.2px; }
.sidebar-close { font-size: 16px; padding: 5px 10px; line-height: 1; }

.sidebar-body { flex: 1; overflow-y: auto; padding: 4px 10px 10px; display: flex; flex-direction: column; }
.new-chat-btn { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 12px; }
.new-chat-btn:hover { text-decoration: none; }

.side-nav { display: flex; flex-direction: column; gap: 3px; }
.side-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px; color: var(--muted);
  font-weight: 600; font-size: 14px; border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.side-link .ico { font-size: 16px; width: 20px; text-align: center; flex: 0 0 auto; }
.side-link:hover { color: var(--text); background: var(--surface); text-decoration: none; }
.side-link.active { color: #fff; background: var(--blue-soft); border-color: rgba(79,140,255,.35); }

.side-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--faint); font-weight: 700; padding: 16px 12px 6px;
}
.session-list { display: flex; flex-direction: column; gap: 3px; }
.session-list .placeholder { padding: 8px; }
.session-item {
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; transition: background .14s, border-color .14s;
}
.session-item:hover { background: var(--surface); border-color: var(--border); }
.session-item.active { background: var(--surface-2); border-color: rgba(79,140,255,.45); box-shadow: inset 2px 0 0 var(--blue); }
.session-item .s-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .s-date { font-size: 11px; color: var(--faint); margin-top: 3px; }
.session-item .s-actions { margin-top: 8px; display: none; gap: 12px; }
.session-item:hover .s-actions, .session-item.active .s-actions { display: flex; }
.s-actions button { background: transparent; border: 0; color: var(--muted); font-size: 12px; cursor: pointer; padding: 0; transition: color .15s; }
.s-actions button:hover { color: var(--blue-bright); }

/* Inline rename editor in the sidebar (replaces the blockable window.prompt). */
.session-item.renaming { background: var(--surface); border-color: var(--border); cursor: default; }
.session-item.renaming .s-actions { display: flex; }
.rename-input {
  width: 100%; padding: 6px 8px; border-radius: 8px; font-size: 14px;
  background: var(--surface-2); border: 1px solid rgba(79,140,255,.45);
  color: var(--text); outline: none;
}

.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); flex: 0 0 auto; }
.sidebar-foot .btn { display: flex; align-items: center; justify-content: center; gap: 8px; }

/* scrim behind the mobile drawer */
#scrim { display: none; }

/* ---- Topbar (minimal: toggle + page title) ---- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  /* top inset clears the notch; right/left clear it in landscape */
  padding: calc(12px + var(--sa-top)) calc(18px + var(--sa-right)) 12px
           calc(18px + var(--sa-left));
  border-bottom: 1px solid var(--border);
  background: var(--glass-bg); backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 10; flex: 0 0 auto;
}
.topbar .btn-icon { flex: 0 0 auto; }
.topbar-title {
  font-weight: 700; font-size: 15px; letter-spacing: -.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.muted { color: var(--muted); font-size: 13px; }

/* ---- Desktop: sidebar is collapsible (slides out of the flow) ---- */
@media (min-width: 901px) {
  #sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
  .sidebar-open #sidebar { margin-left: 0; }
}

/* ---- Mobile/tablet: off-canvas drawer + scrim ---- */
@media (max-width: 900px) {
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
    width: 84vw; max-width: 320px; flex-basis: auto;
    transform: translateX(-100%); box-shadow: var(--shadow-lg);
    /* fixed to the physical edges, so it owns its own insets */
    padding-top: var(--sa-top);
    padding-bottom: var(--sa-bottom);
    padding-left: var(--sa-left);
  }
  .sidebar-open #sidebar { transform: translateX(0); }
  #scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(0, 0, 0, 0.55); opacity: 0; visibility: hidden;
    transition: opacity .25s ease, visibility .25s ease;
  }
  .sidebar-open #scrim { opacity: 1; visibility: visible; }
}

.content {
  flex: 1; overflow: hidden;
  padding: 24px calc(24px + var(--sa-right)) calc(24px + var(--sa-bottom))
           calc(24px + var(--sa-left));
}
.content.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

#panels { display: grid; grid-template-columns: 1fr; gap: 18px; max-width: 860px; margin: 0 auto; height: 100%; }
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
.panel-body { padding: 18px; flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.placeholder { color: var(--faint); font-style: italic; }

/* Soft centered welcome — the empty state of a fresh chat (not a message). */
.welcome-msg {
  flex: 1 1 auto; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  gap: 6px; padding: 24px; animation: rise .3s ease both;
}
.welcome-msg h2 {
  margin: 0; font-size: 24px; font-weight: 650;
  background: var(--accent-grad);            /* theme blue -> purple */
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.welcome-msg p { margin: 0; font-size: 14.5px; color: var(--muted); }

/* chat bubbles */
.msg { display: flex; animation: rise .25s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-user { justify-content: flex-end; }
.msg-bot { justify-content: flex-start; }
.msg .bubble { max-width: 82%; padding: 12px 15px; border-radius: 16px; line-height: 1.58; font-size: 14.5px; }
.msg-user .bubble { background: var(--accent-grad); color: #fff; border-bottom-right-radius: 5px; box-shadow: var(--blue-glow); }
.msg-bot .bubble { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 5px; }

.answer-text { line-height: 1.62; margin: 0; white-space: pre-wrap; }
.meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.tag { display: inline-block; background: var(--surface-3); border: 1px solid var(--border); border-radius: 7px; padding: 2px 8px; margin-right: 6px; font-size: 12px; }
.tag.escalated { background: rgba(255,107,107,.16); color: var(--danger); border-color: rgba(255,107,107,.4); }

/* Suicide Risk Check suggestion attached to elevated-risk replies. */
.quiz-link {
  display: block; margin-top: 10px; padding: 10px 13px; border-radius: 12px;
  background: rgba(255, 209, 102, .12); border: 1px solid rgba(255, 209, 102, .45);
  color: var(--text); font-size: 13.5px; line-height: 1.55; text-decoration: none;
}
.quiz-link:hover { background: rgba(255, 209, 102, .2); }

.dots::after { content: "…"; animation: dots 1.2s steps(4, end) infinite; display: inline-block; width: 1em; text-align: left; }
@keyframes dots { 0% { content: "";} 25% { content: ".";} 50% { content: "..";} 75% { content: "...";} }

/* composer */
#composer {
  display: flex; gap: 10px; align-items: flex-end;
  /* bottom inset keeps the input above the iPhone home indicator */
  padding: 16px calc(24px + var(--sa-right)) calc(16px + var(--sa-bottom))
           calc(24px + var(--sa-left));
  border-top: 1px solid var(--border);
  background: var(--glass-bg); backdrop-filter: blur(12px);
}
#message {
  flex: 1; resize: none; max-height: 140px; padding: 13px 15px;
  background: var(--bg-soft); border: 1px solid var(--border-strong);
  border-radius: 14px; color: var(--text); font: inherit; line-height: 1.5;
  transition: border-color .18s, box-shadow .18s;
}
#message::placeholder { color: var(--faint); }
#message:disabled { opacity: .55; cursor: not-allowed; }
/* #message:focus shares the input focus-ring rule defined in the AUTH section */

/* ---- experiment mode (supervised live counselling) ---- */
.mode-toggle {
  padding: 10px 24px; border-top: 1px solid var(--border);
  background: var(--glass-bg); backdrop-filter: blur(12px);
  font-size: 13px; color: var(--muted);
}
.mode-toggle label { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.mode-toggle input { width: 16px; height: 16px; accent-color: var(--blue); flex: 0 0 auto; }
.tag.experiment { background: var(--blue-soft); color: var(--blue-bright); border-color: rgba(79, 140, 255, .4); }
.bubble.waiting-review { border-color: rgba(79, 140, 255, .45); }
.s-supervised { color: var(--blue-bright); font-weight: 600; }

/* ===================== ANALYSIS PAGE ===================== */
.analysis-wrap { max-width: 920px; margin: 0 auto; }
.analysis-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.analysis-controls select {
  flex: 1; min-width: 200px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: 11px; color: var(--text); font: inherit;
}
.analysis-controls select:focus { outline: none; border-color: var(--blue); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 15px; margin-bottom: 24px; }
.stat-card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; color: #fff; }
.stat-card .stat-value.danger { color: var(--danger); }

.section-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 22px; }
.section-card h3 { margin: 0 0 18px; font-size: 16px; }

.bar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.bar-label { width: 130px; font-size: 13px; flex: 0 0 auto; color: var(--muted); }
.bar-track { flex: 1; height: 22px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent-grad); border-radius: 999px; transition: width .5s ease; box-shadow: 0 0 12px rgba(79,140,255,.4); }
.bar-count { width: 56px; text-align: right; font-size: 13px; color: var(--muted); flex: 0 0 auto; }

.timeline-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: 0; }
.timeline-when { width: 160px; flex: 0 0 auto; font-size: 12px; color: var(--faint); }
.timeline-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emotion-pill { flex: 0 0 auto; font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 999px; background: var(--blue-soft); border: 1px solid rgba(79,140,255,.3); color: var(--blue-bright); }

/* ===================== RESOURCES PAGE ===================== */
.resources-wrap { max-width: 1020px; margin: 0 auto; }
.resources-wrap h2 { margin: 0 0 16px; font-size: 24px; letter-spacing: -.3px; }
.resource-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 20px; }
/* category filter chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.chip {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 14px; cursor: pointer; transition: .15s;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active { color: #fff; background: var(--accent-grad); border-color: transparent; box-shadow: var(--blue-glow); }

.resource-card {
  position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; cursor: pointer; display: flex; flex-direction: column;
  transition: transform .12s ease, box-shadow .2s ease, border-color .2s ease;
}
/* icon tile on resource cards + detail pages, tinted per category */
.rc-icon {
  width: 48px; height: 48px; border-radius: 13px;
  display: grid; place-items: center; font-size: 24px;
  margin-bottom: 13px; border: 1px solid var(--border-strong);
}
.rc-icon.lg { width: 58px; height: 58px; font-size: 29px; border-radius: 15px; margin-bottom: 14px; }
.tint-calm   { background: linear-gradient(135deg, rgba(79, 140, 255, .28), rgba(52, 211, 153, .18)); }
.tint-stress { background: linear-gradient(135deg, rgba(108, 99, 255, .30), rgba(79, 140, 255, .16)); }
.tint-anger  { background: linear-gradient(135deg, rgba(255, 140, 66, .28), rgba(255, 107, 107, .18)); }
.tint-love   { background: linear-gradient(135deg, rgba(255, 107, 168, .26), rgba(108, 99, 255, .16)); }
.tint-test   { background: linear-gradient(135deg, rgba(52, 211, 153, .26), rgba(79, 140, 255, .16)); }

/* self-test flow (questions -> result) */
.test-intro { color: var(--muted); line-height: 1.65; margin: 0 0 20px; }
.q-block { padding: 15px 0; border-bottom: 1px solid var(--border); }
.q-text { font-weight: 600; margin-bottom: 11px; line-height: 1.5; }
.q-opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 14px; cursor: pointer; transition: .15s;
}
.opt:hover { color: var(--text); border-color: var(--border-strong); }
.opt.selected { color: #fff; background: var(--accent-grad); border-color: transparent; box-shadow: var(--blue-glow); }
.test-actions { display: flex; align-items: center; gap: 14px; margin-top: 22px; flex-wrap: wrap; }
.test-result {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px; text-align: center; margin: 6px 0 18px; box-shadow: var(--shadow);
}
.score-big { font-size: 44px; font-weight: 700; color: #fff; }
.score-max { font-size: 18px; color: var(--faint); margin-left: 6px; font-weight: 600; }
.score-band { font-size: 15px; font-weight: 700; color: var(--blue-bright); margin-top: 2px; }
.score-advice { color: var(--muted); line-height: 1.65; margin: 14px auto 0; max-width: 560px; }
.test-alert {
  margin-top: 16px; padding: 13px 16px; border-radius: 12px; text-align: left;
  background: rgba(255, 107, 107, .12); border: 1px solid rgba(255, 107, 107, .4);
  color: var(--text); font-size: 14px; line-height: 1.6;
}
.resource-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: rgba(79,140,255,.4); }
.resource-card .rc-body { padding: 17px; }
.resource-card .rc-cat { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--blue-bright); }
.resource-card h3 { margin: 7px 0 7px; font-size: 17px; }
.resource-card p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.55; }

/* resource detail */
.resource-detail { max-width: 780px; margin: 0 auto; }
.back-link { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 18px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--muted); transition: color .15s; }
.back-link:hover { color: var(--blue-bright); }
.detail-hero { width: 100%; max-height: 300px; object-fit: cover; border-radius: var(--radius); margin-bottom: 20px; border: 1px solid var(--border); }
.detail-cat { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--blue-bright); }
.resource-detail h2 { margin: 7px 0 18px; font-size: 27px; letter-spacing: -.4px; }

.detail-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.detail-tab {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  font: inherit; font-weight: 600; color: var(--muted); padding: 11px 15px; cursor: pointer; transition: color .15s;
}
.detail-tab:hover { color: var(--text); }
.detail-tab.active { color: var(--blue-bright); border-bottom-color: var(--blue); }
.tab-panel { line-height: 1.75; font-size: 15px; color: var(--text); }
.tab-panel.hidden { display: none; }

.step { display: flex; gap: 15px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.step:last-child { border-bottom: 0; }
.step-num {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 999px;
  background: var(--accent-grad); color: #fff; font-weight: 700; font-size: 14px;
  display: grid; place-items: center; box-shadow: var(--blue-glow);
}
.step-body h4 { margin: 3px 0 5px; font-size: 15px; }
.step-body p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }

/* source citation at the bottom of a guide/exercise */
.reference {
  margin: 26px 0 0; padding-top: 14px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--faint);
}

/* ===================== MY PROFILE ===================== */
.profile-wrap { max-width: 560px; margin: 0 auto; }
.profile-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px; box-shadow: var(--shadow);
}
.profile-card h3 { margin: 0 0 6px; }
.profile-note { margin: 0 0 20px; }
.profile-card .field span em { font-style: normal; margin-left: 6px; }
.profile-actions { display: flex; align-items: center; gap: 14px; margin-top: 4px; }
.profile-joined { margin: 18px 0 0; text-align: right; }

/* ---- General mobile refinements ----
   EVERY breakpoint lives below this line. A page section added after these
   would silently out-rank its own overrides (same specificity, later wins) —
   which is exactly what happened when .profile-card was appended at the end. */
@media (max-width: 760px) {
  /* NOTE: these re-state the safe-area insets, because a `padding` shorthand
     would otherwise reset the values set on the base rules above. */
  .content {
    padding: 16px calc(16px + var(--sa-right)) calc(16px + var(--sa-bottom))
             calc(16px + var(--sa-left));
  }
  .auth-card { padding: 24px; }
  #composer {
    padding: 12px calc(14px + var(--sa-right)) calc(12px + var(--sa-bottom))
             calc(14px + var(--sa-left));
    gap: 8px;
  }
  #message { padding: 11px 13px; border-radius: 12px; }
  .msg .bubble { max-width: 88%; }
  .topbar {
    padding: calc(11px + var(--sa-top)) calc(14px + var(--sa-right)) 11px
             calc(14px + var(--sa-left));
  }
  .cards { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
  .section-card { padding: 16px; }
  .timeline-item { flex-wrap: wrap; gap: 6px 12px; }
  .timeline-when { width: 100%; order: -1; }
  .bar-label { width: 92px; }
  .resources-wrap h2 { font-size: 21px; }
  .resource-detail h2 { font-size: 23px; }
  .profile-card { padding: 18px; }
  /* stack the Save button and its status line rather than squeezing them.
     flex-basis 100% (not width) so the empty status <p> can't keep a slot on
     the button's row and shrink it. */
  .profile-actions { flex-wrap: wrap; gap: 10px; }
  .profile-actions .btn { flex: 1 0 100%; }
  .profile-joined { text-align: left; }
}

/* very small phones */
@media (max-width: 380px) {
  #sendBtn { padding: 10px 13px; }
  .msg .bubble { max-width: 92%; font-size: 14px; }
}

/* ---- Touch devices: finger-sized controls ----
   Keyed on the POINTER, not the viewport width — a 1024px tablet is touch and
   a 360px-wide desktop window is not, so a width breakpoint targets the wrong
   one. Desktop keeps its tighter proportions untouched. */
@media (hover: none) and (pointer: coarse) {
  .btn, .side-link, .tab { min-height: var(--tap); }
  .btn-icon {
    min-width: var(--tap); min-height: var(--tap);
    display: inline-flex; align-items: center; justify-content: center;
  }
  /* iOS Safari zooms the whole page when a focused field is under 16px */
  .field input, .field select, #message { font-size: 16px; }
  .agree-check input { width: 20px; height: 20px; }
}

/* ===================== UTILITIES =====================
   !important so the utility always wins, like the inline styles it replaced. */
.text-danger { color: var(--danger) !important; }
/* moved here from admin.css: the profile page needs it too, and admin.css
   layers on this file, so shared utilities belong in the base. */
.no-margin { margin: 0; }
