:root {
  --navy: #0f2942;
  --navy-light: #163a5c;
  --teal: #0d9488;
  --teal-light: #14b8a6;
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--teal); text-decoration: none; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, #0a1d31 100%);
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.login-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
  color: var(--navy);
}
.login-card .sub {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 13px;
}
.brand-badge {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--teal), var(--navy));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 20px;
  margin-bottom: 16px;
}

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--navy);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 18px 0;
}
.sidebar .brand { padding: 0 20px 18px; font-weight: 700; font-size: 16px; border-bottom: 1px solid rgba(255,255,255,0.1); margin-bottom: 12px; }
.sidebar .brand small { display: block; font-weight: 400; color: #94a3b8; font-size: 11px; margin-top: 2px; }
.sidebar nav { flex: 1; }
.sidebar nav a, .sidebar nav button.navlink {
  display: block; width: 100%; text-align: left;
  padding: 11px 20px; color: #cbd5e1; text-decoration: none;
  border: none; background: none; font-size: 14px; cursor: pointer;
  font-family: inherit;
}
.sidebar nav a:hover, .sidebar nav button.navlink:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active, .sidebar nav button.navlink.active { background: var(--teal); color: #fff; font-weight: 600; }
.sidebar .footer { padding: 12px 20px; border-top: 1px solid rgba(255,255,255,0.1); font-size: 12px; color: #94a3b8; }
.sidebar .footer button { color: #fca5a5; background: none; border: none; cursor: pointer; font-size: 12px; padding: 0; margin-top: 6px; }

.main { flex: 1; min-width: 0; }
.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 14px 24px; display: flex; align-items: center; justify-content: space-between;
}
.topbar h2 { margin: 0; font-size: 18px; }
.topbar .who { color: var(--text-muted); font-size: 13px; }
.content { padding: 24px; max-width: 1200px; }

.view { display: none; }
.view.active { display: block; }

/* ---------- Components ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-card .label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.stat-card .value { font-size: 24px; font-weight: 700; color: var(--navy); }
.stat-card .value.teal { color: var(--teal); }

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.panel-head h3 { margin: 0; font-size: 15px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: #f8fafc; }
.table-wrap { overflow-x: auto; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--teal); color: #fff; border: none; border-radius: 7px;
  padding: 9px 16px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--teal-light); }
.btn.secondary { background: #fff; color: var(--navy); border: 1px solid var(--border); }
.btn.secondary:hover { background: #f1f5f9; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #ef4444; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge.active, .badge.ok { background: #dcfce7; color: #166534; }
.badge.suspended, .badge.warn { background: #fef3c7; color: #92400e; }
.badge.disconnected, .badge.disabled, .badge.danger { background: #fee2e2; color: #991b1b; }

input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 7px;
  font-size: 13.5px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal-light); outline-offset: 0; border-color: var(--teal); }
label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 5px; font-weight: 600; }
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,41,66,0.5);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); padding: 24px; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.alert.error { background: #fee2e2; color: #991b1b; }
.alert.success { background: #dcfce7; color: #166534; }
.alert.info { background: #e0f2fe; color: #075985; }

.empty { color: var(--text-muted); font-style: italic; padding: 20px 0; text-align: center; }

.toast-wrap { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 8px; font-size: 13.5px; box-shadow: 0 6px 20px rgba(0,0,0,0.2); animation: slidein .2s ease; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

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

/* ---------- Receipt (print) ---------- */
.receipt {
  max-width: 340px; margin: 0 auto; background: #fff; padding: 20px; font-size: 13px;
}
.receipt h2 { text-align: center; margin: 0 0 2px; font-size: 17px; }
.receipt .sub { text-align: center; color: var(--text-muted); font-size: 11.5px; margin-bottom: 14px; }
.receipt table { font-size: 13px; }
.receipt .total-row td { font-weight: 700; font-size: 15px; border-top: 2px solid var(--navy); border-bottom: none; }
.receipt .thanks { text-align: center; margin-top: 16px; color: var(--text-muted); font-size: 11.5px; }

@media print {
  body * { visibility: hidden; }
  #receiptPrintArea, #receiptPrintArea * { visibility: visible; }
  #receiptPrintArea { position: absolute; top: 0; left: 0; width: 100%; }
}

/* ---------- Mobile (collector view) ---------- */
@media (max-width: 780px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 14px; overflow-x: auto; }
  .sidebar .brand { border: none; padding: 0 14px 0 0; margin: 0; white-space: nowrap; }
  .sidebar .brand small { display: none; }
  .sidebar nav { display: flex; flex: none; }
  .sidebar nav a, .sidebar nav button.navlink { padding: 8px 12px; white-space: nowrap; border-radius: 6px; }
  .sidebar .footer { border: none; padding: 0 0 0 10px; margin-left: auto; }
  .content { padding: 14px; }
  .topbar { padding: 12px 14px; }
  th, td { padding: 8px 6px; }
}
