:root {
  --bg: #eef2ee;
  --surface: #ffffff;
  --surface-2: #e3eae3;
  --ink: #14201b;
  --ink-2: #4b5a53;
  --ink-3: #64756d;
  --border: rgba(20, 32, 27, 0.12);
  --border-strong: rgba(20, 32, 27, 0.22);
  --accent: #0f766e;
  --accent-text: #115e59;
  --accent-soft: #ccfbf1;
  --ok: #15803d;
  --warn: #b42318;
  --font: 'Schibsted Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
[data-theme="dark"] {
  --bg: #0f1613;
  --surface: #17211d;
  --surface-2: #1f2d27;
  --ink: #ecf2ee;
  --ink-2: #b4c2ba;
  --ink-3: #83958b;
  --border: rgba(236, 242, 238, 0.12);
  --border-strong: rgba(236, 242, 238, 0.24);
  --accent: #14b8a6;
  --accent-text: #5eead4;
  --accent-soft: rgba(20, 184, 166, 0.18);
  --ok: #4ade80;
  --warn: #f87171;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: var(--font); -webkit-font-smoothing: antialiased; overflow-x: hidden; }
a { color: var(--accent-text); }
.skip { position: absolute; left: -999px; }
.skip:focus { position: fixed; left: 10px; top: 10px; z-index: 999; background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 8px; }
.ico { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; fill: none; flex-shrink: 0; }
.hp, .visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.muted { color: var(--ink-2); }

[data-theme="dark"] .ico-sun { display: inline; }
[data-theme="dark"] .ico-moon { display: none; }
:root:not([data-theme="dark"]) .ico-sun { display: none; }
:root:not([data-theme="dark"]) .ico-moon { display: inline; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px; padding: 10px 16px;
  font: inherit; font-size: 0.9rem; font-weight: 700; cursor: pointer;
  background: var(--accent); color: #fff; text-decoration: none; white-space: nowrap;
}
[data-theme="dark"] .btn { color: #052e2b; }
.btn:hover { filter: brightness(0.95); }
.btn:disabled { opacity: 0.55; cursor: wait; }
.btn.secondary { background: var(--surface-2); color: var(--ink); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--border); }
.btn.small, .btn.sm { padding: 7px 12px; font-size: 0.82rem; border-radius: 9px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); cursor: pointer;
}

/* Native App Frame */
.app-frame { display: flex; min-height: 100dvh; }
.app-sidebar {
  position: sticky; top: 0; height: 100dvh; width: 256px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 14px; padding: 18px 14px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.app-side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.app-brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.06rem; color: var(--ink); text-decoration: none; }
.app-side-nav { display: grid; gap: 4px; }
.app-nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; border-radius: 10px;
  padding: 10px 12px; background: transparent; color: var(--ink-2); font: inherit; font-size: 0.92rem; font-weight: 600;
  cursor: pointer; text-align: left;
}
.app-nav-item:hover { background: var(--surface-2); color: var(--ink); }
.app-nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
.app-nav-badge {
  margin-left: auto; font-size: 0.72rem; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink); font-variant-numeric: tabular-nums;
}
.app-side-foot { margin-top: auto; display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.side-sync-card {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 1px solid var(--border);
  border-radius: 12px; background: var(--bg); padding: 9px 10px; cursor: pointer; text-align: left; font: inherit; color: var(--ink);
}
.side-avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 0.92rem; flex-shrink: 0;
}
[data-theme="dark"] .side-avatar { color: #052e2b; }
.side-sync-meta { display: grid; gap: 1px; min-width: 0; }
.side-sync-meta strong { font-size: 0.84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-sync-meta small { font-size: 0.72rem; color: var(--ink-3); display: inline-flex; align-items: center; gap: 5px; }
.app-rail-util {
  border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 0.79rem;
  font-weight: 600; text-align: left; padding: 5px 4px; cursor: pointer; text-decoration: none;
}

.app-stage { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
  position: sticky; top: 0; z-index: 40; height: 56px; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
}
.app-topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-topbar-left h1 { margin: 0; font-size: 1.08rem; font-weight: 800; white-space: nowrap; }
.app-top-ico, .app-mob-theme { display: none; }
.app-topbar-right { display: flex; align-items: center; gap: 8px; }

.sync-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg); color: var(--ink-2); font: inherit; font-size: 0.76rem; font-weight: 700; cursor: pointer;
}
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex-shrink: 0; }
.sync-pill.is-synced .sync-dot, .sync-dot.is-synced { background: #10b981; }
.sync-pill.is-syncing .sync-dot, .sync-dot.is-syncing { background: #f59e0b; }
.sync-pill.is-offline .sync-dot, .sync-dot.is-offline { background: #ef4444; }

.app-canvas { width: 100%; max-width: 1040px; margin: 0 auto; padding: 22px 24px 48px; }
.app-view { display: none; }
.app-view.is-active { display: block; }
.app-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; box-shadow: 0 1px 2px rgba(20,32,27,0.04);
}
.app-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.app-card-head h2, .app-card-head h3 { margin: 0; font-size: 1.08rem; }
.app-card-head p { margin: 3px 0 0; font-size: 0.84rem; color: var(--ink-2); }

.field { display: grid; gap: 5px; font-size: 0.8rem; font-weight: 700; color: var(--ink-2); min-width: 0; }
.field input, .field select, .field textarea {
  width: 100%; min-width: 0; font: inherit; font-size: 0.9rem; font-weight: 500;
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--ink);
}
.row-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

/* Timer Hero */
.rp-timer-hero {
  display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 20px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 22px;
}
.eyebrow { display: inline-block; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; color: var(--accent-text); text-transform: uppercase; }
.rp-clock { display: block; font-size: clamp(2.2rem, 5vw, 3.1rem); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; margin: 4px 0; }
.rp-timer-inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.rp-timer-inputs .field:first-child { grid-column: 1 / -1; }
.rp-timer-btns { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }

.rp-manual-form {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.2fr) 96px 86px 132px auto; gap: 8px; align-items: center;
}
.rp-manual-form input {
  width: 100%; min-width: 0; font: inherit; font-size: 0.85rem; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--ink);
}

.rp-time-list, .rp-arch-list { display: grid; gap: 8px; }
.rp-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 11px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg);
}
.rp-row-main { display: grid; gap: 2px; min-width: 0; }
.rp-row-main small { color: var(--ink-2); font-size: 0.8rem; }
.rp-row-acts { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sb-del { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; font: inherit; font-size: 0.9rem; font-weight: 700; padding: 4px 8px; border-radius: 7px; }
.sb-del:hover { background: var(--surface-2); color: var(--warn); }
.sb-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.sb-pill.is-ok { color: var(--ok); }
.sb-empty-msg { padding: 14px; border: 1px dashed var(--border-strong); border-radius: 12px; color: var(--ink-2); font-size: 0.86rem; }

/* Regierapport */
.rp-head-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.rp-sec-h { font-size: 0.92rem; margin: 16px 0 8px; }
.rp-items-wrap { display: grid; gap: 8px; }
.rp-item-row {
  display: grid; grid-template-columns: minmax(0, 1.8fr) 84px 76px 96px 86px 32px; gap: 6px; align-items: center;
}
.rp-item-row input, .rp-item-row select {
  width: 100%; min-width: 0; font: inherit; font-size: 0.84rem; padding: 8px 9px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--ink);
}
.rp-item-sum { font-size: 0.84rem; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rp-total-bar {
  display: flex; justify-content: space-between; align-items: center; margin-top: 12px;
  padding: 11px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); font-weight: 700;
}
.rp-total-bar strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.rp-media-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 14px; }
.rp-photo-prev { margin-top: 10px; max-width: 100%; max-height: 180px; border-radius: 10px; border: 1px solid var(--border); object-fit: cover; }
.rp-sig-pad {
  width: 100%; height: 150px; border: 1px dashed var(--border-strong); border-radius: 10px;
  background: #ffffff; touch-action: none; cursor: crosshair; display: block;
}

.rp-legal-foot { margin-top: 20px; text-align: center; font-size: 0.78rem; color: var(--ink-3); }

/* Modals + Toast + PWA */
.modal-backdrop { position: fixed; inset: 0; z-index: 900; background: rgba(15, 22, 19, 0.55); display: grid; place-items: center; padding: 16px; }
.modal-backdrop[hidden] { display: none; }
.modal-card { width: 100%; max-width: 440px; max-height: 92dvh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 16px; padding: 20px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.modal-head h2 { margin: 0; font-size: 1.12rem; }
.auth-hint { margin: 0 0 12px; font-size: 0.85rem; color: var(--ink-2); }
.auth-err { margin: 0; font-size: 0.82rem; font-weight: 600; color: var(--warn); min-height: 1.1em; }
.pwa-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.pwa-tab { border: 1px solid var(--border); background: var(--bg); color: var(--ink-2); padding: 8px; border-radius: 9px; font: inherit; font-size: 0.82rem; font-weight: 700; cursor: pointer; }
.pwa-tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent); }
.pwa-steps ol { margin: 0; padding-left: 18px; display: grid; gap: 8px; font-size: 0.86rem; line-height: 1.45; }

.sb-toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 16px); z-index: 960;
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 999px;
  font-size: 0.84rem; font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.sb-toast.show { opacity: 1; transform: translate(-50%, 0); }

.pwa-update-bar {
  position: fixed; right: 20px; bottom: 20px; z-index: 950;
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px);
  padding: 12px 14px; border-radius: 14px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border-strong); box-shadow: 0 14px 36px rgba(16, 26, 20, 0.22);
}
.pwa-update-bar[hidden] { display: none !important; }
.pwa-upd-txt { display: grid; gap: 2px; font-size: 0.84rem; }
.pwa-upd-txt span { color: var(--ink-2); font-size: 0.78rem; }
.pwa-upd-acts { display: flex; align-items: center; gap: 6px; }
.pwa-upd-close { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; width: 28px; height: 28px; font-size: 1.15rem; }

.app-bottom-bar { display: none; }
@media (max-width: 899px) {
  .app-sidebar { display: none; }
  .app-top-ico, .app-mob-theme { display: inline-flex; }
  .app-topbar { padding: 0 14px; }
  .app-canvas { padding: 14px 14px calc(82px + env(safe-area-inset-bottom)); }
  .sb-toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .pwa-update-bar { bottom: calc(74px + env(safe-area-inset-bottom)); right: 14px; left: 14px; justify-content: space-between; }
  .rp-timer-hero, .rp-media-grid, .row-3, .row-2 { grid-template-columns: 1fr; }
  .rp-manual-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rp-manual-form input:first-child, .rp-manual-form button { grid-column: 1 / -1; }
  .rp-item-row { grid-template-columns: minmax(0, 1fr) 74px 68px; }
  .rp-item-row input:first-child { grid-column: 1 / -1; }
  .app-bottom-bar {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: color-mix(in srgb, var(--surface) 95%, transparent); backdrop-filter: blur(14px);
    border-top: 1px solid var(--border); padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .app-bnav-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    border: 0; border-radius: 10px; background: transparent; color: var(--ink-2);
    font: inherit; font-size: 0.7rem; font-weight: 600; padding: 6px 2px; cursor: pointer;
  }
  .app-bnav-btn[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
}

html.is-pwa-installed .pwa-install-only,
html.is-pwa-installed #pwaOpenBtn,
html.is-pwa-installed [data-open-pwa],
html.is-standalone .pwa-install-only,
html.is-standalone #pwaOpenBtn,
html.is-standalone [data-open-pwa],
html.is-standalone .hide-standalone { display: none !important; }
@media (display-mode: standalone), (display-mode: window-controls-overlay), (display-mode: minimal-ui) {
  #pwaOpenBtn, [data-open-pwa], .pwa-install-only, .hide-standalone { display: none !important; }
}

/* Prose legal pages */
.prose-body { padding: 28px 18px; max-width: 760px; margin: 0 auto; line-height: 1.65; }
.prose-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 26px; }

/* A4 Print Regierapport */
.rp-print-sheet { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; color: #111; }
  .app-sidebar, .app-topbar, .app-bottom-bar, .no-print { display: none !important; }
  .app-canvas { padding: 0; max-width: none; }
  .app-view { display: none !important; }
  #v-rapport { display: block !important; }
  .rp-print-sheet { display: block !important; font-family: var(--font); color: #111; }
  .rp-p-head { display: flex; justify-content: space-between; border-bottom: 2px solid #0f766e; padding-bottom: 12px; margin-bottom: 18px; }
  .rp-p-table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 13px; }
  .rp-p-table th, .rp-p-table td { border-bottom: 1px solid #d5ddd9; padding: 7px 6px; text-align: left; }
  .rp-p-table th:last-child, .rp-p-table td:last-child { text-align: right; }
  .rp-p-sig { margin-top: 22px; display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; }
  .rp-p-sig img { max-height: 90px; border-bottom: 1px solid #333; }
}
