:root {
  --brand: #a1710a;
  --brand-dark: #855b06;
  --brand-soft: #fdf6e7;
  --brand-border: #ead39c;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1e2430;
  --muted: #647084;
  --border: #e5e9f0;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.45; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; }
p { margin: 0; }

/* Login */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(145deg, #fdf6e7 0%, #f6f7f9 60%); }
.login-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: 0 12px 32px rgba(15,23,42,0.08); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand h1 { font-size: 18px; }
.login-brand p { font-size: 12.5px; color: var(--muted); }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-foot { margin-top: 20px; text-align: center; font-size: 12px; color: var(--muted); }

/* Brand & Topbar */
.brand-logo { width: 38px; height: 38px; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 700; display: grid; place-items: center; letter-spacing: 0.5px; flex-shrink: 0; }
.topbar { position: sticky; top: 0; z-index: 30; background: var(--card); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top); -webkit-tap-highlight-color: transparent; }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { display: flex; gap: 6px; margin-top: 2px; flex-wrap: wrap; }
.nav-desktop { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 10px; }
.nav-btn { border: 0; background: transparent; color: var(--muted); font-weight: 600; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13.5px; transition: all 0.15s; }
.nav-btn:hover { color: var(--text); }
.nav-btn.active { background: var(--card); color: var(--brand); box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-chip { font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* Container & Layout */
.container { max-width: 1320px; margin: 0 auto; padding: 16px; padding-bottom: 86px; }
.tab-panel { display: none; flex-direction: column; gap: 14px; }
.tab-panel.active { display: flex; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.table-card { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.section-title { font-size: 16px; margin-bottom: 2px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt-sm { margin-top: 10px; }
.mt-md { margin-top: 16px; }
.hidden { display: none !important; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 9px; padding: 8px 14px; font-weight: 600; font-size: 13.5px; cursor: pointer; text-decoration: none; transition: all 0.15s; white-space: nowrap; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-secondary { background: var(--brand-soft); color: var(--brand-dark); border-color: var(--brand-border); }
.btn-secondary:hover:not(:disabled) { background: #fae9c3; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-danger-outline { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger-bg); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; padding: 10px; }

/* Pills & Badges */
.pill { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-danger { background: var(--danger-bg); color: var(--danger); }
.pill-info { background: var(--info-bg); color: var(--info); }
.pill-muted { background: #eef1f5; color: var(--muted); }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.text-danger { color: var(--danger); }
.text-brand { color: var(--brand); }

/* Scanner Bar */
.scanner-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-left: 4px solid var(--brand); }
.scanner-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.status-dot.on { background: #16a34a; box-shadow: 0 0 0 3px #dcfce7; }

/* Toggle Switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: #cbd5e1; border-radius: 22px; transition: 0.2s; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider:before { transform: translateX(16px); }

/* Filter Pills & Inputs */
.status-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-pill { border: 1px solid var(--border); background: var(--card); color: var(--muted); padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.filter-pill.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.filter-pill .badge { background: rgba(0,0,0,0.08); padding: 1px 6px; border-radius: 999px; font-size: 11.5px; }
.filter-pill.active .badge { background: rgba(255,255,255,0.22); }

.filter-grid { display: grid; grid-template-columns: 1fr 150px 150px auto; gap: 8px; }
input[type="text"], input[type="password"], input[type="search"], input[type="date"], input[type="number"], select {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; background: #fff; color: var(--text); outline: none;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(161,113,10,0.12); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.check-inline { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; user-select: none; }
.grow { flex: 1; min-width: 200px; }

/* KPI & Toolbars */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-val { font-size: 22px; font-weight: 700; margin-top: 4px; }
.toolbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { background: #f8fafc; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px; text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:hover { background: #fcfaf5; }
.data-table.compact td, .data-table.compact th { padding: 7px 8px; font-size: 13px; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty-cell { text-align: center; color: var(--muted); padding: 28px !important; }
.tx-note { max-width: 290px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 12px; }
.stock-avail { font-weight: 700; color: var(--brand-dark); }

/* Settings */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.kv-list { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.kv-row { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dashed var(--border); padding-bottom: 5px; }
.kv-row span:first-child { color: var(--muted); }
.kv-row code { font-size: 12px; background: var(--bg); padding: 1px 6px; border-radius: 5px; word-break: break-all; }
.test-output { margin-top: 10px; padding: 10px 12px; border-radius: 8px; font-size: 12.5px; }
.test-output.ok { background: var(--ok-bg); color: var(--ok); }
.test-output.err { background: var(--danger-bg); color: var(--danger); }
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Alerts & Toast */
.alert { padding: 10px 12px; border-radius: 9px; font-size: 13px; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #fde68a; }
.toast { position: fixed; top: 68px; right: 16px; z-index: 90; max-width: 420px; padding: 11px 16px; border-radius: 10px; color: #fff; background: #1e2430; box-shadow: 0 8px 24px rgba(0,0,0,0.18); font-size: 13.5px; font-weight: 500; }
.toast.ok { background: #15803d; }
.toast.err { background: #b91c1c; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(15, 23, 42, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-sheet { width: 100%; max-width: 1040px; max-height: 92vh; background: var(--card); border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,0.22); }
.modal-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: #fafafa; }
.footer-left, .footer-right { display: flex; gap: 8px; flex-wrap: wrap; }

.invoice-meta-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.meta-box { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; }
.meta-label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.money-lg { font-size: 16px; color: var(--brand-dark); }
.audit-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.audit-panel { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.audit-panel h4 { font-size: 13px; margin-bottom: 6px; color: var(--text); }
.audit-panel ul { margin: 4px 0 0; padding-left: 18px; }
.code-log { background: #1e2430; color: #e2e8f0; padding: 8px 10px; border-radius: 8px; font-size: 11.5px; overflow-x: auto; margin-top: 8px; white-space: pre-wrap; word-break: break-word; }

/* Mobile Bottom Nav */
.nav-mobile { display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: var(--card); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); grid-template-columns: repeat(4, 1fr); }
.nav-m-btn { border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; padding: 4px; cursor: pointer; }
.nav-m-btn .nav-icon { font-size: 16px; line-height: 1; }
.nav-m-btn.active { color: var(--brand); }

@media (max-width: 820px) {
  .nav-desktop, .user-chip { display: none; }
  .nav-mobile { display: grid; }
  .kpi-grid, .invoice-meta-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-grid, .form-row-2, .audit-cols { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal-sheet { max-height: 95vh; border-radius: 16px 16px 0 0; }
}
