:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --page-plane: #f2f2ef;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.16);

  --series-1: #2a78d6; /* blue */
  --series-2: #008300; /* green */
  --series-3: #e87ba4; /* magenta */
  --series-4: #eda100; /* yellow */
  --series-5: #1baf7a; /* aqua */
  --series-6: #eb6834; /* orange */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 1px 2px rgba(11,11,11,0.04), 0 4px 16px rgba(11,11,11,0.05);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #202020;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255,255,255,0.10);
    --border-strong: rgba(255,255,255,0.16);
    --series-1: #3987e5;
    --series-3: #d55181;
    --series-4: #c98500;
    --series-5: #199e70;
    --series-6: #d95926;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #202020;
  --page-plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255,255,255,0.10);
  --border-strong: rgba(255,255,255,0.16);
  --series-1: #3987e5;
  --series-3: #d55181;
  --series-4: #c98500;
  --series-5: #199e70;
  --series-6: #d95926;
  --series-7: #9085e9;
  --series-8: #e66767;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select { font-family: inherit; font-size: inherit; }

/* ---------- Auth pages ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 32px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--series-1), var(--series-5));
  flex-shrink: 0;
}
.brand-name { font-weight: 650; font-size: 17px; letter-spacing: -0.01em; }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
.auth-card .subtitle { color: var(--text-secondary); font-size: 13.5px; margin: 0 0 22px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-primary);
  outline: none; transition: border-color .15s ease;
}
.field input:focus, .field select:focus { border-color: var(--series-1); }
.field small { display:block; margin-top:6px; color: var(--text-muted); font-size: 11.5px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 10px 16px; border-radius: var(--radius-sm); border: none;
  background: var(--text-primary); color: var(--surface-1); font-weight: 600; font-size: 14px;
  cursor: pointer; transition: opacity .15s ease;
}
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--text-primary); border: 1px solid var(--border-strong); }

.auth-footer { margin-top: 18px; text-align: center; font-size: 13px; color: var(--text-secondary); }
.auth-footer a { font-weight: 600; text-decoration: none; }

.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; }
.alert.error { background: rgba(208,59,59,0.10); color: var(--status-critical); border: 1px solid rgba(208,59,59,0.25); }
.alert.info { background: rgba(42,120,214,0.10); color: var(--series-1); border: 1px solid rgba(42,120,214,0.25); }

.test-users { margin-top: 20px; padding-top: 18px; border-top: 1px dashed var(--border-strong); }
.test-users summary { cursor: pointer; font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.test-users table { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 12px; }
.test-users td { padding: 4px 0; color: var(--text-secondary); }
.test-users td:first-child { font-weight: 600; color: var(--text-primary); }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--surface-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px;
}
.sidebar .brand { padding: 0 8px; margin-bottom: 28px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none; font-size: 13.5px; font-weight: 550; margin-bottom: 2px;
  cursor: pointer; border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--page-plane); color: var(--text-primary); }
.nav-item.active { background: var(--series-1); color: white; }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--series-7); color: white;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.user-meta { min-width: 0; flex: 1; }
.user-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-muted); }
.icon-btn {
  width: 28px; height: 28px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface-1); color: var(--text-secondary); display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 16px 28px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.topbar h1 { font-size: 16px; margin: 0; letter-spacing: -0.01em; }
.rls-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  padding: 5px 10px; border-radius: 999px; background: rgba(42,120,214,0.10); color: var(--series-1);
}
.content { padding: 24px 28px; overflow: auto; flex: 1; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 20px; box-shadow: var(--shadow-card);
}
.card-title { font-size: 12.5px; font-weight: 650; color: var(--text-secondary); margin: 0 0 12px; text-transform: uppercase; letter-spacing: 0.04em; }

.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.stat-label { font-size: 12.5px; color: var(--text-secondary); margin-top: 4px; }
.stat-delta { font-size: 12px; font-weight: 600; margin-top: 8px; display: inline-flex; align-items: center; gap: 4px; }
.stat-delta.good { color: var(--status-good); }
.stat-delta.critical { color: var(--status-critical); }

.meter-track { height: 8px; border-radius: 999px; background: var(--gridline); overflow: hidden; margin-top: 10px; }
.meter-fill { height: 100%; border-radius: 999px; transition: width .3s ease; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-label { width: 168px; flex-shrink: 0; font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 14px; background: var(--gridline); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; min-width: 2px; }
.bar-value { width: 52px; flex-shrink: 0; text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--text-primary); font-weight: 600; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

.tooltip-svg { pointer-events: none; }

/* ---------- Table / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.chip-select {
  position: relative;
}
.chip-btn {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); font-size: 13px; cursor: pointer; color: var(--text-primary);
}
.chip-btn .count { background: var(--series-1); color: white; border-radius: 999px; font-size: 10.5px; padding: 1px 6px; font-weight: 700; }
.dropdown-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; min-width: 220px; max-height: 320px; overflow: auto;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-card);
  padding: 10px;
}
.dropdown-panel.wide { min-width: 300px; }
.dropdown-panel label.opt {
  display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 6px; font-size: 13px; cursor: pointer;
}
.dropdown-panel label.opt:hover { background: var(--page-plane); }
.dropdown-actions { display: flex; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.dropdown-actions button { flex: 1; padding: 6px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-1); font-size: 12px; cursor: pointer; }

.search-input { padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-2); min-width: 220px; }
.date-input { padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-2); }

.table-wrap {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: auto;
  box-shadow: var(--shadow-card); max-height: calc(100vh - 300px);
}
table.data-table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.data-table thead th {
  position: sticky; top: 0; background: var(--surface-2); text-align: left; padding: 10px 14px;
  font-weight: 650; color: var(--text-secondary); border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; z-index: 5;
}
table.data-table thead th:hover { color: var(--text-primary); }
table.data-table tbody td {
  padding: 9px 14px; border-bottom: 1px solid var(--gridline); white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-primary);
}
table.data-table tbody tr:hover { background: var(--page-plane); }
.badge { display: inline-flex; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 650; }
.badge.ok { background: rgba(12,163,12,0.12); color: var(--status-good); }
.badge.bad { background: rgba(208,59,59,0.12); color: var(--status-critical); }

.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; font-size: 12.5px; color: var(--text-secondary); }
.pagination .controls { display: flex; gap: 6px; align-items: center; }
.pagination button { padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-2); cursor: pointer; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-2); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-secondary); }

/* ---------- Agendamentos ---------- */
.schedule-form { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px; align-items: end; }
.schedule-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--text-secondary); }
.schedule-form input, .schedule-form select {
  padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text-primary);
}
.schedule-form .toolbar { grid-column: 1 / -1; }
.schedule-form #schCreate { grid-column: 1 / -1; justify-self: start; }
@media (max-width: 1100px) { .schedule-form { grid-template-columns: repeat(2, 1fr); } }

.schedule-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.schedule-row:last-child { border-bottom: none; }
.schedule-main { display: flex; flex-direction: column; gap: 2px; }
.schedule-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); cursor: pointer; }

.loading { color: var(--text-muted); font-size: 13px; padding: 20px; text-align: center; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
