/* Brand colours are injected at runtime from Settings > Branding */
:root {
  --primary: #1f4e79;
  --secondary: #f2a900;
  --primary-ink: #ffffff;
  --primary-soft: color-mix(in srgb, var(--primary) 10%, white);
  --secondary-soft: color-mix(in srgb, var(--secondary) 18%, white);
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #e3e6eb;
  --ok: #18794e;
  --ok-bg: #e6f6ee;
  --low: #a15c00;
  --low-bg: #fff3dc;
  --out: #b42318;
  --out-bg: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--primary); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--primary); color: var(--primary-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand img { max-height: 36px; max-width: 120px; object-fit: contain; background: rgba(255,255,255,.95); border-radius: 6px; padding: 3px; }
.brand .name { font-weight: 700; font-size: 16px; line-height: 1.2; }
.brand .accent { width: 8px; height: 28px; border-radius: 4px; background: var(--secondary); flex: none; }
.nav { padding: 10px 8px; overflow-y: auto; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; padding: 8px 12px; border-radius: 8px; opacity: .85; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.08); opacity: 1; }
.nav a.active { background: rgba(255,255,255,.16); opacity: 1; box-shadow: inset 3px 0 0 var(--secondary); }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .55; padding: 14px 12px 4px; }
.nav svg { width: 18px; height: 18px; flex: none; }
.userbox { padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.12); font-size: 12.5px; }
.userbox button { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 0; opacity: .85; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 18px 28px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.content { padding: 24px 28px 60px; max-width: 1400px; }

body.embedded .brand { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; transform: translateX(-100%); transition: transform .2s; z-index: 30; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .btn.menu-btn { display: inline-flex; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
@media (max-width: 500px) { .grid.two { grid-template-columns: 1fr; } }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi.warn .value { color: var(--low); }
.kpi.bad .value { color: var(--out); }
.kpi { border-top: 3px solid var(--primary); }
.kpi.warn { border-top-color: var(--secondary); }
.kpi.bad { border-top-color: var(--out); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.accent { background: var(--secondary); border-color: var(--secondary); color: var(--secondary-ink, #1c1c1c); }
.btn.danger { color: var(--out); }
.btn.danger.solid { background: var(--out); border-color: var(--out); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 180px; }

input, select, textarea { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 38px; width: 56px; }
textarea { min-height: 90px; resize: vertical; }
label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: color-mix(in srgb, var(--primary) 3%, white); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--primary-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.card table th { background: none; }
.card .table-flat td, .card .table-flat th { padding: 7px 6px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.low { background: var(--low-bg); color: var(--low); }
.badge.out { background: var(--out-bg); color: var(--out); }
.badge.neutral, .badge.untracked, .badge.inactive { background: #eef0f3; color: var(--muted); }
.badge.placed { background: var(--primary-soft); color: var(--primary); }
.badge.fulfilled { background: var(--ok-bg); color: var(--ok); }
.badge.cancelled { background: #eef0f3; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; background: var(--secondary-soft); font-size: 12px; margin: 1px 2px 1px 0; }
.delta.pos { color: var(--ok); font-weight: 600; }
.delta.neg { color: var(--out); font-weight: 600; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; color: var(--muted); }
.empty { padding: 36px; text-align: center; color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; font: inherit; font-weight: 600; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--secondary); }

/* ---------- modal ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(720px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: #fafbfc; border-radius: 0 0 14px 14px; }

.comp-row { display: grid; grid-template-columns: 1fr 90px 36px; gap: 8px; margin-bottom: 8px; }
.line-row { display: grid; grid-template-columns: 1fr 80px 100px 36px; gap: 8px; margin-bottom: 8px; align-items: center; }

/* ---------- toast ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; border-left: 4px solid var(--secondary); }
.toast.error { border-left-color: #f97066; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 60%, black)); }
.login { width: min(380px, 100%); }
.login .logo { text-align: center; margin-bottom: 14px; }
.login .logo img { max-height: 64px; max-width: 220px; }
.login h1 { text-align: center; margin-bottom: 18px; }
.login .bar { height: 4px; background: var(--secondary); border-radius: 4px; margin: -18px -18px 18px; border-radius: var(--radius) var(--radius) 0 0; }

.detail-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.big-qty { font-size: 40px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
pre.snippet { background: #0f1720; color: #e6edf3; padding: 12px 14px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; margin: 6px 0 14px; white-space: pre; }
.preview-swatch { display: flex; gap: 10px; align-items: center; padding: 12px; border: 1px dashed var(--border); border-radius: 8px; }
.logo-preview { max-height: 60px; max-width: 200px; border: 1px solid var(--border); border-radius: 6px; padding: 4px; background: #fff; }
.secret-box { background: var(--secondary-soft); border: 1px solid var(--secondary); padding: 12px; border-radius: 8px; margin-bottom: 12px; word-break: break-all; }
td > strong:first-child, td > a > strong { white-space: nowrap; }
