/* Cflow ERP — design system v2
   Principles: dense, high-contrast, action-first, no pastels, system fonts, fast.
   Inspiration: Linear, Retool, Shopify admin. NOT marketing-template SaaS dashboards. */

:root {
  /* Neutrals (stone scale) */
  --bg:        #fafaf9;
  --surface:   #ffffff;
  --surface-2: #f5f5f4;
  --border:    #e7e5e4;
  --border-strong: #d6d3d1;
  --text:      #0c0a09;
  --text-muted:#57534e;
  --text-dim:  #a8a29e;

  /* Sidebar (always dark) */
  --side-bg:   #0c0a09;
  --side-text: #d6d3d1;
  --side-text-dim: #78716c;
  --side-hover: #1c1917;
  --side-active: #292524;

  /* Single accent + status */
  --accent:    #4338ca;
  --accent-h:  #3730a3;
  --ok:        #047857;
  --ok-bg:     #ecfdf5;
  --warn:      #b45309;
  --warn-bg:   #fffbeb;
  --err:       #b91c1c;
  --err-bg:    #fef2f2;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Scale */
  --t-xs: 11px;
  --t-sm: 12px;
  --t-md: 13px;
  --t-lg: 15px;
  --t-xl: 20px;
  --t-2xl: 28px;
  --t-hero: 36px;

  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;

  --shadow-sm: 0 1px 2px rgba(12,10,9,.04);
  --shadow:    0 1px 3px rgba(12,10,9,.06), 0 1px 2px rgba(12,10,9,.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-sans); font-size: var(--t-md); line-height: 1.45;
  font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Tabular numerals everywhere numbers appear */
.num, .kpi-value, .hero-value, .tbl td, .tbl th { font-variant-numeric: tabular-nums; }

/* ---------- LOGIN ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(ellipse 60% 50% at 50% -10%, rgba(67,56,202,.08), transparent),
    var(--bg); }
.login-card { background: var(--surface); padding: 36px; border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow); width: 100%; max-width: 380px; }
.login-logo { width: 56px; height: 56px; background: var(--accent); border-radius: var(--r-md);
  display: grid; place-items: center; margin-bottom: 20px; }
.login-logo img { width: 32px; height: 32px; filter: brightness(0) invert(1); }
.login-card h1 { margin: 0 0 4px; font-size: var(--t-xl); font-weight: 600; letter-spacing: -0.01em; }
.login-card .sub { color: var(--text-muted); margin-bottom: 28px; font-size: var(--t-md); }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: var(--t-xs); color: var(--text-muted);
  margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.field input { width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--r-md); font-size: var(--t-md); background: var(--surface);
  color: var(--text); transition: border-color .15s, box-shadow .15s; }
.field input:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(67,56,202,.12); }
.btn-primary { background: var(--accent); color: #fff; border: none; padding: 11px 16px;
  border-radius: var(--r-md); font-weight: 500; width: 100%; font-size: var(--t-md);
  transition: background .15s; }
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.err-msg { color: var(--err); font-size: var(--t-sm); margin-top: 12px; min-height: 18px; }

/* ---------- SHELL ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--side-bg); color: var(--side-text);
  flex-shrink: 0; transition: transform .2s; display: flex; flex-direction: column;
  border-right: 1px solid #1c1917; }
.brand { padding: 20px 20px 24px; display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 28px; height: 28px; background: var(--accent); border-radius: var(--r-sm);
  display: grid; place-items: center; flex-shrink: 0; }
.brand-logo img { width: 18px; height: 18px; filter: brightness(0) invert(1); }
.brand-text { font-size: var(--t-lg); font-weight: 600; color: #fff; letter-spacing: -0.01em; }
.brand-sub { font-size: var(--t-xs); color: var(--side-text-dim); margin-top: 1px; }
.nav { flex: 1; padding: 4px 8px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  color: var(--side-text); font-size: var(--t-md); border-radius: var(--r-md);
  margin-bottom: 1px; transition: background .12s; }
.nav-item:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--side-active); color: #fff; }
.nav-icon { width: 16px; height: 16px; opacity: .7; flex-shrink: 0; }
.nav-item.active .nav-icon { opacity: 1; }
.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 28px; display: flex; align-items: center; gap: 16px; }
.topbar-title { font-weight: 600; font-size: var(--t-lg); flex: 1; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip { color: var(--text-muted); font-size: var(--t-sm); }
.btn-link { background: none; border: none; color: var(--accent); font-size: var(--t-sm); padding: 0; }
.btn-link:hover { text-decoration: underline; }
.hamburger { display: none; background: none; border: none; font-size: 22px; color: var(--text); }
.content { padding: 24px 28px; flex: 1; overflow-y: auto; }

@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; height: 100vh; z-index: 100; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: block; }
  .content { padding: 16px; }
}

/* ---------- HERO STRIP (action-first) ---------- */
.hero-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 24px; }
.hero { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px 20px; position: relative; transition: border-color .12s; }
.hero:hover { border-color: var(--border-strong); }
.hero-label { font-size: var(--t-xs); color: var(--text-muted); text-transform: uppercase;
  letter-spacing: .05em; font-weight: 500; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.hero-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); }
.hero-value { font-size: var(--t-hero); font-weight: 600; line-height: 1; letter-spacing: -0.02em; color: var(--text); }
.hero-sub { font-size: var(--t-sm); color: var(--text-muted); margin-top: 6px; }
.hero.alert .hero-dot { background: var(--err); box-shadow: 0 0 0 3px rgba(185,28,28,.15); }
.hero.alert .hero-value { color: var(--err); }
.hero.warn .hero-dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(180,83,9,.15); }
.hero.warn .hero-value { color: var(--warn); }
.hero.ok .hero-dot { background: var(--ok); }

/* ---------- KPI strip (secondary) ---------- */
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px; background: var(--border); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden; margin-bottom: 24px; }
.kpi { background: var(--surface); padding: 14px 16px; }
.kpi-label { font-size: var(--t-xs); color: var(--text-muted); text-transform: uppercase;
  letter-spacing: .04em; font-weight: 500; margin-bottom: 4px; }
.kpi-value { font-size: var(--t-2xl); font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; }
.kpi.warn .kpi-value { color: var(--warn); }
.kpi.err .kpi-value { color: var(--err); }

/* ---------- Sections + tables ---------- */
.split { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }
.section { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden; }
.section-head { padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; }
.section-head h2 { margin: 0; font-size: var(--t-md); font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.section-body { max-height: 480px; overflow-y: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--t-md); }
.tbl thead { position: sticky; top: 0; background: var(--surface-2); z-index: 1; }
.tbl th { text-align: left; padding: 8px 18px; color: var(--text-muted);
  font-weight: 500; font-size: var(--t-xs); text-transform: uppercase;
  letter-spacing: .04em; border-bottom: 1px solid var(--border); }
.tbl td { padding: 10px 18px; border-bottom: 1px solid var(--border); color: var(--text); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .ref { font-family: var(--font-mono); font-size: var(--t-sm); font-weight: 500; }
.tbl .num-r { text-align: right; }
.empty { color: var(--text-dim); padding: 32px 18px; text-align: center; font-size: var(--t-md); }

/* Status pill */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: var(--t-xs); font-weight: 500; line-height: 1.5; }
.pill-err  { background: var(--err-bg); color: var(--err); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-ok   { background: var(--ok-bg); color: var(--ok); }

/* ---------- Scanner (kept compatible) ---------- */
.scanner-page { max-width: 720px; margin: 0 auto; }
.scan-input-wrap { background: var(--surface); border: 1px solid var(--border);
  padding: 28px; border-radius: var(--r-lg); margin-bottom: 16px; }
.scan-input-wrap label { display: block; font-size: var(--t-xs); color: var(--text-muted);
  margin-bottom: 10px; text-transform: uppercase; letter-spacing: .05em; font-weight: 500; }
.scan-input { width: 100%; padding: 18px 20px; font-size: 24px; font-weight: 600;
  border: 2px solid var(--border-strong); border-radius: var(--r-md); text-align: center;
  letter-spacing: 2px; font-family: var(--font-mono); background: var(--surface); color: var(--text); }
.scan-input:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(67,56,202,.12); }
.scan-feedback { min-height: 64px; margin-top: 14px; display: flex; align-items: center;
  justify-content: center; font-size: var(--t-lg); font-weight: 500; border-radius: var(--r-md);
  padding: 12px; border: 1px solid var(--border); color: var(--text-muted); }
.scan-feedback.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.scan-feedback.err { background: var(--err-bg); color: var(--err); border-color: transparent; }
.scan-stats { display: flex; gap: 24px; margin-bottom: 14px; font-size: var(--t-sm); color: var(--text-muted); }
.scan-history { max-height: 50vh; overflow-y: auto; }
.scan-row { display: flex; justify-content: space-between; padding: 10px 18px;
  border-bottom: 1px solid var(--border); font-size: var(--t-sm); }
.scan-row.ok { color: var(--ok); }
.scan-row.err { color: var(--err); }

/* ---------- Toast ---------- */
.cflow-toast { position: fixed; top: 20px; right: 20px; background: var(--text); color: #fff;
  padding: 10px 16px; border-radius: var(--r-md); font-size: var(--t-sm);
  box-shadow: var(--shadow); opacity: 0; transform: translateY(-10px);
  transition: all .2s; z-index: 9999; }
.cflow-toast.show { opacity: 1; transform: translateY(0); }
.cflow-toast-err { background: var(--err); }
.cflow-toast-ok { background: var(--ok); }
