/* Riigikohtu Lahendite Otsing — stiilileht
   Disainisuund: õigusvaldkonna tööriist, mitte "AI-demo" vestlusaken.
   Toimikute/registri motiiv: allikakaardid = toimiku sakid, statistika = registri
   loendur. Süsteemifondid ainult, väliseid CDN-e ei kasutata.
*/

/* ---------- Tokens ---------- */
:root {
  --paper: #f5f6f8;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --ink: #1d1e2c;
  --ink-muted: #5b5d72;
  --ink-faint: #8a8ca0;
  --line: #e1e3ea;
  --line-strong: #c9ccd8;

  --violet-1: #667eea;
  --violet-2: #764ba2;
  --violet-deep: #4c3575;
  --violet-wash: #f1eefc;
  --violet-wash-strong: #e6e0f8;

  --gradient-hero: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-button: linear-gradient(135deg, #5a6bd8 0%, #6b3f8f 100%);
  --gradient-button-hover: linear-gradient(135deg, #4f5fc7 0%, #5f3680 100%);

  --good: #1f7a4d;
  --good-wash: #e7f5ee;
  --warn: #92660b;
  --warn-wash: #fbf1de;
  --bad: #b23a3a;
  --bad-wash: #fbeaea;

  --focus: #5a6bd8;

  --font-display: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;

  --shadow-card: 0 1px 2px rgba(29, 30, 44, 0.06), 0 1px 1px rgba(29, 30, 44, 0.04);
  --shadow-raised: 0 8px 24px rgba(29, 30, 44, 0.14);

  --transition-fast: 120ms ease;
  --transition-med: 220ms ease;
}

/* ---------- Reset ---------- */
* , *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p, ul, ol, figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--violet-deep); }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--violet-1), var(--violet-2));
  border-radius: 8px;
  border: 2px solid var(--paper);
}

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  padding: 0.55em 1em;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}
.btn:hover { border-color: var(--ink-faint); background: #fbfbfc; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  border: none;
  background: var(--gradient-button);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: var(--gradient-button-hover); }

.btn-ghost {
  border-color: transparent;
  background: transparent;
}
.btn-ghost:hover { background: var(--violet-wash); }

.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-wash); border-color: var(--bad); }

.btn-icon {
  padding: 0.4em 0.55em;
  line-height: 1;
}

.btn-sm { padding: 0.35em 0.7em; font-size: 13px; }

/* ---------- Login view (+ register/reset: sama kaheveeruline auth-kest) ---------- */
.auth-split {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.login-hero {
  background: var(--gradient-hero);
  color: #fff;
  padding: clamp(2rem, 5vw, 4.5rem);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.login-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 85% 15%, rgba(255,255,255,0.10), transparent 55%);
  pointer-events: none;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 0.65em;
}
.brand-mark .emblem {
  font-size: 2rem;
  line-height: 1;
}
.brand-mark .wordmark {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.login-hero .headline {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 3.4vw, 2.6rem);
  font-weight: 600;
  line-height: 1.15;
  max-width: 18ch;
  margin-top: 2.5rem;
}
.login-hero .subhead {
  margin-top: 1rem;
  max-width: 42ch;
  font-size: 15px;
  color: rgba(255,255,255,0.86);
  line-height: 1.6;
}

.registry {
  display: flex;
  gap: clamp(1.25rem, 3vw, 2.5rem);
  flex-wrap: wrap;
  border-top: 1px solid rgba(255,255,255,0.25);
  padding-top: 1.5rem;
  margin-top: 2rem;
}
.registry dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.7);
}
.registry dd {
  margin: 0.25em 0 0;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  font-weight: 600;
}

.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--surface);
}
.login-form {
  width: 100%;
  max-width: 360px;
}
.login-form h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 0.35em;
}
.login-form .lede {
  color: var(--ink-muted);
  font-size: 14px;
  margin-bottom: 1.75rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4em;
  margin-bottom: 1.1rem;
}
.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
}
.field input {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 0.65em 0.8em;
  background: var(--surface);
  font-size: 15px;
}
.field input:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--violet-wash-strong);
}
.field input::placeholder { color: var(--ink-faint); opacity: 0.75; }

/* Parooliväli: näita/peida nupp välja sees + elav nõuete loend (roheliseks
   muutuvad linnukesed). Nupu ja ikoonid süstib app.js — ilma JS-ita jääb
   tavaline paroolisisend. */
.pw-wrap { position: relative; }
.pw-wrap input { width: 100%; padding-right: 2.9em; }
.pw-toggle {
  position: absolute; top: 50%; right: 0.35em; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 2em; height: 2em;
  border: none; background: transparent;
  color: var(--ink-faint);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}
.pw-toggle:hover { color: var(--ink); background: var(--violet-wash); }
.pw-toggle svg { width: 18px; height: 18px; }
.pw-toggle .ico-eye-off { display: none; }
.pw-toggle.is-visible .ico-eye { display: none; }
.pw-toggle.is-visible .ico-eye-off { display: block; }

.pw-rules {
  list-style: none;
  margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 0.3em;
  max-height: 0; opacity: 0; overflow: hidden;
  transition: max-height var(--transition-med), opacity var(--transition-med),
              margin var(--transition-med);
}
.pw-rules.show { max-height: 6em; opacity: 1; margin-top: 0.15rem; }
.pw-rules li {
  display: flex; align-items: center; gap: 0.5em;
  font-size: 13px;
  color: var(--ink-faint);
  transition: color var(--transition-med);
}
.pw-rules li svg { width: 14px; height: 14px; flex: none; }
.pw-rules li .ico-check { display: none; }
.pw-rules li.ok { color: var(--good); }
.pw-rules li.ok .ico-circle { display: none; }
.pw-rules li.ok .ico-check { display: block; }

.auth-alert {
  border: 1px solid;
  border-radius: var(--radius-md);
  padding: 0.65em 0.85em;
  font-size: 13.5px;
  margin-bottom: 1rem;
}
.auth-alert-error {
  border-color: var(--bad);
  background: var(--bad-wash);
  color: var(--bad);
}
.auth-alert-ok {
  border-color: var(--good);
  background: var(--good-wash);
  color: var(--good);
}

.login-form .btn-primary {
  width: 100%;
  padding: 0.75em 1em;
  font-size: 15px;
}

@media (max-width: 760px) {
  .auth-split { grid-template-columns: 1fr; }
}

/* ---------- App shell ---------- */
/* Fikseeritud viewport-kõrgus: lõim kerib .thread sees, mitte body peal —
   nii jääb ajaloo külgriba pika vastuse kerimisel nähtavaks. */
#view-app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand-mark .wordmark { font-size: 1.15rem; color: var(--ink); }
.topbar .brand-mark .emblem { font-size: 1.4rem; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.username-tag {
  font-size: 13px;
  color: var(--ink-muted);
  padding: 0.3em 0.6em;
}

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---------- Sidebar (history) ---------- */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-header {
  padding: 1rem 1rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-header h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
}
.sidebar-new {
  padding: 0.25rem 1rem 0.6rem;
}
.sidebar-new .btn { width: 100%; }
.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.25rem 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.history-empty {
  color: var(--ink-faint);
  font-size: 13px;
  padding: 0.75rem 0.5rem;
}
.history-item {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 0.55rem 0.6rem;
  text-align: left;
  background: transparent;
}
.history-item:hover { background: var(--paper); border-color: var(--line); }
.history-item .hit-main {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  text-align: left;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.history-item .hit-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}
.history-item .hit-question {
  font-size: 13px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item .hit-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0.2em 0.3em;
  border-radius: var(--radius-sm);
  color: var(--ink-faint);
  font-size: 13px;
}
.history-item .hit-delete:hover { color: var(--bad); background: var(--bad-wash); }

.sidebar-footer {
  padding: 0.6rem 1rem 1rem;
  border-top: 1px solid var(--line);
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform var(--transition-med);
    box-shadow: var(--shadow-raised);
  }
  .sidebar.open { transform: translateX(0); }
}

/* ---------- Main / thread ---------- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.banner {
  margin: 0.75rem 1.25rem 0;
  padding: 0.6em 0.9em;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  border: 1px solid var(--line-strong);
  background: var(--violet-wash);
  color: var(--violet-deep);
}

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem clamp(1rem, 4vw, 3rem);
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 440px;
  color: var(--ink-muted);
}
.empty-state .emblem {
  font-size: 2.25rem;
  display: block;
  margin-bottom: 0.6rem;
}
.empty-state h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--ink);
  margin-bottom: 0.5rem;
}
.empty-state p { font-size: 14px; line-height: 1.6; }

.turn { display: flex; flex-direction: column; gap: 0.85rem; }

.msg-user {
  align-self: flex-end;
  max-width: 78%;
  background: var(--violet-wash);
  border: 1px solid var(--violet-wash-strong);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
  padding: 0.7em 1em;
  white-space: pre-wrap;
  font-size: 15px;
}

.msg-assistant {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}
.msg-avatar {
  flex-shrink: 0;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--gradient-hero);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.msg-content {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--violet-1);
  border-radius: var(--radius-sm) var(--radius-md) var(--radius-md) var(--radius-sm);
  padding: 0.9em 1.1em;
  box-shadow: var(--shadow-card);
}

.rewritten {
  font-style: italic;
  color: var(--ink-muted);
  font-size: 13.5px;
  margin-bottom: 0.5em;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-size: 13px;
  color: var(--ink-muted);
  margin-bottom: 0.5em;
}
.status-line:empty { display: none; }
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--violet-1);
  animation: pulse 1.2s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

.answer-body { font-size: 15.5px; line-height: 1.65; }
.answer-body > * + * { margin-top: 0.75em; }
.answer-body h1, .answer-body h2, .answer-body h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.3;
}
.answer-body h1 { font-size: 1.25em; }
.answer-body h2 { font-size: 1.15em; }
.answer-body h3 { font-size: 1.05em; }
.answer-body ul, .answer-body ol { padding-left: 1.4em; display: flex; flex-direction: column; gap: 0.35em; }
.answer-body strong { font-weight: 700; }
.answer-body em { font-style: italic; }

/* Viitekiip: asjanumber väite küljes. Klikk viib allpool olevale allikakaardile
   (ctrl/cmd-klikk või puuduv kaart → avab allika uues sakis). */
.answer-body a.cite {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.86em;
  font-weight: 600;
  line-height: 1.4;
  padding: 0 0.28em;
  border: 1px solid var(--violet-wash-strong);
  border-radius: var(--radius-sm);
  background: var(--violet-wash);
  color: var(--violet-deep);
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.answer-body a.cite:hover {
  background: var(--violet-wash-strong);
  border-color: var(--violet-1);
}
.answer-body a.lnk {
  color: var(--violet-deep);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.answer-body.streaming::after {
  content: "\258c";
  display: inline-block;
  margin-left: 2px;
  color: var(--violet-1);
  animation: blink 1s step-start infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.error-card {
  border: 1px solid var(--bad);
  background: var(--bad-wash);
  color: var(--bad);
  border-radius: var(--radius-md);
  padding: 0.75em 0.9em;
  font-size: 14px;
}

/* ---------- Source cards (signature: file-tab index cards) ---------- */
.sources { margin-top: 1rem; }
.sources h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin-bottom: 0.6em;
}
.source-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.source-card {
  position: relative;
  display: flex;
  gap: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 0.7em 0.9em 0.7em 0.75em;
  background: var(--surface);
  overflow: hidden;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}
.source-card:hover { box-shadow: var(--shadow-card); transform: translateY(-1px); }
.source-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
}
.source-card.tier-good::before { background: var(--good); }
.source-card.tier-warn::before { background: var(--warn); }
.source-card.tier-bad::before { background: var(--bad); }
.source-card::after {
  content: "";
  position: absolute;
  top: 0; right: 0;
  border-width: 0 10px 10px 0;
  border-style: solid;
  border-color: transparent var(--paper) transparent transparent;
}

/* Kontekstilõik kaardil: originaalsõnastus, mille mudel tegelikult sai.
   Nii saab viidet kontrollida rakendusest lahkumata. */
.source-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  margin-top: 0.5em;
  padding: 0.15em 0;
  border: none;
  background: none;
  color: var(--ink-muted);
  font-size: 12.5px;
  font-weight: 500;
}
.source-toggle:hover { color: var(--violet-deep); }
.source-caret { font-size: 10px; line-height: 1; }

.source-excerpt {
  margin: 0.5em 0 0;
  padding: 0.65em 0.8em;
  border-left: 3px solid var(--line-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--paper);
  color: var(--ink-muted);
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;      /* säilitab lahendi lõigujaotuse */
  overflow-wrap: anywhere;
  max-height: 22em;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.source-card.tier-good .source-excerpt { border-left-color: var(--good); }
.source-card.tier-warn .source-excerpt { border-left-color: var(--warn); }
.source-card.tier-bad  .source-excerpt { border-left-color: var(--bad); }

/* Esiletõst, kui vastuse viitekiibilt kaardile hüpatakse */
.source-card.is-highlighted {
  border-color: var(--violet-1);
  animation: cite-flash 2.2s ease-out;
}
@keyframes cite-flash {
  0%   { background: var(--violet-wash-strong); box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.35); }
  100% { background: var(--surface); box-shadow: 0 0 0 0 rgba(102, 126, 234, 0); }
}

.source-index {
  flex-shrink: 0;
  align-self: flex-start;
  min-width: 1.55em;
  padding: 0.1em 0.35em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--violet-wash);
  color: var(--violet-deep);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
}

.source-icon { font-size: 1.1rem; line-height: 1.4; flex-shrink: 0; }

.source-main { flex: 1; min-width: 0; }
.source-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5em;
}
.source-case {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13.5px;
}
.source-title {
  font-size: 13.5px;
  color: var(--ink-muted);
}
.source-date {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-faint);
}
.source-meta {
  margin-top: 0.3em;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em 0.8em;
  align-items: center;
  font-size: 12px;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.15em 0.55em;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge.tier-good { background: var(--good-wash); color: var(--good); }
.badge.tier-warn { background: var(--warn-wash); color: var(--warn); }
.badge.tier-bad { background: var(--bad-wash); color: var(--bad); }
.source-similarity { color: var(--ink-faint); font-family: var(--font-mono); }
.party-warning {
  margin-top: 0.35em;
  font-size: 12px;
  color: var(--bad);
}
.source-refs {
  margin-top: 0.3em;
  font-size: 12px;
  color: var(--ink-muted);
}
.source-links {
  margin-top: 0.45em;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6em;
}
.source-links a {
  font-size: 12.5px;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.source-links a:hover { border-bottom-color: currentColor; }

/* ---------- Turn actions: feedback + export ---------- */
.turn-actions {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.feedback { display: flex; align-items: center; gap: 0.5em; font-size: 13px; color: var(--ink-muted); }
.feedback .fb-thanks { color: var(--good); font-size: 13px; }
.feedback button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.3em 0.55em;
  font-size: 14px;
}
.feedback button:hover { background: var(--paper); }
.feedback button[aria-pressed="true"] { background: var(--violet-wash); border-color: var(--violet-1); }
.export { display: flex; gap: 0.5em; }

/* ---------- Composer ---------- */
.composer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 0.85rem clamp(1rem, 4vw, 3rem) 1rem;
}
.composer-hint {
  font-size: 12px;
  color: var(--ink-faint);
  margin-bottom: 0.4em;
}
.composer-hint.warn { color: var(--bad); }
.composer-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 0.7em 0.85em;
  font-size: 15px;
  font-family: var(--font-body);
  line-height: 1.5;
  max-height: 200px;
  min-height: 46px;
}
.composer textarea:focus-visible { border-color: var(--focus); }
.composer .btn-primary {
  padding: 0.7em 1.3em;
  white-space: nowrap;
}

/* ---------- Settings drawer ---------- */
.settings-backdrop {
  position: fixed; inset: 0;
  background: rgba(29, 30, 44, 0.32);
  z-index: 45;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-med);
}
.settings-backdrop.open { opacity: 1; pointer-events: auto; }

.settings-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(400px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  z-index: 50;
  transform: translateX(100%);
  transition: transform var(--transition-med);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-raised);
}
.settings-panel.open { transform: translateX(0); }

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.settings-header h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
}
.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}
.setting-group h3 {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
  margin-bottom: 0.6em;
}
.setting-group .help {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 0.4em;
  line-height: 1.5;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 0.75em;
}
.range-row input[type="range"] { flex: 1; accent-color: var(--violet-1); }
.range-row output {
  font-family: var(--font-mono);
  font-weight: 600;
  min-width: 1.6em;
  text-align: right;
}

.year-row { display: flex; align-items: center; gap: 0.6em; }
.year-row select { flex: 1; }
.year-row span { color: var(--ink-faint); font-size: 13px; }

select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 0.55em 0.7em;
  background: var(--surface);
}

.chip-list { display: flex; flex-wrap: wrap; gap: 0.4em; }
.chip {
  display: inline-flex;
  align-items: center;
}
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span {
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.3em 0.6em;
  color: var(--ink-muted);
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.chip input:checked + span {
  background: var(--violet-deep);
  border-color: var(--violet-deep);
  color: #fff;
}
.chip input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.switch-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1em;
  padding: 0.15em 0;
}
.switch-row + .switch-row { margin-top: 0.9em; }
.switch-label { font-size: 14px; font-weight: 500; }
.switch-help { font-size: 12px; color: var(--ink-muted); margin-top: 0.2em; }
.switch {
  position: relative;
  flex-shrink: 0;
  width: 40px; height: 22px;
}
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--line-strong);
  border-radius: 999px;
  transition: background var(--transition-fast);
}
.switch .thumb {
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform var(--transition-fast);
}
.switch input:checked ~ .track { background: var(--violet-1); }
.switch input:checked ~ .thumb { transform: translateX(18px); }
.switch input:focus-visible ~ .track { outline: 2px solid var(--focus); outline-offset: 2px; }

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35em;
}
.segmented label {
  position: relative;
}
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented span {
  display: inline-block;
  font-size: 12.5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.4em 0.65em;
  color: var(--ink-muted);
}
.segmented input:checked + span {
  background: var(--violet-deep);
  border-color: var(--violet-deep);
  color: #fff;
}
.segmented input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Responsive ---------- */
.sidebar-toggle { display: none; }
@media (max-width: 900px) {
  .sidebar-toggle { display: inline-flex; }
  .msg-user { max-width: 90%; }
}

/* ======================================================================
   Kasutajahaldus: auth-vood, konto-menüü, kvoot, modaalid, admin
   ====================================================================== */

/* ---------- Auth-vormide lisad ---------- */
a.btn { text-decoration: none; }

.auth-links {
  margin-top: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--violet-deep);
  font-size: 13.5px;
  text-decoration: none;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

.field-hint {
  font-size: 12px;
  color: var(--ink-faint);
  margin: 0;
}

/* Honeypot: robotilõks — visuaalselt olematu, aga vormis olemas.
   NB! Mitte display:none — osa botte täidab ainult "nähtavaid" välju. */
.hp-wrap {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.auth-hero-slim .headline { margin-top: 2rem; }
.hero-foot {
  font-size: 13px;
  color: rgba(255,255,255,0.75);
  margin-top: 2rem;
}

.auth-result {
  width: 100%;
  max-width: 360px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}
.auth-result-icon { font-size: 2.4rem; line-height: 1; }
.auth-result h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 600;
}
.auth-result p {
  color: var(--ink-muted);
  font-size: 14px;
  line-height: 1.6;
}

/* ---------- Tokeni-kviitung (/verify, /confirm-email-change) ---------- */
#view-token {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-hero);
  padding: 1.5rem;
}
.token-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-raised);
  padding: 2.5rem 2.25rem;
  max-width: 460px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  text-align: center;
}
.token-brand { justify-content: center; }
.token-brand .wordmark { font-size: 1.15rem; }
.token-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}
.token-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--violet-wash-strong);
  border-top-color: var(--violet-1);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.token-glyph {
  font-size: 2.2rem;
  line-height: 1;
  font-weight: 700;
}
.token-glyph.ok { color: var(--good); }
.token-glyph.fail { color: var(--bad); }
.token-msg {
  font-size: 15px;
  color: var(--ink);
  line-height: 1.55;
  max-width: 34ch;
}

/* ---------- Kinnitamata kasutaja värav ---------- */
#view-verify-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  padding: 1.5rem;
}
.gate-card {
  max-width: 480px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--violet-1);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  box-shadow: var(--shadow-card);
  text-align: center;
}
.gate-icon { font-size: 2.5rem; line-height: 1; margin-bottom: 0.75rem; }
.gate-card h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
}
.gate-card p {
  color: var(--ink-muted);
  font-size: 14.5px;
  line-height: 1.6;
  margin-bottom: 1rem;
}
.gate-card #gateEmail { color: var(--ink); word-break: break-all; }
.gate-actions {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

/* ---------- Konto-menüü ---------- */
.account-menu { position: relative; }
.account-trigger { gap: 0.45em; }
.account-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gradient-hero);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.account-name {
  max-width: 14ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-caret { font-size: 10px; color: var(--ink-faint); }
.account-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-raised);
  padding: 0.35rem;
  z-index: 60;
}
.account-head {
  padding: 0.5rem 0.65rem 0.6rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.35rem;
}
.account-head-name { font-weight: 600; font-size: 14px; }
.account-head-email {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-muted);
  word-break: break-all;
}
.account-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.5em 0.65em;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}
.account-item:hover { background: var(--violet-wash); }
.account-item-danger { color: var(--bad); }
.account-item-danger:hover { background: var(--bad-wash); }
.account-sep { height: 1px; background: var(--line); margin: 0.35rem 0; }

@media (max-width: 560px) {
  .account-name { display: none; }
}

/* ---------- Kvoodinäidik (seadete paneelis) ---------- */
.quota-meter {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
}
.quota-counter {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.5rem;
  font-weight: 600;
}
.quota-slash { color: var(--ink-faint); padding: 0 1px; }
.quota-caption { font-size: 12px; color: var(--ink-muted); }
.quota-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  margin-top: 0.5em;
}
.quota-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--gradient-button);
  transition: width var(--transition-med);
}
.quota-bar-fill.quota-full { background: var(--bad); }

/* ---------- Neutraalne teade vestlusreal (nt kvoot täis) ---------- */
.notice-card {
  border: 1px solid var(--violet-wash-strong);
  background: var(--violet-wash);
  color: var(--violet-deep);
  border-radius: var(--radius-md);
  padding: 0.75em 0.9em;
  font-size: 14px;
}

/* ---------- Modaalid ---------- */
.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(29, 30, 44, 0.45);
}
.modal {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-raised);
  width: min(440px, 100%);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
}
.modal-body {
  padding: 1.1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.modal-body .field { margin-bottom: 0; }
.modal-body .auth-alert { margin-bottom: 0; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.modal-warn {
  border: 1px solid var(--bad);
  background: var(--bad-wash);
  color: var(--bad);
  border-radius: var(--radius-md);
  padding: 0.7em 0.9em;
  font-size: 13.5px;
  line-height: 1.55;
}
.modal-note { font-size: 13px; color: var(--ink-muted); }
.modal-export-first { align-self: flex-start; }
.btn-danger-solid {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}
.btn-danger-solid:hover {
  background: #9c3131;
  border-color: #9c3131;
  color: #fff;
}

/* ---------- Admin-vaade: registripidaja "toimikusakid" ---------- */
#view-admin {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}
.admin-shell {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem clamp(1rem, 3vw, 2rem) 3rem;
}
.admin-tabs {
  display: flex;
  gap: 0.35rem;
  border-bottom: 1px solid var(--line-strong);
  padding: 0 0.25rem;
}
.admin-tab {
  border: 1px solid var(--line);
  border-bottom: none;
  background: var(--paper);
  color: var(--ink-muted);
  padding: 0.5em 1.15em;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin-bottom: -1px;
  font-size: 14px;
  font-weight: 500;
}
.admin-tab.is-active {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
  font-weight: 600;
}
.admin-notify {
  margin-top: 0.9rem;
  border: 1px solid;
  border-radius: var(--radius-md);
  padding: 0.6em 0.9em;
  font-size: 13.5px;
}
.admin-notify.ok {
  border-color: var(--good);
  background: var(--good-wash);
  color: var(--good);
}
.admin-notify.err {
  border-color: var(--bad);
  background: var(--bad-wash);
  color: var(--bad);
}
.admin-panel { margin-top: 1rem; }
.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.admin-toolbar-hint { font-size: 13px; color: var(--ink-muted); }

.admin-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.admin-loading {
  padding: 1rem;
  color: var(--ink-faint);
  font-size: 13px;
}
.user-row, .invite-row {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
}
.user-row:last-child, .invite-row:last-child { border-bottom: none; }
.user-row:hover, .invite-row:hover { background: #fbfbfc; }

.user-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5em;
}
.u-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  align-self: center;
  flex-shrink: 0;
}
.u-dot.on { background: var(--good); }
.u-dot.off { background: var(--bad); }
.user-email {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13.5px;
  word-break: break-all;
}
.user-name { color: var(--ink-muted); font-size: 13px; }
.u-flag {
  font-size: 11px;
  font-weight: 600;
  padding: 0.15em 0.55em;
  border-radius: 999px;
  white-space: nowrap;
}
.u-flag.on { background: var(--good-wash); color: var(--good); }
.u-flag.warn { background: var(--warn-wash); color: var(--warn); }
.u-flag.off { background: var(--bad-wash); color: var(--bad); }
.u-flag.admin { background: var(--violet-wash); color: var(--violet-deep); }
.user-meta {
  margin-top: 0.35em;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink-muted);
}
.user-actions {
  margin-top: 0.55em;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

/* ---------- Kutsete vorm + värske koodi ühekordne kuva ---------- */
.invite-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.25rem 1.25rem;
  margin-bottom: 1rem;
}
.invite-form h3 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.2em;
}
.invite-form-hint {
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-bottom: 0.9rem;
}
.invite-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem 1rem;
}
.invite-grid .field { margin-bottom: 0; }
.invite-form .auth-alert { margin: 0.9rem 0 0; }
.invite-form .btn-primary { margin-top: 0.9rem; }

.invite-fresh {
  border: 1.5px dashed var(--violet-1);
  background: var(--violet-wash);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.invite-fresh-head {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
  font-size: 13.5px;
  color: var(--violet-deep);
}
.invite-fresh-icon { flex-shrink: 0; }
.code-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.code-value {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.35em 0.6em;
  word-break: break-all;
}

/* --- Google'iga sisselogimine ------------------------------------------ */
.oauth-block { margin-top: 18px; }
.oauth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--ink-faint, #8a8ca0);
  margin-bottom: 14px;
}
.oauth-divider::before,
.oauth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: currentColor;
  opacity: 0.35;
}
#googleBtn { display: flex; justify-content: center; }
.account-head-google {
  font-size: 12px;
  color: var(--good, #2e7d32);
  margin-top: 4px;
}

/* --- Jätkuküsimuste kiibid ---------------------------------------------- */
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.suggestions-label { font-size: 0.85rem; color: var(--ink-muted, #5b5d72); }
.suggestion-chip {
  border: 1px solid var(--line-strong, #c9ccd8); background: var(--surface, #fff);
  border-radius: var(--radius-md, 8px); padding: 6px 12px; font-size: 0.85rem;
  color: var(--ink, #1d1e2c);
  cursor: pointer; text-align: left;
  transition: background var(--transition-fast, 0.15s), border-color var(--transition-fast, 0.15s);
}
.suggestion-chip:hover { background: var(--violet-wash, #f1eefc); border-color: var(--violet-1, #667eea); }

/* --- Teavitusteemade loend seadetes -------------------------------------- */
.topic-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line, #e1e3ea);
}
.topic-row span { font-size: 0.9rem; color: var(--ink, #1d1e2c); }

/* ======================================================================
   Mobiilikest (≤768 px): tab-riba, üherealine päis, täisekraani-sakid.
   Desktop (>768 px) ja vahemik 769–900 px jäävad senise käitumise peale.
   ====================================================================== */

:root {
  --mobile-header-h: 56px;
  --mobile-tabbar-h: 56px;
}

.mobile-tabbar { display: none; }
.topbar .wordmark-short { display: none; }

@media (min-width: 769px) {
  .account-item-mobile { display: none; } /* Admin elab desktopil päisenupus */
}

@media (max-width: 768px) {
  /* --- Päis üherealiseks (ainult äpi-vaade; admini päis jääb puutumata) --- */
  #view-app .topbar {
    height: var(--mobile-header-h);
    padding: 0 0.5rem 0 0.75rem;
  }
  #view-app .topbar .wordmark { display: none; }
  #view-app .topbar .wordmark-short {
    display: inline;
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 600;
    white-space: nowrap;
    color: var(--ink);
  }
  #view-app .topbar .sidebar-toggle { display: none; } /* ajalugu elab tab-ribal */
  #settingsToggle { display: none; }         /* seaded elavad tab-ribal */
  #adminBtn { display: none; }               /* admin elab kontomenüüs */
  .account-trigger { min-width: 44px; min-height: 44px; justify-content: center; }
  .account-dropdown .account-item { min-height: 44px; } /* 44px puutepind kõigil menüüpunktidel */

  /* --- Tab-riba --- */
  .mobile-tabbar {
    display: flex;
    flex-shrink: 0;
    border-top: 1px solid var(--line);
    background: var(--surface);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 35;
  }
  .mtab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--mobile-tabbar-h);
    border: none;
    background: none;
    font-size: 20px; /* emoji-ikoon */
    color: var(--ink-muted);
  }
  .mtab-btn span { font-size: 11px; font-weight: 600; }
  .mtab-btn.is-active { color: var(--violet-deep); }

  /* Klaviatuur lahti → tab-riba peitu (:has — iOS 15.4+/Chrome 105+;
     vanemates jääb riba lihtsalt nähtavale). */
  #view-app:has(#questionInput:focus) .mobile-tabbar { display: none; }

  /* --- Ajalugu-sakk: külgriba täisekraaniks .layout sees --- */
  .layout { position: relative; }
  .sidebar {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%;
    transform: none;
    transition: none;
    box-shadow: none;
    border-right: none;
    z-index: 30;
  }
  #view-app[data-mtab="history"] .sidebar { display: flex; }
  #closeSidebar { display: none !important; } /* sakilt lahkumine = teine sakk */

  /* --- Seaded-sakk: sahtel täisekraaniks --- */
  .settings-panel {
    display: none;
    top: var(--mobile-header-h);
    left: 0; right: 0;
    bottom: calc(var(--mobile-tabbar-h) + env(safe-area-inset-bottom));
    width: 100%;
    transform: none;
    transition: none;
    box-shadow: none;
    border-left: none;
  }
  #view-app[data-mtab="settings"] .settings-panel { display: flex; }
  #settingsClose { display: none; }
  .settings-backdrop { display: none; }
}

/* --- Vestluse vaade mobiilis: täislaiuses vastus, õhem mull, komposter --- */
@media (max-width: 768px) {
  .thread { padding: 1rem 0.75rem; gap: 1.4rem; }

  /* Vastus täislaiuses: avatar ja kaardikest maha */
  .msg-avatar { display: none; }
  .msg-assistant { gap: 0; }
  .msg-content {
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }

  /* Küsimuse mull õhemaks ja heledamaks */
  .msg-user {
    max-width: 88%;
    padding: 0.55em 0.85em;
    background: #f7f5fd;
    border-color: var(--violet-wash);
  }

  /* Komposter: 16 px sisend (iOS ei suumi), 44 px nupp, vihje peitu */
  .composer { padding: 0.6rem 0.75rem 0.75rem; }
  .composer-hint { display: none; }
  .composer-hint.warn { display: block; }
  .composer textarea { font-size: 16px; }
  .composer .btn-primary { min-height: 46px; }

  /* Puutepinnad */
  .btn-icon { min-width: 44px; min-height: 44px; }
  .feedback button { min-width: 44px; min-height: 44px; }
  .export { width: 100%; display: flex; gap: 0.5em; }
  .export .btn { flex: 1; min-height: 44px; }
  .suggestion-chip { min-height: 44px; }
  .source-toggle { min-height: 44px; }

  /* Kõik vormisisendid 16 px, et iOS ei suumiks */
  .field input, .field select, .settings-body select, .composer textarea { font-size: 16px; }
}

/* --- Ajalugu- ja Seaded-sakk mobiilis --- */
@media (max-width: 768px) {
  .sidebar-header { padding: 0.9rem 1rem 0.4rem; }
  .sidebar-header h2 { font-size: 1.2rem; }
  .sidebar-new { padding: 0.35rem 1rem 0.75rem; }
  .sidebar-new .btn { min-height: 44px; font-size: 14px; }
  .history-item { padding: 0.55rem 0.4rem 0.55rem 0.75rem; align-items: center; }
  .history-item .hit-question {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.35;
  }
  .history-item .hit-delete { min-width: 44px; min-height: 44px; font-size: 15px; }
  .sidebar-footer .btn { min-height: 44px; }

  /* Seaded: suuremad lülitid, mugavamad valikud */
  .settings-body { padding: 1rem 1rem 2.5rem; }
  .switch { width: 48px; height: 28px; }
  .switch .thumb { width: 24px; height: 24px; }
  .switch input:checked ~ .thumb { transform: translateX(20px); }
  /* Puutepind ≥44px: lüliti nähtav suurus jääb 48×28, klikitav ala laieneb */
  .switch input { top: -8px; right: -8px; bottom: -8px; left: -8px; width: auto; height: auto; }
  .segmented span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 0.8em; font-size: 13px; }
  .chip span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 0.7em; font-size: 13px; }
  .topic-row .btn-icon { min-width: 44px; min-height: 44px; }
}

/* --- Login kompaktseks, modaalid bottom-sheet'iks, admin kergelt --- */
@media (max-width: 768px) {
  /* Login-hero: kompaktne bänner, vorm kohe nähtav */
  .login-hero {
    min-height: 0;
    padding: 1rem 1.25rem;
    justify-content: flex-start;
  }
  .login-hero .headline { font-size: 1.1rem; margin-top: 0.6rem; max-width: none; }
  .login-hero .subhead { display: none; }
  .login-hero .brand-mark .emblem { font-size: 1.4rem; }
  .login-hero .brand-mark .wordmark { font-size: 1.1rem; }
  .registry { margin-top: 0.6rem; padding-top: 0.6rem; gap: 1.5rem; }
  .registry dd { font-size: 1.05rem; }
  .auth-hero-slim .headline { margin-top: 0.6rem; }
  .hero-foot { display: none; }
  .login-panel { padding: 1.5rem 1.25rem 2.5rem; }

  /* Modaalid: bottom-sheet */
  .modal-layer { align-items: flex-end; padding: 0; }
  .modal {
    width: 100%;
    max-height: 85vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-actions .btn { min-height: 44px; }

  /* Admin: kerged parandused */
  .admin-tabs { width: 100%; }
  .admin-tab { flex: 1; padding: 0.7em 0.5em; min-height: 44px; }
  .admin-toolbar { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .user-actions .btn { min-height: 44px; }
  .invite-grid { grid-template-columns: 1fr; }
}

/* --- Google-logini laadimisolek --- */
.oauth-progress {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem 0;
  color: var(--ink-muted);
  font-size: 14.5px;
}
