/* ===== Perusta ja lasiteema ===== */
:root {
  --bg-1: #0f0c29;
  --bg-2: #302b63;
  --bg-3: #24243e;
  --glass: rgba(255, 255, 255, 0.07);
  --glass-strong: rgba(255, 255, 255, 0.12);
  --glass-border: rgba(255, 255, 255, 0.14);
  --text: #f1f0fa;
  --text-muted: rgba(241, 240, 250, 0.6);
  --accent: #8b7cf6;
  --accent-2: #4ecdc4;
  --accent-grad: linear-gradient(135deg, #8b7cf6 0%, #4ecdc4 100%);
  --danger: #ff6b8a;
  --ok: #4ecdc4;
  --radius: 18px;
  --radius-small: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
  background-attachment: fixed;
  min-height: 100dvh;
}

/* Taustan leijuvat valopallot */
.bg-blobs {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: -1;
  pointer-events: none;
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.45;
  animation: float 18s ease-in-out infinite alternate;
}
.blob-1 { width: 45vw; height: 45vw; background: #6d5df6; top: -12%; left: -8%; }
.blob-2 { width: 38vw; height: 38vw; background: #2fb8b0; bottom: -10%; right: -6%; animation-delay: -6s; }
.blob-3 { width: 28vw; height: 28vw; background: #c95bd6; top: 38%; left: 56%; animation-delay: -12s; }

@keyframes float {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(4vw, -4vh) scale(1.12); }
}

.glass {
  background: var(--glass);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

h1, h2, h3 { font-weight: 700; }
a { color: var(--accent-2); }
.muted { color: var(--text-muted); font-style: normal; }
.hidden { display: none !important; }

/* ===== Lomakkeet ja napit ===== */
input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-small);
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 124, 246, 0.25);
}
textarea { resize: vertical; }
label > span { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
label { display: block; margin-bottom: 14px; }
label.checkbox { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
label.checkbox input { width: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: var(--radius-small);
  border: 1px solid var(--glass-border);
  background: var(--glass-strong);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s, box-shadow 0.15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent-grad);
  border: none;
  box-shadow: 0 4px 18px rgba(139, 124, 246, 0.4);
}
.btn-block { width: 100%; justify-content: center; }
.btn-report {
  background: rgba(78, 205, 196, 0.16);
  border-color: rgba(78, 205, 196, 0.4);
  text-decoration: none;
  padding-top: 13px;    /* reilu kosketusalue peukalolle */
  padding-bottom: 13px;
}
.btn-report:hover { background: rgba(78, 205, 196, 0.28); }
.btn-small { padding: 6px 10px; font-size: 0.85rem; }
.btn-danger { background: rgba(255, 107, 138, 0.18); border-color: rgba(255, 107, 138, 0.4); }
.link-btn {
  background: none; border: none; color: var(--accent-2);
  font: inherit; cursor: pointer; padding: 0;
}
.icon-btn {
  background: none; border: none; color: var(--text);
  font-size: 1.3rem; cursor: pointer; padding: 6px 10px; border-radius: 10px;
}
.icon-btn:hover { background: var(--glass-strong); }

/* ===== Ilmoitukset ===== */
.flash-stack {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(560px, calc(100vw - 28px));
}
.flash {
  padding: 12px 18px;
  border-radius: var(--radius-small);
  backdrop-filter: blur(18px);
  border: 1px solid var(--glass-border);
  background: rgba(20, 18, 48, 0.85);
  animation: slide-in 0.25s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.flash-success { border-color: rgba(78, 205, 196, 0.5); }
.flash-error { border-color: rgba(255, 107, 138, 0.55); }
@keyframes slide-in { from { opacity: 0; transform: translateY(-10px); } }

.banner {
  text-align: center;
  padding: 10px 16px;
  font-size: 0.9rem;
  background: rgba(255, 196, 87, 0.15);
  border-bottom: 1px solid rgba(255, 196, 87, 0.4);
}
.banner a { color: #ffc457; font-weight: 600; }

/* ===== Kirjautuminen / tili ===== */
.centered-page {
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: min(420px, 100%);
  padding: 40px 34px;
  text-align: center;
}
.auth-logo { font-size: 3rem; }
.auth-avatar img {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--glass-border);
  box-shadow: 0 6px 24px rgba(139, 124, 246, 0.45);
  animation: pinja-float 5.5s ease-in-out infinite;
}
.auth-card h1 { margin: 8px 0 4px; }
.auth-card .muted { margin-top: 0; }
.form-stack { margin-top: 26px; text-align: left; }
.back-link { display: inline-block; margin-top: 18px; }
.email-form { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--glass-border); }
.code-input {
  font-size: 1.6rem !important;
  letter-spacing: 0.4em;
  text-align: center;
}
.resend-form { margin-top: 14px; }

/* ===== Chat-näkymä ===== */
.chat-page { overflow: hidden; }
.chat-layout {
  display: flex;
  height: 100vh; /* varalla selaimille ilman dvh-tukea */
  height: 100dvh;
  gap: 14px;
  padding: 14px;
  padding-bottom: calc(22px + env(safe-area-inset-bottom));
}

.sidebar {
  width: 290px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 18px;
  gap: 14px;
}
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand { font-weight: 800; font-size: 1.05rem; text-decoration: none; color: var(--text); }
.sidebar-close { display: none; }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.conversation-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: var(--radius-small);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: background 0.12s;
}
.conversation-item:hover { background: var(--glass-strong); }
.conversation-item.active { background: var(--glass-strong); color: var(--text); }
.conversation-item .conv-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-delete {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 0.9rem; visibility: hidden; padding: 2px 4px;
}
.conversation-item:hover .conv-delete { visibility: visible; }
.conv-delete:hover { color: var(--danger); }

.sidebar-foot { border-top: 1px solid var(--glass-border); padding-top: 14px; padding-bottom: 6px; }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-grad);
  font-weight: 700;
}
.user-name { font-weight: 600; font-size: 0.92rem; }
.sidebar-links { display: flex; flex-direction: column; gap: 7px; font-size: 0.88rem; }
.sidebar-links a { text-decoration: none; }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 12px;
}
.chat-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
}
#sidebarOpen { display: none; }
.topbar-title {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 40%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Pinja-avatar: läsnäolo ja reagointi ===== */
.pinja-presence {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.pinja-avatar {
  position: relative;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  /* Kevyt kallistus osoitinta kohti (JS asettaa --pinja-tx/-ty) */
  transform: translate(calc(var(--pinja-tx, 0) * 2px), calc(var(--pinja-ty, 0) * 1.5px))
    rotate(calc(var(--pinja-tx, 0) * 3deg));
  transition: scale 0.3s ease;
}
.pinja-face-stack {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--glass-border);
  animation: pinja-breathe 4.2s ease-in-out infinite;
}
.pinja-face-stack .face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.38s ease; /* ilmeet häivytetään pohjakerroksen päälle */
}
.pinja-face-stack .face-base { opacity: 1; } /* aina näkyvissä — tausta ei vilahda läpi */
.pinja-face-stack .face.active { opacity: 1; }
.pinja-face-stack .face-blink { transition: opacity 0.11s ease; } /* räpäytys nopea mutta pehmeä */
.pinja-face-stack .face-talk { transition: opacity 0.05s linear; } /* huulisynkka ohjaa suoraan */
.pinja-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  pointer-events: none;
  transition: box-shadow 0.3s ease;
}
.pinja-info { display: flex; flex-direction: column; min-width: 0; }
.pinja-name { font-weight: 700; font-size: 0.95rem; display: flex; align-items: center; gap: 6px; }
.pinja-status {
  font-size: 0.74rem;
  color: var(--text-muted);
  transition: color 0.3s;
}
.presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
  transition: background 0.3s, box-shadow 0.3s;
}

/* Tilakohtaiset reaktiot */
[data-state="listening"] .pinja-avatar { scale: 1.1; }
[data-state="listening"] .pinja-ring { box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.6), 0 0 14px rgba(78, 205, 196, 0.45); }
[data-state="listening"] .presence-dot { background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }

[data-state="thinking"] .pinja-ring {
  background: conic-gradient(from 0deg, transparent 0deg 250deg, var(--accent) 320deg, transparent 360deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  animation: pinja-spin 1.1s linear infinite;
}
[data-state="thinking"] .pinja-face-stack { animation: pinja-breathe 1.8s ease-in-out infinite; }
[data-state="thinking"] .presence-dot { background: #ffc457; box-shadow: 0 0 8px #ffc457; }
[data-state="thinking"] .pinja-status { color: #ffc457; }

[data-state="speaking"] .pinja-face-stack { animation: pinja-talk 0.6s ease-in-out infinite; }
[data-state="speaking"] .presence-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
[data-state="speaking"] .pinja-status { color: var(--accent-2); }

[data-state="error"] .pinja-avatar { animation: pinja-shake 0.5s ease; }
[data-state="error"] .presence-dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

@keyframes pinja-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}
@keyframes pinja-talk {
  0%, 100% { transform: scale(1) translateY(0); }
  35% { transform: scale(1.04) translateY(-1.5px); }
  70% { transform: scale(1.01) translateY(0.5px); }
}
@keyframes pinja-spin {
  to { transform: rotate(360deg); }
}
@keyframes pinja-shake {
  0%, 100% { translate: 0 0; }
  25% { translate: -3px 0; }
  50% { translate: 3px 0; }
  75% { translate: -2px 0; }
}

/* Kikatus: iloinen heilahdus klikkauksesta */
.pinja-avatar { cursor: pointer; }
.pinja-avatar:hover .pinja-face-stack { filter: brightness(1.08); }
.pinja-avatar.giggling {
  animation: pinja-giggle 0.95s ease-in-out;
}
@keyframes pinja-giggle {
  0%, 100% { rotate: 0deg; translate: 0 0; }
  12% { rotate: -6deg; translate: 0 -2px; }
  28% { rotate: 5deg; translate: 0 1px; }
  44% { rotate: -5deg; translate: 0 -2px; }
  60% { rotate: 4deg; translate: 0 1px; }
  78% { rotate: -2deg; translate: 0 -1px; }
}

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 6px 4px;
  scroll-behavior: smooth;
}

.welcome {
  margin: auto;
  text-align: center;
  padding: 30px 30px 38px;
  max-width: 560px;
}
.welcome-avatar {
  display: inline-block;
  transform: translate(calc(var(--pinja-tx, 0) * 5px), calc(var(--pinja-ty, 0) * 3px))
    rotate(calc(var(--pinja-tx, 0) * 1.5deg));
}
.welcome-stack {
  position: relative;
  animation: pinja-float 5.5s ease-in-out infinite;
}
.welcome-stack img {
  width: min(340px, 70vw);
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  box-shadow: 0 12px 40px rgba(139, 124, 246, 0.35);
  display: block;
}
.welcome-blink {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.11s ease; /* räpäytys pohjakuvan päälle, ei taustan vilahdusta */
  box-shadow: none !important;
}
.welcome-blink.active { opacity: 1; }
@keyframes pinja-float {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-6px) scale(1.012); }
}
.welcome h2 { font-size: 1.15rem; font-weight: 600; line-height: 1.5; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }
.suggestion {
  padding: 10px 16px;
  font: inherit;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  border-radius: 999px;
  transition: filter 0.15s;
}
.suggestion:hover { filter: brightness(1.3); }

.message {
  max-width: min(720px, 88%);
  padding: 14px 18px;
  border-radius: var(--radius);
  line-height: 1.55;
  word-wrap: break-word;
  animation: msg-in 0.2s ease;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
.message.user {
  align-self: flex-end;
  background: var(--accent-grad);
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}
.message.assistant {
  align-self: flex-start;
  background: var(--glass);
  backdrop-filter: blur(22px);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 6px;
}

/* Vastausrivi: Pinjan kasvot kuplan vieressä */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  max-width: min(764px, 92%);
  align-self: flex-start;
  animation: msg-in 0.2s ease;
}
.msg-row .message.assistant {
  max-width: calc(100% - 43px);
  animation: none;
}
.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--glass-border);
  margin-bottom: 2px;
}
.msg-row.streaming .msg-avatar { animation: pinja-talk 0.6s ease-in-out infinite; }
.message.assistant > *:first-child { margin-top: 0; }
.message.assistant > *:last-child { margin-bottom: 0; }

/* Listojen rytmi: alakohdat kiinni otsikkoonsa, tyhjä tila ryhmien väliin.
   Marginaalit yhdistyvät sisarusten välillä (collapsing), joten väli annetaan
   aina alemman elementin margin-topina. */
.message.assistant p,
.message.assistant ul,
.message.assistant ol { margin: 12px 0 2px; }
.message.assistant p + ul,
.message.assistant p + ol { margin-top: 2px; }   /* otsikkokappale + lista = yksi ryhmä */
.message.assistant li > ul,
.message.assistant li > ol { margin: 2px 0 0; }  /* numerokohdan alalista kiinni otsikkoon */
.message.assistant li p { margin: 0; }
.message.assistant li + li { margin-top: 3px; }
.message.assistant ol > li + li { margin-top: 12px; }  /* numeroitujen ryhmien väli */
.message.assistant h1,
.message.assistant h2,
.message.assistant h3,
.message.assistant h4 { margin: 14px 0 4px; font-size: 1rem; }
.message.assistant pre {
  background: rgba(0, 0, 0, 0.35);
  padding: 12px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.85rem;
}
.message.assistant code { background: rgba(0, 0, 0, 0.3); padding: 1px 5px; border-radius: 5px; }
.message.assistant pre code { background: none; padding: 0; }
.message.assistant ul, .message.assistant ol { padding-left: 22px; }
.message.error { border-color: rgba(255, 107, 138, 0.6); color: #ffb3c4; }

.message-sources { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.source-chip {
  font-size: 0.74rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(78, 205, 196, 0.13);
  border: 1px solid rgba(78, 205, 196, 0.35);
  color: var(--accent-2);
}

.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 70%, 100% { opacity: 0.25; } 35% { opacity: 1; } }

.composer-wrap { padding-bottom: env(safe-area-inset-bottom); }
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px;
}
.composer textarea {
  border: none;
  background: transparent;
  max-height: 160px;
  padding: 10px 12px;
}
.composer textarea:focus { box-shadow: none; }
.send-btn {
  flex-shrink: 0;
  width: 42px; height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--accent-grad);
  color: white;
  font-size: 1.05rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.1s, filter 0.15s;
}
.send-btn:hover { filter: brightness(1.15); }
.send-btn:disabled { opacity: 0.4; cursor: default; }
.stop-btn { background: rgba(255, 107, 138, 0.8); }
.composer-hint {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 8px 0 2px;
}

/* Työkalunapit: kamera ja mikrofoni */
.tool-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--glass-strong);
  font-size: 1.05rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: filter 0.15s, background 0.2s;
}
.tool-btn:hover { filter: brightness(1.25); }
.tool-btn.recording {
  background: rgba(255, 107, 138, 0.85);
  animation: rec-pulse 1.2s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 138, 0.55); }
  50% { box-shadow: 0 0 0 9px rgba(255, 107, 138, 0); }
}
/* Handsfree päällä: mikrofoninappi hehkuu turkoosina */
.tool-btn.handsfree {
  background: rgba(78, 205, 196, 0.35);
  box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.5);
}
.tool-btn.handsfree.recording {
  background: rgba(255, 107, 138, 0.85);
  box-shadow: none;
}

/* Lähetettävän kuvan esikatselu */
.photo-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px;
  border-radius: var(--radius-small);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  width: fit-content;
}
.photo-preview img {
  height: 72px;
  border-radius: 8px;
  display: block;
}

/* Käyttäjän lähettämä kuva viestikuplassa */
.user-photo {
  display: block;
  max-width: min(280px, 100%);
  max-height: 280px;
  border-radius: 12px;
  margin-bottom: 6px;
  cursor: zoom-in;
}
.message.user .user-text { white-space: pre-wrap; }

/* Kuuntele vastaus -nappi */
.msg-speak {
  display: block;
  margin-top: 8px;
  border: none;
  background: var(--glass-strong);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: filter 0.15s;
}
.msg-speak:hover { filter: brightness(1.3); }

/* Ohjekuvat vastauksissa */
.guide-image {
  display: block;
  max-width: 100%;
  max-height: 460px;
  margin: 10px 0;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.9);
  cursor: zoom-in;
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 4, 18, 0.88);
  backdrop-filter: blur(8px);
  cursor: zoom-out;
  animation: msg-in 0.15s ease;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 14px;
  background: white;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

/* ===== Hallinta ===== */
.admin-page { overflow-y: auto; }
.admin-layout {
  max-width: 980px;
  margin: 0 auto;
  padding: 14px 14px 60px;
}
.admin-topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  flex-wrap: wrap;
  position: sticky;
  top: 10px;
  z-index: 30;
}
.admin-tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.admin-tabs a {
  padding: 8px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}
.admin-tabs a:hover { background: var(--glass-strong); color: var(--text); }
.admin-tabs a.active { background: var(--accent-grad); color: white; }
.back-to-chat { font-size: 0.88rem; text-decoration: none; }

.admin-content h1 { margin: 26px 6px 16px; }
.card { padding: 24px; margin-bottom: 18px; }
.card h2 { margin-top: 0; font-size: 1.05rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.note {
  padding: 10px 14px;
  border-radius: var(--radius-small);
  background: rgba(78, 205, 196, 0.1);
  border: 1px solid rgba(78, 205, 196, 0.3);
  font-size: 0.88rem;
}
.test-result { margin-left: 10px; font-size: 0.9rem; }
.test-result.ok { color: var(--ok); }
.test-result.fail { color: var(--danger); }

.upload-form { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.upload-form input[type="file"] { flex: 1; min-width: 220px; color: var(--text-muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--glass-border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
.row-disabled { opacity: 0.45; }
.row-actions { display: flex; gap: 6px; }
.row-actions form { margin: 0; }
.doc-name { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}
.badge-ok { background: rgba(78, 205, 196, 0.15); color: var(--accent-2); border: 1px solid rgba(78, 205, 196, 0.35); }
.badge-warn { background: rgba(255, 196, 87, 0.15); color: #ffc457; border: 1px solid rgba(255, 196, 87, 0.35); }
.badge-err { background: rgba(255, 107, 138, 0.15); color: var(--danger); border: 1px solid rgba(255, 107, 138, 0.35); }

/* Indeksoinnin edistymispalkki */
.index-progress { min-width: 200px; }
.progress-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--glass-border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent-grad);
  box-shadow: 0 0 8px rgba(139, 124, 246, 0.6);
  transition: width 0.6s ease;
}
.progress-text {
  display: block;
  margin-top: 5px;
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Tilastot: FAQ ja kysymykset */
.faq-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.faq-head p { margin: 0; }
.faq-list { padding-left: 24px; margin: 14px 0 0; }
.faq-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--glass-border);
}
.faq-list li:last-child { border-bottom: none; }
.faq-list li::marker { color: var(--accent-2); font-weight: 700; }
.faq-question { flex: 1; }
.question-cell { max-width: 420px; }
.stats-subtitle { margin: 26px 6px 14px; }
.role-form select {
  padding: 6px 8px;
  font-size: 0.85rem;
  width: auto;
}

/* Huoltoraportit */
.reports-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 26px 6px 16px;
}
.reports-head h1 { margin: 0; }
.topbar-spacer { flex: 1; }
.report-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px;
  border-radius: var(--radius-small);
  text-decoration: none;
  color: var(--text);
  transition: background 0.12s;
}
.report-row:hover { background: var(--glass-strong); }
.report-row img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  flex-shrink: 0;
}
.report-row-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.report-row-info .muted { font-size: 0.82rem; }

.report-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}
.report-meta > div { display: flex; flex-direction: column; gap: 3px; }
.report-meta .muted { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }

.report-photos {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}
.report-photos figure { margin: 0; }
.report-photos figcaption {
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.report-photos img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
}
.report-photos p { font-size: 0.92rem; color: var(--text-muted); }

.photo-field { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.report-photo-preview {
  max-width: 180px;
  max-height: 140px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
}
.analysis-text { white-space: pre-wrap; line-height: 1.6; }
.form-hint { font-size: 0.82rem; margin-top: 12px; }
.report-delete { margin-top: 6px; text-align: right; }
.report-actions-card { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.report-actions-card form { margin: 0; }

/* Kuvakirjasto */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}
.image-card { padding: 16px; margin-bottom: 0; }
.image-card img {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--glass-border);
  cursor: zoom-in;
}
.image-meta { font-size: 0.78rem; margin: 8px 0 10px; }
.image-card label { margin-bottom: 10px; }
.image-card label > span { font-size: 0.78rem; }
.image-actions { display: flex; gap: 8px; justify-content: space-between; }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 180px;
  padding-top: 10px;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
}
.bar {
  width: 100%;
  min-height: 2px;
  border-radius: 6px 6px 0 0;
  background: var(--accent-grad);
}
.bar-label { font-size: 0.62rem; color: var(--text-muted); white-space: nowrap; }

/* ===== Mobiili ===== */
@media (max-width: 860px) {
  .chat-layout { padding: 10px; gap: 10px; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 84vw);
    z-index: 50;
    border-radius: 0 var(--radius) var(--radius) 0;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open ~ .chat-main .sidebar-backdrop,
  .sidebar-backdrop.visible { display: block; }
  .sidebar-close { display: block; }

  #sidebarOpen { display: block; }
  .message { max-width: 94%; }
  .msg-row { max-width: 96%; }
  .topbar-title { display: none; }
  .field-row { grid-template-columns: 1fr; }
  .admin-topbar { position: static; }
  .bar-label { display: none; }
}
