/* ---------- Theme tokens ---------- */
:root[data-theme="dark"] {
  --bg: #0A1628;
  --surface: #112240;
  --surface-2: #0D1B36;
  --sidebar: #0D1B36;
  --text: #FFFFFF;
  --text-muted: #94A3B8;
  --border: #1E3A5F;
  --accent: #CC0000;
  --accent-hover: #E60000;
  --danger: #FF4D4D;
  --success: #4ADE80;
  --input-bg: #0A1628;
  --row-hover: #14284A;
  --shadow: 0 6px 24px rgba(0,0,0,0.4);
}
:root[data-theme="light"] {
  --bg: #FFFFFF;
  --surface: #F5F5F5;
  --surface-2: #FAFAFA;
  --sidebar: #F0F0F0;
  --text: #000000;
  --text-muted: #6B7280;
  --border: #E5E7EB;
  --accent: #CC0000;
  --accent-hover: #B30000;
  --danger: #CC0000;
  --success: #16A34A;
  --input-bg: #FFFFFF;
  --row-hover: #F0F0F0;
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

/* ---------- Logo ---------- */
.logo-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 0;
}
.logo-block.compact {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 0;
}
.logo-img-wrap {
  width: 72px;
  height: 72px;
  border-radius: 12px;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.logo-img-wrap.small { width: 44px; height: 44px; border-radius: 8px; }
.logo-img-wrap img { width: 100%; height: 100%; object-fit: contain; }
.logo-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--accent);
  font-size: 24px;
  letter-spacing: 1px;
}
.logo-img-wrap.small .logo-fallback { font-size: 16px; }
.logo-text {
  margin: 0;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 2px;
  color: var(--text);
}
.logo-sub {
  margin: 0;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 4px;
  color: var(--accent);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--row-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------- Forms ---------- */
label {
  display: block;
  margin-bottom: 12px;
}
label > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.row > label { margin-bottom: 12px; }

.form-msg {
  margin: 8px 0 0;
  min-height: 18px;
  font-size: 13px;
}
.form-msg.ok { color: var(--success); }
.form-msg.error { color: var(--danger); }
.error-msg {
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 16px;
  font-size: 18px;
}
.card h3 {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---------- Login screen ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-form { margin-top: 16px; }
.login-form .btn { width: 100%; margin-top: 8px; }

/* ---------- Specials page ---------- */
.specials-body {
  min-height: 100vh;
  padding: 20px;
}
.specials-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 600px;
  margin: 0 auto 20px;
}
.specials-main {
  max-width: 600px;
  margin: 0 auto;
}
.form-card { padding: 24px; }

/* ---------- Suggestion dropdown ---------- */
.suggestions {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 4px;
  display: none;
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
}
.suggestion {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.suggestion:last-child { border-bottom: none; }
.suggestion:hover { background: var(--row-hover); }
.suggestion.empty { color: var(--text-muted); cursor: default; }
.muted { color: var(--text-muted); font-size: 12px; }

/* ---------- App layout (admin) ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 8px 4px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  user-select: none;
}
.nav-item:hover { background: var(--surface); text-decoration: none; }
.nav-item.active { background: var(--surface); color: var(--accent); }
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-group { margin-top: 4px; }
.nav-group-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  user-select: none;
}
.nav-group-label:hover { background: var(--surface); }
.nav-group-label .chevron { margin-left: auto; transition: transform 0.2s; }
.nav-group.open .chevron { transform: rotate(90deg); }
.nav-sub {
  display: none;
  flex-direction: column;
  padding-left: 16px;
  margin-top: 2px;
  gap: 2px;
}
.nav-group.open .nav-sub { display: flex; }

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.main {
  padding: 24px;
  overflow-x: hidden;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-header h1 {
  margin: 0;
  font-size: 22px;
}
.page-header .subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

/* Stat tiles */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.stat .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.stat .value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 4px;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  background: var(--surface-2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}
tbody tr:hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.badge.open { background: rgba(74, 222, 128, 0.15); color: var(--success); }
.badge.closed { background: rgba(148, 163, 184, 0.15); color: var(--text-muted); }
.badge.paid { background: rgba(204, 0, 0, 0.15); color: var(--accent); }
.badge.unpaid { background: rgba(255, 77, 77, 0.15); color: var(--danger); }
.badge.active { background: rgba(74, 222, 128, 0.15); color: var(--success); }
.badge.inactive { background: rgba(148, 163, 184, 0.15); color: var(--text-muted); }

.color-swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 6px;
  border: 1px solid var(--border);
}

/* Driver board grid */
.board-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.board-table { width: 100%; min-width: 720px; }
.board-table th, .board-table td {
  text-align: center;
  white-space: nowrap;
}
.board-table th.day { width: 100px; }
.board-table td.driver-cell {
  text-align: left;
  font-weight: 600;
  border-left: 4px solid transparent;
}
.board-cell {
  cursor: pointer;
  min-width: 80px;
}
.board-cell:hover { background: var(--row-hover); }
.board-cell .stops { font-weight: 700; }
.board-cell .pkgs { color: var(--text-muted); font-size: 12px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal h3 { margin-top: 0; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* Slide-up panel (mobile-friendly) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 20px;
  z-index: 201;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease-out;
  box-shadow: var(--shadow);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.sheet h3 {
  margin: 0 0 4px;
}
.sheet .subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
}
.summary-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}
.summary-list li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.summary-list li:last-child { border-bottom: none; }
.summary-list .label { color: var(--text-muted); }
.summary-list .value { font-variant-numeric: tabular-nums; }
.summary-list .deduction { color: var(--danger); }
.summary-list .total {
  font-weight: 800;
  font-size: 18px;
  border-top: 2px solid var(--border);
  margin-top: 6px;
  padding-top: 12px;
}

/* Filter tabs */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 10px;
  width: max-content;
  margin-bottom: 16px;
}
.tab {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
}
.tab.active { background: var(--surface); color: var(--text); }

/* Misc */
.flex { display: flex; }
.between { justify-content: space-between; }
.center-items { align-items: center; }
.gap-sm { gap: 6px; }
.gap-md { gap: 12px; }
.wrap { flex-wrap: wrap; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 16px; }
.danger { color: var(--danger); }
.success { color: var(--success); }
.text-muted { color: var(--text-muted); }
.bold { font-weight: 700; }
.big { font-size: 20px; }
.hidden { display: none !important; }

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar select, .toolbar input {
  width: auto;
  min-width: 180px;
}

/* Mobile */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    bottom: 0;
    top: auto;
    left: 0;
    right: 0;
    height: auto;
    max-height: 56px;
    overflow: hidden;
    flex-direction: row;
    padding: 8px;
    border-top: 1px solid var(--border);
    border-right: none;
    z-index: 100;
    transition: max-height 0.25s;
  }
  .sidebar.open {
    max-height: 80vh;
    overflow-y: auto;
    flex-direction: column;
  }
  .sidebar-header { display: none; }
  .sidebar.open .sidebar-header { display: block; }
  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 4px;
  }
  .sidebar.open .sidebar-nav { flex-direction: column; overflow-x: visible; }
  .nav-item { padding: 8px; font-size: 12px; }
  .nav-group { display: none; }
  .sidebar.open .nav-group { display: block; }
  .sidebar-footer { display: none; }
  .sidebar.open .sidebar-footer { display: flex; }
  .main { padding: 16px 16px 80px; }
  .row { grid-template-columns: 1fr; }
  .toolbar select, .toolbar input { width: 100%; }
}

/* Print (for generate report) */
@media print {
  .sidebar, .page-header .btn, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .table-wrap { box-shadow: none; border-color: #ccc; }
  .main { padding: 0; }
}
