/* ═══════════════════════════════════════════════════════════════════
   Virtuelle Baustelle · Web-Panel — v2
   Klar, hell, präzise. Flache dunkle Navigation, Firmenfarbe als
   sparsamer Akzent, einheitliche SVG-Stroke-Icons.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --nav-bg: #111826;
  --nav-line: rgba(255, 255, 255, .07);
  --nav-ink: #92a2b3;
  --nav-ink-strong: #e9eef4;

  --brick: var(--company-color, #b45309);
  /* Fallbacks für Browser ohne color-mix (werden unten überschrieben) */
  --brick-dark: #8f4207;
  --brick-soft: #f4e7da;
  --brick-text: #8f4207;
}

@supports (color: color-mix(in srgb, red 50%, white)) {
  :root {
    --brick-dark: color-mix(in srgb, var(--brick) 80%, #000);
    --brick-soft: color-mix(in srgb, var(--brick) 10%, #fff);
    --brick-text: color-mix(in srgb, var(--brick) 80%, #1a232c);
  }
}

:root {

  --bg: #f6f7f8;
  --card: #ffffff;
  --ink: #182230;
  --ink-soft: #67737f;
  --line: #e7eaed;
  --line-strong: #d6dbe0;

  --ok: #177a3d;      --ok-bg: #e6f4ea;
  --warn: #92650f;    --warn-bg: #faf0d9;
  --bad: #b02a24;     --bad-bg: #fbe7e5;
  --info: #235d92;    --info-bg: #e6eff8;

  --radius: 12px;
  --radius-sm: 9px;
  --shadow-1: 0 1px 2px rgba(24, 34, 48, .06);
  --shadow-2: 0 12px 32px rgba(24, 34, 48, .16);
  --sidebar-w: 244px;
  --topbar-h: 54px;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { letter-spacing: -0.015em; margin: 0 0 .5rem; font-weight: 650; }
h1 { font-size: 1.42rem; }
h2 { font-size: 1.05rem; }
a { color: var(--brick-text); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--brick); outline-offset: 2px; border-radius: 4px; }
.icon { flex: none; vertical-align: -3px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ── Marke ───────────────────────────────────────────────────────── */
.login-brand {
  display: flex; align-items: center; gap: .6rem;
  font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; line-height: 1.12;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: grid; place-items: center; color: #fff;
  background: var(--brick);
  background: linear-gradient(150deg, color-mix(in srgb, var(--brick) 88%, #fff), var(--brick-dark));
}

/* ── Login ───────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.2rem;
  background: linear-gradient(170deg, #1a2433, #0e1420 60%);
}
.login-card {
  width: min(400px, 100%); background: var(--card);
  border-radius: 16px; padding: 2rem 1.8rem 1.7rem;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .45);
}
.login-card .login-brand { margin-bottom: 1.4rem; }
.login-hint { color: var(--ink-soft); font-size: .82rem; margin-top: 1rem; }

/* ── App-Rahmen ──────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.content { min-width: 0; display: flex; flex-direction: column; }
.content > .main { flex: 1; }

.sidebar {
  background: var(--nav-bg);
  border-right: 1px solid var(--nav-line);
  color: var(--nav-ink-strong);
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  padding: 1.05rem .75rem .8rem;
  overflow-y: auto; scrollbar-width: thin; scrollbar-color: #2c3a4d transparent;
}
.sidebar .login-brand { color: #fff; margin: 0 .4rem 1.3rem; }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
  color: var(--nav-ink); padding: .5rem .7rem; border-radius: 8px;
  font-weight: 500; font-size: .92rem;
  display: flex; gap: .65rem; align-items: center;
  border-left: 2px solid transparent;
  transition: background .12s ease, color .12s ease;
}
.nav a .icon { opacity: .75; }
.nav a:hover { background: rgba(255, 255, 255, .05); color: #fff; text-decoration: none; }
.nav a:hover .icon { opacity: 1; }
.nav a.active {
  background: rgba(180, 83, 9, .25);
  background: color-mix(in srgb, var(--brick) 22%, transparent);
  border-left-color: var(--brick);
  color: #fff; font-weight: 600;
}
.nav a.active .icon { opacity: 1; color: var(--brick-soft); }
.nav .sep {
  margin: .95rem .7rem .3rem; font-size: .64rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .13em; color: #5c6b7c;
}
.sidebar .foot {
  margin-top: auto; padding: .8rem .45rem 0; font-size: .8rem; color: #7b8a9b;
  border-top: 1px solid var(--nav-line);
}
.sidebar .foot .foot-user { display: flex; align-items: center; gap: .5rem; margin-bottom: .55rem; }
.sidebar .foot .foot-user strong { color: #cbd6e1; font-weight: 600; display: block; }
.sidebar .foot .foot-actions { display: flex; gap: .4rem; }
.sidebar .foot .foot-actions .btn { flex: 1; }

/* ── Topbar (mobil) + Off-Canvas ─────────────────────────────────── */
.nav-toggle, .drawer-toggle { display: none; }
.topbar { display: none; }
.nav-backdrop { display: none; }

/* ── Hauptbereich ────────────────────────────────────────────────── */
.main { padding: 1.5rem 1.9rem 3.2rem; max-width: 1240px; width: 100%; min-width: 0; }
.topline {
  display: flex; justify-content: space-between; align-items: center; gap: .8rem;
  margin-bottom: 1.2rem; flex-wrap: wrap;
}
.topline h1 { margin: 0; }
.topline .who { color: var(--ink-soft); font-size: .87rem; }
.topline .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Impersonation-Banner ────────────────────────────────────────── */
.impersonation-banner {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
  background: #2e2409; color: #f3e3bd;
  padding: .5rem 1rem; font-size: .87rem; font-weight: 500;
  border-bottom: 1px solid rgba(243, 227, 189, .25);
}
.impersonation-banner .btn { margin-left: auto; }

/* ── Bausteine ───────────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; margin-bottom: 1rem; box-shadow: var(--shadow-1);
  min-width: 0;
}
.grid { display: grid; gap: .9rem; }
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }
.kpi .card { margin: 0; padding: .95rem 1.05rem; }
.kpi .num { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi .lbl { color: var(--ink-soft); font-size: .78rem; font-weight: 500; margin-top: .1rem; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1.2rem; padding: 0 1.2rem; }
table { width: 100%; border-collapse: collapse; font-size: .91rem; }
th {
  text-align: left; font-size: .69rem; font-weight: 650; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-soft);
  padding: .45rem .6rem; border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
td { padding: .58rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td, table tr:hover td { background: #f6f8f9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.empty { text-align: left; }

.badge {
  display: inline-block; padding: .14rem .55rem; border-radius: 99px;
  font-size: .74rem; font-weight: 600; background: #edf0f2; color: var(--ink-soft);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.brick { background: var(--brick-soft); color: var(--brick-text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border: 0; cursor: pointer; font: inherit; font-weight: 600; font-size: .9rem;
  padding: .5rem .95rem; border-radius: var(--radius-sm);
  background: var(--brick); color: #fff;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--brick-dark); text-decoration: none; color: #fff; }
.btn.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line-strong); }
.btn.ghost:hover { background: #f1f3f5; border-color: #c3cad1; }
.btn.sm { padding: .3rem .65rem; font-size: .82rem; }
.btn.danger { background: #b02a24; }
.btn.danger:hover { background: #8f1f1a; }

form.inline { display: inline; }
label { display: block; font-size: .8rem; font-weight: 600; margin: .7rem 0 .26rem; }
input, select, textarea {
  width: 100%; padding: .52rem .7rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); font: inherit; background: #fff; color: var(--ink);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brick);
  box-shadow: 0 0 0 3px rgba(180, 83, 9, .2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brick) 18%, transparent);
}
input:disabled, select:disabled, textarea:disabled { background: #f0f2f4; color: var(--ink-soft); cursor: not-allowed; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-actions { margin-top: 1.05rem; display: flex; gap: .6rem; flex-wrap: wrap; }

.errors { background: var(--bad-bg); color: var(--bad); border-radius: var(--radius-sm); padding: .7rem 1rem; margin-bottom: 1rem; }
.errors ul { margin: 0; padding-left: 1.1rem; }

.empty { color: var(--ink-soft); padding: 1.4rem 0; text-align: center; }

/* ── Toasts ──────────────────────────────────────────────────────── */
.toast-stack {
  position: fixed; top: 1rem; right: 1rem; z-index: 200;
  display: flex; flex-direction: column; gap: .5rem; width: min(360px, calc(100vw - 2rem));
}
.toast {
  display: flex; align-items: flex-start; gap: .6rem;
  background: #1c2735; color: #eef3f8;
  border-radius: 10px; padding: .7rem .85rem; font-size: .88rem; font-weight: 500;
  box-shadow: var(--shadow-2);
  animation: toast-in .22s ease;
}
.toast .icon { margin-top: .05rem; }
.toast.ok .icon { color: #5fd08a; }
.toast.bad .icon { color: #ff8d85; }
.toast .toast-close {
  margin-left: auto; background: none; border: 0; color: #9fb0c0; cursor: pointer;
  padding: 0 .1rem; font: inherit; line-height: 1;
}
.toast .toast-close:hover { color: #fff; }
.toast.hide { animation: toast-out .25s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(12px); } }

/* Fallback: alte Flash-Optik, falls irgendwo noch direkt gerendert */
.flash { padding: .7rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.bad { background: var(--bad-bg); color: var(--bad); }

/* ── Einstellungs-Drawer (Slide-over rechts) ─────────────────────── */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 110; background: rgba(13, 19, 28, .5);
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.drawer {
  position: fixed; top: 0; right: 0; z-index: 120; height: 100vh; height: 100dvh;
  width: min(340px, 92vw); background: var(--card);
  box-shadow: var(--shadow-2);
  transform: translateX(103%); transition: transform .22s ease;
  display: flex; flex-direction: column; padding: 1.1rem 1.15rem;
  overflow-y: auto;
}
.drawer-toggle:checked ~ .drawer { transform: translateX(0); }
.drawer-toggle:checked ~ .drawer-backdrop { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.drawer-head h2 { margin: 0; }
.drawer .who-card {
  display: flex; gap: .65rem; align-items: center;
  background: var(--bg); border-radius: 10px; padding: .7rem .8rem; margin-bottom: 1rem;
}
.drawer .who-card .avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; color: #fff;
  background: var(--brick);
}
.drawer .who-card small { color: var(--ink-soft); display: block; }
.drawer-nav { display: flex; flex-direction: column; gap: 2px; }
.drawer-nav a, .drawer-nav button {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  padding: .55rem .6rem; border-radius: 8px; border: 0; background: none;
  font: inherit; font-weight: 500; color: var(--ink); cursor: pointer; text-align: left;
}
.drawer-nav a:hover, .drawer-nav button:hover { background: #f1f3f5; text-decoration: none; }
.drawer-nav .icon { color: var(--ink-soft); }
.drawer-nav .sep { border-top: 1px solid var(--line); margin: .55rem 0; }
.drawer-close { cursor: pointer; color: var(--ink-soft); padding: .25rem; border-radius: 7px; display: inline-flex; }
.drawer-close:hover { background: #f1f3f5; color: var(--ink); }
.settings-gear { display: inline-flex; cursor: pointer; color: inherit; padding: .35rem; border-radius: 8px; }
.settings-gear:hover { background: rgba(255,255,255,.08); }

/* ── Einstellungs-Seiten ─────────────────────────────────────────── */
.settings-layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 1.1rem; align-items: start; }
.settings-menu { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 1rem; }
.settings-menu a {
  display: flex; gap: .55rem; align-items: center; padding: .5rem .65rem;
  border-radius: 8px; color: var(--ink); font-weight: 500; font-size: .92rem;
}
.settings-menu a:hover { background: #eef1f3; text-decoration: none; }
.settings-menu a.active { background: var(--brick-soft); color: var(--brick-text); font-weight: 600; }
.color-row { display: flex; align-items: center; gap: .7rem; }
.color-row input[type=color] { width: 54px; height: 40px; padding: .15rem; flex: none; }
.logo-preview { max-height: 56px; max-width: 200px; border-radius: 8px; border: 1px solid var(--line); padding: .3rem .5rem; background: #fff; }

/* ── Modal ───────────────────────────────────────────────────────── */
.modal-toggle { display: none; }
.modal {
  display: none; position: fixed; inset: 0; background: rgba(13, 19, 28, .55);
  z-index: 130; padding: 4vh 1rem; overflow: auto;
}
.modal-toggle:checked + .modal { display: block; }
.modal .card { max-width: 640px; margin: 0 auto; box-shadow: var(--shadow-2); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4rem; gap: .6rem; }
.modal-close { cursor: pointer; font-size: 1.2rem; color: var(--ink-soft); padding: .1rem .45rem; border-radius: 7px; line-height: 1.3; }
.modal-close:hover { background: #f1f3f5; color: var(--ink); }

/* ── Kalender ────────────────────────────────────────────────────── */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; min-width: 640px; }
.cal .dow { font-size: .69rem; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); padding: .2rem .4rem; }
.cal .day {
  background: var(--card); border: 1px solid var(--line); border-radius: 9px;
  min-height: 92px; padding: .35rem .45rem; font-size: .79rem; min-width: 0;
}
.cal .day.dim { opacity: .45; }
.cal .day.today { border-color: var(--brick); box-shadow: inset 0 0 0 1px var(--brick); }
.cal .dnum { font-weight: 650; margin-bottom: .25rem; }
.cal .evt {
  display: block; background: var(--brick-soft); color: var(--brick-text); border-radius: 5px;
  padding: .1rem .35rem; margin-bottom: 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.cal .evt.besprechung { background: var(--info-bg); color: var(--info); }
.cal .evt.abnahme { background: var(--ok-bg); color: var(--ok); }

/* ── Chat ────────────────────────────────────────────────────────── */
.chat-grid { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 1rem; min-height: 60vh; }
.chan { display: flex; gap: .5rem; align-items: center; padding: .55rem .7rem; border-radius: 8px; color: var(--ink); font-weight: 500; }
.chan:hover { background: #eef1f3; text-decoration: none; }
.chan.active { background: var(--nav-bg); color: #fff; }
.chat-log { display: flex; flex-direction: column; gap: .5rem; max-height: 55vh; overflow-y: auto; padding: .3rem; }
.msg { max-width: 78%; padding: .5rem .8rem; border-radius: 13px 13px 13px 4px; background: #eef1f3; }
.msg.mine { align-self: flex-end; background: var(--brick-soft); border-radius: 13px 13px 4px 13px; }
.msg .meta { font-size: .72rem; color: var(--ink-soft); margin-top: .18rem; }

/* ── Fotogitter ──────────────────────────────────────────────────── */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .8rem; }
.media-grid figure { margin: 0; }
.media-grid img {
  width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 9px;
  border: 1px solid var(--line);
}
.media-grid figcaption { font-size: .78rem; color: var(--ink-soft); margin-top: .28rem; }

/* ── Tabs ────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: .2rem; margin-bottom: 1rem; flex-wrap: wrap;
  background: #e9ecef; border-radius: 10px; padding: .25rem; width: fit-content; max-width: 100%;
}
.tabs a { padding: .4rem .8rem; border-radius: 8px; color: var(--ink-soft); font-weight: 600; font-size: .89rem; white-space: nowrap; }
.tabs a.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow-1); }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* ── Statistik ───────────────────────────────────────────────────── */
.chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 180px; padding: .4rem .2rem 0; min-width: 480px; }
.chart .col { display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; position: relative; }
.chart .bar { border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .bar.a { background: var(--brick); }
.chart .bar.b { background: #c5ced6; }
.chart .cap { font-size: .68rem; color: var(--ink-soft); text-align: center; margin-top: .3rem; }
.chart .col:hover .tip { display: block; }
.chart .tip {
  display: none; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--nav-bg); color: #fff; padding: .3rem .55rem; border-radius: 7px;
  font-size: .72rem; white-space: nowrap; z-index: 5; margin-bottom: 4px; box-shadow: var(--shadow-2);
}
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--ink-soft); margin-top: .5rem; flex-wrap: wrap; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .3rem; }
.hbar { display: flex; align-items: center; gap: .6rem; margin: .38rem 0; }
.hbar .lbl { width: 200px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { flex: 1; background: #e9ecef; border-radius: 6px; height: 16px; overflow: hidden; min-width: 60px; }
.hbar .fill { height: 100%; background: var(--brick); border-radius: 6px; }
.hbar .val { width: 110px; flex: none; text-align: right; font-variant-numeric: tabular-nums; font-size: .85rem; }

/* ═══ Responsive ═════════════════════════════════════════════════── */
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }

  .topbar {
    display: flex; align-items: center; gap: .55rem;
    position: sticky; top: 0; z-index: 70; height: var(--topbar-h);
    background: var(--nav-bg); color: #fff; padding: 0 .8rem;
    border-bottom: 1px solid var(--nav-line);
  }
  .topbar .login-brand { font-size: .95rem; color: #fff; }
  .topbar .brand-mark { width: 28px; height: 28px; border-radius: 7px; }
  .topbar .settings-gear { margin-left: auto; }
  .nav-burger {
    display: inline-flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 40px; height: 40px; padding: 0 11px; border-radius: 9px; cursor: pointer;
  }
  .nav-burger:hover { background: rgba(255, 255, 255, .08); }
  .nav-burger span { display: block; height: 2px; border-radius: 2px; background: #dbe3ea; transition: transform .16s ease, opacity .16s ease; }

  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 90; height: 100vh; height: 100dvh;
    width: min(290px, 84vw);
    transform: translateX(-102%);
    transition: transform .2s ease;
    box-shadow: 0 0 50px rgba(0, 0, 0, .45);
    border-right: 0;
  }
  .nav-toggle:checked ~ .shell .sidebar { transform: translateX(0); }
  .nav-backdrop {
    position: fixed; inset: 0; z-index: 85; background: rgba(13, 19, 28, .5);
    opacity: 0; pointer-events: none; transition: opacity .18s ease; display: block;
  }
  .nav-toggle:checked ~ .nav-backdrop { opacity: 1; pointer-events: auto; }
  .nav-toggle:checked ~ .shell .topbar .nav-burger span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .nav-toggle:checked ~ .shell .topbar .nav-burger span:nth-child(2) { opacity: 0; }
  .nav-toggle:checked ~ .shell .topbar .nav-burger span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

  .main { padding: 1.05rem .95rem 2.4rem; }
  .impersonation-banner { position: static; }
  .chat-grid { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .settings-menu { position: static; flex-direction: row; flex-wrap: wrap; }
  .hbar .lbl { width: 118px; font-size: .84rem; }
  .hbar .val { width: 88px; font-size: .8rem; }
  .table-wrap { margin: 0 -.95rem; padding: 0 .95rem; }
}

@media (max-width: 640px) {
  html { font-size: 14.5px; }
  .form-row { grid-template-columns: 1fr; }
  .grid.kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .kpi .num { font-size: 1.4rem; }
  .topline { flex-direction: column; align-items: stretch; gap: .6rem; }
  .topline .actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
  .topline .actions .btn { width: 100%; }
  .topline > .btn, .topline > form .btn, .topline > label.btn { width: 100%; }
  .modal { padding: 2vh .6rem; }
  .card { padding: .9rem .95rem; }
  .table-wrap { margin: 0 -.95rem; padding: 0 .95rem; }
  .msg { max-width: 92%; }
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); }
  .toast-stack { top: auto; bottom: 1rem; }
}
