:root {
  --primary: #1A2E5E;
  --primary-700: #142447;
  --primary-100: #e8edf5;
  --accent: #2196f3;
  --success: #27ae60;
  --warning: #f39c12;
  --danger: #e74c3c;
  --text: #1a202c;
  --text-muted: #718096;
  --border: #e2e8f0;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --sidebar-width: 240px;
  --header-height: 56px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.12);
}

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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--surface-2);
  color: var(--text);
  direction: rtl;
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; right: 0;
  z-index: 100;
  overflow-y: auto;
  transition: transform .25s;
}

.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo .logo-icon {
  width: 40px; height: 40px;
  background: rgba(255,255,255,.15);
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 900;
  letter-spacing: -1px;
  flex-shrink: 0;
}

.sidebar-logo .logo-text { line-height: 1.2; }
.sidebar-logo .logo-text strong { display: block; font-size: 15px; }
.sidebar-logo .logo-text small  { font-size: 11px; opacity: .65; }

.sidebar-user {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  font-size: 12px;
  opacity: .8;
}
.sidebar-user strong { display: block; font-size: 13px; opacity: 1; margin-bottom: 2px; }

.nav { flex: 1; padding: 8px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: 8px;
  margin: 2px 8px;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s;
  color: rgba(255,255,255,.8);
}

.nav-item:hover   { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active  { background: rgba(255,255,255,.18); color: #fff; font-weight: 700; }
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid rgba(255,255,255,.1);
}

.btn-logout {
  width: 100%;
  padding: 9px 16px;
  background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.85);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .15s;
  font-family: inherit;
}
.btn-logout:hover { background: rgba(255,255,255,.18); color: #fff; }

/* ── Main ── */
.main {
  flex: 1;
  margin-right: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky;
  top: 0; z-index: 50;
}

.topbar h1 { font-size: 16px; font-weight: 700; flex: 1; }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #ccc;
}
.status-dot.online { background: var(--success); }

.content { padding: 24px; flex: 1; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-header h3 { font-size: 15px; font-weight: 700; }

.card-body { padding: 20px; }

/* ── Stat cards ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-card .stat-icon {
  font-size: 22px;
  width: 44px; height: 44px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--primary-100);
}

.stat-card .stat-value { font-size: 26px; font-weight: 800; color: var(--primary); }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity .15s, background .15s;
  font-family: inherit;
  white-space: nowrap;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-700); }

.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { opacity: .88; }

.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: .88; }

.btn-outline  {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover:not(:disabled) { background: var(--primary-100); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

input, select, textarea {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color .15s;
  outline: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); }

textarea { resize: vertical; min-height: 80px; }

.help { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Tables ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  padding: 10px 12px;
  text-align: right;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  font-size: 12px;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--surface-2); }

.data-table .actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-ok      { background: #d4edda; color: #155724; }
.badge-neutral { background: #e2e8f0; color: #4a5568; }
.badge-info    { background: #cce5ff; color: #004085; }
.badge-warn    { background: #fff3cd; color: #856404; }
.badge-danger  { background: #f8d7da; color: #721c24; }

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn .2s ease;
  max-width: 320px;
  direction: rtl;
}

.toast-success { background: #d4edda; color: #155724; }
.toast-error   { background: #f8d7da; color: #721c24; }
.toast-info    { background: #cce5ff; color: #004085; }

@keyframes slideIn {
  from { transform: translateX(-20px); opacity: 0; }
  to   { transform: translateX(0);     opacity: 1; }
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%; max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body  { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

.btn-close {
  background: none; border: none; font-size: 18px;
  cursor: pointer; color: var(--text-muted); padding: 4px;
  line-height: 1;
}

@keyframes modalIn {
  from { transform: translateY(-12px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

/* ── Charts ── */
.chart-bar-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 20px;
}

.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.chart-bar-label { width: 70px; color: var(--text-muted); text-align: left; }

.chart-bar-track {
  flex: 1;
  height: 10px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}

.chart-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width .4s ease;
}

.chart-bar-value { width: 40px; text-align: left; font-weight: 600; }

/* ── States ── */
.state-loading, .state-empty, .state-error {
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.state-loading::before { content: '⏳ '; }
.state-empty::before   { content: '📭 '; }
.state-error           { color: var(--danger); }

/* ── Login ── */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--primary);
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%; max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  font-size: 36px;
  font-weight: 900;
  color: var(--primary);
  margin-bottom: 8px;
}

.login-card h2 { font-size: 20px; margin-bottom: 4px; }
.login-card p  { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }

.login-form { display: flex; flex-direction: column; gap: 12px; text-align: right; }

/* ── Stop picker ── */
.stop-picker {
  border: 1px solid var(--border); border-radius: 10px;
  max-height: 240px; overflow-y: auto; background: #fff;
}
.stop-picker .pick-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none;
}
.stop-picker .pick-row:last-child { border-bottom: 0; }
.stop-picker .pick-row:hover { background: var(--surface-2); }
.stop-picker .pick-row.selected { background: rgba(26,46,94,.06); }
.stop-picker .pick-row .order {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: #fff; display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
}
.stop-picker .pick-row.unselected .order {
  background: transparent; color: var(--text-muted); border: 1px dashed var(--border);
}

/* =========================================================================
   80mm THERMAL CHARGE CARD — print-ready design
   ========================================================================= */
.charge-card-80mm {
  width: 72mm;
  margin: 16px auto;
  background: #fff;
  border: 1.5px solid #1a2e5e;
  border-radius: 6px;
  overflow: hidden;
  font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
  color: #000;
  page-break-inside: avoid;
  break-inside: avoid;
}
.charge-card-80mm .cc-header {
  background: #1a2e5e;
  color: #fff;
  padding: 6px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.charge-card-80mm .cc-brand     { font-size: 11px; font-weight: 800; letter-spacing: .5px; display: flex; align-items: center; gap: 5px; }
.charge-card-80mm .cc-icon      { width: 20px; height: 20px; border-radius: 4px; object-fit: cover; flex-shrink: 0; }
.charge-card-80mm .cc-type      { background: #f39c12; color: #fff; font-size: 9px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.charge-card-80mm .cc-body      { padding: 10px; display: flex; gap: 10px; align-items: center; }
.charge-card-80mm .cc-qr canvas { display: block; border: 1px solid #eee; border-radius: 4px; }
.charge-card-80mm .cc-info      { flex: 1; }
.charge-card-80mm .cc-amount    { font-size: 22px; font-weight: 900; color: #1a2e5e; line-height: 1; direction: ltr; text-align: right; }
.charge-card-80mm .cc-amt-label { font-size: 9px; color: #6b7a8d; margin: 2px 0 6px; }
.charge-card-80mm .cc-token     { font-size: 7.5px; color: #555; direction: ltr; word-break: break-all; line-height: 1.4; background: #f7f9fc; padding: 3px 5px; border-radius: 3px; border: 1px dashed #c7d3e3; font-family: monospace; }
.charge-card-80mm .cc-note      { font-size: 9px; color: #555; margin-top: 5px; text-align: center; font-style: italic; }
.charge-card-80mm .cc-footer    { background: #f7f9fc; border-top: 1px dashed #c7d3e3; padding: 5px 10px; display: flex; justify-content: space-between; align-items: center; font-size: 8px; color: #888; }
.charge-card-80mm .cc-foot-logo { font-weight: 800; color: #1a2e5e; opacity: .5; }

/* Print-only container that holds the card during printing */
#print-target { display: none; }

/* =========================================================================
   MISSING UTILITY & LAYOUT RULES
   ========================================================================= */

/* Critical: hide/show toggle used by app.js */
.hidden { display: none !important; }

/* ── Splash screen ── */
.splash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  z-index: 9999;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--primary-100);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login screen ── */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  z-index: 200;
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand h1 { font-size: 22px; font-weight: 800; color: var(--primary); }
.login-brand p  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.brand-mark {
  width: 56px; height: 56px;
  background: var(--primary);
  color: #fff;
  border-radius: 14px;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 900;
  margin: 0 auto 12px;
}
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.login-form input {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  direction: ltr;
  text-align: right;
}
.login-form input:focus { border-color: var(--primary); }
.form-error { color: var(--danger); font-size: 12px; min-height: 16px; }
.login-hint { font-size: 11px; color: var(--text-muted); text-align: center; margin-top: 20px; line-height: 1.6; }
.login-hint code { background: var(--surface-2); padding: 2px 5px; border-radius: 4px; font-family: monospace; }

/* ── App shell ── */
.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar brand ── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  flex-shrink: 0;
}
.sidebar-title    { font-size: 15px; font-weight: 800; }
.sidebar-subtitle { font-size: 11px; opacity: .6; }

/* ── Sidebar nav ── */
.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin: 2px 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,.8);
  transition: background .15s;
}
.sidebar-nav a:hover  { background: rgba(255,255,255,.1); color: #fff; }
.sidebar-nav a.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 700; }
.sidebar-nav .ico { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

/* ── Sidebar user pill ── */
.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  margin-bottom: 8px;
}
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; font-size: 13px; line-height: 1.4; }

/* ── Button extras ── */
.btn-ghost {
  background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.85);
  border: none;
}
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,.18); color: #fff; }
.btn-block { width: 100%; justify-content: center; }

/* ── Icon / menu button ── */
.icon-btn, .menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--text);
  display: none;
}

/* ── Topbar extras ── */
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-right: auto; }
.topbar h2 { font-size: 16px; font-weight: 700; flex: 1; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge-ok  { background: #d1fae5; color: #065f46; }
.badge-err { background: #fee2e2; color: #991b1b; }

/* ── View area ── */
.view { padding: 24px; flex: 1; }

/* ── Typography helpers ── */
.muted { color: var(--text-muted); }
.small { font-size: 11px; }

/* ── Mobile sidebar ── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main { margin-right: 0 !important; }
  .icon-btn, .menu-btn { display: flex; }
  .view { padding: 16px; }
}



@media print {
  @page { size: 80mm auto; margin: 3mm 4mm; }

  /* Hide everything */
  body * { visibility: hidden !important; }

  /* Show only the print target and its descendants */
  #print-target, #print-target * { visibility: visible !important; }

  #print-target {
    display: block !important;
    position: absolute;
    top: 0; left: 0; right: 0;
    width: 100%;
    background: #fff;
  }

  .charge-card-80mm {
    margin: 0 auto !important;
    border: 1px solid #000 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    page-break-after: always;
  }
  .charge-card-80mm:last-child { page-break-after: auto; }
  .charge-card-80mm .cc-header { background: #000 !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  .charge-card-80mm .cc-type   { background: #555 !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  .charge-card-80mm .cc-amount { color: #000 !important; }
  .charge-card-80mm .cc-footer { background: #f0f0f0 !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}