/* Admin AbisoftGT · una sola hoja de estilos, claro y oscuro según el sistema */

:root {
  --bg: #f5f5f2;
  --surface: #fdfdfc;
  --surface-2: #f1f0ec;
  --field: #ffffff;
  --row-hover: #f8f8f5;
  --line: #e4e3dc;
  --line-strong: #d0cfc7;
  --ink: #141413;
  --ink-2: #4d4c48;
  --muted: #6c6b66;
  --link: #1f5fb8;

  --accent: #1f62bf;
  --accent-hover: #1a54a5;
  --accent-soft: #e6eefb;
  --accent-text: #1a4f9a;
  --accent-ring: rgba(42, 120, 214, 0.25);
  --on-accent: #ffffff;

  --danger: #c43333;
  --danger-hover: #a92a2a;
  --danger-text: #b42f2f;

  --ok-bg: #ecf7ec;   --ok-line: #b9e0b9;
  --warn-bg: #fdf4e1; --warn-line: #f1d494;
  --err-bg: #fcecec;  --err-line: #f0bcbc;

  /* Estados (punto de color + texto, nunca solo color) */
  --st-trial: #2a78d6;
  --st-active: #0ca30c;
  --st-grace: #e39a00;
  --st-blocked: #d03b3b;
  --st-cancelled: #898781;

  /* Gráfica */
  --series-1: #2a78d6;
  --series-1-strong: #1c5cab;
  --grid: #e8e7e1;
  --hover-band: rgba(42, 120, 214, 0.08);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --field: #141413;
    --row-hover: #20201e;
    --line: #2c2c2a;
    --line-strong: #3d3d3a;
    --ink: #f3f3f0;
    --ink-2: #c3c2b7;
    --muted: #9b9a91;
    --link: #79aef0;

    --accent: #2f74cc;
    --accent-hover: #3a82dc;
    --accent-soft: #1d2b40;
    --accent-text: #9cc4f5;
    --accent-ring: rgba(57, 135, 229, 0.35);

    --danger: #c94040;
    --danger-hover: #d65151;
    --danger-text: #f08a8a;

    --ok-bg: #16261a;   --ok-line: #26502f;
    --warn-bg: #2b2414; --warn-line: #5c4a1f;
    --err-bg: #2d1819;  --err-line: #5e2c2d;

    --st-trial: #3987e5;
    --st-active: #2fb52f;
    --st-grace: #fab219;
    --st-blocked: #e66767;
    --st-cancelled: #8f8d86;

    --series-1: #3987e5;
    --series-1-strong: #6da7ec;
    --grid: #2a2a28;
    --hover-band: rgba(57, 135, 229, 0.12);

    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0 0 8px; }
code {
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
  word-break: break-all;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.block { display: block; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger-text); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ───── estructura ───── */

.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 18px 12px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 650; font-size: 15px; padding: 0 6px; }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.brand-mark {
  flex: none; width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 15px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { padding: 7px 10px; border-radius: 7px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.is-active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.side-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 6px 0; border-top: 1px solid var(--line); }
.side-user { min-width: 0; font-size: 13px; font-weight: 600; }
.side-user small { display: block; font-weight: 400; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-foot form { margin: 0; }
.main { min-width: 0; width: 100%; max-width: 1340px; padding: 24px 28px 56px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 3px 0 0; }
.head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.head-actions form { margin: 0; }
.crumbs { display: flex; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--ink-2); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 24px 0 10px; }
.section-head h2 { font-size: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.card-flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; min-height: 28px; }
.card-head form { margin: 0; }
.card-flush > .card-head { padding: 14px 18px 0; }
.card > .table-wrap { margin: 0 -18px -16px; }
.card-flush > .table-wrap { margin: 0; }
.count { font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--surface-2); border-radius: 999px; padding: 1px 9px; }
.empty { color: var(--muted); margin: 0; padding: 4px 0 2px; }
.card-flush > .empty { padding: 16px 18px; }
.narrow { max-width: 560px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 16px; margin-bottom: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.empty-page { max-width: 520px; margin: 64px auto; text-align: center; }
.empty-page h1 { margin-bottom: 8px; }

/* ───── indicadores ───── */

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(164px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
  color: inherit;
}
a.kpi:hover { border-color: var(--line-strong); background: var(--row-hover); text-decoration: none; }
.kpi-label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.kpi-value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.kpi-hint { font-size: 12px; color: var(--muted); }
.totals { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.total-main, .total-item { display: flex; flex-direction: column; gap: 1px; min-width: 140px; padding: 12px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.total-value { font-size: 17px; font-weight: 600; }

/* ───── tablas ───── */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th:first-child, .table td:first-child { padding-left: 18px; }
.table th:last-child, .table td:last-child { padding-right: 18px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--row-hover); }
.table td form { margin: 0; }
.table code { white-space: nowrap; word-break: normal; }
.col-wide { min-width: 240px; }
.table-compact th, .table-compact td { padding-top: 5px; padding-bottom: 5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.num { text-align: right; }
.details { color: var(--ink-2); font-size: 12.5px; min-width: 200px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-width: 160px; max-width: 320px; }
.person { display: inline-flex; flex-direction: column; min-width: 170px; color: var(--ink); line-height: 1.3; margin-right: 6px; }
.person span { font-weight: 550; }
.person small { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.wrap-any { overflow-wrap: anywhere; min-width: 150px; }
.person:hover { text-decoration: none; }
.person:hover span { text-decoration: underline; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 18px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.pager-links { display: flex; gap: 6px; }

/* ───── estados ───── */

.pills { display: flex; flex-wrap: wrap; gap: 5px 6px; }
.pills a:hover { text-decoration: none; }
.pill {
  --st: var(--st-cancelled);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 18px; white-space: nowrap;
  color: var(--ink);
  background: color-mix(in srgb, var(--st) 11%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--st) 30%, var(--surface));
}
.pill::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--st); }
.pill b { font-weight: 600; }
.st-trial { --st: var(--st-trial); }
.st-active { --st: var(--st-active); }
.st-grace { --st: var(--st-grace); }
.st-blocked { --st: var(--st-blocked); }
.st-cancelled { --st: var(--st-cancelled); }

/* ───── botones y formularios ───── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid transparent; background: var(--accent); color: var(--on-accent);
  font: inherit; font-size: 13.5px; font-weight: 600; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-danger-text { color: var(--danger-text); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn.is-disabled { opacity: 0.45; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row form { margin: 0; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; margin: 0; }
.field > span { font-size: 12.5px; font-weight: 550; color: var(--ink-2); }
input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="number"], input[type="date"], select, textarea {
  width: 100%; min-width: 0; height: 34px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--field); color: var(--ink);
  font: inherit; font-size: 13.5px;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
input[readonly] { background: var(--surface-2); }
.readonly { height: 34px; display: flex; align-items: center; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
.form-row { display: flex; gap: 10px; align-items: flex-end; }
.form-row .field { width: 120px; }
.inline-form { display: flex; gap: 8px; align-items: center; margin: 0; }
.inline-form select { width: auto; height: 28px; font-size: 12.5px; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters .field { flex: 0 1 170px; }
.filters .field.grow { flex: 1 1 240px; }
.filter-actions { display: flex; gap: 8px; }

.flash { padding: 10px 14px; margin-bottom: 14px; border-radius: 9px; border: 1px solid; font-size: 13.5px; }
.flash-ok { background: var(--ok-bg); border-color: var(--ok-line); }
.flash-warn { background: var(--warn-bg); border-color: var(--warn-line); }
.flash-error { background: var(--err-bg); border-color: var(--err-line); }
.note { margin: 0; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }
.note-warn { background: var(--warn-bg); }
.note-danger { background: var(--err-bg); }

/* ───── datos en lista ───── */

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px 18px; margin: 0; }
.facts dt { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.facts dd { margin: 0; font-weight: 500; }
.facts-wide { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.facts-list { grid-template-columns: 1fr; gap: 0; }
.facts-list > div { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 4px 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.facts-list > div:last-child { border-bottom: 0; }
.facts-list dt { font-size: 13px; margin: 0; }
.facts-list dd { font-weight: 400; }

/* ───── ficha de persona ───── */

.app-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 16px; margin-bottom: 16px; }
.app-card { margin: 0; display: flex; flex-direction: column; gap: 14px; scroll-margin-top: 16px; }
.app-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.app-actions { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
details.action { border: 1px solid var(--line); border-radius: 9px; }
details.action > summary {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; cursor: pointer; list-style: none;
  font-size: 13.5px; font-weight: 600;
}
details.action > summary::-webkit-details-marker { display: none; }
details.action > summary::after { content: "+"; color: var(--muted); font-weight: 500; font-size: 16px; line-height: 1; }
details.action[open] > summary::after { content: "−"; }
details.action[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 12px; }
details.action > form, details.action > .hint { padding: 0 12px 12px; }

/* ───── gráfica ───── */

.chart { overflow-x: auto; }
.bar-chart { display: block; width: 100%; min-width: 560px; height: auto; }
.bar-chart .bar { fill: var(--series-1); }
.bar-chart .hit { fill: transparent; }
.bar-chart .col:hover .hit { fill: var(--hover-band); }
.bar-chart .col:hover .bar { fill: var(--series-1-strong); }
.bar-chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.bar-chart .axis { stroke: var(--line-strong); stroke-width: 1; shape-rendering: crispEdges; }
.bar-chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-table { margin-top: 8px; }
.chart-table summary { cursor: pointer; font-size: 12.5px; color: var(--muted); }
.chart-table .table-wrap { margin-top: 8px; max-height: 280px; overflow-y: auto; }

/* ───── entrar ───── */

body.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; padding: 28px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.auth-card h1 { font-size: 20px; margin: 20px 0 16px; }
.brand-lg { padding: 0; }
.auth-card .muted { margin: 16px 0 0; }

pre.err { white-space: pre-wrap; font-size: 12px; }

/* ───── teléfono y tableta ───── */

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: sticky; z-index: 10; height: auto;
    flex-direction: row; align-items: center; gap: 12px;
    padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }
  .brand { padding: 0; }
  .brand small, .side-user { display: none; }
  .nav { flex-direction: row; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .side-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .main { padding: 16px 16px 40px; }
}
@media (max-width: 700px) {
  .form-grid, .form-grid-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2, .span-3 { grid-column: auto; }
  .facts-list > div { grid-template-columns: minmax(0, 1fr); }
  .filters .field, .filters .field.grow { flex: 1 1 100%; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 22px; }
}
