/* ============================================================================
   Pinordo — designjärjestelmä
   Vaalea & ilmava + moderni futuristinen lasimorfismi (frosted glass).
   Komponenttien luokka-API pidetään yhteensopivana olemassa olevien
   templatejen kanssa: .card, table, button/.btn, input/select/textarea,
   .flash, .muted, otsikot, linkit.
   ========================================================================== */

:root {
  /* Brändi */
  --brand-red: #e93525;
  --brand-red-deep: #c62b20;
  --brand-black: #1c1d22;
  --brand-graphite: #4e4e4e;
  --brand-silver: #9fa3a7;

  /* Futuristinen sekundääriaksentti (hehkut, kaaviot) */
  --accent: #4f7cff;
  --accent-2: #16c8c8;

  /* Muste ja tekstihierarkia */
  --ink: #191a1f;
  --ink-soft: #3c3f47;
  --muted: #6b7078;

  /* Lasipinnat */
  --glass: rgba(255, 255, 255, 0.62);
  --glass-strong: rgba(255, 255, 255, 0.80);
  --glass-thin: rgba(255, 255, 255, 0.44);
  --glass-border: rgba(255, 255, 255, 0.75);
  --hairline: rgba(28, 29, 34, 0.10);

  /* Varjot ja kohotus */
  --shadow: 0 24px 64px rgba(24, 26, 40, 0.14);
  --shadow-soft: 0 12px 32px rgba(24, 26, 40, 0.09);
  --shadow-crisp: 0 1px 2px rgba(24, 26, 40, 0.06);
  --glow-red: 0 10px 30px rgba(233, 53, 37, 0.24);
  --glow-accent: 0 10px 30px rgba(79, 124, 255, 0.22);

  /* Muoto */
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --blur: blur(22px) saturate(150%);

  --font-heading: "Montserrat", "Arial", sans-serif;
  --font-body: "Ubuntu", "Arial", sans-serif;

  --sidebar-w: 260px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #eef1f6; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 300;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Ilmava, hienovaraisen futuristinen kangas: kylmiä valoja + brändipunainen hehku */
  background:
    radial-gradient(1100px 700px at 88% -8%, rgba(79, 124, 255, 0.14), transparent 60%),
    radial-gradient(900px 620px at -6% 4%, rgba(233, 53, 37, 0.10), transparent 55%),
    radial-gradient(1200px 800px at 60% 120%, rgba(22, 200, 200, 0.08), transparent 60%),
    linear-gradient(180deg, #f7f9fc 0%, #eef1f6 100%);
  background-attachment: fixed;
}

/* Hienovarainen ruudukkokuvio taustalle (futuristinen vihje) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(28, 29, 34, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(28, 29, 34, 0.028) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(1000px 700px at 70% 0%, rgba(0, 0, 0, 0.5), transparent 75%);
  -webkit-mask-image: radial-gradient(1000px 700px at 70% 0%, rgba(0, 0, 0, 0.5), transparent 75%);
}

/* ------------------------------------------------------------------ Kuori */

/* Fonttikoko (käyttäjäasetus): zoom skaalaa koko käyttöliittymän
   suhteessa, jolloin myös px-mitoitetut komponentit kasvavat. */
body[data-font="small"] { zoom: 0.9; }
body[data-font="large"] { zoom: 1.18; }

.app-shell { position: relative; z-index: 1; min-height: 100vh; }

.app-shell:has(.sidebar) {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

/* Sivupalkki — lasinen, sticky */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 14px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(78, 78, 78, 0.32) transparent;
  border-right: 1px solid var(--glass-border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.74), rgba(255, 255, 255, 0.52));
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  margin: 4px 8px 14px;
  color: var(--brand-black);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(150deg, var(--brand-red), var(--brand-red-deep));
  box-shadow: var(--glow-red), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 800;
}

.brand-copy { display: grid; gap: 1px; }
.brand-copy strong {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.2px;
}
.brand-copy small { color: var(--brand-graphite); font-size: 11px; font-weight: 400; }

/* Käyttäjälohko sivupalkin ylässä */
.side-user {
  display: grid;
  gap: 2px;
  margin: 0 6px 12px;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline);
  background: var(--glass-thin);
}
.side-user strong { font-family: var(--font-heading); font-size: 13px; }
.side-user small { color: var(--muted); font-size: 11px; }

/* Navigaatioryhmät */
.nav-group { margin: 8px 6px 2px; }
.nav-group-title {
  padding: 6px 10px 4px;
  font-family: var(--font-heading);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--brand-silver);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 2px 6px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 400;
  border: 1px solid transparent;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 120ms ease;
}
.nav-link svg { width: 19px; height: 19px; flex: 0 0 auto; opacity: 0.7; transition: opacity 160ms ease; }
.nav-link:hover {
  color: var(--brand-black);
  background: var(--glass-strong);
  border-color: var(--glass-border);
  transform: translateX(2px);
  text-decoration: none;
}
.nav-link:hover svg { opacity: 1; }
.nav-link.active {
  color: var(--brand-red);
  font-weight: 500;
  background: linear-gradient(135deg, rgba(233, 53, 37, 0.14), rgba(233, 53, 37, 0.05));
  border-color: rgba(233, 53, 37, 0.28);
  box-shadow: var(--shadow-crisp);
}
.nav-link.active svg { opacity: 1; color: var(--brand-red); }

.side-foot { margin-top: auto; padding: 10px 12px 4px; }
.side-foot a { color: var(--brand-red); font-size: 12.5px; font-weight: 500; }

/* Pääalue */
.main { min-width: 0; display: flex; flex-direction: column; }

/* Yläpalkki — lasinen */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 13px 24px;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.topbar .page-title { font-family: var(--font-heading); font-size: 17px; font-weight: 800; color: var(--brand-black); }
.topbar .spacer { flex: 1 1 auto; }
.topbar .user-menu { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.topbar .user-menu .who { display: grid; justify-items: end; gap: 1px; line-height: 1.15; }
.topbar .user-menu .who span { font-weight: 500; color: var(--brand-black); }
.topbar .user-menu .who small { color: var(--muted); font-size: 11px; }
.topbar .user-menu a {
  color: var(--brand-red);
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(233, 53, 37, 0.28);
  background: rgba(255, 255, 255, 0.5);
  transition: background 150ms ease, color 150ms ease;
}
.topbar .user-menu a:hover { color: #fff; background: var(--brand-red); text-decoration: none; }

.content {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 26px 24px 64px;
}

/* Kirjautumaton näkymä (ei sivupalkkia) — keskitä sisältö */
body:not(:has(.sidebar)) .content {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

/* ------------------------------------------------------------- Komponentit */

.card {
  position: relative;
  margin-bottom: 20px;
  padding: 24px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  background: var(--glass);
  box-shadow: var(--shadow-soft);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
/* Kiiltävä ylähiusviiva */
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.95), transparent);
  pointer-events: none;
}
/* Sisäkkäinen kortti kevyempi */
.card .card {
  background: var(--glass-thin);
  box-shadow: none;
  border-color: var(--hairline);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

h1, h2, h3, h4 {
  margin: 0 0 14px;
  color: var(--brand-black);
  font-family: var(--font-heading);
  font-weight: 800;
  line-height: 1.15;
}
h2 { font-size: clamp(22px, 2.6vw, 30px); }
h3 { font-size: 19px; }
h4 { font-size: 15px; }

p { margin: 0 0 14px; }
p:last-child { margin-bottom: 0; }

a { color: var(--brand-red); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); font-size: 13px; font-weight: 300; }

/* Lomakkeet */
label {
  display: block;
  margin: 12px 0 5px;
  color: var(--brand-graphite);
  font-family: var(--font-heading);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  font: inherit;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--brand-red); }
input:focus, textarea:focus, select:focus {
  border-color: rgba(233, 53, 37, 0.7);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 0 0 4px rgba(233, 53, 37, 0.13);
}

/* Napit */
button, .btn, input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  width: auto;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 17px;
  color: #fff !important;
  background: linear-gradient(150deg, var(--brand-red), var(--brand-red-deep)) !important;
  box-shadow: var(--glow-red), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  cursor: pointer;
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none !important;
  transition: transform 150ms ease, box-shadow 150ms ease, filter 150ms ease;
}
button:hover, .btn:hover, input[type="submit"]:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 34px rgba(233, 53, 37, 0.30), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  filter: saturate(1.06);
  text-decoration: none !important;
}
button:active, .btn:active, input[type="submit"]:active { transform: translateY(0); }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid rgba(79, 124, 255, 0.5);
  outline-offset: 2px;
}

/* Toissijainen / vaarallinen nappi */
button.danger, .danger,
.btn[style*="background:#888"], .btn[style*="background: #888"] {
  background: linear-gradient(150deg, var(--brand-black), var(--brand-graphite)) !important;
  box-shadow: 0 12px 26px rgba(24, 26, 40, 0.20), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

/* Haamu-/tekstinappi (templatet käyttävät inline background:none) */
button[style*="background:none"], .btn.ghost {
  min-height: 0;
  color: var(--brand-red) !important;
  background: transparent !important;
  box-shadow: none;
  border-color: transparent;
}

/* Ilmoitukset */
.flash {
  margin-bottom: 14px;
  padding: 12px 16px;
  border: 1px solid var(--glass-border);
  border-left: 3px solid var(--brand-red);
  border-radius: var(--radius-sm);
  background: var(--glass-strong);
  box-shadow: var(--shadow-soft);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.flash.error { color: #7a1c12; border-left-color: var(--brand-red); }
.flash.success { color: #14622e; border-left-color: #1faf54; }
.flash.info { color: var(--brand-black); border-left-color: var(--accent); }

/* Taulukot */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.4);
}
th, td {
  border: 0;
  border-bottom: 1px solid var(--hairline);
  padding: 11px 13px;
  text-align: left;
  font-size: 14px;
  vertical-align: middle;
}
tr:last-child td, tr:last-child th { border-bottom: 0; }
th {
  font-family: var(--font-heading);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--brand-graphite);
  background: rgba(255, 255, 255, 0.66);
}
td { background: rgba(255, 255, 255, 0.28); }
tr:nth-child(even) td { background: rgba(255, 255, 255, 0.46); }
tbody tr:hover td, tr:hover td { background: rgba(233, 53, 37, 0.06); }

code {
  padding: 2px 6px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  color: var(--brand-black);
  background: rgba(255, 255, 255, 0.66);
  font-size: 0.9em;
}

/* ------------------------------------------------------- Koontinäkymä (ALKUUN) */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.kpi {
  position: relative;
  overflow: hidden;
  padding: 18px 20px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  background: var(--glass);
  box-shadow: var(--shadow-soft);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.kpi .kpi-label {
  display: block;
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
}
.kpi .kpi-value {
  margin-top: 6px;
  font-family: var(--font-heading);
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  color: var(--brand-black);
}
.kpi .kpi-sub { margin-top: 5px; font-size: 12px; color: var(--muted); }
/* Aksenttihehku vasempaan reunaan */
.kpi::after {
  content: "";
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 3px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--brand-red), var(--brand-red-deep));
}
.kpi.accent::after { background: linear-gradient(180deg, var(--accent), #3b63e0); }
.kpi.good::after { background: linear-gradient(180deg, #1faf54, #158a41); }
.kpi.warn::after { background: linear-gradient(180deg, #f5a524, #d98a10); }

.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 360px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.donut-wrap { position: relative; width: 260px; height: 260px; margin: 6px auto 4px; }
.donut-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  text-align: center;
}
.donut-center .num {
  font-family: var(--font-heading);
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
  color: var(--brand-black);
}
.donut-center .cap { font-size: 11px; letter-spacing: 0.6px; text-transform: uppercase; color: var(--muted); }

.legend { display: grid; gap: 8px; margin-top: 8px; }
.legend .row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.legend .dot { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }
.legend .row .n { margin-left: auto; font-family: var(--font-heading); font-weight: 700; color: var(--brand-black); }

/* Statuspilleri */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 700;
  border: 1px solid transparent;
}
.pill.queued { color: #2a4bd0; background: rgba(79,124,255,0.14); border-color: rgba(79,124,255,0.3); }
.pill.in_progress { color: #9a6200; background: rgba(245,165,36,0.16); border-color: rgba(245,165,36,0.34); }
.pill.done { color: #14622e; background: rgba(31,175,84,0.15); border-color: rgba(31,175,84,0.32); }
.pill.cancelled { color: #5c6066; background: rgba(159,163,167,0.18); border-color: rgba(159,163,167,0.34); }

.empty-state {
  padding: 28px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--glass-thin);
}

@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: 1fr; }
  .donut-wrap { }
}
@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* Templatejen inline flex-lomakkeet rivittyvät */
form[style*="display:flex"], p[style*="display:flex"] { flex-wrap: wrap; }
.card > p:has(.btn), .card > p:has(button) {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}

/* ------------------------------------------------------------- Responsiiv. */

@media (max-width: 1024px) {
  :root { --sidebar-w: 76px; }
  .brand-copy, .side-user, .nav-group-title, .nav-link span, .side-foot span { display: none; }
  .brand { justify-content: center; margin-inline: 0; }
  .nav-link { justify-content: center; }
  .nav-link svg { opacity: 0.85; }
}

@media (max-width: 680px) {
  .app-shell:has(.sidebar) { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0;
    height: auto; width: 100%;
    flex-direction: row; gap: 2px;
    padding: 6px 8px;
    overflow-x: auto;
    border-right: 0; border-top: 1px solid var(--glass-border);
    z-index: 50;
  }
  .brand, .side-user, .nav-group-title, .side-foot { display: none; }
  .nav-group { display: contents; }
  .nav-link { margin: 0; }
  .content { padding: 18px 16px 90px; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ================================================================
   DATAGRID — sortattava, suodatettava taulukon kehys
   Käyttö: <div class="datagrid-wrap" data-datagrid>
             <div data-datagrid-slot="actions">…napit…</div>
             <table>…</table>
           </div>
   JS: static/js/datagrid.js aktivoi automaattisesti.
   ================================================================ */

/* Ulkoinen kehys — vähän tilaa ympärille */
.datagrid-wrap {
  position: relative;
}

/* ----- Työkalupalkki (toolbar) ---------------------------------- */
.dg-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.dg-toolbar-spacer {
  flex: 1 1 auto;
}

/* Globaali hakukenttä — kompakti, ei täysleveys */
.dg-search {
  width: auto;
  min-width: 180px;
  max-width: 260px;
  padding: 8px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.dg-search:focus {
  border-color: rgba(233, 53, 37, 0.6);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 0 0 3px rgba(233, 53, 37, 0.12);
}
.dg-search::placeholder { color: var(--brand-silver); }

/* ----- Sortattavat sarakeotsikoita ------------------------------ */
th.dg-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.dg-sortable:hover {
  color: var(--brand-red);
  background: rgba(233, 53, 37, 0.07);
}
th.dg-sorted {
  color: var(--brand-red);
}

/* Sort-nuoli-indikaattori */
.dg-sort-icon {
  display: inline-block;
  margin-left: 5px;
  font-size: 10px;
  opacity: 0.5;
  vertical-align: middle;
  transition: opacity 120ms ease, color 120ms ease;
}
th.dg-sortable:hover .dg-sort-icon,
th.dg-sorted .dg-sort-icon {
  opacity: 1;
  color: var(--brand-red);
}

/* ----- Per-sarake-suodatusrivi ---------------------------------- */
tr.dg-filter-row th.dg-filter-cell {
  padding: 4px 6px;
  background: rgba(255, 255, 255, 0.55);
  border-bottom: 1px solid var(--hairline);
}

.dg-filter-input {
  display: block;
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.80);
  font: inherit;
  font-size: 11.5px;
  color: var(--ink);
  outline: none;
  transition: border-color 130ms ease, box-shadow 130ms ease;
}
.dg-filter-input:focus {
  border-color: rgba(233, 53, 37, 0.55);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 0 0 2px rgba(233, 53, 37, 0.10);
}
.dg-filter-input::placeholder { color: var(--brand-silver); font-style: italic; }

/* Tyhjä solut suodatusrivillä (toiminto-sarake tms.) */
tr.dg-filter-row th.dg-filter-cell:empty {
  background: rgba(255, 255, 255, 0.40);
}

/* ----- Footer-laskuri ------------------------------------------- */
.dg-footer {
  display: flex;
  align-items: center;
  margin-top: 8px;
  padding: 5px 2px;
}

.dg-counter {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* ----- Responsiivisuus: vaakascrollaus kapealla ----------------- */
@media (max-width: 680px) {
  .datagrid-wrap {
    overflow-x: auto;
  }
  .dg-toolbar {
    gap: 8px;
  }
  .dg-search {
    min-width: 120px;
    max-width: 100%;
    flex: 1 1 auto;
  }
}

/* ================================================================
   TYÖAIKA-MODUULI (WP-L.4) — viikkonäkymä, ajastin, tilapillerit
   ================================================================ */

/* Tilapillerit tuntikirjauksille */
.pill.draft     { color: #4e4e4e; background: rgba(159,163,167,0.15); border-color: rgba(159,163,167,0.32); }
.pill.submitted { color: #7a5200; background: rgba(245,165,36,0.16);  border-color: rgba(245,165,36,0.38); }
.pill.approved  { color: #14622e; background: rgba(31,175,84,0.15);   border-color: rgba(31,175,84,0.32); }
.pill.rejected  { color: #7a1c12; background: rgba(233,53,37,0.12);   border-color: rgba(233,53,37,0.28); }

/* ================================================================
   OSTOLASKUT (WP-L.6) — tilapillerit hyväksyntäkierrolle
   ================================================================ */
.pill.received   { color: #2a4bd0; background: rgba(79,124,255,0.14);  border-color: rgba(79,124,255,0.30); }
.pill.in_review  { color: #7a5200; background: rgba(245,165,36,0.16);  border-color: rgba(245,165,36,0.34); }
/* .pill.approved — yhteinen myynti- ja ostolaskuille, määritelty jo yllä */
.pill.paid       { color: #0a6b6b; background: rgba(22,200,200,0.14);  border-color: rgba(22,200,200,0.30); }
/* .pill.rejected — yhteinen, määritelty jo yllä */

/* Ostolaskujen statusvälilehdet */
.pi-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.5);
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}
.pi-tab:hover {
  color: var(--brand-black);
  background: var(--glass-strong);
  border-color: var(--glass-border);
  text-decoration: none;
}
.pi-tab.pi-tab-active {
  color: var(--brand-red);
  background: rgba(233, 53, 37, 0.10);
  border-color: rgba(233, 53, 37, 0.28);
}
.pi-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(233, 53, 37, 0.14);
  color: var(--brand-red);
  font-size: 10px;
  font-weight: 700;
}

/* Viikkonavigointi */
.worktime-week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  padding: 14px 20px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  background: var(--glass);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  flex-wrap: wrap;
}
.worktime-week-title {
  text-align: center;
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 700;
  color: var(--brand-black);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1 1 auto;
}
.worktime-week-total {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 800;
  color: var(--brand-red);
}
.worktime-nav-btn {
  flex: 0 0 auto;
}

/* Viikkoruudukko — 7 päivää rinnakkain, responsiivinen */
.worktime-week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 1200px) {
  .worktime-week-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .worktime-week-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
  .worktime-week-grid { grid-template-columns: 1fr; }
}

/* Päiväkortti */
.worktime-day-card {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 110px;
}
.worktime-day-card.worktime-day-weekend {
  background: rgba(255, 255, 255, 0.36);
  opacity: 0.8;
}
.worktime-day-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hairline);
}
.worktime-day-name {
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--brand-graphite);
}
.worktime-day-date {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
.worktime-day-footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--hairline);
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 700;
  color: var(--brand-black);
  text-align: right;
}
.worktime-day-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand-silver);
  font-size: 20px;
}

/* Kirjausrivi päiväkortissa */
.worktime-day-entries { display: flex; flex-direction: column; gap: 6px; }
.worktime-entry-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--hairline);
  font-size: 12px;
}
.worktime-entry-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.worktime-entry-job {
  font-weight: 500;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.worktime-entry-desc {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.worktime-entry-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex: 0 0 auto;
}
.worktime-entry-hours {
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 700;
  color: var(--brand-black);
  white-space: nowrap;
}

/* Viikon yhteenveto */
.worktime-week-summary {
  margin-bottom: 0;
}

/* Käynnissä oleva banneri */
.worktime-running-banner {
  margin-bottom: 18px;
}

/* Käynnissä olevan kortti (start.html) */
.worktime-running-card {
  padding: 18px;
  border-radius: var(--radius-sm);
  background: rgba(79, 124, 255, 0.06);
  border: 1px solid rgba(79, 124, 255, 0.22);
  margin: 14px 0;
}

/* ================================================================
   MODAALIT (WP-L.5) — htmx-modaalilomakkeet lasimorfismilla
   Käyttö: {% from "components/modal.html" import modal %}
           {% call modal("Otsikko") %}...{% endcall %}
   ================================================================ */

/* Taustahimmennys — peittää koko ikkunan, sentröi dialogin */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 16, 20, 0.52);
  backdrop-filter: blur(6px) saturate(120%);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  animation: modal-fade-in 180ms ease both;
}

/* Dialogikortti */
.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(78, 78, 78, 0.28) transparent;
  border-radius: var(--radius-lg);
  border: 1px solid var(--glass-border);
  background: var(--glass-strong);
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(255, 255, 255, 0.55) inset;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  animation: modal-slide-in 220ms cubic-bezier(0.34, 1.3, 0.64, 1) both;
}

/* Värikäs gradienttiraita dialogin ylälaidassa */
.modal-stripe {
  height: 4px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: linear-gradient(
    90deg,
    var(--brand-red) 0%,
    #f0622f 28%,
    var(--accent) 62%,
    var(--accent-2) 100%
  );
}

/* Otsikkorivi */
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--hairline);
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 800;
  color: var(--brand-black);
  line-height: 1.15;
}

/* Sulkunappi */
.modal-close {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.5) !important;
  color: var(--muted) !important;
  box-shadow: none;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}
.modal-close:hover {
  background: rgba(233, 53, 37, 0.08) !important;
  color: var(--brand-red) !important;
  border-color: rgba(233, 53, 37, 0.28);
  transform: none;
  box-shadow: none;
  filter: none;
}

/* Lomakesisältö */
.modal-body {
  padding: 20px 24px 24px;
}

/* Rinnakkaiset kentät modaalin sisällä */
.modal-field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0 20px;
}

/* Footeririvi nappeille */
.modal-footer {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
  flex-wrap: wrap;
}

/* Peruuta-nappi modaalissa — toissijainen tyyli */
.modal-cancel-btn {
  background: none !important;
  color: var(--muted) !important;
  box-shadow: none !important;
  border: 1px solid var(--hairline) !important;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease !important;
}
.modal-cancel-btn:hover {
  background: rgba(28, 29, 34, 0.06) !important;
  color: var(--brand-black) !important;
  border-color: rgba(28, 29, 34, 0.18) !important;
  transform: none !important;
  filter: none !important;
}

/* Saapumisanimaatiot */
@keyframes modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modal-slide-in {
  from {
    opacity: 0;
    transform: translateY(-18px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Kunnioita käyttäjän liikeasetuksia */
@media (prefers-reduced-motion: reduce) {
  .modal-backdrop,
  .modal-dialog {
    animation: none;
  }
}

/* Kapeat näytöt — lähes koko ruutu */
@media (max-width: 680px) {
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .modal-dialog {
    max-width: 100%;
    max-height: 94vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: modal-slide-up 240ms cubic-bezier(0.34, 1.2, 0.64, 1) both;
  }
  @keyframes modal-slide-up {
    from {
      opacity: 0;
      transform: translateY(40px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  .modal-field-row {
    grid-template-columns: 1fr;
  }
}

/* ------------------------------------------------------- Asetukset-valikko (i18n, WP-L.7) */
.side-settings { margin-top: 8px; }
.side-settings > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 500;
  transition: background 150ms ease, color 150ms ease;
}
.side-settings > summary::-webkit-details-marker { display: none; }
.side-settings > summary svg { width: 16px; height: 16px; opacity: 0.7; }
.side-settings > summary:hover { background: var(--glass-strong); color: var(--brand-black); }
.side-settings[open] > summary { color: var(--brand-black); }
.side-settings-menu {
  display: grid;
  gap: 2px;
  margin: 4px 0 2px;
  padding: 6px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--glass-thin);
}
.side-settings-menu > a {
  padding: 7px 9px;
  border-radius: 8px;
  color: var(--ink-soft);
  font-size: 12.5px;
  text-decoration: none;
}
.side-settings-menu > a:hover { background: var(--glass-strong); color: var(--brand-red); text-decoration: none; }
.side-settings-langs {
  display: flex;
  gap: 6px;
  padding: 4px 2px;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  margin: 2px 0;
}
.side-settings-langs > a {
  flex: 1;
  text-align: center;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--hairline);
  text-decoration: none;
}
.side-settings-langs > a:hover { color: var(--brand-black); text-decoration: none; }
.side-settings-langs > a.active {
  color: #fff;
  background: linear-gradient(150deg, var(--brand-red), var(--brand-red-deep));
  border-color: transparent;
}

/* ------------------------------------------------------- Koontinäkymän korttirivi (WP-L.7+) */
.card-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}
.card-row .card { margin-bottom: 0; }
.panel-stat { display: flex; align-items: baseline; gap: 10px; }
.panel-num {
  font-family: var(--font-heading);
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  color: var(--brand-black);
}

/* ------------------------------------------------------- Globaali haku yläpalkissa */
.topbar-search {
  display: flex;
  align-items: center;
  margin: 0;
}
.topbar-search input[type="search"] {
  width: min(320px, 40vw);
  min-width: 140px;
  padding: 7px 13px;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(10px) saturate(130%);
  -webkit-backdrop-filter: blur(10px) saturate(130%);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease, width 220ms ease;
}
.topbar-search input[type="search"]:focus {
  border-color: rgba(233, 53, 37, 0.55);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 0 0 4px rgba(233, 53, 37, 0.11);
  width: min(400px, 50vw);
}
.topbar-search input[type="search"]::placeholder { color: var(--muted); }
/* Poista selaimen oletustyyli search-tyypistä */
.topbar-search input[type="search"]::-webkit-search-decoration,
.topbar-search input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ------------------------------------------------------- Hakutulossivu */
.search-group { margin-bottom: 28px; }
.search-group-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hairline);
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
}
.search-group-title .search-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--hairline);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}
.search-result-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.search-result-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.32);
  transition: background 140ms ease, border-color 140ms ease;
}
.search-result-list li:hover {
  background: rgba(255, 255, 255, 0.72);
  border-color: var(--glass-border);
}
.search-result-list .sr-primary { font-weight: 500; color: var(--brand-red); }
.search-result-list .sr-secondary { font-size: 12.5px; color: var(--muted); }
.empty-state {
  padding: 36px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

/* ------------------------------------------------------- "Vie CSV" -sekundäärinappi */
.btn-csv {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.55) !important;
  color: var(--ink-soft) !important;
  font-family: var(--font-heading);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none !important;
  cursor: pointer;
  box-shadow: var(--shadow-crisp);
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}
.btn-csv:hover {
  background: rgba(255, 255, 255, 0.88) !important;
  border-color: rgba(79, 124, 255, 0.35);
  color: var(--brand-black) !important;
  text-decoration: none !important;
}

/* ----- Toiminnot-valikko (kootut sivutoiminnot, oikea yläkulma) ---------
   Kevyt, vaalea alasvetovalikko: valkoinen ääriviivanappi + pieni paneeli,
   pienet harmaat ikonit, ei koristeita. */
.actions-menu { position: relative; }
.actions-menu > summary.actions-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid #d7dae0;
  border-radius: 8px;
  background: #fff;
  color: var(--brand-black);
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background 130ms ease, border-color 130ms ease;
}
.actions-menu > summary.actions-btn:hover,
.actions-menu[open] > summary.actions-btn {
  background: #f6f7f9;
  border-color: #b9bdc6;
}
.actions-menu > summary::-webkit-details-marker { display: none; }
.actions-menu > summary .chev { display: inline-flex; }
.actions-menu > summary .chev svg {
  width: 12px;
  height: 12px;
  transition: transform 0.15s ease;
}
.actions-menu[open] > summary .chev svg { transform: rotate(180deg); }
.act-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 80;
  min-width: 220px;
  padding: 6px;
  display: grid;
  gap: 1px;
  background: #fff;
  border: 1px solid #e3e5ea;
  border-radius: 10px;
  box-shadow: 0 10px 32px rgba(24, 26, 40, 0.14);
}
.act-form { margin: 0; }
/* !important: globaali button-sääntö käyttää !important-taustaa/väriä */
.act-item,
button.act-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: none !important;
  box-shadow: none !important;
  color: #2c2f36 !important;
  font: inherit;
  font-size: 13.5px;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
}
.act-item svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  color: #6b7078;
}
.act-item:hover,
button.act-item:hover {
  background: #f3f4f6 !important;
  color: #16171b !important;
  text-decoration: none;
  transform: none;
  box-shadow: none !important;
  filter: none;
}
.act-item:hover svg { color: #3c3f47; }
.act-item.act-danger,
button.act-item.act-danger { color: #c02717 !important; }
.act-item.act-danger svg { color: #c02717; }
.act-item.act-danger:hover,
button.act-item.act-danger:hover {
  background: rgba(233, 53, 37, 0.07) !important;
  color: #a01f11 !important;
}
.act-sep {
  height: 1px;
  margin: 4px 6px;
  background: #ebedf0;
}

/* ----- Sivutoimintorivi yläpalkin alla: takaisin vasemmalla, muut oikealla */
.page-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 26px 0;
}
.page-actions .btn-quiet { margin-right: auto; }
.page-actions:not(:has(a, details, form, button)) { display: none; }

/* Kielivalinta käyttäjävalikossa */
.act-langs {
  display: flex;
  gap: 6px;
  padding: 8px 10px 6px;
}
.act-langs > a {
  padding: 5px 12px;
  border: 1px solid #e3e5ea;
  border-radius: 999px;
  color: #2c2f36;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.act-langs > a:hover { background: #f3f4f6; text-decoration: none; }
.act-langs > a.active {
  color: #fff;
  background: linear-gradient(150deg, var(--brand-red), var(--brand-red-deep));
  border-color: transparent;
}

/* ----- Käyttäjävalikko yläpalkissa: nimi avaa pudotusvalikon ------------- */
.user-dd > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 10px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-size: 13px;
}
.user-dd > summary::-webkit-details-marker { display: none; }
.user-dd > summary:hover,
.user-dd[open] > summary { background: rgba(255, 255, 255, 0.6); }
.user-dd .who { display: grid; justify-items: end; gap: 1px; line-height: 1.15; }
.user-dd .who span { font-weight: 500; color: var(--brand-black); }
.user-dd .who small { color: var(--muted); font-size: 11px; }
.user-dd > summary .chev { display: inline-flex; color: var(--muted); }
.user-dd > summary .chev svg { width: 12px; height: 12px; transition: transform 0.15s ease; }
.user-dd[open] > summary .chev svg { transform: rotate(180deg); }

/* Hillitty paluulinkki toimintonapin viereen */
.btn.btn-quiet,
.btn.btn-quiet:hover {
  background: none !important;
  color: var(--muted) !important;
  box-shadow: none;
  border: 1px solid var(--hairline);
}
.btn.btn-quiet:hover { color: var(--brand-black) !important; }

/* ----- Annika-tukiavustajan chat-widget --------------------------------- */
.annika { position: fixed; right: 22px; bottom: 22px; z-index: 150; }
.annika-fab {
  width: 52px;
  height: 52px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.annika-panel[hidden] { display: none; } /* display:flex ohittaisi hidden-attribuutin */
.annika-panel {
  position: absolute;
  right: 0;
  bottom: 64px;
  width: min(360px, calc(100vw - 44px));
  height: min(480px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid #e3e5ea;
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(24, 26, 40, 0.22);
  overflow: hidden;
}
.annika-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #ebedf0;
  font-family: var(--font-heading);
}
.annika-head-actions button {
  min-height: 0;
  padding: 3px 8px;
  background: none !important;
  box-shadow: none !important;
  color: var(--muted) !important;
  border: 0;
  font-size: 14px;
}
.annika-head-actions button:hover { color: var(--brand-black) !important; }
.annika-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.annika-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.annika-msg-user {
  align-self: flex-end;
  background: linear-gradient(150deg, var(--brand-red), var(--brand-red-deep));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.annika-msg-assistant {
  align-self: flex-start;
  background: #f1f2f5;
  color: #23252b;
  border-bottom-left-radius: 4px;
}
.annika-typing { opacity: 0.6; font-style: italic; }
.annika-input {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #ebedf0;
}
.annika-input input { flex: 1 1 auto; }
.annika-input button {
  min-height: 0;
  padding: 8px 14px;
}

/* ----- Annika-avatar ja animaatiot -------------------------------------- */
.annika-avatar {
  position: relative;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  cursor: pointer;
}
/* Kerrostetut kasvokuvat: pohja aina näkyvissä, ilmeet häivytetään päälle */
.annika-face-stack {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  animation: annika-breathe 4.2s ease-in-out infinite;
  isolation: isolate;
  transform: translateZ(0); /* vakaa komposiittikerros mobiilissa */
}
.annika-face-stack .face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.38s ease;
  border-radius: 50%;
  will-change: opacity;
}
.annika-face-stack .face-base { opacity: 1; } /* tausta ei vilahda läpi */
.annika-face-stack .face.active { opacity: 1; }
.annika-face-stack .face-blink { transition: opacity 0.11s ease; }
.annika-presence {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #1faf54;
  border: 2px solid #fff;
}
.annika-title-wrap { display: grid; gap: 0; line-height: 1.2; flex: 1 1 auto; margin-left: 10px; }
.annika-title-wrap small { color: var(--muted); font-size: 11px; font-weight: 400; }
.annika-head { gap: 0; }

/* Tilat: mietintä hengittää tiheämmin, puhe pomppii kevyesti */
.annika-avatar.annika-thinking .annika-face-stack {
  animation: annika-breathe 1.8s ease-in-out infinite;
}
.annika-avatar.annika-talking .annika-face-stack {
  animation: annika-talkbounce 0.6s ease-in-out infinite;
}
/* Kikatus: iloinen heilahdus klikkauksesta */
.annika-avatar.giggling { animation: annika-giggle 0.95s ease-in-out; }
@keyframes annika-breathe {
  0%, 100% { transform: scale(1) translateZ(0); }
  50% { transform: scale(1.035) translateZ(0); }
}
@keyframes annika-talkbounce {
  0%, 100% { transform: scale(1) translateY(0) translateZ(0); }
  35% { transform: scale(1.02) translateY(-1px) translateZ(0); }
  70% { transform: scale(1.005) translateY(0.5px) translateZ(0); }
}
@keyframes annika-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; }
  80% { rotate: -2deg; translate: 0 0; }
}

/* Pinyan kasvot vastausten vieressä */
.annika-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 100%;
}
.annika-msg-row .annika-msg { max-width: calc(85% - 31px); }
.annika-msg-face {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex: 0 0 auto;
  object-fit: cover;
}

/* Kirjoitusindikaattori: kolme pomppivaa pistettä */
.annika-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  min-height: 20px;
}
.annika-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: annika-bounce 1.2s infinite ease-in-out;
}
.annika-typing span:nth-child(2) { animation-delay: 0.15s; }
.annika-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes annika-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Vastuuvapaus paneelin alareunassa */
.annika-disclaimer {
  padding: 4px 10px 8px;
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  .annika-face-stack,
  .annika-avatar.annika-thinking .annika-face-stack,
  .annika-avatar.annika-talking .annika-face-stack,
  .annika-avatar.giggling,
  .annika-typing span { animation: none; }
}
