:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222535;
  --border: #2e3148;
  --accent: #6c63ff;
  --accent-h: #857dff;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --radius: 8px;
  --shadow: 0 4px 16px rgba(0,0,0,.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
}

/* ── LIGHT THEME ── */
body.light {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #e8eaf0;
  --border: #d0d4de;
  --text: #111827;
  --text-muted: #6b7280;
  --shadow: 0 4px 16px rgba(0,0,0,.1);
}
body.light .badge-reserved { background: rgba(245,158,11,.18); }
body.light .badge-sold { background: rgba(34,197,94,.15); }
body.light select option { background: #e8eaf0; color: #111827; }
body.light #toast { color: #111827; }

/* ── THEME TOGGLE ── */
#theme-toggle { font-size: 16px; padding: 6px 10px; }

/* ── LOGIN ── */
#login-section {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin-bottom: 8px; }
.login-card p { color: var(--text-muted); margin-bottom: 24px; font-size: 13px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ── FORM ELEMENTS ── */
label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; margin-top: 14px; }
input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[readonly] { color: var(--text-muted); cursor: default; }
textarea { resize: vertical; min-height: 64px; }
select option { background: var(--surface2); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, background .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { opacity: .85; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: .85; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; background: transparent; border: none; cursor: pointer; color: var(--text-muted); border-radius: 4px; }
.btn-icon:hover { color: var(--text); background: var(--surface2); }
.btn-full { width: 100%; }

/* ── APP HEADER ── */
#app-section { display: none; flex-direction: column; min-height: 100vh; }
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: stretch;
  gap: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-logo {
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  padding: 14px 16px 14px 0;
  white-space: nowrap;
  border-right: 1px solid var(--border);
  margin-right: 8px;
}
.main-tabs {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}
.main-tabs::-webkit-scrollbar { display: none; }
.main-tab {
  padding: 0 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  height: 100%;
  display: flex;
  align-items: center;
}
.main-tab:hover { color: var(--text); }
.main-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0 10px 16px;
  border-left: 1px solid var(--border);
  margin-left: 8px;
}
.header-user span { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* ── BRAND TABS ── */
.brand-tabs-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 4px;
}
.brand-tabs-bar::-webkit-scrollbar { display: none; }
.brand-tab {
  padding: 8px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px 6px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  flex-shrink: 0;
}
.brand-tab:hover { color: var(--text); background: var(--surface2); }
.brand-tab.active { color: var(--text); background: var(--surface2); border-color: var(--border); border-bottom-color: var(--surface2); }

/* ── MAIN CONTENT ── */
.tab-panel { display: none; padding: 20px 16px; flex: 1; }
.tab-panel.active { display: block; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-title { font-size: 18px; font-weight: 600; }

/* ── SEARCH/FILTER BAR ── */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filter-bar input, .filter-bar select { width: auto; flex: 1; min-width: 140px; }

/* ── TABLE ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
th {
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }
.td-num { text-align: right; font-variant-numeric: tabular-nums; }
.balance-zero { color: var(--text-muted); }
.balance-negative { color: var(--danger); font-weight: 600; }
.balance-low { color: var(--warning); }
.balance-ok { color: var(--success); }

/* ── TAGS/BADGES ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-reserved { background: rgba(245,158,11,.15); color: var(--warning); }
.badge-sold { background: rgba(34,197,94,.12); color: var(--success); }

/* ── RECEIPT/SALE FORM CARD ── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  max-width: 540px;
}
.form-card h3 { font-size: 15px; margin-bottom: 14px; }
.form-row { display: flex; gap: 10px; align-items: flex-end; }
.form-row .field { flex: 1; }
.barcode-found { color: var(--success); font-size: 12px; margin-top: 4px; }
.barcode-error { color: var(--danger); font-size: 12px; margin-top: 4px; }

/* ── MODAL ── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h3 { font-size: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ── PRODUCT PHOTO ── */
.product-photo { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.product-photo-placeholder { width: 56px; height: 56px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface2); display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 18px; }

/* ── ANALYTICS ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-card .label { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .value { font-size: 24px; font-weight: 700; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.chart-card h4 { font-size: 13px; font-weight: 600; margin-bottom: 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

/* ── EMPTY STATE ── */
.empty { text-align: center; padding: 48px 16px; color: var(--text-muted); }
.empty-icon { font-size: 40px; margin-bottom: 12px; }

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 999;
  display: none;
  max-width: 320px;
}
#toast.success { border-left: 3px solid var(--success); }
#toast.error { border-left: 3px solid var(--danger); }

/* ── PRODUCT NAME AUTOCOMPLETE ── */
.suggestion-wrap { position: relative; }
.product-suggestions {
  position: absolute;
  z-index: 150;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  width: 100%;
  box-shadow: var(--shadow);
  top: calc(100% + 4px);
  left: 0;
}
.product-suggestion {
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.product-suggestion:last-child { border-bottom: none; }
.product-suggestion:hover { background: var(--border); }
.suggestion-name { font-size: 13px; font-weight: 500; }
.suggestion-meta { color: var(--text-muted); font-size: 11px; margin-top: 2px; }

/* ── LIGHTBOX ── */
#photo-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.88);
  z-index: 400;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
#photo-lightbox.open { display: flex; }
#photo-lightbox img { max-width: 92vw; max-height: 88vh; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); }
.product-photo-clickable { cursor: zoom-in; transition: opacity .15s; }
.product-photo-clickable:hover { opacity: .75; }

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  .app-logo { display: none; }
  .form-card { max-width: 100%; }
  td, th { padding: 8px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .modal { padding: 20px; }
}
