:root {
  --bg: #14161a;
  --surface: #1c1f25;
  --surface-raised: #23262e;
  --border: #2c3038;
  --text: #e9eaec;
  --text-muted: #8b909a;
  --accent: #f2a65a;
  --accent-dim: #a8703a;
  --blue: #5b8def;
  --green: #4cae7d;
  --red: #e5484d;
  --radius: 10px;
  --font-display: "Space Grotesk", "Segoe UI", -apple-system, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-data: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- shell layout ---------- */

.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidenav content";
  min-height: 100vh;
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 1.05rem;
  color: var(--text);
}

.brand-mark { width: 22px; height: 22px; color: var(--accent); flex-shrink: 0; }

.topbar-spacer { flex: 1; }

.logout-link {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}
.logout-link:hover { color: var(--text); }

/* Zero-JS Mobile Nav Toggle using CSS Checkbox Hack */
.nav-toggle-checkbox {
  display: none;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 30px;
  height: 30px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.nav-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--text);
  border-radius: 2px;
}

.sidenav {
  grid-area: sidenav;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
}

.sidenav a {
  text-decoration: none;
  color: var(--text-muted);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-weight: 500;
}
.sidenav a:hover { background: var(--surface-raised); color: var(--text); }
.sidenav a.active { background: var(--surface-raised); color: var(--accent); }
.sidenav a.export-link {
  margin-top: auto;
  border-top: 1px solid var(--border);
  margin-top: 12px;
  padding-top: 14px;
  color: var(--blue);
}

.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 25;
}

.content {
  grid-area: content;
  padding: 26px 30px 60px;
  max-width: 1100px;
  width: 100%;
}

@media (max-width: 820px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "content";
  }
  .nav-toggle { display: flex; }
  .sidenav {
    position: fixed;
    top: 58px;
    left: 0;
    width: 220px;
    height: calc(100vh - 58px);
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    z-index: 30;
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }
  .nav-toggle-checkbox:checked ~ .shell .sidenav {
    transform: translateX(0);
  }
  .nav-toggle-checkbox:checked ~ .nav-backdrop {
    display: block;
  }
  .content { padding: 18px 16px 50px; }
}

/* ---------- typography helpers ---------- */

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0 0 4px;
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
.page-sub { color: var(--text-muted); margin: 0 0 22px; font-size: 0.92rem; }
.section-gap { margin-top: 34px; }

.num, .data { font-family: var(--font-data); font-variant-numeric: tabular-nums; }

/* ---------- cards / surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-label { color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.stat-value { font-family: var(--font-data); font-size: 1.6rem; font-weight: 600; }
.stat-value.accent { color: var(--accent); }
.stat-value.red { color: var(--red); }
.stat-note { color: var(--text-muted); font-size: 0.78rem; margin-top: 6px; }

/* ---------- forms ---------- */

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 640px;
}
.form-grid.narrow { grid-template-columns: 1fr; max-width: 420px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 0.82rem; color: var(--text-muted); }
.field input, .field select, .field textarea {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
}
.field textarea { resize: vertical; min-height: 60px; }
.field .hint { font-size: 0.76rem; color: var(--text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 8px;
  padding: 11px 20px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #1a1300; }
.btn-primary:hover { background: #f5b878; }
.btn-secondary { background: var(--surface-raised); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #2a2e37; }
.btn-danger { background: var(--red); color: #fff; }
.btn-link { background: none; color: var(--blue); padding: 6px 0; border: none; cursor: pointer; text-decoration: none; }

.form-actions { display: flex; gap: 10px; margin-top: 18px; align-items: center; }

.banner {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 0.9rem;
}
.banner-success { background: rgba(76, 174, 125, 0.14); border: 1px solid rgba(76, 174, 125, 0.35); color: #8fe0b4; }
.banner-error { background: rgba(229, 72, 77, 0.14); border: 1px solid rgba(229, 72, 77, 0.35); color: #ff9b9e; }
.banner-warning { background: rgba(242, 166, 90, 0.14); border: 1px solid rgba(242, 166, 90, 0.4); color: var(--accent); }

/* ---------- tables ---------- */

table.datatable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.datatable th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
table.datatable td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.datatable tr:last-child td { border-bottom: none; }
table.datatable tr:hover td { background: rgba(255,255,255,0.02); }

.tag {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.tag-low { background: rgba(229, 72, 77, 0.16); color: #ff9b9e; }
.tag-in { background: rgba(76, 174, 125, 0.16); color: #8fe0b4; }
.tag-out { background: rgba(91, 141, 239, 0.16); color: #a9c4fb; }

/* level meter -- styled after an AV receiver bar display */
.meter {
  display: flex;
  gap: 2px;
  height: 16px;
  align-items: flex-end;
  width: 90px;
}
.meter .seg {
  flex: 1;
  height: 100%;
  background: var(--border);
  border-radius: 1px;
}
.meter .seg.lit-ok { background: var(--green); }
.meter .seg.lit-warn { background: var(--accent); }
.meter .seg.lit-low { background: var(--red); }

.empty-state {
  color: var(--text-muted);
  padding: 30px 10px;
  text-align: center;
  font-size: 0.9rem;
}

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 30% 20%, rgba(242,166,90,0.08), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(91,141,239,0.08), transparent 45%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 34px 30px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
}
.login-brand svg { width: 26px; height: 26px; color: var(--accent); }
.login-sub { color: var(--text-muted); font-size: 0.86rem; margin-bottom: 26px; }
.login-card .field { margin-bottom: 16px; }

/* ---------- Zero-JS Modals via CSS :target ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,11,13,0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay.open,
.modal-overlay:target {
  display: flex;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 16px 36px rgba(0,0,0,0.6);
  position: relative;
}

/* ---------- Zero-JS Server-Rendered Bar Chart ---------- */

.css-barchart {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}
.chart-row {
  display: grid;
  grid-template-columns: minmax(120px, 180px) 1fr 50px;
  align-items: center;
  gap: 14px;
  font-size: 0.88rem;
}
.chart-row-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.chart-track {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  height: 22px;
  position: relative;
  overflow: hidden;
}
.chart-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--green);
  min-width: 3px;
}
.chart-bar-fill.low {
  background: var(--red);
}
.chart-row-val {
  font-family: var(--font-data);
  text-align: right;
  color: var(--text-muted);
}

/* ---------- filters row & toolbar ---------- */

.filter-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 20px;
}
.filter-row .field { min-width: 160px; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

/* ---------- Input with Unit Addon & Product Info Banner ---------- */

.input-with-addon {
  display: flex;
  align-items: stretch;
  position: relative;
  width: 100%;
}
.input-with-addon input {
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
  flex: 1;
}
.input-addon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-left: none;
  border-top-right-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  user-select: none;
  min-width: 85px;
  text-align: center;
}

.product-info-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: rgba(242, 166, 90, 0.08);
  border: 1px solid rgba(242, 166, 90, 0.28);
  border-radius: 8px;
  padding: 10px 16px;
  margin-top: 8px;
  margin-bottom: 6px;
  font-size: 0.88rem;
  transition: all 0.2s ease;
}
.product-info-banner.hidden {
  display: none;
}
.product-info-banner .info-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.product-info-banner .info-label {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.product-info-banner .info-val {
  font-weight: 600;
  color: var(--text);
}
.field-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ---------- Voided Transaction Indicators ---------- */

.voided-row {
  opacity: 0.62;
  background: rgba(235, 87, 87, 0.03);
}
.voided-row:hover {
  opacity: 0.95;
}
.voided-strike {
  text-decoration: line-through;
  opacity: 0.8;
}
.badge-voided {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #eb5757;
  background: rgba(235, 87, 87, 0.15);
  border: 1px solid rgba(235, 87, 87, 0.35);
  text-transform: uppercase;
}
.btn-sm-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 9px;
  font-size: 0.76rem;
  font-weight: 600;
  border-radius: 5px;
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(235, 87, 87, 0.4);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-sm-danger:hover {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

/* ---------- Print-Ready Layout Styles ---------- */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 10pt !important;
  }
  .topbar,
  .sidenav,
  .filter-row,
  .form-actions,
  .btn,
  .btn-sm-danger,
  .pagination-bar,
  .modal-overlay,
  .banner,
  .export-link,
  th:last-child,
  td:last-child {
    display: none !important;
  }
  .app-layout,
  .main-content,
  .content,
  .card {
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    max-width: 100% !important;
    width: 100% !important;
  }
  .print-only-header {
    display: block !important;
    margin-bottom: 16px !important;
    border-bottom: 2px solid #333 !important;
    padding-bottom: 8px !important;
  }
  .print-only-header h2 {
    margin: 0 0 4px 0 !important;
    font-size: 16pt !important;
    color: #000 !important;
  }
  .print-only-header p {
    margin: 0 !important;
    font-size: 9pt !important;
    color: #555 !important;
  }
  .datatable {
    width: 100% !important;
    border-collapse: collapse !important;
  }
  .datatable th,
  .datatable td {
    border: 1px solid #ccc !important;
    padding: 6px 8px !important;
    color: #000 !important;
  }
  .datatable th {
    background: #f0f0f0 !important;
    font-weight: bold !important;
  }
  .datatable tr {
    page-break-inside: avoid !important;
  }
  .badge-voided {
    border: 1px solid #000 !important;
    color: #000 !important;
    background: #eee !important;
  }
  .tag {
    background: none !important;
    border: none !important;
    color: #000 !important;
    padding: 0 !important;
  }
}

/* ---- Bulk entry ---- */
.bulk-textarea { width: 100%; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; line-height: 1.5; white-space: pre; }
table.bulk-preview tr.bulk-error td { background: rgba(229, 72, 77, 0.07); }
table.bulk-preview tr.bulk-negative td { background: rgba(242, 166, 90, 0.08); }
.bulk-message { font-size: 0.75rem; color: var(--text-muted); margin-top: 3px; line-height: 1.3; max-width: 260px; }
.batch-tag { font-size: 0.68rem; text-decoration: none; background: rgba(91, 141, 239, 0.14); color: #a9c4fb; }
.batch-tag:hover { background: rgba(91, 141, 239, 0.26); }
