:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --surface2: #20243280;
  --border:   #2a2d3a;
  --accent:   #00c896;
  --warn:     #f59e0b;
  --danger:   #ef4444;
  --info:     #38bdf8;
  --text:     #e2e8f0;
  --muted:    #64748b;
  --font:     'Segoe UI', system-ui, sans-serif;
  --radius:   10px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
}

/* ══════════════════════════════════════════════════════
 * Login overlay
 * ══════════════════════════════════════════════════════ */
.login-overlay {
  position: fixed; inset: 0;
  background:
    radial-gradient(1100px 560px at 50% -12%, rgba(0,200,150,0.12), transparent 60%),
    rgba(8,10,15,0.88);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 9999;
}

.login-card {
  position: relative;
  background: linear-gradient(180deg, #1c2030, #15181f);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 38px 34px 34px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 28px 70px -24px rgba(0,0,0,0.7), inset 0 1px 0 rgba(255,255,255,0.04);
  overflow: hidden;
  animation: loginIn 0.4s cubic-bezier(0.22,1,0.36,1);
}
.login-card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
@keyframes loginIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.login-logo {
  font-size: 25px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}

.login-title {
  font-size: 11.5px;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2.4px;
  margin-bottom: 26px;
}

.login-err {
  color: #fecaca;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.28);
  border-radius: 8px;
  font-size: 12.5px;
  padding: 8px 11px;
  margin: 4px 0 12px;
  text-align: center;
}

/* Login-specific field + button polish */
.login-card .field-label { margin-top: 15px; letter-spacing: 0.4px; }
.login-card .field-input { padding: 11px 13px; border-radius: 9px; }
.login-card .field-input:focus { box-shadow: 0 0 0 3px rgba(0,200,150,0.16); }
.login-card .btn-primary {
  width: 100%;
  margin-top: 22px !important;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 9px;
  background: linear-gradient(180deg, #00d6a2, #00b083);
  box-shadow: 0 10px 24px -10px rgba(0,200,150,0.55);
  transition: filter 0.15s ease, transform 0.15s ease;
}
.login-card .btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }

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

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}

.logo { font-size: 16px; font-weight: 700; white-space: nowrap; }

.tabs { display: flex; gap: 2px; flex: 1; }

.tab {
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.tab:hover  { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.uptime { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ── Tab content ── */
.tab-content { display: none; padding: 24px; flex-direction: column; gap: 32px; }
.tab-content.active { display: flex; }

section { display: flex; flex-direction: column; gap: 14px; }

/* ══════════════════════════════════════════════════════
 * Buttons
 * ══════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-primary:hover { background: #00e6ab; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(239,68,68,0.12); }

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

/* ══════════════════════════════════════════════════════
 * Form inputs
 * ══════════════════════════════════════════════════════ */
.field-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.field-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: var(--font);
  transition: border-color 0.15s;
}
.field-input:focus { outline: none; border-color: var(--accent); }
.field-input::placeholder { color: var(--muted); }
.field-sm { max-width: 180px; }

select.field-input { cursor: pointer; }

/* ══════════════════════════════════════════════════════
 * Badges
 * ══════════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge.online  { background: #064e3b; color: var(--accent); }
.badge.offline { background: #3f1515; color: var(--danger); }
.badge:not(.online):not(.offline) { background: #78350f; color: var(--warn); }

/* ══════════════════════════════════════════════════════
 * Section headings
 * ══════════════════════════════════════════════════════ */
h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

/* ══════════════════════════════════════════════════════
 * Card grid
 * ══════════════════════════════════════════════════════ */
.card-row { display: flex; flex-wrap: wrap; gap: 12px; }

/* ── Pump card ── */
.pump-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 190px;
  flex: 1 1 190px;
  max-width: 250px;
  transition: border-color 0.3s;
}
.pump-card.fueling    { border-color: var(--accent); }
.pump-card.fault      { border-color: var(--danger); }
.pump-card.authorized { border-color: var(--warn); }

.pump-card .pump-id    { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.pump-card .pump-state {
  font-size: 15px; font-weight: 700;
  margin: 4px 0 12px; text-transform: capitalize;
}
.pump-state.fueling    { color: var(--accent); }
.pump-state.fault      { color: var(--danger); }
.pump-state.authorized { color: var(--warn); }
.pump-state.idle       { color: var(--muted); }

.pump-metric { display: flex; justify-content: space-between; margin-top: 6px; }
.pump-metric .label { color: var(--muted); }
.pump-metric .value { font-weight: 600; font-variant-numeric: tabular-nums; }

.pump-auth-btn {
  margin-top: 14px; width: 100%; padding: 8px;
  border: 1px solid var(--accent); border-radius: 7px;
  background: transparent; color: var(--accent);
  font-weight: 600; cursor: pointer; font-size: 13px;
  transition: background 0.15s;
}
.pump-auth-btn:hover:not(:disabled) { background: rgba(0,200,150,0.12); }
.pump-auth-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Tank card ── */
.tank-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 170px;
  flex: 1 1 170px;
  max-width: 230px;
}
.tank-id  { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.tank-vol { font-size: 18px; font-weight: 700; margin: 4px 0; }

.tank-bar-wrap {
  height: 8px; background: var(--border);
  border-radius: 4px; margin: 10px 0 6px; overflow: hidden;
}
.tank-bar {
  height: 100%; border-radius: 4px;
  background: var(--accent); transition: width 0.6s ease;
}
.tank-bar.low { background: var(--danger); }
.tank-bar.mid { background: var(--warn); }

.tank-stats {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted);
}

/* ══════════════════════════════════════════════════════
 * Tables
 * ══════════════════════════════════════════════════════ */
table {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border);
}
thead th {
  padding: 10px 14px; text-align: left;
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.12s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.025); }
tbody td { padding: 10px 14px; }

.synced-yes { color: var(--accent); }
.synced-no  { color: var(--warn); }

/* ══════════════════════════════════════════════════════
 * Transactions filter bar
 * ══════════════════════════════════════════════════════ */
.filter-bar {
  display: flex; flex-wrap: wrap;
  align-items: flex-end; gap: 12px;
}

.daily-totals {
  display: flex; gap: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 13px; color: var(--muted);
}
.daily-totals strong { color: var(--text); }

/* ══════════════════════════════════════════════════════
 * Alert items
 * ══════════════════════════════════════════════════════ */
#alerts-list { display: flex; flex-direction: column; gap: 8px; }

.alert-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.alert-item.sev-0 { border-left-color: var(--info); }
.alert-item.sev-1 { border-left-color: var(--warn); }
.alert-item.sev-2 { border-left-color: var(--danger); }
.alert-item.acked { opacity: 0.5; }

.alert-body { display: flex; flex-direction: column; gap: 3px; }
.alert-type { font-size: 11px; font-weight: 600; text-transform: uppercase;
              letter-spacing: 0.4px; color: var(--muted); }
.alert-desc { font-weight: 500; }
.alert-meta { color: var(--muted); font-size: 12px; }
.acked-label { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ══════════════════════════════════════════════════════
 * Config form
 * ══════════════════════════════════════════════════════ */
.config-form {
  display: flex; flex-direction: column; gap: 28px;
  max-width: 600px;
}

.form-group {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.form-section-title {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--muted); margin-bottom: 2px;
}

.price-grid {
  display: flex; flex-wrap: wrap; gap: 12px;
}

.form-actions {
  display: flex; align-items: center; gap: 16px;
}

.save-status { font-size: 13px; }
.save-status.ok  { color: var(--accent); }
.save-status.err { color: var(--danger); }

/* ══════════════════════════════════════════════════════
 * Users tab
 * ══════════════════════════════════════════════════════ */
.role-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.role-badge.role-0 { background: #1e293b; color: var(--muted); }
.role-badge.role-1 { background: #422006; color: var(--warn); }
.role-badge.role-2 { background: #064e3b; color: var(--accent); }

/* ── In-page modal ── */
.modal-wrap {
  margin-top: 20px;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-card h3 {
  font-size: 14px; font-weight: 600; margin-bottom: 4px;
}

/* ══════════════════════════════════════════════════════
 * Misc
 * ══════════════════════════════════════════════════════ */
.empty-msg {
  color: var(--muted);
  font-size: 13px;
  padding: 8px 0;
}

/* ══════════════════════════════════════════════════════
 * Responsive
 * ══════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  header { flex-wrap: wrap; height: auto; padding: 12px 16px; }
  .tabs  { order: 3; width: 100%; overflow-x: auto; }
  .tab-content { padding: 16px; }
  .pump-card, .tank-card { max-width: 100%; }
  .config-form { max-width: 100%; }
  .filter-bar label { flex-direction: column; }
}

/* Fix: make the [hidden] attribute actually hide elements (overrides .login-overlay/.app display:flex) */
[hidden] { display: none !important; }
