:root {
  color-scheme: light;

  --page-plane: #f2f3f8;
  --surface-1: #ffffff;
  --surface-2: #f7f7fb;
  --text-primary: #0b1f3f;
  --text-secondary: #4b5468;
  --text-muted: #8a8fa3;
  --gridline: #edeef4;
  --baseline: #d8dae6;
  --border: #e6e7f0;

  --brand-red: #e2001a;
  --brand-red-dark: #b50015;
  --brand-navy: #0b1f3f;
  --brand-navy-soft: #16305c;

  --series-1: #0b1f3f;
  --series-2: #e2001a;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #2a78d6;
  --series-6: #8a5cf6;
  --series-7: #e87ba4;
  --series-8: #4b5468;

  --good: #0ca30c;
  --critical: #d03b3b;

  --sidebar-width: 240px;
  --topbar-height: 60px;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

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;
}

input,
select {
  max-width: 100%;
}

a {
  color: inherit;
}

/* ---------- App shell / sidebar ---------- */

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

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  z-index: 30;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
}

.app-shell.sidebar-open .sidebar {
  transform: translateX(0);
  box-shadow: 8px 0 24px rgba(11, 31, 63, 0.15);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 31, 63, 0.4);
  z-index: 20;
}

.app-shell.sidebar-open .sidebar-backdrop {
  display: block;
}

.sidebar::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--brand-red);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
}

.logo-text {
  font-weight: 700;
  font-size: 15px;
  color: var(--brand-navy);
  white-space: nowrap;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(226, 0, 26, 0.08);
  color: var(--brand-red);
  font-weight: 700;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand-navy);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-link {
  color: var(--text-muted);
}

.logout-link:hover {
  color: var(--brand-red);
  background: var(--surface-2);
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

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

.page-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  color: var(--brand-navy);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--brand-navy);
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  min-width: 20px;
}

.icon-btn:hover {
  background: var(--border);
}

.mobile-only {
  display: none;
}

.desktop-only {
  display: flex;
}

.menu-toggle-btn {
  width: auto;
  height: 38px;
  padding: 0 12px 0 10px;
  gap: 6px;
  background: rgba(226, 0, 26, 0.08);
  border-color: rgba(226, 0, 26, 0.3);
  color: var(--brand-red);
}

.menu-toggle-btn:hover {
  background: rgba(226, 0, 26, 0.14);
}

.menu-toggle-btn svg {
  transition: transform 0.2s ease;
}

.menu-toggle-label {
  font-size: 13px;
  font-weight: 700;
}

.app-shell.sidebar-open .menu-toggle-btn svg {
  transform: rotate(180deg);
}

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

body.no-shell .app-shell {
  min-height: 100vh;
}

body.no-shell .content {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ---------- Cards / grids ---------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-kpis {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.grid-charts {
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
}

.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.kpi-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.kpi-icon svg {
  width: 16px;
  height: 16px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--brand-navy);
}

.kpi-trend {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
}

.kpi-trend.up {
  color: var(--good);
}

.kpi-trend.down {
  color: var(--critical);
}

.chart-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--brand-navy);
  margin: 0 0 12px;
}

.chart-wrap {
  position: relative;
  height: 280px;
}

/* ---------- Forms ---------- */

form.filters {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 20px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

form.filters label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--text-muted);
  gap: 4px;
  font-weight: 600;
}

input,
select {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}

input:focus,
select:focus {
  outline: 2px solid rgba(226, 0, 26, 0.25);
  border-color: var(--brand-red);
}

button,
.btn {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--brand-red);
  color: white;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

button:hover,
.btn:hover {
  background: var(--brand-red-dark);
}

button.secondary,
.btn.secondary {
  background: var(--surface-1);
  color: var(--text-secondary);
  border-color: var(--border);
}

button.secondary:hover,
.btn.secondary:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

/* ---------- Tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}

th {
  color: var(--text-muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.table-scroll {
  overflow-x: auto;
}

.table-link {
  color: var(--brand-red);
  font-weight: 700;
  text-decoration: none;
}

.table-link:hover {
  text-decoration: underline;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 4px 2px;
  font-size: 13px;
  color: var(--text-muted);
}

.pagination-buttons {
  display: flex;
  gap: 8px;
}

.badge-flag {
  background: rgba(208, 59, 59, 0.12);
  color: var(--critical);
}

/* ---------- Alerts / badges ---------- */

.alert {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
}

.alert-error {
  background: rgba(208, 59, 59, 0.1);
  color: var(--critical);
}

.alert-success {
  background: rgba(12, 163, 12, 0.1);
  color: var(--good);
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  width: fit-content;
}

.badge-admin {
  background: rgba(226, 0, 26, 0.12);
  color: var(--brand-red);
}

.badge-viewer {
  background: rgba(11, 31, 63, 0.08);
  color: var(--text-secondary);
}

/* ---------- Login ---------- */

.login-card {
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.login-card h2 {
  margin: 0;
  color: var(--brand-navy);
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.password-field {
  position: relative;
  display: flex;
}

.password-field input {
  width: 100%;
  padding-right: 40px;
}

.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  background: transparent;
  border-color: transparent;
}

.password-toggle svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  min-width: 18px;
}

.password-toggle.active {
  color: var(--brand-red);
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .mobile-only {
    display: flex;
  }

  .desktop-only {
    display: none;
  }

  .content {
    padding: 16px;
  }

  .topbar {
    padding: 0 16px;
  }

  form.filters {
    flex-direction: column;
    align-items: stretch;
  }

  form.filters > * {
    width: 100%;
  }

  .grid-kpis {
    grid-template-columns: repeat(2, 1fr);
  }

  /* ---------- Tabelas viram cards no mobile ---------- */

  .table-scroll {
    overflow-x: visible;
  }

  .table-scroll table,
  .table-scroll thead,
  .table-scroll tbody,
  .table-scroll tr,
  .table-scroll td {
    display: block;
    width: 100%;
  }

  .table-scroll thead {
    display: none;
  }

  .table-scroll tr {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 12px;
    padding: 4px 14px;
  }

  .table-scroll tr:last-child {
    margin-bottom: 0;
  }

  .table-scroll td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--gridline);
    white-space: normal;
    text-align: right;
  }

  .table-scroll td:last-child {
    border-bottom: none;
  }

  .table-scroll td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-muted);
    text-align: left;
    margin-right: 8px;
    flex-shrink: 0;
  }

  .table-scroll td[data-label=""]::before,
  .table-scroll td:not([data-label])::before {
    content: none;
  }
}

@media (max-width: 480px) {
  .grid-kpis {
    grid-template-columns: 1fr 1fr;
  }

  .kpi-value {
    font-size: 21px;
  }
}
