:root {
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --bg: #f5f5f7;
  --panel: rgba(255,255,255,0.78);
  --panel-solid: #ffffff;
  --line: rgba(0,0,0,0.08);
  --blue: #0a8a5c;
  --blue-dark: #076b47;
  --blue-bg: rgba(10,138,92,0.08);
  --green: #1d7a46;
  --green-bg: rgba(29,122,70,0.09);
  --amber: #a5680a;
  --amber-bg: rgba(165,104,10,0.1);
  --red: #d93025;
  --red-bg: rgba(217,48,37,0.09);
  --radius: 14px;
  --radius-sm: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  background:
    radial-gradient(1100px 500px at 15% -10%, rgba(10,138,92,0.08), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(165,104,10,0.05), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.shell { display: flex; min-height: 100vh; }

.rail {
  width: 232px;
  background: var(--panel);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 24px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(145deg, #34c98a, var(--blue));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 16px;
  box-shadow: 0 4px 14px rgba(10,138,92,0.35);
}
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  text-align: left; background: none; border: none; color: var(--muted);
  padding: 9px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px;
  font-family: inherit; font-weight: 500; transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: rgba(0,0,0,0.04); color: var(--ink); }
.nav-item.active { background: var(--blue); color: #fff; font-weight: 600; }
.rail-footer { margin-top: auto; font-size: 10.5px; color: #9a9a9e; padding: 0 6px; line-height: 1.6; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 32px; border-bottom: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 22px; margin: 0; font-weight: 600; letter-spacing: -0.015em; }
.view-root { padding: 28px 32px; overflow: auto; }

.btn {
  background: var(--blue); color: #fff; border: none; padding: 9px 18px;
  border-radius: 980px; cursor: pointer; font-size: 13.5px; font-weight: 500;
  font-family: inherit; transition: background 0.15s ease, transform 0.1s ease;
}
.btn:hover { background: var(--blue-dark); }
.btn:active { transform: scale(0.98); }
.btn.secondary { background: rgba(0,0,0,0.05); color: var(--ink); border: none; }
.btn.secondary:hover { background: rgba(0,0,0,0.09); }
.btn.small { padding: 6px 13px; font-size: 12px; }
.btn.danger { background: var(--red); }

.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.stat-card .label { font-size: 12px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.stat-card .value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.stat-card .value.warn { color: var(--amber); }

table {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
th { background: rgba(0,0,0,0.02); font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(10,138,92,0.045); }

.badge { display: inline-block; padding: 3px 11px; border-radius: 980px; font-size: 11.5px; font-weight: 600; }
.badge.confirmed, .badge.priced, .badge.paid, .badge.received, .badge.confirmed-po { background: var(--green-bg); color: var(--green); }
.badge.quote_pending { background: var(--amber-bg); color: var(--amber); }
.badge.overdue, .badge.cancelled { background: var(--red-bg); color: var(--red); }
.badge.draft, .badge.unpaid, .badge.submitted { background: rgba(0,0,0,0.06); color: var(--muted); }
.badge.partial { background: var(--amber-bg); color: var(--amber); }
.badge.shipped { background: rgba(90,110,140,0.1); color: #4a5c78; }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 8px 13px; border: 1px solid var(--line); border-radius: 980px;
  font-family: inherit; font-size: 13px; background: var(--panel-solid);
}

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.32);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: flex-start; justify-content: center; padding: 48px 20px;
  overflow: auto; z-index: 10;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px);
  border-radius: 20px; padding: 28px; width: 100%; max-width: 560px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.22);
  border: 1px solid rgba(255,255,255,0.6);
}
.modal h2 { margin-top: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.015em; }
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13.5px; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.line-editor { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 12px; background: rgba(0,0,0,0.02); }
.line-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.line-row select { flex: 2; border-radius: var(--radius-sm) !important; }
.line-row input { flex: 1; border-radius: var(--radius-sm) !important; }
.line-total { font-family: ui-monospace, monospace; width: 90px; text-align: right; font-size: 12.5px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.subtle { color: var(--muted); font-size: 12.5px; }
.right { text-align: right; }
.mono { font-family: ui-monospace, "SF Mono", monospace; font-variant-numeric: tabular-nums; }
.warning-banner {
  background: var(--amber-bg); color: #7a5008; border: 1px solid rgba(165,104,10,0.25);
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 18px;
}

.hidden { display: none !important; }

.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--panel); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--line); border-radius: 20px; padding: 32px; width: 100%; max-width: 360px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.1);
}
.login-error {
  background: var(--red-bg); color: var(--red); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 12.5px; margin-bottom: 14px;
}
#user-badge { font-size: 12px; color: var(--ink); font-weight: 600; }
#user-badge .role { color: var(--muted); font-weight: 400; text-transform: capitalize; }
#user-badge button {
  background: none; border: none; color: var(--blue); cursor: pointer; font-size: 11.5px;
  padding: 0; margin-top: 4px; font-family: inherit; text-decoration: underline;
}

.analytics-section { margin-bottom: 30px; }
.analytics-section h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; margin: 0 0 4px; }
.analytics-section .section-sub { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.bar-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 20px; backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.bar-row { display: grid; grid-template-columns: 170px 1fr 100px 1fr 90px; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.bar-row:last-child { border-bottom: none; }
.bar-row .bar-label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-label .sku-count { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.bar-track { background: rgba(0,0,0,0.05); border-radius: 6px; height: 9px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; }
.bar-fill.qty { background: linear-gradient(90deg, #34c98a, var(--green)); }
.bar-fill.value { background: linear-gradient(90deg, #6fa0c9, #3b6d99); }
.bar-num { text-align: right; font-family: ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.bar-legend { display: flex; gap: 18px; font-size: 11.5px; color: var(--muted); margin-bottom: 10px; }
.bar-legend span { display: inline-flex; align-items: center; gap: 6px; }
.bar-legend .dot { width: 9px; height: 9px; border-radius: 50%; }
.bar-legend .dot.qty { background: var(--green); }
.bar-legend .dot.value { background: #3b6d99; }
.quote-pending-note { font-size: 11px; color: var(--amber); margin-top: 2px; }

.subtabs { display: flex; gap: 6px; margin-bottom: 18px; }
.subtabs button {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 7px 14px; border-radius: 980px; font-size: 12.5px; font-weight: 500;
  cursor: pointer; font-family: inherit;
}
.subtabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.stock-warn { color: var(--red); font-weight: 700; }
.stock-low { color: var(--amber); font-weight: 700; }
