:root {
  --bg: #f6f1e9;
  --surface: #fffdf9;
  --surface-2: #efe7da;
  --ink: #2a2420;
  --muted: #7a6f65;
  --line: #e0d5c5;
  --accent: #b4532a;
  --accent-ink: #ffffff;
  --accent-soft: #f4e2d6;
  --olive: #5f6b3a;
  --ok: #3f7a4d;
  --ok-soft: #e0efe2;
  --warn: #b3261e;
  --warn-soft: #f9e1de;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1815;
    --surface: #26211d;
    --surface-2: #322b26;
    --ink: #f1e9df;
    --muted: #a99c8f;
    --line: #40372f;
    --accent: #d9774a;
    --accent-ink: #1c1815;
    --accent-soft: #46291b;
    --olive: #a8b672;
    --ok: #7fc08d;
    --ok-soft: #22382a;
    --warn: #f2867d;
    --warn-soft: #472320;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
svg.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Knappar och fält */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--accent); padding: 0 8px; }
.btn.danger { color: var(--warn); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; flex: none; }
a.icon-btn { color: inherit; }
.icon-btn.on { background: var(--accent); color: var(--accent-ink); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px; font-weight: 400; color: var(--ink);
}
textarea { resize: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.notice { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 48px 24px; }

/* Inloggning */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px calc(24px + var(--safe-b)); }
.auth .card { width: 100%; max-width: 400px; padding: 22px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.brand img { width: 44px; height: 44px; border-radius: 11px; }
.brand h1 { font-size: 26px; letter-spacing: -.01em; }

/* Skal */
.shell { height: 100dvh; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; }
.top { display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--safe-t)) 12px 8px 16px; border-bottom: 1px solid var(--line); background: var(--bg); }
.top .title { font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top select { border: 0; background: transparent; font-weight: 700; font-size: 18px; padding: 0 4px 0 0; min-height: 40px; width: auto; max-width: 100%; }
.banner { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--ok-soft); color: var(--ok); font-weight: 600; font-size: 14px; border: 0; width: 100%; text-align: left; }
.view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 14px 24px; }
.view.flush { padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.tabs { display: flex; border-top: 1px solid var(--line); background: var(--surface); padding-bottom: var(--safe-b); }
.tabs button { flex: 1; border: 0; background: none; padding: 8px 2px 7px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); min-width: 0; }
.tabs button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs button[aria-current=page] { color: var(--accent); }

/* Chatt */
.msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 84%; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg .who { font-size: 12px; color: var(--muted); margin: 0 6px 2px; }
.msg.mine .who { text-align: right; }
.bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 18px 18px 18px 6px; padding: 9px 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine .bubble { background: var(--accent-soft); border-color: transparent; border-radius: 18px 18px 6px 18px; }
.bubble .orig { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 14px; }
.bubble .pending { color: var(--muted); font-size: 13px; font-style: italic; }
.msg .meta { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--muted); margin: 2px 6px 0; }
.msg.mine .meta { justify-content: flex-end; }
.msg .meta button { border: 0; background: none; padding: 4px 0; color: var(--accent); font-size: 12px; font-weight: 600; }
.file-chip { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 10px; width: 100%; text-align: left; font-weight: 600; font-size: 14px; }
.file-chip + .text { margin-top: 6px; }
.file-chip img { width: 100%; max-height: 220px; object-fit: cover; border-radius: 6px; display: block; }
.file-chip.photo { padding: 4px; }
.composer { display: flex; align-items: flex-end; gap: 4px; padding: 8px 8px calc(8px + 0px); border-top: 1px solid var(--line); background: var(--surface); }
.composer textarea { border-radius: 20px; max-height: 140px; min-height: 44px; }
.composer .send { background: var(--accent); color: var(--accent-ink); }
.composer .listening { background: var(--warn); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .composer .listening { animation: none; } }

/* Listor */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip[aria-pressed=true] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; width: 100%; text-align: left; }
.item .thumb { width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; color: var(--accent); flex: none; font-size: 11px; font-weight: 800; letter-spacing: .03em; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 700; background: var(--surface-2); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.due { background: var(--accent-soft); color: var(--accent); }
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.totals .num { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.invoice summary { list-style: none; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.invoice summary::-webkit-details-marker { display: none; }
.invoice .amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.invoice dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 12px 0; font-size: 14px; }
.invoice dt { color: var(--muted); }
.invoice dd { margin: 0; overflow-wrap: anywhere; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--olive); color: var(--bg); display: grid; place-items: center; font-weight: 700; flex: none; }
.linkbox { background: var(--surface-2); border-radius: 10px; padding: 10px; font-size: 13px; overflow-wrap: anywhere; user-select: all; }

/* Lager: dokumentvisare, dialoger och videomöte */
#layer:empty { display: none; }
.sheet-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: end center; z-index: 30; }
.sheet { background: var(--bg); width: 100%; max-width: 520px; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); max-height: 90dvh; overflow-y: auto; }
@media (min-width: 600px) { .sheet-back { place-items: center; } .sheet { border-radius: 20px; } }
.viewer { position: fixed; inset: 0; background: var(--surface-2); z-index: 20; display: flex; flex-direction: column; }
.viewer .bar { display: flex; align-items: center; gap: 4px; padding: calc(6px + var(--safe-t)) 8px 6px; background: var(--bg); border-bottom: 1px solid var(--line); }
.viewer .bar .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer .tools { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; border-radius: 8px; padding: 6px 14px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button[aria-pressed=true] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.pages { flex: 1; overflow: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.page { position: relative; margin: 0 auto 12px; background: #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, .18); }
.page canvas { display: block; width: 100%; height: 100%; }
.page .ov { position: absolute; inset: 0; overflow: hidden; }
.page.original .ov { display: none; }
.blk { position: absolute; line-height: 1.2; font-family: Helvetica, Arial, sans-serif; overflow-wrap: break-word; }
.blk.one { white-space: nowrap; }
.clip-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px; overflow: auto; }
.clip { position: relative; width: 100%; max-width: 900px; background: #000; border-radius: 14px; overflow: hidden; }
.clip video { display: block; width: 100%; max-height: 62vh; }
.clip.sound video { height: 56px; }
.clip .sub { position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%); max-width: 92%; padding: 4px 10px; border-radius: 8px; background: rgba(0, 0, 0, .72); color: #fff; font-size: clamp(15px, 2.6vw, 21px); font-weight: 600; line-height: 1.3; text-align: center; pointer-events: none; }
.clip.sound .sub { position: static; transform: none; max-width: none; border-radius: 0; }
.lines { width: 100%; max-width: 900px; display: flex; flex-direction: column; gap: 2px; }
.lines .line { display: flex; gap: 10px; text-align: left; border: 0; background: none; color: var(--ink); padding: 8px 10px; border-radius: 10px; font-size: 15px; line-height: 1.35; }
.lines .line.on { background: var(--accent-soft); }
.lines .at { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 38px; }
.status-line { padding: 10px 14px; background: var(--accent-soft); font-size: 14px; display: flex; align-items: center; gap: 10px; }

.call { position: fixed; inset: 0; z-index: 40; background: #14110f; color: #fff; display: flex; flex-direction: column; }
.call .grid { flex: 1; display: grid; gap: 6px; padding: calc(6px + var(--safe-t)) 6px 6px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); grid-auto-rows: 1fr; min-height: 0; }
.call .tile { position: relative; background: #26211d; border-radius: 14px; overflow: hidden; min-height: 0; }
.call video { width: 100%; height: 100%; object-fit: cover; display: block; }
.call .tile.me video { transform: scaleX(-1); }
.call .tag { position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, .55); border-radius: 8px; padding: 2px 8px; font-size: 13px; font-weight: 600; }
.call .caps { padding: 6px 14px; min-height: 64px; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; font-size: 17px; }
.call .caps b { color: #f0b796; font-weight: 600; }
.call .caps .live { color: #a99c8f; font-style: italic; }
.call .voice-hint { padding: 4px 14px; font-size: 13px; color: #a99c8f; text-align: center; }
.call .mode-row { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 4px 10px; color: #a99c8f; }
.call .seg { background: #26211d; }
.call .seg button { color: #cfc4b8; }
.call .seg button[aria-pressed=true] { background: #f0b796; color: #14110f; box-shadow: none; }
.call .caps .hint { font-size: 13px; color: #a99c8f; }
.call .controls { display: flex; justify-content: center; gap: 14px; padding: 10px 10px calc(14px + var(--safe-b)); }
.call .controls button { width: 54px; height: 54px; border-radius: 50%; border: 0; background: #3a322c; color: #fff; display: grid; place-items: center; }
.call .controls button.off { background: #fff; color: #14110f; }
.call .controls button.hang { background: #c5392f; width: 70px; border-radius: 27px; }

#toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; }

@media print {
  body { background: #fff; }
  #app, #toast, .viewer .bar, .viewer .tools, .status-line { display: none !important; }
  .viewer { position: static; background: #fff; display: block; }
  .pages { overflow: visible; padding: 0; }
  .page { box-shadow: none; margin: 0; page-break-after: always; break-after: page; max-width: 100%; }
}

/* Samtal, siffror på flikar och aviseringsfråga */
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; font-style: normal; }
.tabs .ic-wrap { position: relative; display: grid; }
.tabs .badge { position: absolute; top: -5px; left: 14px; }
.chips.threads { padding: 8px 12px; border-bottom: 1px solid var(--line); flex: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed=true] .badge { background: var(--bg); color: var(--ink); }
.chip.add { padding: 4px 8px; }
.chip.add svg { width: 18px; height: 18px; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); display: inline-block; flex: none; }
.live-dot.big { width: 16px; height: 16px; background: var(--warn); animation: pulse 1.2s infinite; }
.rec-time { font-variant-numeric: tabular-nums; color: var(--muted); }
.banner.ask { background: var(--accent-soft); color: var(--ink); font-weight: 400; flex-wrap: wrap; }
.banner.ask .grow { min-width: 180px; }
.msg.sys { align-self: center; max-width: 94%; width: 100%; }
.msg.sys .text { white-space: pre-wrap; }
.msg.found .bubble, .msg.found .card { outline: 2px solid var(--accent); }
label.item { cursor: pointer; }
label.item input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
input[type=text], textarea { min-width: 0; }

/* Fotodagbok */
h3.day { font-size: 14px; color: var(--muted); font-weight: 600; }
h3.day::first-letter { text-transform: uppercase; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; }
.photos button { position: relative; aspect-ratio: 1; border: 0; padding: 0; border-radius: 10px; overflow: hidden; background: var(--surface-2); color: var(--accent); display: grid; place-items: center; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .tag { position: absolute; left: 4px; bottom: 4px; max-width: calc(100% - 8px); background: rgba(0, 0, 0, .6); color: #fff; border-radius: 6px; padding: 1px 6px; font-size: 11px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photos .badge { position: absolute; top: 4px; right: 4px; }

/* Markeringar i dokument */
.page .notes { position: absolute; inset: 0; pointer-events: none; }
.ring { position: absolute; pointer-events: auto; border: 3px solid #d6401f; border-radius: 50%; background: rgba(214, 64, 31, .08); padding: 0; min-width: 22px; min-height: 22px; }
.ring span { position: absolute; top: -11px; left: -11px; min-width: 22px; height: 22px; border-radius: 11px; background: #d6401f; color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.ring.draft { pointer-events: none; border-style: dashed; }
.pages.marking .page { touch-action: none; cursor: crosshair; }
.pages.marking .ring { pointer-events: none; }

/* Ekonomi, beslut och helskärmsvyer */
.bar-track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-track i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.bar-track.over i { background: var(--warn); }
.decision .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.decision.done { opacity: .7; }
.decision .btn svg { width: 16px; height: 16px; }
.panel { max-width: 760px; margin: 0 auto; }
.viewer .lines .line b { font-weight: 600; }
@media print { .page .notes { display: none; } }

/* Rotavdrag */
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.rot-steps { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 8px; font-size: 14px; }
.rot-dl { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: 14px; }
.rot-dl dt { font-weight: 600; }
.rot-dl dt .muted { font-weight: 400; }
.rot-dl dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.checks { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.checks legend { font-size: 13px; color: var(--muted); font-weight: 600; padding: 0; margin-bottom: 6px; }
label.check { display: flex; align-items: flex-start; gap: 10px; font-size: 15px; min-height: 32px; cursor: pointer; }
label.check input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; margin-top: 1px; }
.rot-calc { background: var(--surface-2); }
a.item { color: inherit; text-decoration: none; }
a.item .name { white-space: normal; }
a.item .ic { flex: none; color: var(--accent); }
@media (max-width: 480px) { .rot-dl { grid-template-columns: 1fr; gap: 2px; } .rot-dl dd { margin-bottom: 8px; } }
.panel .grid2 { align-items: end; }
.panel .grid2 > * { min-width: 0; }
.panel .grid2 input, .panel .grid2 select { min-width: 0; width: 100%; box-sizing: border-box; }
