:root {
  --bg: #f5f6f8; --panel: #ffffff; --panel-2: #f9fafb; --border: #e4e7ec; --text: #101828; --muted: #667085;
  --primary: #1f6feb; --primary-ink: #ffffff; --primary-soft: #e8f0fe;
  --ok: #12805c; --ok-soft: #e3f4ec; --warn: #b54708; --warn-soft: #fef0c7;
  --crit: #c4320a; --crit-soft: #fde4d8; --exp: #b42318; --exp-soft: #fee4e2;
  --grey: #475467; --grey-soft: #eef0f3;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --panel: #161b22; --panel-2: #1c222b; --border: #2a313c; --text: #e6edf3; --muted: #8b949e;
    --primary: #4c8dff; --primary-ink: #0d1117; --primary-soft: #1a2a45;
    --ok: #3fb950; --ok-soft: #13291c; --warn: #e3a008; --warn-soft: #33270a;
    --crit: #f0883e; --crit-soft: #3a2010; --exp: #ff6b6b; --exp-soft: #3d1414;
    --grey: #9aa4b2; --grey-soft: #222a35;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 15px; margin: 0; font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 0 8px; }
.brand-lg { font-size: 22px; padding: 0; }
.brand-mark { width: 24px; height: 24px; border-radius: 7px; background: var(--primary) url("favicon.svg") center/cover; flex: none; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 500; }
#nav a:hover { background: var(--grey-soft); text-decoration: none; }
#nav a.active { background: var(--primary-soft); color: var(--primary); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 8px; }
.main { padding: 26px 32px 48px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ---------- Cards ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 18px 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: block; color: var(--text); }
a.tile:hover { text-decoration: none; border-color: var(--primary); }
.tile .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.tile .value { font-size: 28px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile.t-ok .value { color: var(--ok); } .tile.t-warn .value { color: var(--warn); }
.tile.t-crit .value { color: var(--crit); } .tile.t-exp .value { color: var(--exp); }
.tile.t-grey .value { color: var(--grey); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 10px 14px; background: var(--panel-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
tr.dim td { opacity: .55; }
.cell-title { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 12.5px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warning { background: var(--warn-soft); color: var(--warn); }
.b-critical { background: var(--crit-soft); color: var(--crit); }
.b-expired { background: var(--exp-soft); color: var(--exp); }
.b-renewed, .b-grey, .b-null { background: var(--grey-soft); color: var(--grey); }
.days { font-weight: 650; font-variant-numeric: tabular-nums; }
.days.ok { color: var(--ok); } .days.warning { color: var(--warn); } .days.critical { color: var(--crit); } .days.expired { color: var(--exp); } .days.renewed { color: var(--grey); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--grey); }
.dot.on { background: var(--ok); } .dot.off { background: var(--exp); }
.pill { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--grey-soft); color: var(--grey); font-size: 12px; margin-right: 3px; }

/* ---------- Chart (caducidades por mes) ---------- */
.months { display: grid; grid-template-columns: repeat(12, 1fr); gap: 8px; align-items: end; height: 150px; padding-top: 10px; }
.month { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.month .bar { width: 100%; max-width: 38px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.month .bar.zero { background: var(--border); }
.month .bar.soon { background: var(--warn); }
.month .bar.now { background: var(--exp); }
.month .n { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.month .m { font-size: 11.5px; color: var(--muted); text-transform: capitalize; }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; margin-bottom: 12px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
.btn { font: inherit; font-weight: 600; border: 1px solid var(--border); background: var(--panel); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.07); background: var(--primary); }
.btn-danger { color: var(--exp); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.form-error { color: var(--exp); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.search { width: 280px; max-width: 100%; flex: none; }
.row > input:not([type=checkbox]), .row > select { width: auto; flex: 1 1 160px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.table-wrap td:first-child { min-width: 180px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer; color: var(--text); }
.chip.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* ---------- Detail ---------- */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.alert { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 18px; border: 1px solid; }
.alert-warn { background: var(--warn-soft); border-color: var(--warn); color: var(--text); }
.alert-info { background: var(--primary-soft); border-color: var(--primary); color: var(--text); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.secret-box { background: var(--panel-2); border: 1px dashed var(--border); border-radius: 8px; padding: 10px 12px; word-break: break-all; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; user-select: all; }
.steps { padding-left: 18px; margin: 6px 0 0; }
.steps li { margin-bottom: 8px; }
.qr { background: #fff; padding: 8px; border-radius: 8px; display: inline-block; }
.qr svg { display: block; width: 180px; height: 180px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 30px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.login-card p { margin: 4px 0 22px; }

/* ---------- Modal / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--panel); border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; border: 1px solid var(--border); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
#modalBody { padding: 18px 20px 20px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 500; z-index: 60; max-width: 420px; }
.toast.error { background: var(--exp); color: #fff; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 8px; }
  #nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .main { padding: 18px 16px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .months { gap: 3px; }
}
