/* Paleta alinhada ao SGC Mobit (sgc.mobit.com.br): azul-marinho + amarelo Mobit + azul, fonte Montserrat */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #021426;
  --text-2: #374151;
  --muted: #6b7280;
  --border: #e5e7eb;
  --grid: #eef0f3;
  --axis: #d1d5db;
  --primary: #021426;          /* botões principais (marinho) */
  --primary-hover: #03203c;
  --primary-ink: #ffffff;
  --accent: #2756b8;           /* azul Mobit: links, foco, "Planejar" */
  --accent-dark: #1b3f93;
  --brand-yellow: #fdb913;     /* amarelo Mobit */
  --series-1: #2756b8;         /* azul */
  --series-2: #c98500;         /* âmbar (validado com o azul p/ daltonismo) */
  --good: #18794e;
  --warning: #fdb913;
  --critical: #b42318;
  --good-text: #18794e;
  --warn-text: #8a5a00;
  --critical-text: #b42318;
  --critical-bg: #fdecea;
  --warning-bg: #fff4d6;
  --good-bg: #e5f5ec;
  --info-bg: #e8eefb;
  --nav-bg: linear-gradient(180deg, #021426 0%, #03203c 100%);
  --nav-text: #cbd5e1;
  --nav-muted: #9ca3af;
  --nav-active: #fdb913;
  --nav-active-bg: rgba(253, 185, 19, .12);
  --shadow: 0 1px 2px rgba(2, 20, 38, .05), 0 4px 16px rgba(2, 20, 38, .05);
  --radius: 10px;
  font-family: Montserrat, "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #010d1a; --surface: #0b1e33; --surface-2: #10263f; --text: #eef2f7; --text-2: #c3cbd6; --muted: #8b95a3;
    --border: rgba(255, 255, 255, 0.10); --grid: #1a3150; --axis: #2b4566;
    --primary: #2756b8; --primary-hover: #3163cc; --accent: #6f9bef; --accent-dark: #9dbbf5;
    --series-1: #5b8ae6; --series-2: #c98500; --good: #2fa36b; --critical: #e5534b;
    --good-text: #4cc38a; --warn-text: #fdb913; --critical-text: #f59a93; --critical-bg: #3a1714; --warning-bg: #3a2c0a; --good-bg: #0f2e20; --info-bg: #13284a;
    --nav-bg: linear-gradient(180deg, #000a14 0%, #021426 100%); --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #010d1a; --surface: #0b1e33; --surface-2: #10263f; --text: #eef2f7; --text-2: #c3cbd6; --muted: #8b95a3;
  --border: rgba(255, 255, 255, 0.10); --grid: #1a3150; --axis: #2b4566;
  --primary: #2756b8; --primary-hover: #3163cc; --accent: #6f9bef; --accent-dark: #9dbbf5;
  --series-1: #5b8ae6; --series-2: #c98500; --good: #2fa36b; --critical: #e5534b;
  --good-text: #4cc38a; --warn-text: #fdb913; --critical-text: #f59a93; --critical-bg: #3a1714; --warning-bg: #3a2c0a; --good-bg: #0f2e20; --info-bg: #13284a;
  --nav-bg: linear-gradient(180deg, #000a14 0%, #021426 100%); --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 700; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 700; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--critical-text); font-weight: 600; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--nav-bg); color: var(--nav-text); padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { color: #fff; padding: 4px 10px 18px; }
.brand-title { font-weight: 700; font-size: 17px; line-height: 1.2; }
.brand-title span { color: var(--brand-yellow); }
.brand-sub { font-size: 11px; color: var(--nav-text); margin-top: 3px; line-height: 1.3; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--nav-muted); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; justify-content: space-between; color: var(--nav-text); padding: 7px 10px; border-radius: 7px; font-size: 13.5px; border-left: 3px solid transparent; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--nav-active-bg); color: var(--nav-active); border-left-color: var(--brand-yellow); font-weight: 600; }
.nav .pill { background: #e5534b; color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 600; min-width: 20px; text-align: center; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar .ctx { color: var(--text-2); font-size: 13px; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.role-tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.content { padding: 22px 24px 48px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 0; color: var(--text-2); }
.menu-btn { display: none; }

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 14px; }
.cols-2 { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi .label { color: var(--text-2); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 700; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.kpi.critical { border-left: 4px solid var(--critical); }
.kpi.warning { border-left: 4px solid var(--warning); }
.kpi.good { border-left: 4px solid var(--good); }
.kpi.info { border-left: 4px solid var(--accent); }
a.kpi:hover { text-decoration: none; border-color: var(--axis); }
a.kpi { color: inherit; }

.alert { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid var(--border); }
.alert.critical { background: var(--critical-bg); border-color: color-mix(in srgb, var(--critical) 35%, transparent); }
.alert.warning { background: var(--warning-bg); }
.alert.info { background: var(--info-bg); }
.alert.good { background: var(--good-bg); }
.alert strong { display: block; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px 2px 6px; border-radius: 999px; white-space: nowrap; background: var(--surface-2); color: var(--text-2); }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.CRITICO, .badge.EM_RISCO { background: var(--critical-bg); color: var(--critical-text); }
.badge.CRITICO .dot, .badge.EM_RISCO .dot { background: var(--critical); }
.badge.ATENCAO { background: var(--warning-bg); color: var(--warn-text); }
.badge.ATENCAO .dot { background: var(--warning); }
.badge.PLANEJAR { background: var(--info-bg); color: var(--accent-dark); }
.badge.PLANEJAR .dot { background: var(--accent); }
.badge.OK { background: var(--good-bg); color: var(--good-text); }
.badge.OK .dot { background: var(--good); }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 13px; border-radius: 8px; font: inherit; font-size: 13.5px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--axis); background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--critical-text); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
input, select, textarea { font: inherit; font-size: 13.5px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
input.search { min-width: 240px; }
input.cell { width: 76px; padding: 4px 6px; text-align: right; font-variant-numeric: tabular-nums; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }

/* ---------- tabelas ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); max-height: 70vh; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-size: 12px; color: var(--text-2); z-index: 1; white-space: nowrap; cursor: default; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
tr.total td { font-weight: 650; background: var(--surface-2); }
tr.clickable { cursor: pointer; }
td.desc { min-width: 220px; max-width: 420px; }
.cell-risk { background: var(--critical-bg); color: var(--critical-text); font-weight: 600; }
.cell-warn { background: var(--warning-bg); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-word; color: var(--accent-dark); }
tr.muted td { color: var(--muted); }

.chart-box { position: relative; height: 280px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs a { padding: 8px 12px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; border: 1px solid var(--border); width: min(980px, 100%); padding: 20px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.modal.narrow { width: min(520px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.x { background: none; border: 0; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; }
.toast { position: fixed; right: 18px; bottom: 18px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 60; box-shadow: 0 6px 24px rgba(0, 0, 0, .2); max-width: 420px; }
.toast.error { background: var(--critical); color: #fff; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 16px; margin-bottom: 14px; }
.kv div span { display: block; font-size: 12px; color: var(--muted); }
.kv div b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--nav-bg); }
.login { width: min(380px, 100%); padding: 0; overflow: hidden; }
.login-head { background: #021426; color: #fff; padding: 22px 20px 18px; border-bottom: 3px solid var(--brand-yellow); }
.login-head .brand-title { font-size: 22px; }
.login-head .brand-sub { color: #cbd5e1; }
.login form { padding: 0 20px 20px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.err { color: var(--critical-text); font-size: 13px; min-height: 18px; }
.spinner { padding: 40px; text-align: center; color: var(--muted); }

.report-list { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.report-list a.card { color: inherit; display: block; }
.report-list a.card:hover { text-decoration: none; border-color: var(--axis); }

@media (max-width: 1000px) { .cols-2 { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .topbar .ctx { display: none; }
  input.search { min-width: 0; width: 100%; }
}
@media print {
  .sidebar, .topbar, .toolbar, .no-print { display: none !important; }
  .app { display: block; }
  .table-wrap { max-height: none; overflow: visible; border: 0; }
  th { position: static; }
  body { background: #fff; color: #000; font-size: 11px; }
  .content { padding: 0; max-width: none; }
}

/* ---------- painel de alertas ---------- */
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.card-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.seg button { border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 12px; padding: 5px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 4px 3px 10px; border-radius: 999px; background: var(--info-bg); color: var(--accent-dark); font-weight: 600; }
.chip button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 14px; line-height: 1; padding: 0 4px; }
.faixas { display: grid; gap: 10px; padding-top: 6px; }
.faixa { display: grid; grid-template-columns: 110px minmax(0, 1fr) 110px; align-items: center; gap: 10px; font-size: 13px; }
.faixa .fl { color: var(--text-2); }
.fbar { height: 14px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.fbar i { display: block; height: 100%; min-width: 2px; border-radius: 4px; background: var(--accent); }
.fbar i.CRITICO { background: var(--critical); }
.fbar i.ATENCAO { background: var(--warning); }
.prazo.ATENCAO { color: var(--warn-text); font-weight: 600; }
@media (max-width: 600px) { .faixa { grid-template-columns: 90px minmax(0, 1fr) 80px; } }

/* perfis de acesso */
.perm-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); align-items: start; }
.perm-grid .check.perm { padding: 5px 0; border-top: 1px solid var(--border); }
.perm-grid .check.perm:first-of-type { border-top: 0; }
.perm-grid .check.perm.acao { padding-left: 22px; }
.perm-grid .check.small { font-size: 12px; color: var(--text-2); }
