@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap');

:root {
  --sonance-charcoal: #333F48;
  --sonance-blue: #00A3E1;
  --sonance-green: #00B2A9;
  --sonance-light-gray: #D9D9D6;

  --bg: #FFFFFF;
  --bg-2: #f8f9fa;
  --bg-3: #f0f2f3;
  --fg: #333F48;
  --fg-muted: #6b7780;
  --fg-subtle: #8f999f;
  --border: #e2e2e2;
  --surface: #FFFFFF;
  --input-bg: #FFFFFF;
  --success: #2E7D32;
  --success-light: #e8f5e9;
  --error: #C62828;
  --error-light: #ffebee;
  --warning: #F57C00;
  --warning-light: #fff3e0;
  --info: #1565C0;
  --glow: rgba(0,163,225,0.18);
  --glow-strong: rgba(0,163,225,0.35);
  --shadow-sm: 0 1px 2px rgba(51,63,72,0.06);
  --shadow-md: 0 4px 16px rgba(51,63,72,0.08);
  --shadow-lg: 0 12px 32px rgba(51,63,72,0.12);
  --radius: 10px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #1a1f24;
  --bg-2: #242a31;
  --bg-3: #2d343c;
  --fg: #FFFFFF;
  --fg-muted: #8f999f;
  --fg-subtle: #6b7780;
  --border: #3a444c;
  --surface: #242a31;
  --input-bg: #2d343c;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.4);
  --success-light: rgba(46,125,50,0.15);
  --error-light: rgba(198,40,40,0.15);
  --warning-light: rgba(245,124,0,0.15);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: 'Montserrat', system-ui, sans-serif;
  background: var(--bg-2);
  color: var(--fg);
  line-height: 1.5;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}
a { color: var(--sonance-blue); text-decoration: none; }
.hidden { display: none !important; }

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
[data-theme="dark"] .topbar {
  background: rgba(26,31,36,0.85);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text .app { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; color: var(--fg); }
.brand-text .sub { font-weight: 400; font-size: 11px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: var(--bg-3); color: var(--fg-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.pill .dot {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--sonance-blue); box-shadow: 0 0 0 4px var(--glow);
}

/* ---- Theme Toggle ---- */
.theme-toggle {
  width: 36px; height: 36px; border-radius: 999px;
  background: var(--bg-3); border: 1px solid var(--border);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; transition: all var(--transition);
}
.theme-toggle:hover { background: var(--border); }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }

/* ---- Layout ---- */
.container { max-width: 1200px; margin: 0 auto; padding: 28px 20px 80px; }
.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; gap: 16px; margin-bottom: 28px;
}
.page-title { font-size: 30px; font-weight: 300; letter-spacing: -0.02em; margin: 0; color: var(--fg); }
.page-title strong { font-weight: 600; }
.page-sub { font-size: 13px; color: var(--fg-muted); margin: 4px 0 0; }

/* ---- KPI Row ---- */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }
@media (max-width: 720px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.kpi-label { font-size: 11px; font-weight: 600; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.kpi-value { font-size: 28px; font-weight: 300; margin-top: 4px; color: var(--fg); }
.kpi-value strong { font-weight: 600; }
.kpi-foot { font-size: 11px; color: var(--fg-subtle); margin-top: 2px; }
.kpi.accent .kpi-value { color: var(--sonance-blue); }

/* ---- Section Row ---- */
.section-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-title { font-size: 14px; font-weight: 600; color: var(--fg); text-transform: uppercase; letter-spacing: 0.06em; margin: 0; }
.filter-tabs { display: inline-flex; background: var(--bg-3); border-radius: 999px; padding: 3px; font-size: 12px; font-weight: 500; }
.filter-tabs button {
  border: none; background: transparent; color: var(--fg-muted);
  padding: 6px 14px; border-radius: 999px; cursor: pointer; font: inherit;
  transition: all var(--transition);
}
.filter-tabs button.active { background: var(--surface); color: var(--fg); box-shadow: var(--shadow-sm); }

/* ---- Order Cards ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.order-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); padding: 18px;
  cursor: pointer; transition: all 200ms cubic-bezier(0.16,1,0.3,1);
  position: relative; overflow: hidden;
}
.order-card:hover {
  border-color: rgba(0,163,225,0.4);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg), 0 0 24px var(--glow);
}
.order-card .ribbon { position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--sonance-blue); opacity: 0.7; }
.order-card.urgent .ribbon { background: var(--error); }
.order-card .head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.order-card .order-num { font-size: 11px; font-weight: 600; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.order-card .product { font-size: 17px; font-weight: 600; margin: 4px 0 0; color: var(--fg); letter-spacing: -0.01em; }
.order-card .meta { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.meta-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--bg-3); color: var(--fg-muted);
  border-radius: 8px; padding: 4px 8px; font-size: 11px; font-weight: 500;
}
.meta-chip strong { color: var(--fg); font-weight: 600; }
.priority {
  display: inline-flex; padding: 4px 10px; border-radius: 999px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--bg-3); color: var(--fg-muted);
}
.priority.high, .priority.critical { background: var(--warning-light); color: var(--warning); }
.order-card .qty-row {
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--bg-3);
  display: flex; align-items: center; justify-content: space-between;
}
.qty-block { display: flex; flex-direction: column; }
.qty-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-muted); font-weight: 600; }
.qty-value { font-size: 24px; font-weight: 300; color: var(--fg); line-height: 1; margin-top: 2px; }
.qty-value strong { font-weight: 600; color: var(--sonance-blue); }
.splits-count { font-size: 11px; color: var(--fg-subtle); margin-top: 2px; }
.pick-btn {
  background: var(--sonance-charcoal); color: white; border: none;
  border-radius: 12px; padding: 10px 18px;
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  cursor: pointer; transition: all 200ms; font-family: inherit;
}
[data-theme="dark"] .pick-btn { background: var(--sonance-blue); }
.pick-btn:hover { box-shadow: 0 0 24px var(--glow-strong); }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(51,63,72,0.45);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  z-index: 100; display: none;
  align-items: flex-start; justify-content: center;
  overflow-y: auto; padding: 30px 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-2xl);
  width: 100%; max-width: 720px;
  box-shadow: var(--shadow-lg); overflow: hidden;
  animation: slideUp 250ms cubic-bezier(0.16,1,0.3,1);
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-head {
  padding: 22px 26px 18px; border-bottom: 1px solid var(--bg-3);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.modal-eyebrow { font-size: 11px; font-weight: 600; color: var(--sonance-blue); text-transform: uppercase; letter-spacing: 0.08em; }
.modal-title { font-size: 22px; font-weight: 600; margin: 4px 0 6px; letter-spacing: -0.01em; }
.modal-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.close-x {
  border: none; background: var(--bg-3);
  width: 36px; height: 36px; border-radius: 999px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-muted); font-size: 18px; font-family: inherit;
}
.close-x:hover { background: var(--border); color: var(--fg); }
.modal-body { padding: 22px 26px; }

/* Progress ring */
.progress-block { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.progress-ring {
  --pct: 0;
  width: 78px; height: 78px; border-radius: 999px;
  background: conic-gradient(var(--sonance-blue) calc(var(--pct) * 1%), var(--bg-3) 0);
  display: inline-grid; place-items: center; flex-shrink: 0;
}
.progress-ring::after {
  content: ''; width: 62px; height: 62px;
  background: var(--surface); border-radius: 999px; grid-area: 1 / 1;
}
.progress-ring .ring-text { grid-area: 1 / 1; z-index: 2; text-align: center; line-height: 1; }
.progress-ring .ring-num { font-size: 18px; font-weight: 600; color: var(--fg); }
.progress-ring .ring-of { font-size: 10px; color: var(--fg-muted); }
.progress-info { flex: 1; }
.progress-info .lbl { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--fg-muted); letter-spacing: 0.06em; }
.progress-info .val { font-size: 18px; font-weight: 500; color: var(--fg); margin-top: 2px; }
.remaining { font-size: 13px; color: var(--fg-muted); margin-top: 2px; }

/* Scan input */
.scan-row { display: flex; gap: 10px; margin-bottom: 16px; }
.scan-input {
  flex: 1;
  border: 2px solid var(--sonance-blue); border-radius: 14px;
  padding: 14px 16px; font-size: 16px;
  font-family: 'JetBrains Mono', 'Menlo', monospace;
  background: var(--input-bg); color: var(--fg);
  box-shadow: 0 0 0 6px var(--glow), inset 0 1px 0 rgba(255,255,255,0.6);
  outline: none; transition: box-shadow 200ms;
}
.scan-input:focus { box-shadow: 0 0 0 6px var(--glow-strong); }
.scan-input::placeholder { color: var(--fg-subtle); font-family: 'Montserrat', sans-serif; }
.scan-help { font-size: 11px; color: var(--fg-subtle); margin: -10px 0 18px; text-align: center; }

/* Items breakdown */
.items-card {
  background: var(--bg-2); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 18px;
}
.items-card .row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; font-size: 13px; color: var(--fg-muted);
}
.items-card .row + .row { border-top: 1px dashed var(--border); }
.items-card .row .item-id { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--fg); }
.items-card .row .qstat strong { color: var(--fg); }

/* Serial list */
.serial-list-title { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 10px; }
.serial-list-title .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-muted); font-weight: 600; }
.serial-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 22px; }
.serial-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--success-light); border: 1px solid rgba(46,125,50,0.18);
  border-radius: 12px; padding: 10px 14px;
  animation: pop 250ms ease-out;
}
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.serial-item .check {
  width: 22px; height: 22px; border-radius: 999px;
  background: var(--success); color: white;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.serial-item .sn { flex: 1; font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--fg); }
.serial-item .assigned { font-size: 10px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.serial-item .undo {
  border: none; background: transparent; color: var(--fg-subtle);
  cursor: pointer; font-size: 16px; line-height: 1; padding: 0 6px; font-family: inherit;
}
.serial-item .undo:hover { color: var(--error); }
.serial-item.error { background: var(--error-light); border-color: rgba(198,40,40,0.2); }
.serial-item.error .check { background: var(--error); }

/* Modal footer */
.modal-foot {
  padding: 18px 26px; border-top: 1px solid var(--bg-3);
  background: var(--bg-2); display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.btn {
  border: none; border-radius: 12px; padding: 12px 22px;
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  cursor: pointer; font-family: inherit; transition: all 200ms;
}
.btn-ghost { background: transparent; color: var(--fg-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--fg); border-color: var(--fg-muted); }
.btn-primary { background: var(--sonance-blue); color: white; box-shadow: 0 4px 14px var(--glow); }
.btn-primary:hover { box-shadow: 0 6px 24px var(--glow-strong); transform: translateY(-1px); }
.btn-primary:disabled { background: var(--bg-3); color: var(--fg-subtle); box-shadow: none; cursor: not-allowed; transform: none; }

/* Non-serial confirm */
.confirm-block {
  background: var(--bg-2); border-radius: 14px;
  padding: 24px; text-align: center; margin-bottom: 18px;
}
.confirm-block .qty-big { font-size: 48px; font-weight: 300; color: var(--sonance-blue); }
.confirm-block .qty-big strong { font-weight: 600; }

/* Empty / Loading */
.empty-state {
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius-xl); padding: 60px 20px;
  text-align: center; color: var(--fg-muted);
}
.loading-state { text-align: center; padding: 60px 20px; color: var(--fg-muted); }
.spinner {
  display: inline-block; width: 32px; height: 32px;
  border: 3px solid var(--border); border-top-color: var(--sonance-blue);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%);
  padding: 0.75rem 1.5rem; border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500; color: #fff;
  z-index: 3000; animation: toastIn 0.3s ease-out; box-shadow: var(--shadow-lg);
}
.toast-success { background: var(--success); }
.toast-error { background: var(--error); }
.toast-info { background: var(--info); }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(1rem); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* Responsive */
@media (max-width: 768px) {
  .topbar-inner { padding: 12px 16px; }
  .container { padding: 20px 16px 80px; }
  .page-title { font-size: 24px; }
  .grid { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}
