/* =====================================================================
   Millflow Solar – base visual (tokens, componentes e estrutura do painel)
   ===================================================================== */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e5e9ef;
  --text: #0e1726;
  --text-2: #4a5568;
  --muted: #8a94a6;
  --border: #e3e7ee;
  --brand: #f59e0b;
  --brand-2: #f97316;
  --brand-soft: rgba(245, 158, 11, .12);
  --brand-ink: #1f1300;
  --ok: #059669;
  --ok-soft: rgba(16, 185, 129, .12);
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, .10);
  --ring: 0 0 0 4px rgba(245, 158, 11, .22);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 14px 34px -16px rgba(16, 24, 40, .25);
  --raio: 14px;
  --raio-lg: 22px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #080c13; --surface: #0f1520; --surface-2: #151d2b; --surface-3: #1d2738;
    --text: #e8edf5; --text-2: #a4afc0; --muted: #6b778b; --border: #1f2a3b;
    --brand-soft: rgba(245, 158, 11, .14); --ok: #34d399; --ok-soft: rgba(52, 211, 153, .12);
    --danger: #f87171; --danger-soft: rgba(248, 113, 113, .12);
    --shadow: 0 18px 40px -18px rgba(0, 0, 0, .7); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #080c13; --surface: #0f1520; --surface-2: #151d2b; --surface-3: #1d2738;
  --text: #e8edf5; --text-2: #a4afc0; --muted: #6b778b; --border: #1f2a3b;
  --brand-soft: rgba(245, 158, 11, .14); --ok: #34d399; --ok-soft: rgba(52, 211, 153, .12);
  --danger: #f87171; --danger-soft: rgba(248, 113, 113, .12);
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, .7); color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s, color .3s;
}
a { color: inherit; }
.ico { width: 20px; height: 20px; flex: none; }
[hidden] { display: none !important; }

/* Tema: mostrar o ícone certo no botão */
:root[data-theme="dark"] .so-claro, :root[data-theme="light"] .so-escuro { display: none; }

/* ---------- Logo ---------- */
.logo { display: inline-flex; align-items: center; gap: .65rem; text-decoration: none; }
.logo-marca svg { width: 36px; height: 36px; display: block; filter: drop-shadow(0 6px 14px rgba(249, 115, 22, .35)); }
.logo-texto { font-weight: 700; font-size: 1.08rem; letter-spacing: -.01em; }
.logo-texto b { font-weight: 800; margin-left: .28rem; background: linear-gradient(90deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .55rem;
  height: 44px; padding: 0 1.15rem; border-radius: 12px; border: 1px solid transparent;
  font-family: inherit; font-size: .95rem; font-weight: 700; cursor: pointer; text-decoration: none;
  transition: transform .15s, box-shadow .2s, filter .2s, background-color .2s;
}
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-primario {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: var(--brand-ink);
  box-shadow: 0 10px 22px -10px rgba(249, 115, 22, .7);
}
.btn-primario:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 14px 26px -10px rgba(249, 115, 22, .8); }
.btn-primario:active { transform: translateY(0); }
.btn-bloco { width: 100%; height: 54px; font-size: 1rem; border-radius: 14px; }
.btn-fantasma { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-fantasma:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled:not(.carregando) { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn[disabled] { cursor: progress; }

.btn-icone {
  display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); cursor: pointer; transition: background-color .2s, color .2s, border-color .2s;
}
.btn-icone:hover { color: var(--text); background: var(--surface-2); }
.btn-icone:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---------- Sino de alarmes (topo) ---------- */
.sino { position: relative; text-decoration: none; }
.sino.com-alarme { color: var(--danger); border-color: var(--danger); }
.sino-n { position: absolute; top: -6px; right: -6px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 99px;
  background: var(--danger); color: #fff; font-size: .68rem; font-weight: 800; line-height: 19px; text-align: center;
  box-shadow: 0 0 0 2px var(--surface); }

/* ---------- Alarmes (tela e painel) ---------- */
.alarmes { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 10px; }
.alarme { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border-radius: 14px; background: var(--surface-2); }
.alarme-ico { width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.alarme-ico .ico { width: 17px; height: 17px; }
.alarme-corpo { flex: 1; min-width: 0; }
.alarme-corpo strong { display: block; font-size: .92rem; }
.alarme-corpo p { margin: 2px 0 4px; color: var(--text-2); font-size: .85rem; line-height: 1.5; }
.alarme-corpo small { color: var(--muted); font-size: .76rem; }
.alarme.aberto { background: var(--danger-soft); }
.alarme.aberto .alarme-ico { background: var(--danger); color: #fff; }
.alarme.aberto.sev-media .alarme-ico { background: var(--brand); color: var(--brand-ink); }
.alarme.fechado .alarme-ico { background: var(--ok-soft); color: var(--ok); }
.alarme form { flex: none; }
.alarme-corpo p.alarme-nota { color: var(--ok); font-weight: 700; }
.alarme .btn { height: 36px; font-size: .84rem; }
.telegram ol { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 6px; color: var(--text-2); font-size: .88rem; line-height: 1.55; }
.telegram code { font-size: .82rem; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); }
.telegram-estado { display: flex; align-items: flex-start; gap: .5rem; margin: 10px 0 0; color: var(--text-2); font-size: .88rem; line-height: 1.55; }
.telegram-estado .ico { width: 18px; height: 18px; flex: none; margin-top: 2px; color: var(--ok); }
.telegram-acoes { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.kpi-link { color: inherit; text-decoration: none; transition: border-color .2s, transform .2s; }
.kpi-link:hover { border-color: var(--brand); }
.kpi-link:focus-visible { outline: none; box-shadow: var(--ring); }
.alarmes-vazio { margin: 10px 0 0; color: var(--muted); font-size: .84rem; }
.alarmes-regras h2 { display: flex; align-items: center; gap: .5rem; }
.alarmes-regras h2 .ico { width: 18px; height: 18px; color: var(--brand-2); }
.alarmes-regras ul { margin: 10px 0 0; padding-left: 18px; display: grid; gap: 8px; color: var(--text-2); font-size: .88rem; line-height: 1.55; }
@media (max-width: 600px) { .alarme { flex-wrap: wrap; } .alarme form { width: 100%; } .alarme .btn { width: 100%; } }

.spinner {
  display: none; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(31, 19, 0, .25); border-top-color: var(--brand-ink);
  animation: girar .7s linear infinite;
}
.carregando .spinner { display: block; }
.carregando .btn-texto, .carregando > .ico { display: none; }

/* ---------- Campos com rótulo flutuante ---------- */
.campo { position: relative; display: block; margin-bottom: 14px; }
.campo input {
  width: 100%; height: 60px; padding: 22px 48px 6px 48px;
  border-radius: 14px; border: 1.5px solid var(--border); background: var(--surface-2);
  color: var(--text); font-family: inherit; font-size: 1rem; outline: none;
  transition: border-color .2s, background-color .2s, box-shadow .2s;
}
.campo input:hover { border-color: var(--surface-3); }
.campo input:focus { border-color: var(--brand); background: var(--surface); box-shadow: var(--ring); }
.campo input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 60px var(--surface-2) inset;
  -webkit-text-fill-color: var(--text);
}
.campo-ico { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); display: flex; color: var(--muted); pointer-events: none; transition: color .2s; }
.campo:focus-within .campo-ico { color: var(--brand-2); }
.campo-rotulo {
  position: absolute; left: 48px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 1rem; pointer-events: none; transition: all .18s ease;
}
.campo input:focus ~ .campo-rotulo,
.campo input:not(:placeholder-shown) ~ .campo-rotulo,
.campo input:-webkit-autofill ~ .campo-rotulo {
  top: 17px; font-size: .72rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--text-2);
}
.campo input:focus ~ .campo-rotulo { color: var(--brand-2); }
.campo-acao {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.campo-acao:hover { color: var(--text); background: var(--surface-3); }
.campo-acao:focus-visible { outline: none; box-shadow: var(--ring); }
.campo-acao .ico-ocultar, .campo-acao.mostrando .ico-ver { display: none; }
.campo-acao.mostrando .ico-ocultar { display: block; }

/* ---------- Chave (toggle) ---------- */
.chave { position: relative; display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; font-size: .9rem; color: var(--text-2); user-select: none; }
.chave input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.trilho { position: relative; width: 40px; height: 24px; border-radius: 99px; background: var(--surface-3); transition: background-color .2s; }
.trilho::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s;
}
.chave input:checked + .trilho { background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.chave input:checked + .trilho::after { transform: translateX(16px); }
.chave input:focus-visible + .trilho { box-shadow: var(--ring); }

/* ---------- Alertas ---------- */
.alerta { display: flex; align-items: flex-start; gap: .6rem; padding: .85rem 1rem; border-radius: 12px; font-size: .9rem; font-weight: 500; margin-bottom: 18px; line-height: 1.4; }
.alerta .ico { width: 18px; height: 18px; margin-top: 1px; }
.alerta.erro { background: var(--danger-soft); color: var(--danger); animation: tremer .4s; }
.alerta.ok { background: var(--ok-soft); color: var(--ok); }
.alerta.info { background: var(--brand-soft); color: var(--brand-2); }

.link { color: var(--brand-2); font-weight: 600; text-decoration: none; font-size: .9rem; }
.link:hover { text-decoration: underline; }

/* =====================================================================
   Estrutura do painel (menu lateral + topo + barra inferior no celular)
   ===================================================================== */
.shell { display: grid; grid-template-columns: 268px 1fr; min-height: 100vh; }

.lateral {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px;
}
.lateral-topo { padding: 4px 8px 10px; }
.nav { overflow-y: auto; flex: 1; margin: 0 -4px; padding: 0 4px; }
.nav-grupo { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin: 20px 12px 6px; font-weight: 700; }
.nav-item {
  display: flex; align-items: center; gap: .75rem; padding: .62rem .8rem; margin: 2px 0;
  border-radius: 11px; color: var(--text-2); text-decoration: none; font-weight: 500; font-size: .93rem;
  transition: background-color .15s, color .15s;
}
.nav-item .ico { width: 19px; height: 19px; }
a.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.ativo { background: var(--brand-soft); color: var(--text); font-weight: 700; }
.nav-item.ativo .ico { color: var(--brand-2); }
.nav-item.breve { opacity: .5; cursor: default; }
.selo-breve { margin-left: auto; font-size: .62rem; padding: 2px 7px; border-radius: 99px; background: var(--surface-3); color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }

.lateral-rodape { margin-top: 12px; border-top: 1px solid var(--border); padding: 14px 4px 0; display: flex; align-items: center; gap: .7rem; }
.avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; color: var(--brand-ink); background: linear-gradient(135deg, var(--brand), var(--brand-2)); flex: none; }
.quem { min-width: 0; flex: 1; line-height: 1.25; }
.quem strong { display: block; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quem small { color: var(--muted); font-size: .78rem; }

.principal { min-width: 0; display: flex; flex-direction: column; }
.topo {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 14px; padding: 16px 32px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topo h1 { font-size: 1.25rem; margin: 0; font-weight: 800; letter-spacing: -.02em; }
.topo-sub { margin: 2px 0 0; color: var(--text-2); font-size: .88rem; }
.topo .acoes { margin-left: auto; display: flex; gap: 8px; }
.conteudo { padding: 28px 32px 48px; width: 100%; max-width: 1320px; display: grid; gap: 20px; align-content: start; }

.btn-menu, .barra-inferior, .veu { display: none; }

/* ---------- Cartões ---------- */
.cartao-painel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--raio-lg); padding: 22px; box-shadow: var(--shadow-sm); }
.grade-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi .rotulo { display: flex; align-items: center; gap: .5rem; color: var(--text-2); font-size: .85rem; font-weight: 600; }
.kpi .rotulo .ico { width: 18px; height: 18px; color: var(--brand-2); }
.kpi .valor { font-size: 2.2rem; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kpi .valor.perigo { color: var(--danger); }
.kpi .nota { color: var(--muted); font-size: .82rem; }

.vazio { text-align: center; padding: 52px 24px; }
.vazio .ilustra { width: 76px; height: 76px; border-radius: 24px; background: var(--brand-soft); color: var(--brand-2); display: grid; place-items: center; margin: 0 auto 18px; }
.vazio .ilustra .ico { width: 36px; height: 36px; animation: girar 30s linear infinite; }
.vazio h2 { margin: 0 0 8px; font-size: 1.2rem; }
.vazio p { margin: 0 auto; max-width: 460px; color: var(--text-2); line-height: 1.55; }

/* ---------- Celular ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .lateral { position: fixed; left: 0; top: 0; z-index: 30; width: 284px; transform: translateX(-105%); transition: transform .25s ease; box-shadow: var(--shadow); }
  .shell.menu-aberto .lateral { transform: none; }
  .shell.menu-aberto .veu { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(2, 6, 23, .45); }
  .btn-menu { display: inline-grid; }
  .topo { padding: 12px 16px; }
  .conteudo { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); gap: 14px; }
  .barra-inferior {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; justify-content: space-around;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .barra-inferior > a, .barra-inferior > span, .barra-inferior > button {
    display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 10px; border-radius: 12px;
    font: inherit; font-size: .68rem; font-weight: 600; color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer;
  }
  .barra-inferior .ativo { color: var(--brand-2); }
  .barra-inferior .breve { opacity: .45; }
  .kpi .valor { font-size: 1.9rem; }
}

/* ---------- Animações ---------- */
@keyframes girar { to { transform: rotate(360deg); } }
@keyframes tremer { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes subir { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
