/* Boussole UI — sober, instrument-like. Numbers are set in a tabular mono face
   (the signature), everything else in the native system sans. Light/dark via
   tokens; RTL via logical properties. Accent is a CSS var (tenant-themable). */

:root {
  --accent: #2a6fb0;          /* steel blue — overridable per install */
  --accent-ink: #ffffff;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --line: #dde3ec;
  --text: #1c2530;
  --text-dim: #5d6b7d;
  --ok: #2e9e6b;              /* positive margin / sold */
  --warn: #c8870f;           /* aged stock / in-stock */
  --bad: #d9534f;            /* negative margin */
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 35, 55, .06), 0 4px 16px rgba(20, 35, 55, .05);
  --mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1620; --surface: #17202c; --surface-2: #1e2937;
    --line: #2a3645; --text: #e7edf5; --text-dim: #9aa7b8;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1620; --surface: #17202c; --surface-2: #1e2937;
  --line: #2a3645; --text: #e7edf5; --text-dim: #9aa7b8;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
button, input, select { font: inherit; color: inherit; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* --- App shell --- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex: 0 0 auto;
  background: var(--surface); border-inline-end: 1px solid var(--line);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; color: var(--accent-ink); flex: 0 0 auto;
}
.brand b { font-size: 18px; letter-spacing: .2px; }
.navlink {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 10px; color: var(--text-dim); text-decoration: none;
  border: none; background: none; cursor: pointer; width: 100%; text-align: start;
}
.navlink:hover { background: var(--surface-2); color: var(--text); }
.navlink.active { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .foot { color: var(--text-dim); font-size: 12px; padding: 8px; }

.main { flex: 1; min-width: 0; padding: 22px clamp(14px, 4vw, 34px) 90px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.topbar h1 { font-size: 22px; margin: 0; }
.row-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* --- Bottom nav (mobile) --- */
.bottomnav { display: none; }
@media (max-width: 760px) {
  .sidebar { display: none; }
  .main { padding: 16px 14px 84px; }
  .bottomnav {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px env(safe-area-inset-bottom);
  }
  .bottomnav button {
    flex: 1; background: none; border: none; color: var(--text-dim);
    padding: 8px 4px; font-size: 11px; display: flex; flex-direction: column;
    align-items: center; gap: 3px; cursor: pointer;
  }
  .bottomnav button.active { color: var(--accent); }
}

/* --- Cards / KPIs --- */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.kpi .label { color: var(--text-dim); font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; }
.kpi .value { font-size: 26px; margin-top: 6px; }
.kpi .sub { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }

/* --- Objective gauge (signature) --- */
.gauge { display: flex; align-items: center; gap: 18px; }
.gauge svg { flex: 0 0 auto; }
.gauge .g-num { font-size: 30px; }
.gauge .g-meta { color: var(--text-dim); font-size: 13px; }

/* --- Lists --- */
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-dim); margin: 26px 0 10px; }
.vlist { display: flex; flex-direction: column; gap: 8px; }
.vrow {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; text-align: start; width: 100%;
}
.vrow:hover { border-color: var(--accent); }
.thumb {
  width: 54px; height: 42px; border-radius: 7px; object-fit: cover; flex: 0 0 auto;
  background: var(--surface-2); display: grid; place-items: center; color: var(--text-dim);
}
.vrow .meta { flex: 1; min-width: 0; }
.vrow .meta .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vrow .meta .s { color: var(--text-dim); font-size: 12.5px; }
.vrow .right { text-align: end; flex: 0 0 auto; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.stock { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.pill.sold  { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.margin-pos { color: var(--ok); }
.margin-neg { color: var(--bad); }

/* --- Forms / controls --- */
.input, .select {
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; width: 100%;
}
.input:focus, .select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; border-color: var(--accent); }
.btn {
  background: var(--accent); color: var(--accent-ink); border: none;
  border-radius: 9px; padding: 10px 16px; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.iconbtn { background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; cursor: pointer; }

.alerts .alert { display: flex; gap: 10px; align-items: baseline; padding: 9px 12px; border-radius: 9px; }
.alert.warn { background: color-mix(in srgb, var(--warn) 12%, transparent); }
.alert.bad { background: color-mix(in srgb, var(--bad) 12%, transparent); }

.empty { text-align: center; color: var(--text-dim); padding: 40px 16px; }
.muted { color: var(--text-dim); }
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; }

/* --- Login --- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { justify-content: center; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 5px; }
.form-error { color: var(--bad); font-size: 13.5px; margin: 4px 0 10px; }
.center { text-align: center; }
.spin { width: 22px; height: 22px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp .7s linear infinite; margin: 30px auto; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

/* --- Jalon 5b: forms, detail, photos, settings --- */
.fab {
  position: fixed; inset-inline-end: 20px; bottom: 84px; z-index: 25;
  width: 52px; height: 52px; border-radius: 50%; border: none;
  background: var(--accent); color: var(--accent-ink); font-size: 26px;
  box-shadow: var(--shadow); cursor: pointer;
}
@media (min-width: 761px) { .fab { bottom: 28px; } }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.fieldset { margin-bottom: 18px; }
.fieldset > .legend { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-dim); margin: 0 0 10px; }
.actions-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
textarea.input { resize: vertical; min-height: 64px; }

.detail-head { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.detail-head .ttl { font-size: 22px; font-weight: 700; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 18px; }
.kv .k { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
.kv .v { font-weight: 500; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.photo-cell { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); }
.photo-cell img { width: 100%; height: 110px; object-fit: cover; display: block; }
.photo-cell .badge { position: absolute; inset-block-start: 6px; inset-inline-start: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 999px; }
.photo-cell .cov { position: absolute; inset-block-start: 6px; inset-inline-end: 6px; background: var(--ok); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 999px; }
.photo-cell .ops { position: absolute; inset-block-end: 0; inset-inline: 0; display: flex; gap: 6px; padding: 6px; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.photo-cell .ops button { flex: 1; font-size: 11px; padding: 4px; border: none; border-radius: 6px; cursor: pointer; background: rgba(255,255,255,.9); }

.set-section { margin-bottom: 18px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: none; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; }
.swatch.active { outline: 2px solid var(--text); outline-offset: 2px; }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { width: 100%; max-width: 420px; }
.linkrow { display: flex; gap: 8px; align-items: end; }
.linkrow .grow { flex: 1; }
