/* ============================================================
   Hub — the shared shell

   Tokens match ShopFlow / Offer / Invoices so the modules do not look like
   four different products bolted together. Every colour is defined on bare
   :root first and only redefined for dark, so a browser without the dark
   query still paints a complete theme.
   ============================================================ */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, system-ui, sans-serif;

  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f2f2f4;
  --surface-3: #e9e9ec;
  --border: rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.14);
  --text: #1d1d1f;
  --text-2: #55555a;
  --text-3: #8e8e93;
  --accent: #0071e3;
  --accent-soft: rgba(0,113,227,0.10);
  --accent-text: #0071e3;

  --green: #34c759;  --green-soft: rgba(52,199,89,0.13);
  --blue: #007aff;   --blue-soft: rgba(0,122,255,0.11);
  --orange: #ff9500; --orange-soft: rgba(255,149,0,0.13);
  --red: #ff3b30;    --red-soft: rgba(255,59,48,0.11);
  --purple: #af52de; --purple-soft: rgba(175,82,222,0.12);
  --gray: #8e8e93;   --gray-soft: rgba(142,142,147,0.14);

  --shadow-1: 0 1px 2px rgba(0,0,0,0.04), 0 1px 6px rgba(0,0,0,0.04);
  --shadow-2: 0 2px 8px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.07);
  --shadow-3: 0 8px 20px rgba(0,0,0,0.10), 0 24px 60px rgba(0,0,0,0.14);

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
  --spring: cubic-bezier(0.32, 0.72, 0, 1);
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d0f; --bg-elevated: #1c1c1e; --surface: #1c1c1e;
    --surface-2: #26262a; --surface-3: #313136;
    --border: rgba(255,255,255,0.09); --border-strong: rgba(255,255,255,0.16);
    --text: #f5f5f7; --text-2: #b8b8bd; --text-3: #78787e;
    --accent: #0a84ff; --accent-soft: rgba(10,132,255,0.16); --accent-text: #409cff;
    --green: #30d158; --green-soft: rgba(48,209,88,0.16);
    --blue: #0a84ff;  --blue-soft: rgba(10,132,255,0.15);
    --orange: #ff9f0a; --orange-soft: rgba(255,159,10,0.15);
    --red: #ff453a;   --red-soft: rgba(255,69,58,0.15);
    --purple: #bf5af2; --purple-soft: rgba(191,90,242,0.16);
    --gray: #98989e;  --gray-soft: rgba(142,142,147,0.20);
    --shadow-1: 0 1px 2px rgba(0,0,0,0.35), 0 1px 6px rgba(0,0,0,0.30);
    --shadow-2: 0 2px 8px rgba(0,0,0,0.40), 0 8px 24px rgba(0,0,0,0.45);
    --shadow-3: 0 8px 20px rgba(0,0,0,0.5), 0 24px 60px rgba(0,0,0,0.55);
  }
}
:root[data-theme="dark"] {
  --bg: #0d0d0f; --bg-elevated: #1c1c1e; --surface: #1c1c1e;
  --surface-2: #26262a; --surface-3: #313136;
  --border: rgba(255,255,255,0.09); --border-strong: rgba(255,255,255,0.16);
  --text: #f5f5f7; --text-2: #b8b8bd; --text-3: #78787e;
  --accent: #0a84ff; --accent-soft: rgba(10,132,255,0.16); --accent-text: #409cff;
  --green: #30d158; --green-soft: rgba(48,209,88,0.16);
  --blue: #0a84ff;  --blue-soft: rgba(10,132,255,0.15);
  --orange: #ff9f0a; --orange-soft: rgba(255,159,10,0.15);
  --red: #ff453a;   --red-soft: rgba(255,69,58,0.15);
  --purple: #bf5af2; --purple-soft: rgba(191,90,242,0.16);
  --gray: #98989e;  --gray-soft: rgba(142,142,147,0.20);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  height: 100vh; height: 100dvh; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); }

/* ---------- shell ---------- */
.shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.topbar {
  flex: none; height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 14px; background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 680; font-size: 15px; letter-spacing: -0.2px; white-space: nowrap; }
.brand .mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.grow { flex: 1; min-width: 0; }

.modtabs { display: flex; gap: 2px; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.modtabs button {
  border: 0; background: transparent; cursor: pointer; white-space: nowrap;
  padding: 6px 13px; border-radius: 8px; font-size: 13px; font-weight: 560; color: var(--text-2);
}
.modtabs button:hover { color: var(--text); }
.modtabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); font-weight: 620; }

.icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--text-2);
  width: 34px; height: 34px; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.btn {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: var(--r-sm); cursor: pointer;
  font-size: 13px; font-weight: 560; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { border-color: transparent; background: var(--red-soft); color: var(--red); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.sync-chip {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-2); border: 0; cursor: pointer;
}
.sync-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gray); flex: none; }
.sync-chip.idle .dot { background: var(--green); }
.sync-chip.syncing .dot { background: var(--blue); animation: pulse 1.4s ease-in-out infinite; }
.sync-chip.error .dot, .sync-chip.offline .dot { background: var(--orange); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- body ---------- */
.main { flex: 1; min-height: 0; position: relative; }
.pane { position: absolute; inset: 0; overflow: auto; -webkit-overflow-scrolling: touch; }
.pane.pad { padding: 20px; }
.pane iframe { width: 100%; height: 100%; border: 0; display: block; }
[hidden] { display: none !important; }

.view-title { font-size: 20px; font-weight: 680; letter-spacing: -0.3px; margin-bottom: 3px; }
.view-sub { font-size: 13px; color: var(--text-3); margin-bottom: 18px; }

/* ---------- cards & tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px,100%), 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 15px 17px; box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; gap: 3px;
}
.kpi .val { font-size: 27px; font-weight: 660; letter-spacing: -0.6px; line-height: 1.1; }
.kpi .lbl { font-size: 13px; font-weight: 560; }
.kpi .sub { font-size: 12px; color: var(--text-3); }
.kpi.warn .val { color: var(--orange); }
.kpi.ok .val { color: var(--green); }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1); overflow: hidden; margin-bottom: 16px;
}
.panel > header {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.panel > header h2 { font-size: 14px; font-weight: 640; display: flex; align-items: center; gap: 7px; }
.panel-pad { padding: 16px; }
.cols2 { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(0,1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .cols2 { grid-template-columns: minmax(0,1fr); } }

/* ---------- pipeline ---------- */
.pipe { display: flex; align-items: stretch; gap: 0; overflow-x: auto; }
.pipe-step { flex: 1; min-width: 128px; padding: 14px 16px; position: relative; }
.pipe-step + .pipe-step { border-left: 1px solid var(--border); }
.pipe-step .n { font-size: 24px; font-weight: 660; letter-spacing: -0.5px; }
.pipe-step .k { font-size: 12.5px; font-weight: 580; color: var(--text-2); }
.pipe-step .m { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.pipe-step .bar { height: 3px; border-radius: 2px; background: var(--accent); margin-top: 9px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.rows { width: 100%; border-collapse: collapse; }
table.rows th {
  text-align: left; font-size: 11px; font-weight: 640; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-3); padding: 11px 14px 9px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.rows td { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
table.rows tr:last-child td { border-bottom: 0; }
table.rows tbody tr[data-open] { cursor: pointer; }
table.rows tbody tr[data-open]:hover { background: var(--surface-2); }
.cell-main { display: flex; flex-direction: column; }
.cell-main b { font-weight: 620; }
.cell-main span { font-size: 12px; color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }

.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 620; white-space: nowrap;
  background: var(--gray-soft); color: var(--gray);
}
.pill.quote { background: var(--purple-soft); color: var(--purple); }
.pill.design { background: var(--gray-soft); color: var(--text-2); }
.pill.order { background: var(--blue-soft); color: var(--blue); }
.pill.invoice { background: var(--green-soft); color: var(--green); }
.pill.waybill { background: var(--orange-soft); color: var(--orange); }
.pill.warn { background: var(--orange-soft); color: var(--orange); }
.pill.bad { background: var(--red-soft); color: var(--red); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); font-size: 11.5px; }

/* ---------- search + forms ---------- */
.search-box {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
  background: var(--surface-2); border-radius: var(--r-sm); padding: 7px 11px;
}
.search-box input { border: 0; background: transparent; outline: none; flex: 1; min-width: 0; font-size: 13.5px; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.input, .select, textarea.input {
  width: 100%; padding: 8px 11px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: 13.5px; outline: none;
}
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-row { display: flex; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.form-row > .field { flex: 1 1 200px; }

/* ---------- modal ---------- */
.modal-scrim {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fade 0.16s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--bg-elevated); border-radius: var(--r-lg); box-shadow: var(--shadow-3);
  width: min(640px, 100%); max-height: min(86vh, 860px); display: flex; flex-direction: column;
  animation: rise 0.22s var(--spring);
}
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
.modal > header { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.modal > header h2 { font-size: 16px; font-weight: 660; flex: 1; min-width: 0; }
.modal-body { padding: 18px; overflow: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 4px; }
.modal > footer { display: flex; align-items: center; gap: 10px; padding: 13px 18px; border-top: 1px solid var(--border); }

/* ---------- registry lookup ---------- */
.reg-results { border: 1px solid var(--border); border-radius: var(--r-sm); max-height: 240px; overflow: auto; }
.reg-row {
  display: block; width: 100%; text-align: left; border: 0; background: transparent; cursor: pointer;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
}
.reg-row:last-child { border-bottom: 0; }
.reg-row:hover { background: var(--surface-2); }
.reg-row b { display: block; font-size: 13.5px; font-weight: 620; }
.reg-row span { display: block; font-size: 12px; color: var(--text-3); }
.reg-row .vat { color: var(--green); font-weight: 600; }

/* ---------- empty / toast ---------- */
.empty { text-align: center; padding: 44px 20px; color: var(--text-3); }
.empty .big { font-size: 34px; display: block; margin-bottom: 10px; opacity: 0.5; }
.empty h3 { font-size: 15px; font-weight: 620; color: var(--text-2); margin-bottom: 4px; }
.empty p { font-size: 13px; max-width: 380px; margin: 0 auto; }

#toast-root { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 560; box-shadow: var(--shadow-2);
  animation: rise 0.22s var(--spring); max-width: min(90vw, 460px);
}
.toast.leaving { opacity: 0; transition: opacity 0.25s; }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .brand span:not(.mark) { display: none; }
  .modtabs { order: 3; flex: 1 1 100%; overflow-x: auto; }
  .topbar { height: auto; min-height: var(--topbar-h); flex-wrap: wrap; padding-bottom: 8px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
  .pane.pad { padding: 14px; }
  .sync-chip span { display: none; }
}
