/* SAF Engenharia Elétrica — Monitoramento de Usinas
   Identidade: azul-marinho #1B3355, dourado #DAA500, azul de ação #2563EB, fonte Lexend */
:root {
  color-scheme: light;
  --navy: #1b3355;
  --navy-deep: #0b1a2e;
  --gold: #daa500;
  --page: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dce3ec;
  --grid: #e7ecf2;
  --text: #1b2a41;
  --text-2: #4b5b72;
  --muted: #8492a6;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --sidebar: #1b3355;
  --sidebar-text: #d6e0ee;

  /* séries (paleta categórica validada) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --expected: #898781;

  /* status (reservados, sempre com ícone + texto) */
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-bg: #e6f5e6; --warning-bg: #fff4dc; --critical-bg: #fbe9e9; --unknown-bg: #ecebe7;
  --good-ink: #006300; --warning-ink: #7a5200; --critical-ink: #a32222;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0a1322; --surface: #111e33; --surface-2: #15253e; --border: #1e3150; --grid: #1a2b45;
    --text: #e6edf7; --text-2: #b4c2d6; --muted: #8fa3bf; --accent: #3b82f6;
    --sidebar: #0c1729; --sidebar-text: #c9d5e3; --gold: #e0a800;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --good-bg: #13301a; --warning-bg: #3a2e10; --critical-bg: #3d1717; --unknown-bg: #2a2a28;
    --good-ink: #6fd46f; --warning-ink: #fac75a; --critical-ink: #f08a8a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0a1322; --surface: #111e33; --surface-2: #15253e; --border: #1e3150; --grid: #1a2b45;
  --text: #e6edf7; --text-2: #b4c2d6; --muted: #8fa3bf; --accent: #3b82f6;
  --sidebar: #0c1729; --sidebar-text: #c9d5e3; --gold: #e0a800;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good-bg: #13301a; --warning-bg: #3a2e10; --critical-bg: #3d1717; --unknown-bg: #2a2a28;
  --good-ink: #6fd46f; --warning-ink: #fac75a; --critical-ink: #f08a8a;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Lexend, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px; color: var(--text); background: var(--page);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- layout */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.shell > div { min-width: 0; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 2px 10px 16px; margin-bottom: 8px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand img { width: 100%; max-width: 190px; display: block; }
.brand span { display: block; margin-top: 10px; font-size: 10.5px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav a.active { background: rgba(218,165,0,.16); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav a.active svg { color: var(--gold); }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar .spacer { flex: 1; }
.sidebar .user { padding: 10px 12px; font-size: 12px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar .user b { display: block; color: #fff; font-size: 13px; margin-bottom: 2px; }
.sidebar .user button { margin-top: 8px; }
.main { padding: 24px 28px 48px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mobile-bar { display: none; }

/* ---------------------------------------------------------------- componentes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; flex-wrap: wrap; }
.card-head .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.grid { display: grid; gap: 16px; }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.tile { padding: 14px 16px; }
.tile .label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.tile .value { font-size: 24px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tile .value small { font-size: 13px; font-weight: 500; color: var(--text-2); margin-left: 3px; letter-spacing: 0; }
.tile .foot { font-size: 12px; color: var(--muted); margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--critical-ink); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.icon { width: 34px; padding: 0; }
.sidebar .btn { background: transparent; color: var(--sidebar-text); border-color: rgba(255,255,255,.2); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; height: 34px; padding: 0 10px; width: 100%;
}
textarea { height: auto; padding: 8px 10px; min-height: 70px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 500; color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.check input { width: 16px; height: 16px; }
.help { font-size: 12px; color: var(--text-2); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; line-height: 1.5; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--text-2); font: inherit; font-weight: 500; padding: 5px 12px; border-radius: 6px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none; }
.tabs a.on { color: var(--text); border-color: var(--accent); }

/* tabela */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { font-size: 12px; font-weight: 500; color: var(--text-2); background: var(--surface); position: sticky; top: 0; }
td.r, th.r { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.link { cursor: pointer; }
td .sub { font-size: 12px; color: var(--muted); }

/* status */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px 3px 7px; border-radius: 99px; }
.status svg { width: 14px; height: 14px; }
.status.online { background: var(--good-bg); color: var(--good-ink); }
.status.alarm { background: var(--warning-bg); color: var(--warning-ink); }
.status.offline { background: var(--critical-bg); color: var(--critical-ink); }
.status.unknown { background: var(--unknown-bg); color: var(--text-2); }
.status.online svg { color: var(--good); } .status.alarm svg { color: var(--warning); } .status.offline svg { color: var(--critical); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font: inherit; color: var(--text); }
.chip b { font-size: 16px; font-variant-numeric: tabular-nums; }
.chip.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.chip .status { padding: 2px 7px 2px 5px; }

/* faixas de desempenho (bom / médio / ruim) */
.chips-sep { align-self: center; font-size: 12px; color: var(--muted); margin: 0 4px 0 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.good { background: var(--good); } .dot.mid { background: var(--warning); } .dot.bad { background: var(--critical); }
.perf { font-weight: 600; }
.perf.good { color: var(--good-ink); } .perf.mid { color: var(--warning-ink); } .perf.bad { color: var(--critical-ink); }
.heatmap td.hm, .heat-legend i.hm { text-align: center; font-variant-numeric: tabular-nums; }
.heatmap th.c { text-align: center; }
.heatmap td.hm { min-width: 52px; padding: 10px 6px; border-left: 1px solid var(--surface); }
.hm.good { background: var(--good-bg); color: var(--good-ink); }
.hm.mid { background: var(--warning-bg); color: var(--warning-ink); }
.hm.bad { background: var(--critical-bg); color: var(--critical-ink); }
.hm.none { color: var(--muted); }
.heat-legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; padding: 14px 20px; font-size: 12px; color: var(--text-2); }
.heat-legend span { display: inline-flex; align-items: center; gap: 6px; }
.heat-legend i.hm { width: 14px; height: 14px; border-radius: 3px; display: inline-block; border: 1px solid var(--border); }

/* medidor de desempenho */
.meter { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.meter .track { flex: 1; height: 6px; border-radius: 99px; background: #cde2fb; overflow: hidden; }
:root[data-theme="dark"] .meter .track { background: #184f95; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .meter .track { background: #184f95; } }
.meter .fill { height: 100%; border-radius: 99px; background: var(--s1); }
.meter .fill.low { background: var(--warning); }
.meter .fill.bad { background: var(--critical); }
.meter span { font-size: 12px; font-variant-numeric: tabular-nums; width: 44px; text-align: right; }

/* gráficos */
.chart-box { position: relative; height: 300px; padding: 8px 16px 14px; }
.chart-box.sm { height: 210px; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; padding: 10px 20px 0; font-size: 12px; color: var(--text-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.chart-legend i.line { height: 2px; border-radius: 1px; width: 16px; }
.chart-legend i.dash { height: 0; width: 16px; border-top: 2px dashed var(--expected); border-radius: 0; }
.chart-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chart-nav input[type=date], .chart-nav input[type=month], .chart-nav input[type=number] { width: auto; height: 30px; }
.chart-stats { display: flex; gap: 24px; flex-wrap: wrap; padding: 12px 20px 0; }
.chart-stats div { font-size: 12px; color: var(--text-2); }
.chart-stats b { display: block; font-size: 17px; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

.plant-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.plant-head .meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--text-2); font-size: 13px; margin-top: 6px; align-items: center; }
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }

.inv-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-bottom: 16px; }
.inv { padding: 14px 16px; cursor: pointer; }
.inv.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.inv .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.inv dl { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 12px 0 0; font-size: 12px; }
.inv dt { color: var(--muted); } .inv dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }
.charts-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }

.integ { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.integ .row { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.integ .err { font-size: 12px; color: var(--critical-ink); background: var(--critical-bg); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; max-height: 110px; overflow: auto; }
.integ .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); }

/* login */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 28px; padding: 16px;
  background: radial-gradient(800px 500px at 50% -10%, rgba(58,95,143,.5), transparent 60%), linear-gradient(160deg, var(--navy), var(--navy-deep));
}
.login-logo { width: min(320px, 80vw); height: auto; display: block; }
.login { width: 100%; max-width: 380px; padding: 30px 28px; border-top: 3px solid var(--gold); }
.login h1 { font-size: 18px; }
.login form { display: grid; gap: 14px; margin-top: 20px; }
.error { color: var(--critical-ink); font-size: 13px; }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 640px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal header, .modal footer { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal header { border-bottom: 1px solid var(--border); }
.modal footer { border-top: 1px solid var(--border); justify-content: flex-end; }
.modal .body { padding: 18px 20px; overflow-y: auto; display: grid; gap: 14px; }
.plant-picks { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; display: grid; gap: 6px; }
#toast-root { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 8px; font-size: 13px; max-width: 360px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.err { background: var(--critical); color: #fff; }

.spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- celular */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .shell.menu-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--sidebar); color: #fff; font-weight: 600; position: sticky; top: 0; z-index: 30; border-bottom: 2px solid var(--gold); }
  .mobile-bar img { height: 26px; width: auto; }
  .mobile-bar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.25); }
  .main { padding: 16px 16px 40px; }
  .charts-2 { grid-template-columns: 1fr; }
  .chart-box { height: 250px; padding: 6px 8px 10px; }
  .tile .value { font-size: 20px; }
  th, td { padding: 9px 10px; }
}
