/* ============================================================
   COMPONENTS — sivupalkki, topbar, napit, kortit, chipit, AI-kielioppi,
   taulukot, tabit, paletti, modaalit, toastit, skeletonit
   ============================================================ */

/* ---------- Sivupalkki ---------- */
.brand { display: flex; align-items: center; gap: 12px; padding: 18px 16px 14px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--navy-700), var(--navy-850));
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: grid; place-items: center; color: var(--amber-500);
}
.brand-text { line-height: 1.1; white-space: nowrap; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 14px; letter-spacing: 0.1em; color: #fff; }
.brand-sub { font-size: 11px; font-weight: 700; color: var(--amber-400); letter-spacing: 0.02em; margin-top: 2px; }

.side-nav { flex: 1; overflow-y: auto; padding: 8px 12px; }
.side-nav::-webkit-scrollbar-thumb { border-color: transparent; background: rgba(255,255,255,0.12); }
.side-group-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em;
  color: rgba(185, 198, 220, 0.55); padding: 14px 10px 6px;
}
/* Kaksitasoinen navigaatio (app.js NAV): ryhmäotsikko + sisennetty alasivulista ohuen ohjainviivan varassa.
   Ryhmät ovat aina auki. Aktiivisen sivun ryhmän otsikko korostuu (.side-group.on). */
.side-list { margin: 0; padding: 0; }
.side-group { margin-top: 2px; }
.side-group .side-group-title { padding: 12px 10px 4px; }
.side-group-title { transition: color var(--t-fast); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-group.on .side-group-title { color: var(--amber-400); }
.side-sublist { margin-left: 14px; padding-left: 6px; border-left: 1px solid rgba(255, 255, 255, 0.09); }
.side-sublist .side-item { height: auto; min-height: 34px; padding: 0 8px; }
/* Pitkä nimi (esim. Market intelligence + Tulossa-merkki) rivittyy kahdelle riville eikä katkea; yksirivisten korkeus ennallaan. */
.side-sublist .side-label { white-space: normal; line-height: 1.2; padding: 4px 0; }
.side-sublist .side-pill { padding: 1px 5px; }
/* Aktiivisen alasivun merkkiviiva osuu ryhmän ohjainviivan päälle. */
.side-sublist .side-item.active::before { left: -8px; }
.side-list-erotin { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, 0.07); }
.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  height: 40px; padding: 0 10px; border-radius: var(--r-sm);
  color: var(--side-text); font-size: 13px; font-weight: 500;
  position: relative; transition: background var(--t-fast), color var(--t-fast);
  white-space: nowrap;
}
.side-item:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.side-item.active { background: var(--side-active); color: var(--side-text-active); }
.side-item.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 2px; background: var(--amber-500);
}
.side-item.active .icon { color: var(--amber-500); }
.side-label { flex: 1; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.side-pill {
  font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: var(--r-full);
  border: 1px solid rgba(255, 255, 255, 0.25); color: rgba(255, 255, 255, 0.6);
}
.side-count { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--amber-400); font-weight: 600; }
.side-count::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--amber-500); }

.side-footer { padding: 8px 12px 12px; border-top: 1px solid rgba(255, 255, 255, 0.07); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--r-sm); }
.side-user:hover { background: var(--side-hover); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--amber-500), var(--amber-700));
  color: var(--accent-ink); font-size: 12px; font-weight: 700;
  display: grid; place-items: center; letter-spacing: 0.02em;
}
.side-user-info { line-height: 1.2; min-width: 0; }
.side-user-name { font-size: 12.5px; font-weight: 600; color: #f0eeea; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-org { font-size: 11px; color: rgba(196, 191, 180, 0.65); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Topbar ---------- */
.topbar-search {
  display: flex; align-items: center; gap: 8px; width: 320px; height: 36px;
  padding: 0 10px; border: 1px solid var(--line-300); border-radius: var(--r-sm);
  background: var(--bg-card); color: var(--ink-500); cursor: pointer; text-align: left;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.topbar-search:hover { border-color: var(--navy-300); }
.topbar-search .grow { font-size: 13px; overflow: hidden; white-space: nowrap; }
.kbd {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-500);
  border: 1px solid var(--line-300); border-bottom-width: 2px; border-radius: 5px;
  padding: 1px 6px; background: var(--bg-sunken); white-space: nowrap;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--sp-3); }

.demo-badge {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px;
  border-radius: var(--r-full); border: 1px solid var(--amber-500);
  background: var(--amber-050); color: var(--amber-700);
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; cursor: pointer;
  transition: box-shadow var(--t-fast);
}
.demo-badge:hover { box-shadow: var(--shadow-ai); }

.ai-mode { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; color: var(--ink-500); }
.ai-mode .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-300); }
.ai-mode.live .dot { background: var(--green-500); box-shadow: 0 0 0 3px rgba(23, 178, 106, 0.18); }
.ai-mode.live { color: var(--green-600); }

.iconbtn {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--r-sm);
  color: var(--ink-500); position: relative; transition: background var(--t-fast), color var(--t-fast);
}
.iconbtn:hover { background: var(--navy-050); color: var(--ink-900); }
.iconbtn .bubble {
  position: absolute; top: 3px; right: 3px; min-width: 15px; height: 15px; padding: 0 4px;
  border-radius: var(--r-full); background: var(--amber-500); color: var(--navy-950);
  font-size: 9.5px; font-weight: 700; display: grid; place-items: center;
}

/* ---------- Napit ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 600; white-space: nowrap; user-select: none;
  transition: background var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.btn:active { transform: translateY(1px); }
.btn-lg { height: 40px; padding: 0 18px; font-size: 14px; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn { max-width: 100%; }
/* Kapealla näytöllä pitkä napin teksti rivittyy eikä työnnä näkymää oikean reunan yli
   (esim. Kohdearvion "Ehdota huoneistojakauma talon ilmoituksista" 390 px:llä). */
@media (max-width: 560px) {
  .btn { white-space: normal; height: auto; min-height: 36px; padding-top: 6px; padding-bottom: 6px; line-height: 1.3; }
  .btn-sm { min-height: 30px; padding-top: 4px; padding-bottom: 4px; }
  .btn-lg { min-height: 40px; }
}
.btn-block { width: 100%; }
.btn-primary { background: var(--amber-500); color: var(--accent-ink); }
.btn-primary:hover { background: var(--amber-400); }
.btn-primary:active { background: var(--amber-600); }
.btn-ai:hover { box-shadow: var(--shadow-ai); }
.btn-secondary { background: var(--bg-card); border: 1px solid var(--line-300); color: var(--ink-700); }
.btn-secondary:hover { background: var(--navy-050); border-color: var(--navy-200); }
.btn-ghost { color: var(--navy-600); }
.btn-ghost:hover { background: var(--navy-050); }
.btn-danger { background: var(--red-500); color: #fff; }
.btn-danger:hover { background: var(--red-600); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

/* ---------- Lomakekontrollit ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--ink-700); }
.field-hint { font-size: 11.5px; color: var(--ink-500); line-height: 1.45; }
/* Korttiotsikoiden metatekstit AA-kontrastille — ei kosketa .faded-luokkaa yleisesti */
.card-head .faded, .ai-head .faded { color: var(--ink-500); }
/* Tekstilinkkipainike leipätekstin sisään (esim. Laskentaperusteet) */
.linklike {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--navy-600); font-size: inherit; font-family: inherit;
  text-decoration: underline; text-underline-offset: 2px;
}
.linklike:hover { color: var(--navy-700); }
.input, select.input, textarea.input {
  height: 36px; padding: 0 10px; border: 1px solid var(--line-300); border-radius: var(--r-sm);
  background: var(--bg-card); color: var(--ink-900); font-size: 13.5px; width: 100%;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; }
.input::placeholder { color: var(--ink-400); }
.input:focus-visible { border-color: var(--amber-500); box-shadow: var(--focus-ring); }
select.input { appearance: none; background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235C6B85' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px; background: var(--bg-sunken);
  border-radius: var(--r-sm); border: 1px solid var(--line-200);
}
.segmented button {
  height: 28px; padding: 0 12px; border-radius: 6px; font-size: 12.5px; font-weight: 600;
  color: var(--ink-500); transition: background var(--t-base), color var(--t-base), box-shadow var(--t-base);
}
.segmented button:hover { color: var(--ink-900); }
.segmented button.on { background: var(--bg-card); color: var(--ink-900); box-shadow: var(--shadow-xs); }

.toggle { position: relative; width: 36px; height: 20px; border-radius: var(--r-full); background: var(--ink-300); transition: background var(--t-base); flex: 0 0 auto; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs); transition: transform var(--t-base) var(--ease-standard); }
.toggle.on { background: var(--amber-500); }
.toggle.on::after { transform: translateX(16px); }

.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line-300); border-radius: var(--r-sm); background: var(--bg-card); overflow: hidden; }
.stepper button { width: 32px; display: grid; place-items: center; color: var(--ink-500); }
.stepper button:hover { background: var(--navy-050); color: var(--ink-900); }
.stepper input {
  width: 64px; border: 0; text-align: center; font-size: 13.5px; font-weight: 600; color: var(--ink-900);
  background: transparent; font-variant-numeric: tabular-nums; border-left: 1px solid var(--line-200); border-right: 1px solid var(--line-200);
}
.stepper input:focus { outline: none; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--ink-700); user-select: none; }
.check input { appearance: none; width: 17px; height: 17px; border: 1.5px solid var(--line-300); border-radius: 5px; background: var(--bg-card); cursor: pointer; position: relative; transition: background var(--t-fast), border-color var(--t-fast); flex: 0 0 auto; }
.check input:checked { background: var(--amber-500); border-color: var(--amber-500); }
.check input:checked::after {
  content: ""; position: absolute; inset: 0;
  background: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23060D1C' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 11px no-repeat;
}

/* ---------- Kortit ---------- */
.card {
  background: var(--bg-card); border: 1px solid var(--line-200); border-radius: var(--r-md);
  box-shadow: var(--shadow-xs); padding: var(--sp-5); position: relative;
}
.card-tight { padding: var(--sp-4); }
.card-hover { transition: transform 150ms var(--ease-standard), box-shadow 150ms var(--ease-standard); }
.card-hover:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: var(--sp-4); }
.card-head .grow { min-width: 0; }

/* AI-kortti: amber-hiusviiva yläreunassa */
.ai-card { overflow: hidden; }
.ai-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-line), transparent);
}
.ai-head { display: flex; align-items: center; gap: 8px; margin-bottom: var(--sp-3); }
.ai-head .icon { color: var(--amber-500); }
.ai-foot {
  margin-top: var(--sp-4); padding-top: var(--sp-3); border-top: 1px solid var(--line-100);
  font-size: 12px; color: var(--ink-400); display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.ai-principle { font-size: 11.5px; color: var(--ink-400); }

/* ---------- Chipit ja badget ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
  border-radius: var(--r-full); font-size: 12px; font-weight: 500;
  background: var(--bg-sunken); color: var(--ink-700); border: 1px solid transparent;
  white-space: nowrap;
}
.chip .icon-sm { width: 13px; height: 13px; }
.chip-outline { background: var(--bg-card); border-color: var(--line-300); }
.chip-navy { background: var(--navy-050); color: var(--navy-600); }
.chip-click { cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast); }
.chip-click:hover { border-color: var(--navy-300); }

.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: var(--r-full); font-variant-numeric: tabular-nums; }
.delta .icon-sm { width: 13px; height: 13px; }
.delta-up { background: var(--green-050); color: var(--green-600); }
.delta-down { background: var(--red-050); color: var(--red-600); }
.delta-flat { background: var(--bg-sunken); color: var(--ink-500); }
.delta-opp { background: var(--amber-050); color: var(--amber-700); }

/* Luottamusbadge */
.conf { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: var(--r-full); font-size: 11.5px; font-weight: 600; cursor: default; }
.conf::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.conf-korkea { background: var(--green-050); color: var(--green-600); }
.conf-normaali { background: var(--navy-050); color: var(--navy-600); }
.conf-matala { background: var(--amber-050); color: var(--amber-700); }

/* Riskitaso */
.risk { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.risk .icon-sm { width: 14px; height: 14px; }
.risk-matala { color: var(--green-600); }
.risk-kohtalainen { color: var(--amber-600); }
.risk-korkea { color: var(--red-600); }

/* Lähdechip — sama komponentti kaikkialla */
.src-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 3px 9px; line-height: 1.35;
  border-radius: var(--r-full); background: var(--navy-050); border: 1px solid var(--line-200);
  font-family: var(--font-mono); font-size: 11px; color: var(--navy-600);
  cursor: pointer; white-space: nowrap; max-width: 100%; text-align: left;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.src-chip:hover { border-color: var(--navy-300); }
.src-chip .icon-sm { width: 12px; height: 12px; flex: 0 0 auto; }
/* Pitkä lähdenimi rivittyy kapealla näytöllä eikä katkea ellipsiin. */
.src-chip span { min-width: 0; white-space: normal; overflow-wrap: break-word; }
.src-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--sp-3); }

/* Viitenumero tekstissä */
.cite { color: var(--navy-600); font-size: 0.75em; vertical-align: super; font-weight: 600; cursor: default; }

/* ---------- Stat-tilet ---------- */
.stat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat-label { font-size: var(--fs-micro); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-500); white-space: nowrap; }
.stat-value { font-size: var(--fs-kpi); font-weight: 700; color: var(--ink-900); letter-spacing: -0.01em; line-height: 1.2; white-space: nowrap; }
.stat-value small { font-size: 0.55em; font-weight: 600; color: var(--ink-500); margin-left: 2px; }
.stat-sub { font-size: 12px; color: var(--ink-500); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.stat-hero .stat-value { font-size: var(--fs-hero); color: var(--amber-600); }

/* ---------- Taulukot ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line-200); border-radius: var(--r-md); background: var(--bg-card); }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.tbl thead th {
  position: sticky; top: 0; z-index: 2; background: var(--bg-card);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-500); text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-200);
  white-space: nowrap;
}
.tbl thead th.sortable { cursor: pointer; user-select: none; }
.tbl thead th.sortable:hover { color: var(--ink-900); }
.tbl thead th .sort-ind { font-size: 9px; margin-left: 3px; }
.tbl tbody td { padding: 0 12px; height: 44px; border-bottom: 1px solid var(--line-100); color: var(--ink-700); white-space: nowrap; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background var(--t-fast); }
.tbl tbody tr:hover, .tbl tbody tr.hl { background: var(--navy-050); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .strong { font-weight: 600; color: var(--ink-900); }

/* ---------- Tabit ---------- */
.tabs { display: flex; gap: 2px; position: relative; border-bottom: 1px solid var(--line-200); }
.tabs button {
  height: 42px; padding: 0 16px; font-size: 13.5px; font-weight: 500; color: var(--ink-500);
  position: relative; transition: color var(--t-fast); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px;
}
.tabs button:hover { color: var(--ink-900); }
.tabs button.on { color: var(--navy-700); font-weight: 600; }
.tabs .tab-ink { position: absolute; bottom: -1px; height: 2px; background: var(--amber-500); border-radius: 1px; transition: left var(--t-base) var(--ease-standard), width var(--t-base) var(--ease-standard); }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
  background: var(--navy-900); color: #f0eeea; border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.08); box-shadow: var(--shadow-lg);
  font-size: 13px; line-height: 1.45; animation: toastIn 250ms var(--ease-out);
}
.toast .icon { margin-top: 1px; }
.toast-ok .icon { color: var(--green-500); }
.toast-warn .icon { color: var(--amber-400); }
.toast-err .icon { color: var(--red-500); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity var(--t-base), transform var(--t-base); }
/* Tummissa teemoissa toast erottuu taustasta selvemmin */
[data-theme="dark"] .toast { background: #1e2a47; border-color: rgba(255, 255, 255, 0.18); color: #F0F4FB; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Modal / scrim ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 100; background: rgba(6, 13, 28, 0.55);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  display: grid; place-items: center; animation: fadeIn 150ms linear;
}
.scrim.top { align-items: start; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: min(560px, calc(100vw - 40px)); max-height: calc(100vh - 80px); overflow-y: auto;
  background: var(--bg-card); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  border: 1px solid var(--line-200); padding: var(--sp-6);
  animation: modalIn 150ms var(--ease-out);
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- Komentopaletti ---------- */
.palette {
  width: min(640px, calc(100vw - 40px)); margin-top: 15vh;
  background: var(--bg-card); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  border: 1px solid var(--line-200); overflow: hidden; animation: modalIn 150ms var(--ease-out);
}
.palette-input { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line-200); }
.palette-input input { flex: 1; border: 0; background: transparent; font-size: 15px; color: var(--ink-900); }
.palette-input input:focus { outline: none; }
.palette-input .icon { color: var(--ink-400); }
.palette-body { max-height: 420px; overflow-y: auto; padding: 8px; }
.palette-group { padding: 8px 10px 4px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-400); }
.palette-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px;
  border-radius: var(--r-sm); font-size: 13.5px; color: var(--ink-700); text-align: left;
}
.palette-item .icon { color: var(--ink-400); }
.palette-item.sel { background: var(--navy-050); color: var(--ink-900); }
.palette-item.sel .icon { color: var(--navy-600); }
.palette-item mark { background: var(--amber-100); color: inherit; border-radius: 2px; }
.palette-item.sel .chip { background: var(--navy-100); }
.palette-item .pi-right { margin-left: auto; }
.palette-empty { padding: 28px; text-align: center; color: var(--ink-400); font-size: 13px; }

/* ---------- Popover ---------- */
.popover {
  position: fixed; z-index: 150; width: 300px; padding: var(--sp-4);
  background: var(--bg-card); border: 1px solid var(--line-200); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); font-size: 12.5px; line-height: 1.5; color: var(--ink-700);
  animation: modalIn 120ms var(--ease-out);
}
.popover h4 { font-size: 12.5px; font-weight: 700; color: var(--ink-900); margin-bottom: 6px; }
.popover .kv { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.popover .kv b { font-variant-numeric: tabular-nums; }

/* ---------- Skeleton ---------- */
.skel { position: relative; overflow: hidden; background: var(--line-100); border-radius: var(--r-xs); }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.7), transparent);
  animation: shimmer 1.4s infinite;
}
[data-theme="dark"] .skel::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent); }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- Prosessisteppi (lavastettu paljastus) ---------- */
.steps { display: flex; flex-direction: column; gap: 10px; }
.step { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-400); transition: color var(--t-base); }
.step .step-ind { width: 20px; height: 20px; display: grid; place-items: center; flex: 0 0 auto; }
.step.doing { color: var(--ink-900); }
.step.done { color: var(--ink-500); }
.step.done .step-ind { color: var(--green-500); }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line-300); border-top-color: var(--amber-500);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Tyhjätilat ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 48px 24px; text-align: center; }
.empty .icon-xl { width: 34px; height: 34px; color: var(--ink-300); }
.empty h3 { color: var(--ink-700); }
.empty p { font-size: 13px; color: var(--ink-400); max-width: 380px; line-height: 1.5; }

/* Kieltäytymis-/ei dataa -kortti (AI-guardrail — ei koskaan punainen) */
.guard {
  display: flex; gap: 12px; padding: 14px; border-radius: var(--r-md);
  background: var(--bg-sunken); border: 1px solid var(--line-200);
}
.guard .icon { color: var(--navy-600); margin-top: 1px; }
.guard-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-400); margin-bottom: 3px; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed var(--line-300); border-radius: var(--r-lg); padding: 40px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
  cursor: pointer; background: var(--bg-card);
}
.dropzone:hover { border-color: var(--navy-300); }
.dropzone.over { border-color: var(--amber-500); background: var(--amber-050); transform: scale(1.01); }
.dropzone .icon-xl { width: 30px; height: 30px; color: var(--ink-400); }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 400px; max-width: calc(100vw - 40px); z-index: 1200;
  background: var(--bg-card); border-left: 1px solid var(--line-200); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform var(--t-slow) var(--ease-standard);
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--line-200); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--sp-5); }

/* ---------- Intervallipalkki ---------- */
.ibar { width: 100%; height: 6px; border-radius: 3px; background: var(--line-100); position: relative; }
.ibar-range { position: absolute; top: 0; bottom: 0; border-radius: 3px; background: var(--navy-200); transform-origin: left; }
.ibar-med { position: absolute; top: -3px; bottom: -3px; width: 3px; border-radius: 2px; background: var(--navy-700); }
.ibar-amber .ibar-range { background: var(--amber-100); }
.ibar-amber .ibar-med { background: var(--amber-600); }

/* ---------- Divider ---------- */
.hr { height: 1px; background: var(--line-100); border: 0; margin: var(--sp-4) 0; }

/* ---------- Tooltip (data-tip) ---------- */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 7px); left: 50%; transform: translateX(-50%);
  background: rgba(23, 22, 20, 0.96); color: #f0eeea; font-size: 11.5px; font-weight: 500;
  padding: 6px 10px; border-radius: 7px; white-space: pre; z-index: 300; pointer-events: none;
  box-shadow: var(--shadow-md); line-height: 1.4; text-transform: none; letter-spacing: 0;
}
/* Yläpalkissa vihje aukeaa alaspäin: ylöspäin se jäi näkymän yläreunan ulkopuolelle (vaalean ja tumman tilan
   painike, käyttötestaus 31.10.2026, L54). */
.topbar [data-tip]:hover::after { bottom: auto; top: calc(100% + 7px); }
