:root {
  --bg: #f4f6f7; --panel: #ffffff; --ink: #1d2a30; --muted: #6b7a82; --line: #e2e7ea;
  --brand: #0b3057; --brand-2: #0d818f; --accent: #2fa37f; --navy: #00183f;
  --grad: linear-gradient(90deg, #12406e 0%, #0d818f 55%, #38af88 100%); --ok: #2e7d4f; --warn: #b7791f; --bad: #b83232;
  --radius: 10px; --shadow: 0 1px 3px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11181c; --panel: #1a2328; --ink: #e6ecef; --muted: #93a3ab; --line: #2a363c;
          --brand: #5b9bd5; --brand-2: #3fb8b0; --accent: #4fc79c; --ok: #5cc28a; --warn: #e0a84a; --bad: #e46a6a; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 Inter, system-ui, sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
body.busy { cursor: progress; }
body.busy main { opacity: .7; pointer-events: none; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #0b3057, #0d818f 60%, #38af88); }
.login-card { background: var(--panel); padding: 40px 32px; border-radius: 16px; max-width: 380px; width: 100%; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.login-card h1 { margin: 12px 0 4px; color: var(--brand); letter-spacing: .04em; }
.logo { width: 120px; height: 120px; border-radius: 26px; }
.logo.sm { width: 40px; height: 40px; border-radius: 9px; }
.sidebar::before { content: ''; display: block; height: 3px; background: var(--grad); margin: -16px -16px 16px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.login-card #gsi-btn { display: flex; justify-content: center; }
.login-card small { display: block; margin-top: 24px; color: var(--muted); font-size: 12px; }
.brand-mark { width: 56px; height: 56px; border-radius: 14px; background: var(--brand); color: #fff; display: inline-grid; place-items: center; font-weight: 700; font-size: 20px; }
.brand-mark.sm { width: 36px; height: 36px; font-size: 14px; border-radius: 9px; }
.error { color: var(--bad) !important; min-height: 1.5em; margin-top: 12px !important; }

/* Layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 24px; }
.brand small { display: block; color: var(--muted); font-size: 11px; line-height: 1.3; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav button { text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: 8px; font: inherit; color: var(--ink); cursor: pointer; display: flex; justify-content: space-between; }
nav button:hover { background: var(--bg); }
nav button.active { background: var(--grad); color: #fff; }
.badge:not(:empty) { background: var(--bad); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; }
.user { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; }
.user small { color: var(--muted); text-transform: capitalize; }
main { padding: 24px 32px; min-width: 0; }
main header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
main h2 { margin: 0; font-size: 22px; color: var(--brand); }
h3 { margin: 0 0 12px; font-size: 15px; }
.nota { color: var(--muted); font-size: 13px; margin: -8px 0 16px; }

/* Components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); overflow-x: auto; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi span { color: var(--muted); font-size: 12px; display: block; }
.kpi { border-top: 3px solid var(--brand-2); }
.kpi strong { font-size: 26px; font-weight: 700; color: var(--brand); }
.btn { background: var(--brand); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.link { background: none; border: 0; color: var(--brand-2); cursor: pointer; font: inherit; padding: 0; text-align: left; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
td small { color: var(--muted); }
tr.group td { background: var(--bg); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--brand); }
.st { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.st.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.st.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.st.muted { background: var(--bg); color: var(--muted); }
.bad-t { color: var(--bad); font-weight: 600; }
.empty { color: var(--muted); font-style: italic; }
.bar-row { display: grid; grid-template-columns: 1fr 120px 44px; gap: 10px; align-items: center; padding: 6px 0; cursor: pointer; }
.bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; }
.bar i.ok { background: var(--ok); } .bar i.warn { background: var(--warn); } .bar i.bad { background: var(--bad); }
.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0 8px 10px; border-left: 3px solid var(--muted); margin-bottom: 6px; }
.alerts li.p-alta { border-color: var(--bad); } .alerts li.p-media { border-color: var(--warn); }
.alerts small { color: var(--muted); white-space: nowrap; }

/* Forms */
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); width: 100%; }
select#matriz-entidad { width: auto; min-width: 260px; }
.out { white-space: pre-wrap; font: inherit; margin: 0; min-height: 120px; }
.out-head { display: flex; justify-content: space-between; }
dialog { border: 0; border-radius: 14px; padding: 24px; max-width: 640px; width: calc(100% - 32px); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.fields .full { grid-column: 1 / -1; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: .3s; pointer-events: none; max-width: 360px; }
.toast.show { opacity: 1; } .toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  nav { flex-direction: row; overflow-x: auto; }
  nav button { white-space: nowrap; }
  main { padding: 16px; }
  .grid2, .fields { grid-template-columns: 1fr; }
}
