/* Motaro försäljningssystem. Ljust och mörkt tema – följer datorn om inget annat valts under Mitt konto. */
:root {
  /* Ljust tema (standard) */
  --bg: #f4f4f6;
  --panel: #ffffff;
  --panel-2: #eeeef1;
  --line: #d9d9df;
  --text: #16161a;
  --muted: #55555e;
  --accent: #16161a;
  --accent-ink: #ffffff;
  --focus: #2f6bff;
  --ok: #16804f;
  --warn: #9a6200;
  --err: #c2332b;
  --topbar: rgba(244,244,246,.94);
  --shadow: 0 1px 2px rgba(0,0,0,.05);
  --radius: 10px;
  --side-w: 14.5rem;
  --side-w-min: 4rem;
  font-synthesis: none;
  color-scheme: light;
}

/* Mörkt tema – högre kontrast än tidigare för bättre läsbarhet */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111114; --panel: #1b1b1f; --panel-2: #25252a; --line: #36363d;
    --text: #f3f3f5; --muted: #b8b8c2; --accent: #ffffff; --accent-ink: #111114;
    --focus: #7aa2ff; --ok: #4cc98d; --warn: #f0b64a; --err: #ff6b62;
    --topbar: rgba(17,17,20,.94); --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111114; --panel: #1b1b1f; --panel-2: #25252a; --line: #36363d;
  --text: #f3f3f5; --muted: #b8b8c2; --accent: #ffffff; --accent-ink: #111114;
  --focus: #7aa2ff; --ok: #4cc98d; --warn: #f0b64a; --err: #ff6b62;
  --topbar: rgba(17,17,20,.94); --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
html { font-size: 16px; }
/* Mycket breda skärmar (t.ex. 4K utan skalning): lite större text så att allt inte blir pyttelitet */
@media (min-width: 2600px) { html { font-size: 18px; } }
@media (min-width: 3300px) { html { font-size: 21px; } }
body { font: 1rem/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.ic { width: 1.25rem; height: 1.25rem; flex: none; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.side {
  width: var(--side-w); background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  transition: width .15s ease; z-index: 20;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; text-decoration: none; }
.side-brand img { max-height: 34px; max-width: 100%; }
.side-brand .mark { width: 30px; height: 30px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; }
.side-brand .word { font-weight: 800; letter-spacing: .14em; color: var(--muted); }
.side nav, .side-foot { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; }
.side nav { flex: 1; overflow-y: auto; }
.side-foot { border-top: 1px solid var(--line); padding-bottom: 12px; }
.side a, .collapse-btn {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px;
  text-decoration: none; color: var(--muted); white-space: nowrap; overflow: hidden;
  background: none; border: 0; font: inherit; cursor: pointer; text-align: left;
}
.side a:hover, .collapse-btn:hover { background: var(--panel-2); color: var(--text); }
.side a.active { background: var(--panel-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.app.collapsed .side { width: var(--side-w-min); }
.app.collapsed .side span, .app.collapsed .side-brand .word { display: none; }
.app.collapsed .side-brand img { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; background: var(--topbar); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.theme-btn { display: inline-flex; align-items: center; gap: 8px; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font: inherit; font-size: .9em; font-weight: 600; cursor: pointer; white-space: nowrap; }
.theme-btn:hover { border-color: var(--muted); }
.theme-btn .t-dark { display: none; }
:root[data-theme="dark"] .theme-btn .t-light { display: none; }
:root[data-theme="dark"] .theme-btn .t-dark { display: inline-flex; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .t-light { display: none; }
  :root:not([data-theme="light"]) .theme-btn .t-dark { display: inline-flex; }
}
.theme-btn span { display: inline-flex; }
@media (max-width: 600px) { .theme-btn .t-label { display: none; } }
.menu-btn { display: none; background: none; border: 0; color: var(--text); padding: 6px; cursor: pointer; }
.content { padding: clamp(16px, 1.6vw, 36px); width: 100%; }
/* Sidor med mest text (formulär i ett steg, inloggning m.m.) kan välja en smalare läsbredd */
.content.narrow, .narrow { max-width: 980px; }

/* ---------- Snabbsök ---------- */
.search { position: relative; flex: 1; max-width: 48rem; display: flex; align-items: center; }
.search > .ic { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search input { width: 100%; padding: 10px 12px 10px 40px; font-size: 1rem; }
.results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0,0,0,.25);
  max-height: 70vh; overflow-y: auto; padding: 6px;
}
.result { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px; border-radius: 8px; }
.result.sel, .result:hover { background: var(--panel-2); }
.result .title { font-weight: 600; }
.result .sub { color: var(--muted); font-size: .85em; }
.result .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.result-empty { padding: 12px; color: var(--muted); }

/* ---------- Komponenter ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--err); }
.btn.sm { padding: 5px 10px; font-size: .85em; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { width: 1.125rem; height: 1.125rem; padding: 0; flex: none; margin: 0; accent-color: var(--accent); }
label.check > span { flex: 1; }
label { display: flex; flex-direction: column; gap: 5px; font-size: .9em; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 1rem; line-height: 1.4; cursor: pointer; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 14px; }
.grid2 > .full, .form-grid > .full { grid-column: 1 / -1; }
/* Formulärfält sida vid sida – fler kolumner ju bredare rutan är */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 14px 16px; align-items: end; }
.form-grid.wide { grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2, .card-head h3 { margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 16px; margin-bottom: 16px; }
.cards .card { margin: 0; }

/* ---------- Flytande sidlayout ----------
   cols  : rutor som delar raden lika och får fler kolumner på bredare skärmar
   split : huvudinnehåll + sidopanel (sidopanelen hamnar under på smala skärmar)
   Ingen fast maxbredd – sidan fyller skärmen från 1080p upp till 4K. */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 21rem), 1fr)); gap: 16px; margin-bottom: 16px; align-items: start; }
.cols.stretch { align-items: stretch; }
.cols.wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 35rem), 1fr)); }
.cols.md { grid-template-columns: repeat(auto-fit, minmax(min(100%, 27.5rem), 1fr)); }
.cols > .card, .split > .card, .split > * > .card:last-child, .cols > * > .card:last-child { margin-bottom: 0; }
.cols > .span-2 { grid-column: span 2; }
.cols > .full { grid-column: 1 / -1; }
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; margin-bottom: 16px; }
.split > * { min-width: 0; }
@media (min-width: 1440px) {
  .split { grid-template-columns: minmax(0, 1fr) clamp(20rem, 26vw, 34rem); }
  .split.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .split.left { grid-template-columns: clamp(20rem, 26vw, 34rem) minmax(0, 1fr); }
  .split > .sticky { position: sticky; top: 84px; }
}
@media (max-width: 760px) { .cols > .span-2 { grid-column: auto; } }

/* Nyckel/värde i rutnät i stället för långa listor */
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: 0; }
.kv > div { padding: 10px 12px; min-width: 0; box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line); }
.kv dt { color: var(--muted); font-size: .78em; font-weight: 600; margin: 0 0 2px; }
.kv dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.kv dd.empty-v { color: var(--muted); font-weight: 400; }
.kv.big dd { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
/* Lista med etikett till vänster (sammanfattningar) */
.lines { width: 100%; }
.lines th { width: 40%; }
table.compact th, table.compact td { padding: 7px 4px; }
table.lines tr.sum th, table.lines tr.sum td { font-weight: 700; color: var(--text); }
.checklist { list-style: none; margin: 14px 0 0; padding: 12px 0 0; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.checklist li { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.checklist li::before { content: ""; width: 18px; height: 18px; flex: none; border-radius: 50%; border: 2px solid var(--line); box-sizing: border-box; }
.checklist li.done { color: var(--text); }
.checklist li.done::before { background: var(--ok); border-color: var(--ok); box-shadow: inset 0 0 0 3px var(--panel); }
.split-main > .card:last-child { margin-bottom: 0; }
.split > aside .card { margin: 0; }
.actions-stack { display: flex; flex-direction: column; gap: 8px; }
.actions-stack form, .actions-stack .btn { width: 100%; }
.actions-stack form.row { flex-wrap: nowrap; }
.actions-stack form.row input { max-width: none !important; }
@media (max-width: 1439px) { .hide-narrow { display: none; } }
.page-head { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-head .spacer { min-width: 12px; }
.back { display: inline-block; margin-bottom: 10px; color: var(--muted); text-decoration: none; }
.back:hover { color: var(--text); text-decoration: underline; }
.section-title { display: flex; align-items: center; gap: 10px; margin: 6px 0 10px; }
.section-title h2 { margin: 0; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78em; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.warn { color: var(--warn); border-color: currentColor; }
.badge.err { color: var(--err); border-color: currentColor; }

.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--line); background: var(--panel); }
.alert.ok { border-color: var(--ok); border-left-width: 4px; }
.alert.err { border-color: var(--err); border-left-width: 4px; }
.alert.warn { border-color: var(--warn); border-left-width: 4px; }
.alert.info { border-color: var(--focus); border-left-width: 4px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .85em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-color: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat a, a.stat { text-decoration: none; }
a.stat:hover { border-color: var(--muted); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .v { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .85em; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--text); }

.secret { font-family: ui-monospace, Menlo, monospace; color: var(--muted); }
.keybox { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; user-select: all; }

/* ---------- Inloggning ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px 28px; }
.brand-big { font-weight: 800; letter-spacing: .2em; font-size: 1.4rem; margin-bottom: 18px; color: var(--muted); }
.auth-logo { max-width: 180px; margin-bottom: 18px; }

/* ---------- Mobil / iPad ---------- */
@media (max-width: 900px) {
  .side { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease; width: var(--side-w) !important; }
  .app.open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); }
  .app.collapsed .side span, .app.collapsed .side-brand .word { display: inline; }
  .collapse-btn { display: none; }
  .menu-btn { display: block; }
  .top { padding: 10px 16px; }
  .content { padding: 16px; }
}

/* ---------- Utskrift (avtal) ---------- */
@media print {
  .side, .top, .no-print { display: none !important; }
  body, .content { background: #fff !important; color: #000 !important; padding: 0 !important; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
}

/* ---------- Fordonspanel ---------- */
.vpanel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: clamp(16px, 1.4vw, 26px); margin-bottom: 16px; box-shadow: var(--shadow); }
.vp-head { display: flex; align-items: center; gap: 12px 18px; flex-wrap: wrap; }
.vp-title h2 { margin: 0; font-size: 1.45rem; letter-spacing: -.01em; }
.vp-title .muted { margin-top: 2px; }
.vp-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; font-size: .85em; }
.vp-meta .row { justify-content: flex-end; }
.vp-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; font-size: .82em; font-weight: 650; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: color-mix(in srgb, var(--ok) 10%, var(--panel)); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 10%, var(--panel)); }
.chip.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, transparent); background: color-mix(in srgb, var(--err) 10%, var(--panel)); }
.vp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: 14px; margin-top: 14px; }
.vp-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: color-mix(in srgb, var(--panel-2) 35%, var(--panel)); min-width: 0; }
.vp-card h3 { margin: 0 0 10px; font-size: .95rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.vp-card .kv { background: var(--panel); }
.owner-main { display: grid; gap: 3px; }
.owner-name { font-size: 1.2rem; font-weight: 700; }
.owner-real { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.vp-all { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.vp-all > summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.kv .span-all { grid-column: 1 / -1; }
.kv.nested { margin-top: 4px; }
.raw-list { margin: 0; padding-left: 1.3em; display: grid; gap: 8px; }

/* Svensk regskylt */
.plate { display: inline-flex; align-items: stretch; border: 2px solid #1b1b1b; border-radius: 6px; overflow: hidden; background: #fff; color: #111; font-weight: 800; letter-spacing: .08em; line-height: 1; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.plate .eu { background: #1f4fb6; color: #fff; font-size: .7em; padding: 0 6px; display: flex; align-items: flex-end; padding-bottom: 5px; letter-spacing: 0; }
.plate .txt { padding: 8px 12px; font-size: 1.35rem; font-family: "DIN Alternate", "Arial Narrow", Arial, sans-serif; }

/* Tidslinje (ägare, händelser) */
.timeline { list-style: none; margin: 0; padding: 0 0 0 16px; border-left: 2px solid var(--line); display: grid; gap: 12px; }
.timeline li { position: relative; }
.timeline li::before { content: ""; position: absolute; left: -23px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--panel); border: 2px solid var(--muted); }
.timeline li.now::before { background: var(--ok); border-color: var(--ok); }
.timeline .t-date { font-size: .8em; color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline .t-body { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }

/* Val-kort (radioknappar som stora knappar) */
.choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 10px; }
.choice label { flex-direction: row; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); font-size: 1rem; cursor: pointer; }
.choice label:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--panel)); }
.choice label small { display: block; color: var(--muted); font-size: .82em; margin-top: 2px; }
.choice input { margin-top: 3px; }
.verified { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font-weight: 650; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; }
.suggest button { font: inherit; font-size: .9em; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); cursor: pointer; }
.suggest button:hover { border-color: var(--accent); }
[data-show] { }
.cond[hidden] { display: none !important; }

/* ---------- Översikten: kort i samma rad blir lika höga ---------- */
.dash > .card { display: flex; flex-direction: column; min-height: 100%; }
.dash > .card > table { margin-top: 2px; }
.dash > .card .card-head { min-height: 32px; }
.dash > .card > h2 { min-height: 32px; display: flex; align-items: center; margin-bottom: 14px; }
.dash table td { padding: 9px 6px; white-space: nowrap; }
.dash table tr:last-child td { border-bottom: 0; }
.dash td:first-child { max-width: 0; width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash .todo-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.dash .card-head + .todo-row { border-top: 0; }
.dash .foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }

/* ---------- Fordonslistor (lager, sälj bil, inköp, försäljning, rapporter) ----------
   Varje rad är ett kort med skylt, titel och små nyckeltal. Hela raden är klickbar (data-href). */
.page-head .sub { flex-basis: 100%; color: var(--muted); margin: -4px 0 0; }
.toolbar { display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap; margin: 0 0 12px; }
.toolbar input[type=search] { max-width: 20rem; }
.toolbar select { width: auto; }
.period-form { flex-wrap: nowrap; gap: 6px; }
.period-form input { width: auto; padding: 6px 9px; }
.seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; max-width: 100%; overflow-x: auto; }
.seg a { display: inline-flex; align-items: center; gap: 7px; padding: 6px 13px; border-radius: 7px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .9em; white-space: nowrap; }
.seg a:hover { color: var(--text); }
.seg a.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--line); }
.seg .n { min-width: 1.5em; padding: 0 6px; border-radius: 999px; background: var(--line); color: var(--text); font-size: .78em; text-align: center; line-height: 1.6; }
.seg a.active .n { background: var(--accent); color: var(--accent-ink); }

.vlist { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; margin-bottom: 16px; }
.vlist-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.vlist-head h2 { margin: 0; font-size: 1.05rem; }
.vrow { display: flex; align-items: center; gap: 12px 26px; flex-wrap: wrap; padding: 14px 18px; border-top: 1px solid var(--line); transition: background .12s ease; }
.vlist > .vrow:first-child, .vlist-head + .vrow { border-top: 0; }
.vrow[data-href] { cursor: pointer; }
.vrow[data-href]:hover { background: color-mix(in srgb, var(--panel-2) 60%, var(--panel)); }
.vrow[data-href]:hover .v-chev { color: var(--text); transform: translateX(2px); }
.vrow[hidden] { display: none; }
.v-id { display: flex; align-items: center; gap: 14px; flex: 1 1 18rem; min-width: 0; }
.v-txt { min-width: 0; }
.v-title { display: block; font-weight: 650; font-size: 1.02rem; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
a.v-title:hover { text-decoration: underline; }
.v-sub { color: var(--muted); font-size: .85em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-sub .dot { margin: 0 7px; opacity: .6; }
.v-cells { display: flex; align-items: flex-start; gap: 10px 24px; flex-wrap: wrap; }
.v-cell { width: 7.5rem; min-width: 0; }
.v-cell.s { width: 5.5rem; }
.v-cell.w { width: 10rem; }
.v-cell.xw { width: 13rem; }
.v-cell .k { display: block; font-size: .7em; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 1px; }
.v-cell .v { display: block; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-cell .v .muted { font-weight: 400; }
.v-end { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-left: auto; }
.v-chev { color: var(--muted); flex: none; transition: transform .12s ease, color .12s ease; }
.pos { color: var(--ok); }
.neg { color: var(--err); }
.meter { display: block; height: 4px; border-radius: 99px; background: var(--panel-2); overflow: hidden; margin-top: 5px; max-width: 6rem; }
.meter > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.meter.warn > i { background: var(--warn); }
.meter.err > i { background: var(--err); }
.meter:not(.ok):not(.warn):not(.err) > i { background: var(--muted); }
.steps-mini { display: inline-flex; gap: 3px; vertical-align: middle; }
.steps-mini i { width: 13px; height: 5px; border-radius: 3px; background: var(--line); }
.steps-mini i.on { background: var(--accent); }
.plate.sm { border-width: 1.5px; border-radius: 5px; flex: none; width: 7.6rem; }
.plate.sm .txt { flex: 1; padding: 6px 6px; font-size: .98rem; text-align: center; white-space: nowrap; }
.plate.sm .eu { font-size: .55rem; padding: 0 4px 4px; }
.vlist .empty { padding: 40px 16px; }
@media (max-width: 760px) {
  .vrow { gap: 10px 16px; padding: 12px 14px; }
  .v-cell, .v-cell.w, .v-cell.xw { width: calc(50% - 8px); }
  .v-cells { width: 100%; gap: 10px 16px; }
  .v-end { width: 100%; }
}

/* Registreringsnummer som skylt i startformulär */
.plate-input { display: flex; align-items: stretch; border: 2px solid #1b1b1b; border-radius: 8px; overflow: hidden; background: #fff; max-width: 22rem; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.plate-input .eu { background: #1f4fb6; color: #fff; font-weight: 800; font-size: .8rem; padding: 0 9px 7px; display: flex; align-items: flex-end; }
.plate-input input { border: 0; border-radius: 0; background: #fff; color: #111; font: 800 1.9rem/1 "DIN Alternate", "Arial Narrow", Arial, sans-serif; letter-spacing: .12em; text-transform: uppercase; padding: 10px 14px; }
.plate-input input::placeholder { color: #b5b5bb; }
.plate-input:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.plate-input input:focus { outline: 0; }
.start-card { display: flex; align-items: flex-end; gap: 16px 22px; flex-wrap: wrap; }
.start-card .choice { grid-template-columns: repeat(2, minmax(9rem, 1fr)); }
.start-card .choice label { padding: 9px 12px; }

/* Nyckeltal med rubrik över och underrad */
.stat .s { color: var(--muted); font-size: .8em; margin-top: 2px; }
.stat.accent { border-left: 3px solid var(--accent); }

/* Rapporter */
.rtable { width: 100%; }
.rtable th { font-weight: 500; color: var(--text); font-size: 1em; }
.rtable td, .rtable th { padding: 8px 4px; }
.rtable tr.sub th { padding-left: 18px; color: var(--muted); }
.rtable tr.sum th, .rtable tr.sum td { font-weight: 700; border-top: 2px solid var(--text); border-bottom: 0; }
.rtable tr.minus td::before { content: "− "; color: var(--muted); }
.rtable tr.info th, .rtable tr.info td { color: var(--muted); font-size: .9em; }
.check-ok { color: var(--ok); font-weight: 650; }
.check-err { color: var(--err); font-weight: 650; }
.bar { display: inline-block; height: 8px; border-radius: 4px; background: var(--accent); opacity: .75; vertical-align: middle; }
.bar.alt { background: var(--muted); }
tr[data-href] { cursor: pointer; }
tr[data-href]:hover td { background: color-mix(in srgb, var(--panel-2) 60%, var(--panel)); }
.rtable td.num { white-space: nowrap; width: 1%; padding-left: 14px; }
@media (min-width: 761px) and (max-width: 1700px) {
  .vrow { gap: 10px 18px; }
  .v-id { flex: 1 0 22rem; }
  .v-cells { gap: 10px 16px; }
  .v-cell { width: 6.6rem; }
  .v-cell.s { width: 5.2rem; }
  .v-cell.w { width: 8.6rem; }
  .v-cell.xw { width: 10.5rem; }
}

/* ======================================================================
   Mobil och iPad: inget ska behöva scrollas i sidled.
   ====================================================================== */
.steps-nav .no::after { content: ". "; }
.steps-nav a.off { opacity: .45; pointer-events: none; }
code { overflow-wrap: anywhere; }
pre.keybox, .keybox { white-space: pre-wrap; word-break: break-all; }
img, svg, video { max-width: 100%; }

/* Tabeller som inte får plats görs om till kort (klassen sätts av app.js när tabellen är för bred) */
table.stacked, table.stacked tbody, table.stacked tfoot { display: block; width: 100%; }
table.stacked thead, table.stacked tr.rt-head { display: none; }
table.stacked tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 9.5rem), 1fr)); gap: 10px 16px; padding: 14px 2px; border-bottom: 1px solid var(--line); }
table.stacked tr:last-child { border-bottom: 0; }
table.stacked td, table.stacked th { display: block; border: 0; padding: 0; text-align: left !important; min-width: 0; max-width: none !important; width: auto !important; white-space: normal !important; overflow: visible !important; overflow-wrap: anywhere; }
table.stacked td[data-label]:not([data-label=""])::before { content: attr(data-label); display: block; font-size: .7em; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 1px; }
table.stacked td:first-child { grid-column: 1 / -1; font-weight: 650; font-size: 1.02em; }
table.stacked td[data-label=""], table.stacked td.actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; }
table.stacked td:empty { display: none; }
.table-wrap:has(> table.stacked), .card.table-wrap:has(table.stacked) { overflow: visible; }

@media (max-width: 900px) {
  /* Flikar radbryts i stället för att scrollas */
  .tabs { flex-wrap: wrap; overflow: visible; border-bottom: 0; gap: 6px; }
  .tabs a { border: 1px solid var(--line); border-radius: 999px; padding: 6px 13px; background: var(--panel); font-size: .92em; }
  .tabs a.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  .seg { flex-wrap: wrap; overflow: visible; }
  .seg a { padding: 6px 10px; }
  .page-head .btn { padding: 8px 12px; }
  .toolbar input[type=search] { max-width: none; flex: 1 1 100%; }
  .period-form { flex-wrap: wrap; flex: 1 1 100%; }
  .period-form input { flex: 1 1 8rem; min-width: 0; }
  .card { padding: 16px; }
  .split > aside { order: 0; }
}
@media (max-width: 760px) {
  .v-title, .v-sub { white-space: normal; }
  .v-cell .v { white-space: normal; overflow-wrap: anywhere; }
  .v-id { flex-basis: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .v { font-size: 1.35rem; overflow-wrap: anywhere; }
  .page-head { margin-bottom: 12px; }
  .page-head h1 { font-size: 1.35rem; }
  h1 { font-size: 1.35rem; }
  .row > label { flex: 1 1 100%; }
  .row.end, .row { row-gap: 8px; }
  .form-grid, .form-grid.wide, .grid2 { grid-template-columns: minmax(0, 1fr); }
  .cols, .cols.md, .cols.wide { grid-template-columns: minmax(0, 1fr); }
  .cols > .span-2 { grid-column: auto; }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .start-card { gap: 12px; }
  .start-card > label, .start-card .choice, .start-card > .btn { flex: 1 1 100%; }
  .plate-input { max-width: none; }
  .vp-meta { align-items: flex-start; }
  .vp-meta .row { justify-content: flex-start; }
  .search input { font-size: 16px; } /* iPhone zoomar inte in vid fokus */
  input, select, textarea { font-size: 16px; }
  .top { gap: 8px; }
  .content { padding: 12px; }
}
@media (max-width: 760px) {
  .v-cells { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px; }
  .v-cell, .v-cell.s, .v-cell.w, .v-cell.xw { width: auto; }
  .v-cell.xw { grid-column: span 2; }
  .v-end { margin-top: -2px; }
  .vrow { padding: 12px; gap: 10px; }
  .v-id { gap: 10px; }
  .plate.sm { width: 6.6rem; }
  .plate.sm .txt { font-size: .88rem; padding: 5px 4px; }
  .v-cell .k { font-size: .64em; letter-spacing: .04em; }
  .v-cell .v { font-size: .95em; }
  .meter { max-width: none; }
  .page-head form, .page-head input[type=search] { flex: 1 1 100%; }
  .vlist-head { flex-wrap: wrap; }
}
@media (max-width: 360px) {
  .v-cells { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .page-head form { flex: 1 1 100% !important; max-width: none !important; }
  .dash table td { white-space: normal; }
  .dash td:first-child { max-width: none; width: auto; overflow: visible; white-space: normal; overflow-wrap: anywhere; }
}
[hidden] { display: none !important; }
@media (max-width: 760px) {
  .card-head { flex-wrap: wrap; }
  .card-head > * { min-width: 0; }
}

/* Flikar radbryts alltid i stället för att scrollas i sidled */
.tabs { flex-wrap: wrap; overflow: visible; }
@media (max-width: 1300px) {
  /* Stegen i inköp/försäljning: siffror, och namnet bara på steget man står på */
  .steps-nav { flex-wrap: nowrap; gap: 5px; border-bottom: 0; }
  .steps-nav a { border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
  .steps-nav a.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  .steps-nav a { padding: 0; min-width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; }
  .steps-nav .no::after { content: ""; }
  .steps-nav .lbl { display: none; }
  .steps-nav a.active { flex: 0 1 auto; min-width: 0; padding: 0 16px; justify-content: flex-start; gap: 8px; }
  .steps-nav a.active .no::after { content: "."; }
  .steps-nav a.active .lbl { display: inline; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
.stat .v { font-size: clamp(1.2rem, 2.2vw, 1.8rem); white-space: nowrap; overflow-wrap: normal; }
/* iPad och mindre datorskärmar: smal meny med bara ikoner så att innehållet får plats */
@media (min-width: 901px) and (max-width: 1279px) {
  .app:not(.expanded) .side { width: var(--side-w-min); }
  .app:not(.expanded) .side span, .app:not(.expanded) .side-brand .word, .app:not(.expanded) .side-brand img { display: none; }
  .app.expanded .side { width: var(--side-w); box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); position: fixed; left: 0; top: 0; }
  .app.expanded .main { margin-left: var(--side-w-min); }
  .app.expanded .side span, .app.expanded .side-brand .word { display: inline; }
}
.chip, .badge { white-space: nowrap; }
.v-cell.xw .v { white-space: normal; }

/* ---------- Fordonsrapport (Fordonsupplysning) ---------- */
.vr-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 11.5rem), 1fr)); gap: 0 22px; margin-top: 16px; border-top: 1px solid var(--line); }
.vr-stats > div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.vr-stats .k { color: var(--muted); font-size: .9em; white-space: nowrap; }
.vr-stats .v { font-weight: 650; text-align: right; overflow-wrap: anywhere; }
.vr-share { display: flex; height: 12px; border-radius: 99px; overflow: hidden; gap: 2px; }
.vr-share span { display: block; }
.vr-share .seg-pri, .dot-pri { background: #4f7fa8; }
.vr-share .seg-for, .dot-for { background: #7a9a6c; }
.vr-share .seg-okd, .dot-okd { background: #8b8b95; }
[class^="dot-"] { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.vr-owner { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: color-mix(in srgb, var(--panel-2) 35%, var(--panel)); }
.vr-owner.now { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); }
.vr-val { display: grid; gap: 10px; }
.vr-val .big { font-size: 2rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.vr-val > div:not(.big) { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.vr-val .k { color: var(--muted); }
.vr-val .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-wrap { width: 100%; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .axis { fill: var(--muted); font-size: 13px; }
.chart .line { fill: none; stroke: var(--focus); stroke-width: 2.5; stroke-linejoin: round; }
.chart .area { fill: color-mix(in srgb, var(--focus) 14%, transparent); }
.chart .dot { fill: var(--panel); stroke: var(--focus); stroke-width: 2; }
.vr-events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 44rem; overflow-y: auto; }
.vr-events li { display: grid; grid-template-columns: 2rem minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: color-mix(in srgb, var(--panel-2) 30%, var(--panel)); }
.vr-events .ic { width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); font-size: .9em; }
.vr-events .k-besiktning .ic { background: color-mix(in srgb, var(--ok) 18%, var(--panel)); color: var(--ok); font-weight: 800; }
.vr-events .d { color: var(--muted); font-size: .88em; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 760px) {
  .vr-events li { grid-template-columns: 2rem minmax(0, 1fr); }
  .vr-events .d { grid-column: 2; }
  .vr-val .big { font-size: 1.6rem; }
}
/* Fordonsdata i rapporten: sektioner staplade på full bredd, fälten i jämna kolumner */
.vr-sec { padding: 14px 0; border-top: 1px solid var(--line); }
.vr-sec:first-of-type { border-top: 0; padding-top: 4px; }
.vr-sec h3 { margin: 0 0 10px; font-size: .9rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.vr-sec .kv { grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr)); }
.vr-owners { max-height: 34rem; overflow-y: auto; padding-right: 4px; }
.vr-stats .v { white-space: nowrap; }
@media (max-width: 760px) { .vr-owners { max-height: none; } }
/* Inköpstestets protokoll */
.insp-sec { border: 1px solid var(--line); border-radius: 10px; margin-top: 8px; background: var(--panel); }
.insp-sec > summary { cursor: pointer; padding: 10px 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.insp-items { display: grid; gap: 0; border-top: 1px solid var(--line); }
.insp-item { padding: 10px 14px; border-bottom: 1px solid var(--line); display: grid; gap: 4px; }
.insp-item:last-child { border-bottom: 0; }
.insp-photos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.insp-photos img { width: 96px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }

/* Swish-certifikat i inställningar */
.swish-cert { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.swish-cert textarea { width: 100%; }
.payout-list { display: flex; flex-direction: column; gap: 6px; }
.payout-row { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font-size: .92em; }
.payout-row .amt { font-weight: 600; }
.payout-row .err-msg { flex-basis: 100%; color: var(--err); font-size: .9em; }
.err-text { color: var(--err); }
.swish-cert label { margin: 0; }

/* Bilder från bildverktyget */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-top: 12px; }
.photo-grid .photo { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: inherit; }
.photo-grid img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.photo-grid span { font-size: .8em; color: var(--muted, #888); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 600px) { .photo-grid { grid-template-columns: repeat(2, 1fr); } }

/* Inbyte i försäljningen */
.ti-card { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); }
.ti-sum { font-size: .92em; }
.ti-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .88em; }
.ti-steps li { color: var(--muted); }
.ti-steps li::before { content: "○ "; }
.ti-steps li.ok { color: var(--ok, #1a7f4b); }
.ti-steps li.ok::before { content: "✓ "; }

.live-notice { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 50; display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0,0,0,.18); max-width: calc(100% - 32px); }
.nav-count { display: inline-block; min-width: 1.4em; padding: 0 .4em; margin-left: .3em; border-radius: 999px; background: var(--err); color: #fff; font-size: .75em; font-weight: 700; text-align: center; line-height: 1.5; }
.kv-highlights { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.kv-highlights div { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-weight: 600; }
.kv-highlights span { display: block; font-size: .78em; font-weight: 500; color: var(--muted); }
.complaint-qa th { width: 42%; font-weight: 500; color: var(--muted); }

/* Mellanrum under flikar som följs av innehåll */
.seg + .card, .seg + .vlist, .seg + .cards, .seg + form, .seg + div { margin-top: 16px; }

/* Logotypen är svart – vit i mörkt läge */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .auth-logo { filter: invert(1); } }
:root[data-theme="dark"] .auth-logo { filter: invert(1); }

/* ---------- Översikt ---------- */
:root { --series-1: #2a78d6; --series-2: #eb6834; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) { --series-1: #3987e5; --series-2: #d95926; } }
:root[data-theme="dark"] { --series-1: #3987e5; --series-2: #d95926; }

.dash-h { font-size: 1rem; margin: 6px 0 10px; }
.dash-h .muted { font-weight: 400; font-size: .85em; }
.todo-strip { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 18px; }
.todo-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--text); text-decoration: none; font-size: .9em; }
.todo-chip:hover { border-color: var(--text); }
.todo-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.todo-chip.err .dot { background: var(--err); }
.todo-chip.ok .dot { background: var(--ok); }
.todo-chip .go { color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (min-width: 1500px) { .kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); } .kpis.four { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 700px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); text-decoration: none; color: var(--text); min-width: 0; }
.kpi:hover { border-color: var(--muted); }
.kpi .l { color: var(--muted); font-size: .82em; }
.kpi .v { font-size: 1.65rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { color: var(--muted); font-size: .8em; }
.delta { font-weight: 600; margin-right: 4px; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--err); }

.dash-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; }
.chart-card { min-width: 0; }
.chart-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-bottom: 6px; }
.chart-head h2 { font-size: 1rem; margin: 0; flex: 1 1 auto; }
.legend { display: flex; gap: 14px; font-size: .85em; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: middle; margin-right: 4px; }
.sw.s1, .hf.s1 { background: var(--series-1); }
.sw.s2 { background: var(--series-2); }
.dchart { width: 100%; height: auto; display: block; overflow: visible; }
.dchart .grid { stroke: var(--line); stroke-width: 1; }
.dchart .grid.zero { stroke: var(--muted); }
.dchart .ax { fill: var(--muted); font-size: 12px; }
.dchart .bar.s1 { fill: var(--series-1); }
.dchart .bar.s2 { fill: var(--series-2); }
.dchart .hit { fill: transparent; cursor: default; }
.dchart .hit:hover { fill: color-mix(in srgb, var(--text) 6%, transparent); }

.hbars { display: flex; flex-direction: column; gap: 10px; }
.hb { display: grid; grid-template-columns: 7.5rem 1fr 2.5rem; align-items: center; gap: 10px; font-size: .9em; }
.hb .hl { color: var(--muted); }
.hb .ht { height: 14px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.hb .hf { display: block; height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.hb .hv { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.dtip { position: fixed; z-index: 60; pointer-events: none; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: .85em; line-height: 1.5; box-shadow: 0 6px 20px rgba(0,0,0,.15); max-width: 260px; }
@media (max-width: 600px) { .kpi .v { font-size: 1.35rem; } .hb { grid-template-columns: 6.2rem 1fr 2rem; } }

/* Menyn på mobil: iOS Safari räknar 100vh bakom adressfältet – använd synlig höjd så att Logga ut alltid syns */
.side { height: 100vh; height: 100dvh; }
@media (max-width: 900px) {
  .side { height: 100%; height: 100dvh; max-height: -webkit-fill-available; overflow: hidden; }
  .side nav { min-height: 0; -webkit-overflow-scrolling: touch; }
  .side-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); flex: none; }
}

/* Periodväljaren: flikar, datumfält och knapp i samma höjd */
.toolbar.period { align-items: center; }
.toolbar.period .seg { height: 40px; align-items: stretch; }
.toolbar.period .seg a { display: inline-flex; align-items: center; }
.period-form { align-items: center; }
.period-form input[type=date] { height: 40px; padding: 0 10px; box-sizing: border-box; line-height: 40px; -webkit-appearance: none; appearance: none; min-width: 9.5rem; }
.period-form .btn { height: 40px; padding: 0 16px; font-size: .95em; display: inline-flex; align-items: center; }
@media (max-width: 900px) { .toolbar.period .seg { height: auto; } }

/* Integrationer: hopfällda kort */
.integ-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 26rem), 1fr)); gap: 12px; align-items: start; }
.integ { padding: 0; }
.integ > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.integ > summary::-webkit-details-marker { display: none; }
.integ > summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-left: 4px; flex: none; transition: transform .15s; }
.integ[open] > summary::after { transform: rotate(-135deg); }
.integ-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.integ-title .muted { font-size: .85em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.integ[open] .integ-title .muted { white-space: normal; }
.integ-badges { display: flex; gap: 6px; flex: none; }
.integ-body { padding: 0 16px 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.integ[open] { grid-column: 1 / -1; }

/* Provisionsräknare i försäljningens steg 3 */
.comm-calc { border: 1px solid color-mix(in srgb, var(--ok) 40%, var(--line)); background: color-mix(in srgb, var(--ok) 7%, var(--panel)); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.cc-head { display: flex; align-items: baseline; gap: 10px; }
.cc-total { margin-left: auto; font-size: 1.35rem; font-weight: 800; color: var(--ok); font-variant-numeric: tabular-nums; }
.cc-rows { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .9em; }
.cc-steps { font-size: .85em; }

/* Lönsamhet vid inköp */
.margin-calc { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; background: var(--panel-2); }
.margin-calc > div:first-child { display: flex; align-items: baseline; gap: 10px; }
.margin-calc strong { margin-left: auto; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.margin-calc.ok { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); background: color-mix(in srgb, var(--ok) 8%, var(--panel)); }
.margin-calc.ok strong { color: var(--ok); }
.margin-calc.bad { border-color: color-mix(in srgb, var(--warn) 55%, var(--line)); background: color-mix(in srgb, var(--warn) 10%, var(--panel)); }
.margin-calc.bad strong { color: var(--warn); }
.toolbar .seg + form, .toolbar .seg + div { margin-top: 0; }

/* Provision visas bara medan säljaren håller in K (eller knappen Provision) – så att kunden inte ser den */
.comm-secret:not(.on) { display: none !important; }
.comm-hold, .k-btn { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
.comm-hold.on, .k-btn.on { background: var(--ok); color: #fff; border-color: var(--ok); }
/* Marginaler och vinst: dolda tills man håller in K (eller ögat uppe till höger) */
.ksec-m { color: var(--muted); letter-spacing: .12em; }
body:not(.k-on) .ksec-v, body.k-on .ksec-m { display: none; }
body:not(.k-on) .k-block { display: none !important; }
body:not(.k-on) .k-blur { filter: blur(9px); pointer-events: none; user-select: none; }
@media print { body .ksec-v { display: inline !important; } body .ksec-m { display: none !important; } body .k-block { display: block !important; } body .k-blur { filter: none !important; } }

/* Hemsidan på bilens sida */
.web-group { font-size: .95rem; margin: 18px 0 8px; }
.web-details { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.web-details > summary { cursor: pointer; font-weight: 600; }
.web-details[open] > summary { margin-bottom: 4px; }
.web-details .form-grid { align-items: start; }
.photo-grid > * { min-width: 0; }
@media (max-width: 600px) { .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Utrustning och tillval */
.eq-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); gap: 0 24px; }
.eq-list li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.eq-list li > span:last-child { white-space: nowrap; }

/* Fordonsupplysning – att observera, ägartid, mätare, värde */
.vr-w { display: grid; grid-template-columns: 1.9rem minmax(0, 1fr); gap: 10px; align-items: start; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); margin-top: 8px; }
.vr-w:first-of-type { margin-top: 0; }
.vr-w .ic { width: 1.9rem; height: 1.9rem; border-radius: 50%; display: grid; place-items: center; font-weight: 800; }
.vr-w.err { background: color-mix(in srgb, var(--err) 9%, var(--panel)); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.vr-w.err .ic { background: var(--err); color: var(--panel); }
.vr-w.warn { background: color-mix(in srgb, var(--warn) 11%, var(--panel)); border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.vr-w.warn .ic { background: var(--warn); color: var(--panel); }
.vr-w.info .ic { background: var(--panel-2); color: var(--muted); }
.vr-w.ok .ic { background: color-mix(in srgb, var(--ok) 20%, var(--panel)); color: var(--ok); }
.vr-w .muted { font-size: .9em; }
.vr-own { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 40rem; overflow-y: auto; }
.vr-own li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 10px 12px; border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px; }
.vr-own li.now { background: color-mix(in srgb, var(--panel-2) 35%, var(--panel)); }
.vr-own li.lvl-err { border-left-color: var(--err); }
.vr-own li.lvl-warn { border-left-color: var(--warn); }
.vr-own .who { display: flex; flex-direction: column; min-width: 0; }
.vr-own .nm { font-weight: 650; overflow-wrap: anywhere; }
.vr-own .tp { font-size: .85em; }
.vr-own .dur { grid-column: 1; display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: .9em; }
.vr-own .chip { grid-column: 2; grid-row: 1; align-self: start; }
.vr-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr)); gap: 10px; margin-bottom: 12px; }
.vr-kpis > div, .vr-prices > div { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; min-width: 0; }
.vr-kpis .k, .vr-prices .k { color: var(--muted); font-size: .82em; }
.vr-kpis .v { font-weight: 750; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.vr-kpis .s, .vr-prices .s { font-size: .8em; }
.vr-prices { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 10px; }
.vr-prices .v { font-weight: 750; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.vr-fold { border-top: 1px solid var(--line); padding: 10px 0; }
.vr-fold:first-of-type { border-top: 0; padding-top: 0; }
.vr-fold > summary { cursor: pointer; font-weight: 650; padding: 4px 0; }
.vr-fold[open] > summary { margin-bottom: 8px; }
.vr-fold .kv { grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr)); }
.vr-events li.bad .ic { background: color-mix(in srgb, var(--err) 18%, var(--panel)); color: var(--err); }
.chart .line.est { stroke-dasharray: 6 5; }
.chart .dot.est { fill: var(--focus); }
.chart .dot.bad { stroke: var(--err); }
.vr-kpis .v.neg, .vr-kpis .v.neg { color: var(--err); }
.vr-kpis .v.pos { color: var(--ok); }
.chart-wrap .chart { max-height: 260px; }

/* Betrodda enheter under Användare */
.dev-box { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; }
.dev-table { margin-top: 8px; }
.dev-table td { vertical-align: top; }
