:root {
  --page-bg: #f4f6f8;
  --sidebar-bg: #151a24;
  --sidebar-active: #232a3a;
  --sidebar-text: #8891a5;
  --sidebar-muted: #6b7280;
  --sidebar-border: #262c3a;
  --border: #e2e5ea;
  --border-light: #eef0f3;
  --text-dark: #161a22;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --text-faint: #9aa1b0;
  --primary: #004c94;
  --primary-hover: #00325f;
  --danger: oklch(0.55 0.19 25);
  --danger-bg: oklch(0.96 0.05 25);
  --danger-text: oklch(0.5 0.16 25);
  --success: oklch(0.55 0.14 150);
  --success-bg: oklch(0.96 0.04 150);
  --success-text: oklch(0.45 0.12 150);
  --info: oklch(0.55 0.16 255);
  --info-bg: oklch(0.94 0.05 255);
  --info-text: oklch(0.48 0.15 255);
  --warning-bg: oklch(0.97 0.05 85);
  --warning-text: oklch(0.52 0.13 85);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-bg);
  color: var(--text-dark);
}

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

.app { display: flex; min-height: 100vh; }

/* --- sidebar --- */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 8px 12px 24px 12px; }
.sidebar-brand-logo { width: 28px; height: 28px; object-fit: contain; flex-shrink: 0; }
.sidebar-brand-name { color: #fff; font-size: 14px; font-weight: 700; line-height: 1.2; }
.sidebar-brand-tenant { color: var(--sidebar-muted); font-size: 11px; line-height: 1.2; }
.sidebar-section { color: #4b5266; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; padding: 16px 12px 6px 12px; }
.sidebar-link {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px;
  margin-bottom: 2px; font-size: 13.5px; color: var(--sidebar-text);
}
.sidebar-link svg { flex-shrink: 0; }
.sidebar-link.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.sidebar-link.disabled { color: #4b5266; cursor: default; }
.sidebar-spacer { flex: 1; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 12px; border-top: 1px solid var(--sidebar-border); margin-top: 8px; }
.sidebar-avatar { width: 30px; height: 30px; border-radius: 50%; background: #2c3345; display: flex; align-items: center; justify-content: center; color: #c7cbd6; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.sidebar-user-name { color: #dfe2e9; font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { color: var(--sidebar-muted); font-size: 11px; }
.sidebar-logout { background: none; border: none; color: var(--sidebar-muted); cursor: pointer; padding: 4px; }
.sidebar-logout:hover { color: #fff; }

/* --- main / topbar --- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  min-height: 64px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 14px 28px;
}
.topbar-title { color: var(--text-dark); font-size: 16px; font-weight: 700; }
.topbar-breadcrumb { color: var(--text-faint); font-size: 11.5px; margin-bottom: 4px; }
.content { flex: 1; overflow: auto; padding: 24px 28px; display: flex; flex-direction: column; gap: 16px; }

/* --- buttons --- */
.btn {
  border-radius: 8px; padding: 9px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; line-height: 1.2;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-secondary { background: #fff; color: var(--text-secondary); border-color: #d7dbe2; }
.btn-secondary:hover { background: #fafbfc; color: var(--text-secondary); }
.btn-danger-outline { background: #fafbfc; color: var(--danger); border-color: var(--border); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 7px 10px; font-size: 12px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* --- cards / grids --- */
.card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 18px; }
.card-flush { padding: 0; overflow: hidden; }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--border-light); display: flex; justify-content: space-between; align-items: center; }
.card-title { color: var(--text-dark); font-size: 13.5px; font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.stat-label { color: var(--text-muted); font-size: 12px; margin-bottom: 10px; }
.stat-value { color: var(--text-dark); font-size: 22px; font-weight: 700; }
.stat-value small { color: var(--text-faint); font-size: 13px; font-weight: 400; }
.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; align-items: start; }
.kv-list { display: flex; flex-direction: column; gap: 10px; font-size: 12.5px; }
.kv-row { display: flex; justify-content: space-between; }
.kv-label { color: var(--text-faint); }
.kv-value { color: var(--text-secondary); font-weight: 600; }

/* --- tables --- */
.table-wrap { background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; padding: 12px 18px; color: var(--text-faint); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.04em; background: #fafbfc; border-bottom: 1px solid var(--border-light);
}
table.data td { padding: 13px 18px; border-top: 1px solid var(--border-light); font-size: 12.5px; color: var(--text-secondary); }
table.data tr:first-child td { border-top: none; }
.mono { font-family: ui-monospace, monospace; }
.empty-row { padding: 24px; text-align: center; color: var(--text-faint); font-size: 12.5px; }

/* --- badges --- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; padding: 3px 9px; border-radius: 12px; font-weight: 500; white-space: nowrap; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-success .badge-dot { background: var(--success); }
.badge-info { background: var(--info-bg); color: var(--info-text); }
.badge-info .badge-dot { background: var(--info); }
.badge-danger { background: var(--danger-bg); color: var(--danger-text); }
.badge-danger .badge-dot { background: var(--danger); }
.badge-neutral { background: var(--border-light); color: var(--text-muted); }
.badge-neutral .badge-dot { background: var(--text-faint); }

/* --- mapa (Leaflet) --- */
.map-container { height: 600px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.map-popup-title { font-weight: 600; color: var(--text-dark); margin-bottom: 2px; }
.map-popup-meta { font-size: 12px; color: var(--text-muted); }

/* --- live updates (public/js/live.js) --- */
.flash-update { animation: flash-bg 0.8s ease; }
@keyframes flash-bg {
  from { background: var(--info-bg); }
  to { background: transparent; }
}

/* --- forms --- */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { color: #374151; font-size: 12.5px; font-weight: 600; }
.form-control {
  border: 1px solid #d7dbe2; border-radius: 8px; padding: 11px 12px; font-size: 13.5px;
  font-family: inherit; color: var(--text-dark); width: 100%;
}
.form-control:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.form-hint { color: var(--text-faint); font-size: 11.5px; }
.form-error { color: var(--danger-text); font-size: 11.5px; }
.filters-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filters-bar .spacer { flex: 1; }
.filter-box {
  display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; color: var(--text-secondary); font-size: 12.5px;
}
.filter-box select { border: none; background: transparent; font-size: 12.5px; color: var(--text-secondary); font-family: inherit; }

/* --- alerts --- */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 4px; }
.alert-error { background: var(--danger-bg); color: var(--danger-text); }
.alert-success { background: var(--success-bg); color: var(--success-text); }

.form-card { max-width: 560px; }
.page-header { display: flex; justify-content: space-between; align-items: center; }

/* --- guest / login --- */
.guest-shell { width: 100%; min-height: 100vh; display: flex; background: #fff; }
.guest-hero {
  width: 480px; min-width: 480px; background: var(--sidebar-bg); position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between; padding: 56px; color: #fff;
}
.guest-hero-title { font-size: 28px; font-weight: 700; line-height: 1.25; max-width: 380px; }
.guest-hero-sub { color: #8891a5; font-size: 14px; line-height: 1.6; max-width: 360px; margin-top: 16px; }
.guest-hero-brand { display: flex; align-items: center; gap: 10px; }
.guest-hero-logo { width: 34px; height: 34px; object-fit: contain; flex-shrink: 0; }
.guest-hero-brand-name { font-size: 16px; font-weight: 700; }
.guest-hero-footer { color: #4b5266; font-size: 12px; }
.guest-form-side { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px; }
.guest-form { width: 360px; }
.guest-form h1 { font-size: 22px; margin: 0 0 6px 0; }
.guest-form p.lead { color: #6b7280; font-size: 13.5px; margin: 0 0 28px 0; }

@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

/* --- monitoramento (public/js/monitoring.js) --- */
.monitoring-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.monitoring-card { text-align: left; cursor: pointer; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px; font: inherit; }
.monitoring-card.selected { border-color: var(--primary); }
.monitoring-card-station { color: var(--text-faint); font-size: 12px; margin-top: 8px; }
.chart-container { height: 320px; border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
