:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.11);
  --teal: #50b69e;
  --green: #059669;
  --green-soft: rgba(5, 150, 105, 0.13);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.15);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.13);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
}

html[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-alt: #0f172a;
  --border: #1e293b;
  --border-strong: #334155;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: rgba(59, 130, 246, 0.18);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.18);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.2);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.2);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-amber { color: var(--amber); }
.text-red { color: var(--red); }
.text-primary { color: var(--primary); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

/* TOPBAR */
.topbar {
  background: linear-gradient(180deg, #0b1426 0%, #101e38 100%);
  border-bottom: 1px solid rgba(255,255,255,0.09);
  box-shadow: 0 1px 0 rgba(80, 182, 158, 0.35), 0 4px 14px rgba(11, 20, 38, 0.18);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}
.brand-logo-img { height: 32px; width: auto; object-fit: contain; }
.brand-div { width: 1px; height: 26px; background: rgba(255,255,255,0.18); }
.brand-title { font-size: 15px; font-weight: 700; color: #f8fafc; line-height: 1.2; }
.brand-sub { font-size: 11.5px; color: #94a3b8; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* BUTTONS & INPUTS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { opacity: 0.92; }
.btn-outline { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-outline:hover { background: var(--surface-alt); }
.btn-topbar {
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(255,255,255,0.16);
  color: #f8fafc;
}
.btn-topbar:hover { background: rgba(255,255,255,0.16); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-lg { padding: 10px 18px; font-size: 13.5px; font-weight: 700; }

.input, select.input, textarea.input {
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.input-sm { padding: 5px 8px; font-size: 12px; }

/* LAYOUT & CARDS */
.container { max-width: 1480px; margin: 0 auto; padding: 18px 20px 48px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 16px 18px; }
.card-header {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow);
}
.kpi-lbl { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.kpi-val { font-size: 24px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* TABS */
.tabs-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
  white-space: nowrap;
}
.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2.5px solid transparent;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* TABLES */
.table-wrap { width: 100%; overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data-table tbody tr:hover { background: var(--surface-alt); }

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  border: 1px solid var(--border-strong);
  background: var(--surface-alt);
  cursor: pointer;
}
.tag-chip.selected {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 700;
}

/* CHECKOUT SPLIT GRID */
.checkout-grid {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: 16px;
}
@media (max-width: 960px) {
  .checkout-grid { grid-template-columns: 1fr; }
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 640px) {
  .form-grid-2 { grid-template-columns: 1fr; }
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text-secondary);
}

/* TOAST */
.toast {
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--green);
  background: var(--green-soft);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* MODALS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 20, 38, 0.65);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* SSO GATE OVERLAY */
.sso-gate {
  min-height: 85vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.sso-card {
  max-width: 440px;
  width: 100%;
  text-align: center;
  padding: 32px 26px;
}

/* SIGNATURE PAD & CURSIVE SIGN-OFF */
.sig-canvas-wrap {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: #ffffff;
  position: relative;
  overflow: hidden;
  touch-action: none;
}
.sig-canvas {
  display: block;
  width: 100%;
  height: 120px;
  cursor: crosshair;
}
.typed-sig-preview {
  font-family: "Segoe Script", "Bradley Hand", "Brush Script MT", cursive;
  font-size: 26px;
  color: #1e3a8a;
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  min-height: 58px;
  display: flex;
  align-items: center;
}

/* PRINT STYLESHEET FOR PHYSICAL INVENTORY COUNT SHEET & SIGNED CERTIFICATES */
@media print {
  .no-print { display: none !important; }
  body { background: #ffffff !important; color: #000000 !important; font-size: 11.5px; }
  .container { max-width: 100% !important; padding: 0 !important; margin: 0 !important; }
  .modal-backdrop {
    position: static !important;
    background: #ffffff !important;
    padding: 0 !important;
  }
  .modal-box {
    max-width: 100% !important;
    max-height: none !important;
    border: none !important;
    box-shadow: none !important;
    overflow: visible !important;
  }
  .print-sheet {
    border: none !important;
    box-shadow: none !important;
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
  }
  .print-sheet th, .print-sheet td {
    border-bottom: 1px solid #94a3b8 !important;
    color: #000000 !important;
    padding: 7px 6px !important;
  }
  .write-line { border-bottom: 1.5px solid #0f172a !important; height: 18px; }
}
