/* Truckregister – designgrund enligt docs/design.md */
:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --ink: #141414;
  --ink-2: #4a4a46;
  --muted: #5f5f5b;
  --line: #ececea;
  --border: #dcdcd7;
  --placeholder: #ececea;
  --accent: #e4b520;
  --dark-2: #1f1f1d;
  --dark-3: #2a2a28;
  --dark-muted: #c9c9c4;
  --success: #2f8a4a;
  --success-ink: #1f5e33;
  --success-bg: #e3f1e7;
  --danger: #a3261b;
  --danger-bg: #fbe5e2;
  --ja-ink: #5a4400;
  --ja-bg: #fbefc8;
  --to-ink: #8f2a06;
  --to-bg: #fde2d6;
  --font: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-head: Archivo, Inter, system-ui, sans-serif;
  --radius-card: 16px;
  --radius-field: 8px;
  --radius-btn: 10px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.45; }
a { color: var(--ink); }
a:hover { color: var(--ja-ink); }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 8px; background: var(--accent); color: var(--ink); padding: 8px 12px; border-radius: 8px; z-index: 10; font-weight: 700; }
.skip:focus { left: 8px; }

/* ------------------------------------------------ Typografi */
.h1 { margin: 4px 0 0; font-family: var(--font-head); font-weight: 800; font-size: 36px; letter-spacing: -.01em; line-height: 1.1; }
.h1-sm { font-size: 32px; margin: 0; }
.h2 { margin: 0; font-family: var(--font-head); font-weight: 700; font-size: 18px; }
.h2-sm { font-size: 16px; }
.h3 { margin: 8px 0 0; font-size: 14px; font-weight: 600; }
legend.h2 { padding: 0; margin-bottom: 16px; float: left; width: 100%; }
legend.h2 + * { clear: both; }
.eyebrow { font-size: 13px; color: var(--muted); font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
code { font-size: 12px; }

/* ------------------------------------------------ Layout */
.app { display: flex; flex-wrap: wrap; min-height: 100vh; }
.sidebar { flex: 0 0 240px; background: var(--ink); color: var(--bg); padding: 24px 16px; display: flex; flex-direction: column; gap: 28px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; color: inherit; text-decoration: none; }
.brand:hover { color: inherit; }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; background: var(--accent); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; font-family: var(--font-head); font-weight: 800; font-size: 16px; flex: none; }
.brand-name { display: block; font-family: var(--font-head); font-weight: 700; font-size: 16px; }
.brand-sub { display: block; font-size: 12px; color: #a8a8a3; }
.nav-links { display: flex; flex-direction: column; gap: 4px; }
.nav-link { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border-radius: 8px; color: #d6d6d1; text-decoration: none; font-size: 14px; }
.nav-link:hover { background: var(--dark-2); color: #fff; }
.nav-link.active { background: var(--dark-3); color: #fff; font-weight: 600; }
.nav-dot { width: 6px; height: 6px; border-radius: 3px; flex: none; }
.nav-link.active .nav-dot { background: var(--accent); }
.nav-user { margin-top: auto; padding: 12px; border-radius: 10px; background: var(--dark-2); font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.nav-user-name { color: #fff; font-weight: 600; text-decoration: none; }
.nav-user-name:hover { color: var(--accent); }
.nav-user-role { color: #a8a8a3; }
.nav-logout { margin-top: 8px; background: none; border: 0; padding: 4px 0; color: var(--dark-muted); font: inherit; font-size: 12px; cursor: pointer; text-decoration: underline; }
.nav-logout:hover { color: #fff; }

.main { flex: 999 1 560px; min-width: 0; padding: 32px 40px; display: flex; flex-direction: column; gap: 24px; }
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.header-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.back-link { font-size: 13px; color: var(--muted); text-decoration: none; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.card { background: var(--surface); border-radius: var(--radius-card); padding: 24px; display: flex; flex-direction: column; gap: 16px; border: 0; margin: 0; min-width: 0; }
fieldset.card { display: block; }
fieldset.card > * + * { margin-top: 16px; }
.card-flush { padding: 0; gap: 0; }
.card-dark { background: var(--ink); color: var(--bg); }
.narrow { max-width: 720px; }
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.edit-layout { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.edit-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.edit-side { flex: 1 1 340px; min-width: 0; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 16px; }
.split-layout { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.list-panel { flex: 1 1 300px; max-width: 380px; padding: 16px; gap: 12px; }
.split-main { flex: 999 1 560px; min-width: 0; }

/* ------------------------------------------------ Knappar */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: var(--radius-btn); border: 1px solid transparent; font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--ink); font-weight: 700; padding: 0 18px; }
.btn-primary:hover { background: #d6a913; color: var(--ink); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--ink); }
.btn-secondary:hover:not(:disabled) { border-color: var(--ink-2); color: var(--ink); }
.btn-danger { background: var(--surface); border-color: #e3b7b1; color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); color: var(--danger); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--ink); text-decoration: underline; cursor: pointer; }
.inline { display: inline; }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.file-btn { position: relative; align-self: flex-start; }

/* ------------------------------------------------ Fält */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ink-2); min-width: 0; }
.field-label { display: block; }
input, select, textarea { font: inherit; font-size: 14px; font-weight: 400; color: var(--ink); border: 1px solid var(--border); border-radius: var(--radius-field); padding: 0 12px; height: 44px; background: var(--surface); width: 100%; min-width: 0; }
textarea { height: auto; padding: 12px; line-height: 1.5; resize: vertical; }
input:disabled, select:disabled, textarea:disabled { background: var(--bg); color: var(--muted); }
input[type=checkbox] { width: 20px; height: 20px; padding: 0; accent-color: var(--ink); flex: none; }
input[type=file].sr-only { position: absolute !important; }
.field-hint { font-weight: 400; color: var(--muted); }
.field-error { font-weight: 600; color: var(--danger); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.check { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 500; min-height: 44px; cursor: pointer; }
.field-check { align-self: end; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 16px; }

/* ------------------------------------------------ Sök & filter */
.search { position: relative; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-btn); padding: 0 14px; height: 44px; min-width: 260px; color: var(--muted); }
.search input { border: 0; height: 40px; padding: 0; outline: 0; background: transparent; }
.search:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.search-block { min-width: 0; width: 100%; }
.table-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; }
.segmented { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 10px; }
.segmented a { display: inline-flex; align-items: center; height: 36px; padding: 0 14px; border-radius: 8px; font-size: 13px; color: var(--ink-2); text-decoration: none; }
.segmented a.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filter { display: flex; align-items: center; gap: 0; border: 1px solid var(--border); border-radius: 8px; height: 36px; padding-left: 12px; font-size: 13px; color: var(--muted); background: var(--surface); }
.filter select { border: 0; height: 34px; font-size: 13px; padding: 0 8px; width: auto; background: transparent; }
.filter span::after { content: ':'; }

/* ------------------------------------------------ Nyckeltal */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat { background: var(--surface); border-radius: 14px; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ink); }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-family: var(--font-head); font-weight: 800; font-size: 32px; line-height: 1.1; }
.stat-help { font-size: 12px; color: var(--muted); }
.stat-dark { background: var(--ink); color: var(--bg); }
.stat-dark:hover { color: var(--bg); background: var(--dark-2); }
.stat-dark .stat-label, .stat-dark .stat-help { color: var(--dark-muted); }
.stat-dark .stat-value { color: var(--accent); }

/* ------------------------------------------------ Tabell */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 900px; }
.table th { padding: 10px 14px; text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.table td { padding: 12px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
.table .num { text-align: right; }
.table tbody tr:hover { background: #fafaf8; }
.table-footer { padding: 14px 18px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); }
.truck-cell { display: flex; align-items: center; gap: 12px; }
.truck-cell-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-link { font-weight: 600; text-decoration: none; }
.row-link:hover { text-decoration: underline; }
.thumb { width: 64px; height: 48px; border-radius: 8px; object-fit: cover; flex: none; background: var(--placeholder); }
.thumb-empty { display: inline-flex; align-items: center; justify-content: center; color: #8a8a85; }

/* ------------------------------------------------ Chips, status, kanaler */
.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line); color: var(--ink-2); white-space: nowrap; }
.chip-ja-truck { background: var(--ja-bg); color: var(--ja-ink); }
.chip-truckon { background: var(--to-bg); color: var(--to-ink); }
.chip-status-for_sale { background: var(--success-bg); color: var(--success-ink); }
.chip-status-reserved, .chip-pending { background: var(--ja-bg); color: var(--ja-ink); }
.chip-status-sold { background: var(--ink); color: #fff; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 4px; background: #b5b5b0; }
.status-for_sale .status-dot { background: var(--success); }
.status-reserved .status-dot { background: var(--accent); }
.status-sold .status-dot { background: var(--ink); }
.status-draft .status-dot { background: transparent; border: 1.5px solid var(--muted); }
.channels { display: flex; gap: 6px; font-size: 11px; font-weight: 600; }
.channel { padding: 3px 7px; border-radius: 6px; border: 1px dashed #b5b5b0; color: var(--muted); }
.channel.on { background: var(--ink); border: 1px solid var(--ink); color: #fff; }

/* ------------------------------------------------ Flash */
.flash-stack { display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 12px 16px; border-radius: 10px; font-size: 14px; background: var(--surface); border-left: 4px solid var(--ink-2); word-break: break-word; }
.flash-success { background: var(--success-bg); border-color: var(--success); color: var(--success-ink); }
.flash-error { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.flash-info { background: var(--ja-bg); border-color: var(--accent); color: var(--ja-ink); }

/* ------------------------------------------------ Truckformulär */
.image-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.image-tile { position: relative; margin: 0; aspect-ratio: 4 / 3; border-radius: 12px; background: var(--placeholder); overflow: hidden; cursor: grab; }
.image-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-tile.main { grid-column: span 2; grid-row: span 2; }
.image-badge { display: none; position: absolute; left: 10px; bottom: 10px; padding: 3px 8px; border-radius: 6px; background: rgba(20,20,20,.8); color: #fff; font-size: 12px; font-weight: 600; }
.image-tile.main .image-badge { display: block; }
.image-delete { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 16px; border: 0; background: rgba(20,20,20,.75); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; }
.image-delete:hover { background: var(--danger); }
.image-tile.sortable-ghost { opacity: .4; }
.image-upload { position: relative; aspect-ratio: 4 / 3; border-radius: 12px; border: 2px dashed var(--dark-muted); background: #fafaf8; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.image-upload:hover { border-color: var(--ink-2); }
.image-upload:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.image-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.image-upload.busy span::after { content: '…'; }

.price-panel .field { color: var(--dark-muted); }
.price-input { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: var(--radius-field); padding-right: 12px; color: var(--ink); }
.price-input input { border: 0; font-family: var(--font-head); font-weight: 700; font-size: 20px; }
.price-rows { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--dark-muted); }
.price-rows > div { display: flex; justify-content: space-between; }
.price-rows .strong { color: #fff; }
.price-panel .check { color: var(--bg); }
.price-panel input[type=checkbox] { accent-color: var(--accent); }
.price-net { border-top: 1px solid #333330; padding-top: 12px; font-size: 13px; color: var(--dark-muted); }
.accent { color: var(--accent); font-weight: 700; }
.accent-dark { color: var(--ja-ink); }
.standard-text { margin: 0; padding: 12px; border-radius: 8px; background: var(--bg); font: inherit; font-size: 13px; color: var(--ink-2); white-space: pre-wrap; }

.toggles { display: flex; flex-direction: column; gap: 10px; }
.toggle { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; font-weight: 500; padding: 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.toggle-sub { font-size: 12px; font-weight: 600; color: var(--muted); }
.toggle-disabled { cursor: default; }
.history ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; font-size: 13px; color: var(--ink-2); }
.history li { display: flex; flex-direction: column; gap: 2px; }
.danger-zone { display: flex; justify-content: flex-end; }

/* ------------------------------------------------ Återförsäljare */
.dealer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.dealer-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 10px; text-decoration: none; color: var(--ink); }
.dealer-item:hover { background: var(--bg); color: var(--ink); }
.dealer-item.active { background: var(--ja-bg); }
.dealer-item.inactive { opacity: .6; }
.dealer-item-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.dealer-pct { font-weight: 700; font-family: var(--font-head); }
.dealer-logo { width: 44px; height: 44px; border-radius: 8px; object-fit: contain; background: var(--surface); border: 1px solid var(--line); flex: none; }
.dealer-logo-empty { display: inline-flex; align-items: center; justify-content: center; background: var(--placeholder); color: var(--muted); font-size: 10px; font-weight: 700; border: 0; }
.dealer-logo-lg { width: 96px; height: 96px; font-size: 13px; }
.logo-row { display: flex; gap: 20px; align-items: center; }
.example-row { padding: 12px 14px; border-radius: 10px; background: var(--bg); font-size: 13px; }
.user-rows { list-style: none; margin: 0; padding: 0; }
.user-rows li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); }
.user-row-meta { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.invite-form { border-top: 1px solid var(--line); padding-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.role-help { border-top: 1px solid var(--line); padding-top: 12px; font-size: 13px; color: var(--ink-2); }
.role-help p { margin: 4px 0; }

/* ------------------------------------------------ Inställningar */
.type-rows { display: flex; flex-direction: column; gap: 8px; }
.type-row { display: grid; grid-template-columns: 2fr 2fr auto auto; gap: 12px; align-items: center; }
.type-row-new { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }

/* ------------------------------------------------ Tomt läge & auth */
.empty-state { padding: 40px 24px; text-align: center; }
.empty-state p { margin: 6px 0; }
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-wrap { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 20px; }
.auth-brand { display: flex; align-items: center; gap: 10px; }
.auth-card { background: var(--surface); border-radius: var(--radius-card); padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.auth-card .empty-state { padding: 0; text-align: left; }
.auth-card .h1 { font-size: 28px; }
.auth-card p { margin: 0; }
.auth-links { font-size: 13px; }

/* ------------------------------------------------ Mobil */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .edit-side { position: static; }
}
@media (max-width: 760px) {
  .sidebar { flex-basis: 100%; padding: 16px; gap: 12px; }
  .nav-links { flex-direction: row; flex-wrap: wrap; }
  .nav-link { min-height: 40px; }
  .nav-user { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 0; }
  .nav-logout { margin: 0 0 0 auto; }
  .main { padding: 20px 16px; }
  .h1 { font-size: 28px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .image-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search { min-width: 0; flex: 1 1 100%; }
  .list-panel { max-width: none; }
  .type-row { grid-template-columns: 1fr; }
}
