:root {
  --primary: #d62828;
  --primary-dark: #b71c1c;
  --secondary: #1d4ed8;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --white: #ffffff;
  --ink: #1e293b;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #ffffff;
  --glass-bg: rgba(255,255,255,0.72);
  --glass-border: rgba(255,255,255,0.48);
  --glass-shadow: 0 10px 24px rgba(15,23,42,0.08);
  --radius: 10px;
  --radius-lg: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Kanit','Noto Sans Thai',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;
  background: linear-gradient(180deg,#ffffff 0%,#f7f9ff 100%);
  color: var(--ink); min-height: 100vh; font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== Layout ===== */
.shell { display: flex; min-height: 100vh; }

/* ===== Left Sidebar ===== */
.left-sidebar {
  width: 272px; min-width: 272px;
  background: linear-gradient(180deg,#0f3fa8 0%,#0b2f7d 45%,#091f52 100%);
  color: #fff; position: fixed; left: 0; top: 0; height: 100vh;
  overflow-y: auto; z-index: 1000;
  box-shadow: 4px 0 22px rgba(15,23,42,.18);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: transform .3s ease;
}
.left-sidebar::-webkit-scrollbar { width: 5px; }
.left-sidebar::-webkit-scrollbar-track { background: rgba(255,255,255,.05); }
.left-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 3px; }

/* Sidebar Header */
.sidebar-header { padding: 22px 20px 16px; background: rgba(255,255,255,.08); border-bottom: 1px solid rgba(255,255,255,.12); }
.sidebar-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.sidebar-logo-icon { font-size: 30px; }
.sidebar-logo h1 {
  font-size: 17px; font-weight: 700; margin: 0;
  background: linear-gradient(135deg,#ffffff,#bfdbfe);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.sidebar-logo p { font-size: 11px; color: rgba(255,255,255,.82); margin: 3px 0 0; }
.user-profile {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: rgba(255,255,255,.06); border-radius: var(--radius);
}
.user-avatar {
  width: 36px; height: 36px;
  background: linear-gradient(135deg,var(--primary),var(--secondary));
  border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.user-name { font-size: 13px; font-weight: 600; color: #fff; }
.user-role { font-size: 11px; color: rgba(255,255,255,.78); }

/* Sidebar Nav */
.sidebar-nav { padding: 10px 10px; display: flex; flex-direction: column; gap: 2px; }

/* Nav items (links) */
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; margin: 1px 0; color: rgba(255,255,255,.88);
  text-decoration: none; border-radius: 8px; font-size: 13.5px; font-weight: 500;
  transition: all .2s ease; cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-item.active {
  background: linear-gradient(135deg,#d62828,#ef4444);
  color: #fff; font-weight: 700; box-shadow: inset 3px 0 0 rgba(255,255,255,.88);
}
.nav-icon { font-size: 15px; width: 22px; text-align: center; flex-shrink: 0; }

/* Collapsible Nav Group */
.nav-group { margin: 1px 0; }
.nav-group-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer; user-select: none;
  border-radius: 8px; transition: all .18s ease;
}
.nav-group-header:hover { background: rgba(255,255,255,.08); }
.nav-group.open > .nav-group-header { background: rgba(255,255,255,.06); }
.nav-group-icon { font-size: 16px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-group-label {
  flex: 1; font-size: 12px; font-weight: 700; color: rgba(255,255,255,.7);
  text-transform: uppercase; letter-spacing: .8px;
}
.nav-group-badge {
  font-size: 10px; font-weight: 700; color: rgba(255,255,255,.5);
  background: rgba(255,255,255,.1); padding: 1px 7px; border-radius: 10px;
  min-width: 20px; text-align: center; line-height: 16px;
}
.nav-group.open > .nav-group-header .nav-group-badge {
  color: rgba(255,255,255,.7); background: rgba(255,255,255,.15);
}

/* Chevron arrow */
.nav-chevron {
  width: 16px; height: 16px; flex-shrink: 0; position: relative;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.nav-chevron::before {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 6px; height: 6px; border-right: 2px solid rgba(255,255,255,.5);
  border-bottom: 2px solid rgba(255,255,255,.5);
  transform: translate(-50%,-65%) rotate(45deg);
  transition: border-color .2s;
}
.nav-group.open > .nav-group-header .nav-chevron {
  transform: rotate(180deg);
}
.nav-group-header:hover .nav-chevron::before {
  border-color: rgba(255,255,255,.8);
}

/* Collapsible items container */
.nav-group-items {
  overflow: hidden; max-height: 0;
  transition: max-height .3s cubic-bezier(.4,0,.2,1), opacity .25s ease;
  opacity: 0; padding-left: 6px;
}
.nav-group.open > .nav-group-items {
  max-height: 500px; opacity: 1;
}
.nav-group-items .nav-item {
  padding: 8px 12px 8px 18px; font-size: 13px; margin: 0;
  border-left: 2px solid rgba(255,255,255,.08);
}
.nav-group-items .nav-item:hover {
  border-left-color: rgba(255,255,255,.3);
}
.nav-group-items .nav-item.active {
  border-left-color: #ef4444;
}

/* Legacy support */
.nav-badge { background: rgba(239,68,68,.85); color: #fff; font-size: 10px; padding: 1px 7px; border-radius: 10px; font-weight: 600; }

/* Sidebar Footer */
.sidebar-footer { padding: 16px 16px 20px; border-top: 1px solid rgba(255,255,255,.08); margin-top: auto; }
.logout-sidebar {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 14px; background: rgba(239,68,68,.08); border: 1px solid rgba(239,68,68,.25);
  color: #fca5a5; border-radius: var(--radius); cursor: pointer; font-size: 13px; font-weight: 500;
  transition: all .2s ease;
}
.logout-sidebar:hover { background: rgba(239,68,68,.18); border-color: rgba(239,68,68,.45); }

/* ===== Main Content ===== */
.main-content { flex: 1; margin-left: 272px; min-height: 100vh; padding: 22px 26px; }

/* ===== Topbar ===== */
.topbar {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  padding: 14px 20px; border-radius: var(--radius-lg); margin-bottom: 18px;
  box-shadow: var(--glass-shadow); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar h1 { font-size: 22px; font-weight: 700; color: var(--ink); }

/* ===== Buttons ===== */
.btn {
  border: none; border-radius: var(--radius); padding: 9px 18px; cursor: pointer;
  font-size: 14px; font-weight: 600; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .2s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.primary { background: linear-gradient(135deg,var(--primary),var(--secondary)); color: #fff; }
.btn.primary:hover { box-shadow: 0 4px 14px rgba(214,40,40,.4); }
.btn.secondary { background: var(--info); color: #fff; }
.btn.ghost { background: var(--white); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.success { background: var(--success); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 12px; }

/* ===== Cards ===== */
.card {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg); padding: 18px; margin-bottom: 14px;
  box-shadow: var(--glass-shadow); backdrop-filter: blur(8px);
}
.cards { display: grid; grid-template-columns: repeat(auto-fill,minmax(200px,1fr)); gap: 14px; margin-bottom: 18px; }

/* ===== Stat Cards (Dashboard) ===== */
.stat-card {
  padding: 20px; border-radius: var(--radius-lg); color: #fff; position: relative; overflow: hidden;
}
.stat-card .stat-bg { position: absolute; top: 8px; right: 10px; font-size: 2.8em; opacity: .18; }
.stat-value { font-size: 26px; font-weight: 700; position: relative; z-index: 1; }
.stat-label { font-size: 12px; opacity: .85; margin-top: 2px; }
.stat-sub { font-size: 11px; opacity: .7; margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(255,255,255,.25); }

/* ===== Forms ===== */
.grid-2 { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.grid-2 label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: #374151; }
input, select, textarea {
  width: 100%; padding: 9px 12px; border: 2px solid var(--line); border-radius: var(--radius);
  font-size: 14px; font-family: inherit; background: rgba(255,255,255,.78); transition: all .2s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(214,40,40,.14); }
textarea { resize: vertical; min-height: 70px; }

/* ===== Tables ===== */
table { width: 100%; border-collapse: collapse; background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: var(--radius-lg); overflow: hidden; }
th { background: #f1f5f9; font-weight: 600; font-size: 13px; color: #374151; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 12px; text-align: left; font-size: 14px; }
tr:hover td { background: rgba(29,78,216,.05); }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 3px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; }
.badge.open { background: #dbeafe; color: #1d4ed8; }
.badge.paid { background: #dcfce7; color: #16a34a; }
.badge.cancelled { background: #fee2e2; color: #dc2626; }
.badge.closed { background: #e2e8f0; color: #475569; }
.badge.draft { background: #fef9c3; color: #a16207; }
.badge.approved { background: #dcfce7; color: #16a34a; }

/* ===== Misc ===== */
.empty-row { text-align: center; color: var(--muted); padding: 28px; font-size: 14px; }
.loading { text-align: center; color: var(--muted); padding: 20px; }
.scan-bar { display: flex; gap: 8px; margin-bottom: 10px; }
.scan-result { margin-bottom: 12px; }
.scan-card { border: 1px dashed var(--primary); background: #eff6ff; padding: 10px; border-radius: var(--radius); }
.scan-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 2100;
  display: grid;
  place-items: center;
  padding: 16px;
}
.scan-modal-card {
  width: min(92vw, 560px);
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.24);
  padding: 14px;
}
.scan-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.scan-modal-help { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
#scanCameraVideo {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f172a;
  min-height: 220px;
  object-fit: cover;
}
.scan-camera-status {
  margin-top: 8px;
  background: #eef2ff;
  color: #3730a3;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}
.scan-camera-status.error {
  background: #fee2e2;
  color: #991b1b;
}
.scan-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}
h2 { margin: 0 0 14px; font-size: 22px; font-weight: 700; }
h3 { margin: 0 0 10px; font-size: 16px; font-weight: 600; }

/* Section title with accent bar */
.section-title { font-size: 17px; color: #4f46e5; border-bottom: 2px solid rgba(79,70,229,.15); padding-bottom: 10px; margin-bottom: 16px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.section-title::before { content: ''; width: 4px; height: 22px; background: linear-gradient(135deg,#667eea,#764ba2); border-radius: 2px; }

/* ===== Toast ===== */
.toast { position: fixed; right: 16px; bottom: 16px; background: #111827; color: #fff; padding: 12px 20px; border-radius: var(--radius); z-index: 2000; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); transition: opacity .25s; }
.toast.error { background: var(--danger); }
.hidden { display: none; }

/* ===== Login ===== */
.login-bg { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg,#667eea 0%,#764ba2 100%); padding: 16px; }
.login-card { width: min(92vw,420px); background: #fff; border-radius: 20px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.login-header { background: linear-gradient(135deg,#667eea,#764ba2); padding: 32px 24px; text-align: center; color: #fff; }
.login-header .icon { font-size: 52px; margin-bottom: 8px; }
.login-header h1 { font-size: 22px; font-weight: 700; color: #fff; margin: 0; }
.login-header p { font-size: 13px; color: rgba(255,255,255,.8); margin: 4px 0 0; }
.login-body { padding: 28px 24px; }
.login-body label { display: grid; gap: 5px; margin-bottom: 14px; font-size: 14px; font-weight: 600; color: #374151; }
.login-body input { border: 2px solid var(--line); border-radius: var(--radius); padding: 11px 14px; font-size: 15px; }
.login-body input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(102,126,234,.12); }
.login-footer { background: #f9fafb; padding: 14px 24px; border-top: 1px solid var(--line); text-align: center; font-size: 12px; color: var(--muted); }

/* ===== Master-Detail Document Layout ===== */
.doc-container { margin-bottom: 20px; }
.doc-header {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg); padding: 20px; margin-bottom: 14px;
  box-shadow: var(--glass-shadow); backdrop-filter: blur(8px);
}
.doc-header h3 { margin: 0 0 14px; font-size: 17px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.doc-header h3 .doc-icon { font-size: 20px; }
.doc-header-fields {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
}
.doc-header-fields label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: .3px;
}
.doc-header-fields input,
.doc-header-fields select {
  font-size: 14px; padding: 8px 10px;
}

/* Detail lines area */
.doc-detail {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg); margin-bottom: 14px;
  box-shadow: var(--glass-shadow); overflow: visible;
}
.doc-detail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.doc-detail-head h4 { margin: 0; font-size: 15px; font-weight: 700; color: var(--ink); }
/* POS Form Grid */
.pos-form-grid { padding: 0; }
.pos-form-row { display: flex; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.pos-form-row:last-child { border-bottom: none; }
.pos-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; color: var(--muted); }
.pos-field input, .pos-field select { padding: 7px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px; font-family: inherit; background: #fff; }
.pos-field input:read-only { background: #f8f8f8; color: #888; }
.pos-field.w1 { flex: 1; min-width: 100px; }
.pos-field.w2 { flex: 2; min-width: 140px; }
.pos-field.w3 { flex: 3; min-width: 200px; }

.filter-bar { display:flex; align-items:center; gap:12px; padding:10px 18px; background:#f0f4ff; border-bottom:1px solid var(--line); flex-wrap:wrap; }
.filter-bar label { font-size:13px; font-weight:500; color:var(--ink); display:flex; align-items:center; gap:6px; }
.filter-bar input[type="date"] { padding:5px 8px; border-radius:6px; border:1px solid #ccc; font-size:13px; font-family:inherit; }
.doc-detail table { margin: 0; border: none; border-radius: 0; overflow: visible; }
.doc-detail th { background: #eef2ff; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; color: #4338ca; padding: 8px 12px; }
.doc-detail td { padding: 8px 12px; vertical-align: middle; overflow: visible; position: relative; }
.doc-detail td input,
.doc-detail td select {
  padding: 6px 8px; font-size: 13px; border-width: 1px; min-width: 80px;
}
.doc-detail td input[type="number"] { text-align: right; }
.doc-detail tr.line-row:hover td { background: rgba(79,70,229,.04); }
.doc-detail .line-total { font-weight: 700; color: var(--ink); }
.doc-detail .btn-remove-line {
  background: none; border: none; color: var(--danger); cursor: pointer;
  font-size: 18px; padding: 2px 6px; border-radius: 4px; transition: background .15s;
}
.doc-detail .btn-remove-line:hover { background: #fee2e2; }

/* Add-line row */
.add-line-row td { background: #f0fdf4; border-top: 2px dashed #86efac; }

/* ===== Autocomplete Search ===== */
.ac-wrap {
  position: relative; display: flex; align-items: center; gap: 0;
}
.ac-wrap input.ac-input {
  flex: 1; padding-right: 36px;
}
.ac-wrap .ac-scan-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 18px; padding: 2px 4px;
  color: var(--muted); border-radius: 4px; transition: color .15s, background .15s;
  line-height: 1;
}
.ac-wrap .ac-scan-btn:hover { color: var(--primary); background: rgba(214,40,40,.08); }
.ac-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 9999;
  background: #fff; border: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 8px 24px rgba(15,23,42,.18);
  max-height: 260px; overflow-y: auto;
}
.ac-dropdown:empty { display: none; }
.ac-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  transition: background .1s;
  border-bottom: 1px solid #f1f5f9;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.ac-active { background: #eef2ff; }
.ac-item .ac-name { flex: 1; font-weight: 500; }
.ac-item .ac-sku { font-size: 11px; color: var(--muted); font-family: monospace; }
.ac-item .ac-barcode { font-size: 11px; color: #6d28d9; }
.ac-empty {
  padding: 12px; text-align: center; color: var(--muted); font-size: 13px;
}
.ac-selected-tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 6px;
  padding: 4px 10px; font-size: 13px; font-weight: 500; color: #3730a3;
}
.ac-selected-tag .ac-clear {
  background: none; border: none; cursor: pointer; color: #6366f1;
  font-size: 16px; line-height: 1; padding: 0 2px;
}
.ac-selected-tag .ac-clear:hover { color: var(--danger); }

/* Summary footer */
.doc-summary {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg); padding: 18px 20px;
  box-shadow: var(--glass-shadow); backdrop-filter: blur(8px);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 20px;
  margin-bottom: 14px;
}
.doc-summary-totals {
  margin-left: auto; min-width: 280px;
}
.doc-summary-row {
  display: flex; justify-content: space-between; padding: 5px 0;
  font-size: 14px; color: #374151;
}
.doc-summary-row.grand {
  font-size: 18px; font-weight: 700; color: var(--ink);
  border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px;
}
.doc-summary-actions {
  display: flex; gap: 10px; align-items: flex-end;
}

/* Status strip */
.doc-status-strip {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
  padding: 10px 16px; border-radius: var(--radius);
  background: #eef2ff; border: 1px solid #c7d2fe;
}
.doc-status-strip .doc-no { font-weight: 700; font-size: 16px; color: #3730a3; }
.doc-status-strip .doc-date { font-size: 13px; color: var(--muted); }

/* Grid helpers */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* Tabs for document list */
.doc-tabs {
  display: flex; gap: 0; margin-bottom: 14px; border-bottom: 2px solid var(--line);
}
.doc-tab {
  padding: 10px 20px; font-size: 14px; font-weight: 600; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: all .2s;
}
.doc-tab:hover { color: var(--ink); }
.doc-tab.active { color: #4338ca; border-bottom-color: #4338ca; }

@media (max-width: 1024px) {
  .doc-header-fields { grid-template-columns: repeat(2, 1fr); }
  .doc-summary { flex-direction: column; }
  .doc-summary-totals { min-width: 100%; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .doc-header-fields { grid-template-columns: 1fr; }
  .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ===== Camera Scanner Modal ===== */
.scan-modal {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(15,23,42,.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.scan-modal.hidden { display: none; }
.scan-modal-card {
  background: #fff; border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(15,23,42,.25);
  width: 100%; max-width: 480px; overflow: hidden;
}
.scan-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.scan-modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.scan-video-wrap {
  position: relative; width: 100%; aspect-ratio: 4/3;
  background: #000; overflow: hidden;
}
.scan-video-wrap video {
  width: 100%; height: 100%; object-fit: cover;
}
.scan-crosshair {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: 200px; height: 200px;
  border: 3px solid rgba(255,255,255,.7);
  border-radius: 16px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.35);
  pointer-events: none;
}
.scan-crosshair::before, .scan-crosshair::after {
  content: ''; position: absolute; background: var(--primary);
}
.scan-crosshair::before {
  top: 50%; left: 10%; right: 10%; height: 2px; transform: translateY(-50%);
}
.scan-crosshair::after {
  left: 50%; top: 10%; bottom: 10%; width: 2px; transform: translateX(-50%);
}
.scan-camera-status {
  padding: 10px 20px; font-size: 13px; color: var(--muted);
  text-align: center; background: #f0fdf4; border-top: 1px solid #bbf7d0;
}
.scan-camera-status.error {
  background: #fef2f2; border-top-color: #fecaca; color: var(--danger);
}
.scan-manual {
  padding: 12px 20px; border-top: 1px solid var(--line);
}
.scan-manual input {
  width: 100%; padding: 10px 14px; font-size: 15px;
  border: 2px solid var(--line); border-radius: var(--radius);
  text-align: center; font-family: monospace; letter-spacing: 1px;
  transition: border-color .2s;
}
.scan-manual input:focus {
  outline: none; border-color: var(--primary);
}
.scan-modal-actions {
  display: flex; gap: 8px; padding: 12px 20px;
  border-top: 1px solid var(--line); justify-content: center;
}
@media (max-width: 480px) {
  .scan-modal-card { max-width: 100%; border-radius: 12px; }
  .scan-crosshair { width: 160px; height: 160px; }
}

/* ===== Modal Overlay ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.45); display: flex;
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-content {
  background: var(--surface); border-radius: var(--radius);
  padding: 24px; width: 100%; box-shadow: 0 12px 40px rgba(0,0,0,.2);
  max-height: 90vh; overflow-y: auto;
}
.modal-content h3 { margin: 0 0 16px; font-size: 18px; }

/* ===== Autocomplete Inline ===== */
.ac-wrap { position: relative; display: flex; align-items: center; gap: 4px; }
.ac-input { flex: 1; min-width: 140px; }
.ac-scan-btn { background: none; border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 8px; cursor: pointer; font-size: 16px; }
.ac-scan-btn:hover { background: var(--hover); }
/* duplicate ac-dropdown removed — consolidated above */
.ac-price { font-size: 11px; color: var(--success, #22c55e); font-weight: 600; margin-left: auto; }
.ac-empty { padding: 10px; text-align: center; color: var(--muted); font-size: 13px; }
.ac-selected-tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary); color: #fff; border-radius: var(--radius);
  padding: 4px 10px; font-size: 13px; font-weight: 500;
}
.ac-clear { background: none; border: none; color: #fff; cursor: pointer; font-size: 16px; line-height: 1; opacity: .7; }
.ac-clear:hover { opacity: 1; }

/* ===== Line Item Utility ===== */
.btn-remove-line { background: none; border: none; color: var(--danger, #ef4444); cursor: pointer; font-size: 20px; line-height: 1; padding: 2px 6px; border-radius: var(--radius); }
.btn-remove-line:hover { background: rgba(239,68,68,.1); }
.line-row input[type="number"], .line-row input[type="text"] { width: 100%; box-sizing: border-box; }
.btn.success { background: var(--success, #22c55e); color: #fff; }
.btn.success:hover { filter: brightness(.9); }
.btn.danger { background: var(--danger, #ef4444); color: #fff; }
.btn.danger:hover { filter: brightness(.9); }

/* ===== Quick Menu Cards ===== */
.quick-card { text-decoration: none; color: inherit; text-align: center; transition: all .2s ease; }
.quick-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,.1); }
.quick-card .icon { font-size: 30px; margin-bottom: 6px; }
.quick-card .label { font-weight: 600; font-size: 14px; }

/* ===== Mobile ===== */
.mobile-only { display: none; }
.mobile-header { display: none; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 999; }

@media (max-width: 1024px) {
  .left-sidebar { transform: translateX(-100%); box-shadow: none; left: 0; right: auto; }
  .left-sidebar.open { transform: translateX(0); box-shadow: 4px 0 12px rgba(0,0,0,.3); }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-left: 0; padding-top: 70px; }
  .mobile-header {
    display: flex; position: fixed; top: 0; left: 0; right: 0; height: 58px;
    background: rgba(255,255,255,.82); box-shadow: 0 4px 18px rgba(15,23,42,.08);
    backdrop-filter: blur(10px); z-index: 999; align-items: center; padding: 0 16px; gap: 12px;
  }
  .hamburger { background: none; border: none; cursor: pointer; display: flex; flex-direction: column; gap: 5px; padding: 8px; }
  .hamburger span { width: 22px; height: 2px; background: var(--ink); border-radius: 2px; transition: all .3s; }
  .mobile-logo { flex: 1; font-size: 16px; font-weight: 700; color: var(--ink); }
  .mobile-only { display: inline-flex; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .main-content { padding: 12px; padding-top: 70px; }
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: 18px; }
  .cards { grid-template-columns: repeat(auto-fill,minmax(150px,1fr)); }
}

/* ===== Setup Module ===== */
.setup-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  min-height: calc(100vh - 160px);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow);
  overflow: hidden;
}

/* Sidebar Tabs */
.setup-sidebar {
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border-right: 1px solid var(--line);
  padding: 0;
  overflow-y: auto;
}
.setup-sidebar::-webkit-scrollbar { width: 4px; }
.setup-sidebar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.setup-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #94a3b8;
  padding: 18px 18px 8px;
}
.setup-group-label:first-child { padding-top: 16px; }

.setup-tab-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  margin: 2px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: #475569;
  transition: all .18s ease;
  border: 1px solid transparent;
  user-select: none;
}
.setup-tab-item:hover {
  background: rgba(255,255,255,.85);
  color: #1e293b;
  border-color: rgba(0,0,0,.04);
}
.setup-tab-item.active {
  background: #fff;
  color: #4338ca;
  font-weight: 600;
  border-color: rgba(99,102,241,.18);
  box-shadow: 0 2px 8px rgba(99,102,241,.10);
}
.setup-tab-icon {
  font-size: 17px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}
.setup-tab-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  background: #e2e8f0;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 22px;
  text-align: center;
}
.setup-tab-item.active .setup-tab-count {
  background: #e0e7ff;
  color: #4338ca;
}

/* Main Panel */
.setup-main {
  display: flex;
  flex-direction: column;
  background: #fff;
}
.setup-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}
.setup-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.setup-toolbar-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}
.setup-toolbar-title .icon { font-size: 20px; }
.setup-search-box {
  position: relative;
}
.setup-search-box input {
  width: 220px;
  padding: 8px 12px 8px 34px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  transition: all .2s;
}
.setup-search-box input:focus {
  border-color: #818cf8;
  box-shadow: 0 0 0 3px rgba(129,140,248,.12);
  width: 260px;
}
.setup-search-box::before {
  content: '🔍';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  pointer-events: none;
}
.setup-add-btn {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .2s;
  box-shadow: 0 2px 8px rgba(99,102,241,.25);
}
.setup-add-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(99,102,241,.35);
}
.setup-add-btn:active { transform: translateY(0); }

/* Table area */
.setup-table-wrap {
  flex: 1;
  overflow-x: auto;
  padding: 0;
}
.setup-table-wrap table {
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}
.setup-table-wrap th {
  background: #f8fafc;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #64748b;
  padding: 10px 16px;
  border-bottom: 1.5px solid #e2e8f0;
  white-space: nowrap;
}
.setup-table-wrap td {
  padding: 11px 16px;
  font-size: 13.5px;
  border-bottom: 1px solid #f1f5f9;
}
.setup-table-wrap tr:last-child td { border-bottom: none; }
.setup-table-wrap tr:hover td { background: #fafbff; }

.setup-table-wrap .badge {
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 6px;
  font-weight: 600;
}
.setup-table-wrap .btn-edit {
  background: #f0f4ff;
  color: #4338ca;
  border: 1px solid #c7d2fe;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
}
.setup-table-wrap .btn-edit:hover {
  background: #e0e7ff;
  border-color: #a5b4fc;
}
.setup-table-wrap .btn-toggle {
  background: none;
  color: #64748b;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
}
.setup-table-wrap .btn-toggle:hover {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}

/* Setup Modal */
.setup-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all .25s ease;
}
.setup-modal-overlay.open {
  opacity: 1;
  visibility: visible;
}
.setup-modal-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(15,23,42,.2), 0 0 0 1px rgba(0,0,0,.04);
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  overflow: hidden;
  transform: translateY(20px) scale(.97);
  transition: transform .3s cubic-bezier(.16,1,.3,1);
}
.setup-modal-overlay.open .setup-modal-card {
  transform: translateY(0) scale(1);
}
.setup-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid #f1f5f9;
  background: linear-gradient(180deg, #fafbfc, #fff);
}
.setup-modal-header h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}
.setup-modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: #f1f5f9;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  color: #64748b;
  transition: all .15s;
}
.setup-modal-close:hover {
  background: #fee2e2;
  color: #dc2626;
}
.setup-modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  max-height: calc(85vh - 140px);
}
.setup-modal-body .form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.setup-modal-body .form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.setup-modal-body .form-group.full {
  grid-column: 1 / -1;
}
.setup-modal-body .form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: #475569;
  letter-spacing: .2px;
}
.setup-modal-body .form-label .req {
  color: #ef4444;
  margin-left: 2px;
}
.setup-modal-body input,
.setup-modal-body select,
.setup-modal-body textarea {
  padding: 9px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  transition: all .2s;
}
.setup-modal-body input:focus,
.setup-modal-body select:focus,
.setup-modal-body textarea:focus {
  outline: none;
  border-color: #818cf8;
  box-shadow: 0 0 0 3px rgba(129,140,248,.12);
}
.setup-modal-body textarea {
  resize: vertical;
  min-height: 64px;
}
.setup-modal-body .form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}
.setup-modal-body .form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #6366f1;
  cursor: pointer;
}
.setup-modal-body .form-check label {
  font-size: 13.5px;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
}
.setup-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid #f1f5f9;
  background: #fafbfc;
}
.setup-modal-footer .btn-cancel {
  background: #fff;
  color: #475569;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  padding: 9px 20px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
}
.setup-modal-footer .btn-cancel:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}
.setup-modal-footer .btn-save {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 24px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .2s;
  box-shadow: 0 2px 8px rgba(99,102,241,.25);
}
.setup-modal-footer .btn-save:hover {
  box-shadow: 0 4px 14px rgba(99,102,241,.35);
  transform: translateY(-1px);
}
.setup-modal-footer .btn-save:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Empty state */
.setup-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #94a3b8;
}
.setup-empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .5; }
.setup-empty-text { font-size: 14px; font-weight: 500; }

/* Responsive */
@media (max-width: 900px) {
  .setup-layout {
    grid-template-columns: 1fr;
  }
  .setup-sidebar {
    display: flex;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 8px;
    gap: 4px;
  }
  .setup-group-label { display: none; }
  .setup-tab-item {
    white-space: nowrap;
    margin: 0;
    padding: 8px 14px;
    font-size: 12.5px;
  }
  .setup-tab-count { display: none; }
  .setup-modal-body .form-grid { grid-template-columns: 1fr; }
  .setup-search-box input { width: 160px; }
  .setup-search-box input:focus { width: 180px; }
}

/* ===== Procurement Module ===== */
.modal-overlay { visibility: hidden; opacity: 0; transition: opacity .25s, visibility .25s; }
.modal-overlay.active { visibility: visible; opacity: 1; }
.modal-card {
  background: #fff; border-radius: var(--radius-lg); width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.25); max-height: 92vh; overflow-y: auto;
  transform: translateY(20px); transition: transform .25s;
}
.modal-overlay.active .modal-card { transform: translateY(0); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--line); background: #f8fafc;
  position: sticky; top: 0; z-index: 1;
}
.modal-header h3 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 24px; cursor: pointer;
  color: var(--muted); padding: 2px 8px; border-radius: 6px; transition: all .15s;
}
.modal-close:hover { background: #fee2e2; color: var(--danger); }
.modal-body { padding: 20px 22px; }
.modal-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 14px 22px; border-top: 1px solid var(--line); background: #f8fafc;
  position: sticky; bottom: 0; z-index: 1;
}
.form-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
}
.form-grid .form-group { display: flex; flex-direction: column; gap: 4px; }
.form-grid .form-group.full { grid-column: 1 / -1; }
.form-grid .form-group label {
  font-size: 12px; font-weight: 600; color: #6b7280;
  text-transform: uppercase; letter-spacing: .3px;
}
.form-grid .form-group label .req { color: var(--danger); }
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
}
.proc-detail-view { padding: 4px 0; }
.proc-detail-view .info-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px;
  margin-bottom: 16px;
}
.proc-detail-view .info-item label {
  display: block; font-size: 11px; font-weight: 600; color: #6b7280;
  text-transform: uppercase; letter-spacing: .3px; margin-bottom: 2px;
}
.proc-detail-view .info-item .val {
  font-size: 14px; font-weight: 500; color: var(--ink);
}
.progress-bar {
  display: inline-flex; align-items: center; gap: 6px;
}
.progress-bar .bar {
  width: 60px; height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden;
}
.progress-bar .bar .fill {
  height: 100%; border-radius: 3px; transition: width .3s;
}
@media (max-width: 768px) {
  .form-grid { grid-template-columns: 1fr; }
  .modal-card { max-width: 100% !important; }
}
