/* ============================================================
   JARVIS PANEL · capa HUD (dirección "Audaz / HUD")
   Componentes de las vistas Lista de tenants + Detalle de tenant.
   Se carga DESPUÉS de jarvis-hud-tokens.css (que define :root + base
   + .btn / .btn-primary / .btn-danger / .pill / .chip / .control /
   .sec / tabla / .bar). Acá van solo los componentes de layout que
   los prototipos del handoff tenían inline.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
h1, h2, h3, p, dl, dd, figure { margin: 0; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 22px 90px; }
.wrap--narrow { max-width: 1140px; }

/* ---------- HEADER ---------- */
.hd {
  position: sticky; top: 0; z-index: 30;
  background: rgba(7,7,8,.85); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-y);
}
.hd-in {
  max-width: 1200px; margin: 0 auto; padding: 13px 22px;
  display: flex; align-items: center; gap: 16px;
}
.logo { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.mask {
  width: 32px; height: 32px; border-radius: 7px; background: #fff;
  display: grid; place-items: center; flex: none;
  outline: 1.5px solid var(--brand); outline-offset: 2px;
}
.mask img { width: 25px; height: 25px; display: block; }
.bn { font-family: var(--mono); font-weight: 700; font-size: 14px; letter-spacing: .02em; color: var(--text); }
.bn .sep { color: var(--faint); }
.bn .y { color: var(--brand); }
.nav { display: flex; gap: 6px; margin-left: 6px; }
.nav-link {
  font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: .04em;
  color: var(--muted); padding: 7px 11px; cursor: pointer; transition: .15s; text-decoration: none;
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--brand); }
.nav-link.active::before { content: "[ "; color: var(--brand); }
.nav-link.active::after  { content: " ]"; color: var(--brand); }
.spacer { flex: 1; }
.user { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.user::before { content: "@"; color: var(--brand); }
.btn-sm { padding: 7px 11px; }
.hd form { margin: 0; }

/* tokens da .btn sin font-weight; lo afinamos al del prototipo */
.btn { font-weight: 500; line-height: 1; }

/* ---------- KPI STRIP ---------- */
.kpis {
  margin-top: 26px; display: grid; grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line); background: var(--surface);
}
.kpi { padding: 18px 20px; border-right: 1px solid var(--line); position: relative; }
.kpi:last-child { border-right: none; }
.kpi::before { content: ""; position: absolute; left: 0; top: 18px; width: 3px; height: 13px; background: var(--faint); }
.kpi.act::before  { background: var(--ok); }
.kpi.pau::before  { background: var(--paused); }
.kpi.pro::before  { background: var(--warn); }
.kpi.cost::before { background: var(--brand); }
.kpi .lbl { font-family: var(--mono); font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); padding-left: 11px; }
.kpi .val { font-family: var(--mono); font-size: 30px; font-weight: 700; letter-spacing: -.01em; margin-top: 10px; line-height: 1; padding-left: 11px; }
.kpi.cost .val { color: var(--brand); }
.kpi .val small { font-size: 13px; color: var(--faint); margin-right: 3px; }

/* ---------- TOOLBAR / FILTROS ---------- */
.toolbar { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.toolbar form { margin: 0; }
.actions { display: flex; gap: 10px; }
.filters { margin-left: auto; display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.field label::before { content: "› "; color: var(--brand); }
.control { min-width: 128px; }
select.control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23F4B71E' stroke-width='2.4'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; padding-right: 32px;
}
input.control::placeholder { color: var(--faint); }
.control.w-num { min-width: 88px; width: 88px; }

/* ---------- SECTION HEADER ---------- */
.sec { margin-top: 32px; display: flex; align-items: center; gap: 12px; }
.sec .blk { flex: none; }
.sec .meta { font-family: var(--mono); color: var(--faint); font-size: 12px; }

/* ---------- TABLA ---------- */
.table-card { margin-top: 14px; border: 1px solid var(--line); background: var(--surface); overflow-x: auto; }
.table-card table { width: 100%; border-collapse: collapse; }
.table-card thead th.r { text-align: right; }
.table-card tbody td { vertical-align: middle; }
.table-card tbody tr:last-child td { border-bottom: none; }
.idx { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.t-id { font-family: var(--mono); font-size: 13px; color: var(--brand-soft); text-decoration: none; }
.t-name { font-weight: 600; font-size: 14.5px; }
.t-sub { color: var(--faint); font-size: 11.5px; margin-top: 3px; font-family: var(--mono); }
.chip { display: inline-block; }
.pill { display: inline-block; }
.num { font-family: var(--mono); font-size: 13.5px; text-align: right; }
.last { font-family: var(--mono); color: var(--muted); font-size: 12.5px; }
.quota { display: flex; align-items: center; gap: 9px; justify-content: flex-end; }
.quota .pct { font-family: var(--mono); font-size: 13px; width: 36px; text-align: right; }
.quota .pct.hi { color: var(--warn); }
.quota .qtype { font-family: var(--mono); font-size: 10.5px; color: var(--faint); width: 64px; }
.bar { width: 80px; }

/* ---------- CARDS (mobile) ---------- */
.cards { display: none; flex-direction: column; gap: 12px; margin-top: 14px; }
.tcard { border: 1px solid var(--line); background: var(--surface); padding: 15px 16px; position: relative; text-decoration: none; color: inherit; display: block; }
.tcard::before, .tcard::after { content: ""; position: absolute; width: 9px; height: 9px; border-color: var(--line-y); border-style: solid; }
.tcard::before { top: -1px; left: -1px; border-width: 1px 0 0 1px; }
.tcard::after { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }
.tcard .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tcard .top .l { display: flex; align-items: center; gap: 9px; }
.tcard .idx { font-size: 11px; }
.tcard .name { font-weight: 700; font-size: 16px; margin-top: 11px; }
.tcard .sub { color: var(--faint); font-size: 12px; margin-top: 3px; font-family: var(--mono); }
.tcard .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 12px; margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--line); }
.tcard .seg .k { font-family: var(--mono); font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.tcard .seg .v { font-family: var(--mono); font-size: 14px; margin-top: 5px; }
.tcard .seg.full { grid-column: 1/-1; }
.tcard .seg.full .bar { width: 100%; margin-top: 9px; }

.empty { padding: 36px; text-align: center; color: var(--faint); font-family: var(--mono); font-size: 13px; }

/* ---------- ALERT (banner "creado") ---------- */
.alert {
  margin-top: 22px; display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line-y); background: rgba(244,183,30,.06);
  padding: 13px 16px; font-size: 13.5px; color: var(--text);
}
.alert .lbl { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--brand); flex: none; }
.alert form { margin: 0 0 0 auto; }

/* ============================================================
   DETALLE DE TENANT
   ============================================================ */
.back { display: inline-flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 26px; text-decoration: none; transition: .15s; }
.back:hover { color: var(--brand); }

.title-row { display: flex; align-items: flex-start; gap: 20px; margin-top: 18px; }
.title-row .l { flex: 1; min-width: 0; }
.title-row h1 { font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1.05; }
.meta-line { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.lastuse { text-align: right; flex: none; }
.lastuse .k { font-family: var(--mono); font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.lastuse .v { font-family: var(--mono); font-size: 22px; margin-top: 6px; }
.paused-reason { font-family: var(--mono); font-size: 12px; color: var(--paused); margin-top: 10px; }

.divider { height: 1px; background: var(--line); margin: 24px 0; }

.actions-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions-bar form { margin: 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions-bar .motivo {
  flex: 1; min-width: 180px; max-width: 360px; background: var(--surface);
  border: 1px solid var(--line); color: var(--text); font-family: var(--mono);
  font-size: 13px; border-radius: var(--r); padding: 9px 12px; outline: none;
}
.actions-bar .motivo::placeholder { color: var(--faint); }
.actions-bar .motivo:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(244,183,30,.16); }

/* FIELD GRID */
.fgrid { margin-top: 18px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px 28px; border: 1px solid var(--line); background: var(--surface); padding: 22px; }
.fcell .k { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.fcell .v { font-family: var(--mono); font-size: 15px; margin-top: 8px; word-break: break-word; }
.fcell .v.sub { color: var(--faint); font-size: 12px; margin-top: 3px; }
.fcell .v.warn { color: var(--warn); }
.fcell .v .badge { display: inline-block; border: 1px solid var(--line); padding: 2px 8px; font-size: 12px; font-family: var(--mono); }

/* CHART */
.panel { margin-top: 18px; border: 1px solid var(--line); background: var(--surface); padding: 22px; }
.legend { display: flex; gap: 18px; margin-bottom: 14px; }
.legend span { font-family: var(--mono); font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.legend i { width: 14px; height: 3px; display: inline-block; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .gridline { stroke: rgba(255,255,255,.05); stroke-width: 1; }
.chart text { font-family: var(--mono); font-size: 10px; fill: var(--faint); }
.chart text.ax { fill: var(--muted); }
.line-msg { fill: none; stroke: #EDEDEF; stroke-width: 2; }
.line-cost { fill: none; stroke: var(--brand); stroke-width: 2; }
.dot-msg { fill: #EDEDEF; }
.dot-cost { fill: var(--brand); }

/* USAGE BARS */
.usage { margin-top: 16px; border: 1px solid var(--line); background: var(--surface); }
.urow { display: grid; grid-template-columns: 200px 1fr 56px; align-items: center; gap: 18px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.urow:last-child { border-bottom: none; }
.urow .name { font-weight: 600; font-size: 15px; }
.urow .nums { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 4px; }
.urow .nums b { color: var(--text); font-weight: 500; }
.ubar { height: 10px; background: rgba(255,255,255,.07); overflow: hidden; }
.ubar i { display: block; height: 100%; background-image: repeating-linear-gradient(90deg, var(--brand) 0, var(--brand) 6px, transparent 6px, transparent 8px); }
.ubar.hi i { background-image: repeating-linear-gradient(90deg, var(--warn) 0, var(--warn) 6px, transparent 6px, transparent 8px); }
.upct { font-family: var(--mono); font-size: 15px; text-align: right; }
.upct.hi { color: var(--warn); }

/* FEATURES / PROMPT */
.chips { list-style: none; margin-top: 16px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li { font-family: var(--mono); font-size: 12px; color: var(--muted); border: 1px solid var(--line); padding: 5px 10px; }
.prompt-extra {
  margin-top: 16px; font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; background: var(--surface);
  border: 1px solid var(--line); border-left: 3px solid var(--brand);
  padding: 16px; max-height: 24rem; overflow: auto;
}

/* utilidades */
.dim { color: var(--faint); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-feature-settings: "tnum" 1; }
code {
  font-family: var(--mono); font-size: .9em; color: var(--brand-soft);
  background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px;
}
.wrap p { color: var(--muted); font-size: 14px; }
.wrap p strong { color: var(--text); }
.wrap ul { color: var(--muted); font-size: 14px; margin: 10px 0; padding-left: 22px; }
.wrap ul li { margin: 4px 0; }

/* ============================================================
   FORMULARIOS (alta / edición / confirmación) — estética HUD
   ============================================================ */
.hform { display: flex; flex-direction: column; gap: 24px; margin-top: 22px; }
.fset { border: 1px solid var(--line); background: var(--surface); padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.fset > legend {
  font-family: var(--mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--brand); padding: 0 8px; float: none;
}
/* legend dentro de fieldset: lo posicionamos como bloque arriba */
.fset { position: relative; }
.hform .field { gap: 8px; }
.hform .field > label { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.hform .field > label::before { content: "› "; color: var(--brand); }
.hform .control { width: 100%; min-width: 0; }
textarea.control { resize: vertical; min-height: 4rem; line-height: 1.5; font-family: var(--mono); }
.fgrid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.hint { font-family: var(--sans); font-size: 12px; color: var(--faint); line-height: 1.5; max-width: 70ch; }
.hint code { font-size: .92em; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

/* ALERTAS (la base .alert ya existe arriba para el banner "creado") */
.alert.err { border-color: rgba(255,122,102,.4); background: rgba(255,122,102,.08); }
.alert.err .lbl { color: var(--warn); }

/* DIALOG (confirmación de borrado) */
dialog {
  border: 1px solid var(--line-y); background: var(--surface); color: var(--text);
  padding: 26px; max-width: 32rem; box-shadow: 0 20px 60px -20px rgba(0,0,0,.8);
}
dialog::backdrop { background: rgba(7,7,8,.72); backdrop-filter: blur(2px); }
dialog h2 { font-family: var(--mono); font-size: 15px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--warn); margin-bottom: 12px; }
dialog p { margin-bottom: 18px; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-hud { min-height: 100vh; display: grid; place-items: center; padding: 32px 18px; }
.login-card { width: 100%; max-width: 27rem; display: flex; flex-direction: column; gap: 26px; }
.login-card .brand { display: flex; align-items: center; gap: 12px; }
.login-card .brand .bn { font-size: 16px; }
.login-card h1 { font-family: var(--mono); font-size: 13px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.login-card form { display: flex; flex-direction: column; gap: 18px; }
.login-card .field > label { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.login-card .control { width: 100%; min-width: 0; }
.login-card .btn-primary { margin-top: 6px; }

/* ============================================================
   AUDIT — badges por tipo de acción
   ============================================================ */
.tag { font-family: var(--mono); font-size: 11px; letter-spacing: .02em; padding: 3px 8px; border: 1px solid var(--line); color: var(--muted); display: inline-block; white-space: nowrap; }
.tag--login, .tag--logout { color: var(--muted); }
.tag--magic { color: var(--brand-soft); border-color: var(--line-y); }
.tag--pause { color: var(--warn); border-color: rgba(255,122,102,.4); }
.tag--reactivate { color: var(--ok); border-color: rgba(95,208,138,.4); }
.tag--edit, .tag--tenant, .tag--billing { color: var(--brand-soft); border-color: var(--line-y); }
.tag--delete, .tag--restart { color: var(--warn); border-color: rgba(255,122,102,.4); }
.detalle summary { cursor: pointer; font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.detalle summary:hover { color: var(--brand-soft); }
.detalle pre {
  margin-top: 8px; font-family: var(--mono); font-size: 11.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; background: var(--bg);
  border: 1px solid var(--line); padding: 12px; max-height: 14rem; overflow: auto; color: var(--muted);
}

/* link de export / CTA inline en KPI */
.kpi .val .cta { font-size: 14px; }

/* variante gris (cuota pausada) para la barra segmentada de tokens */
.bar.paused i, .ubar.paused i {
  background-image: repeating-linear-gradient(90deg, var(--paused) 0, var(--paused) 5px, transparent 5px, transparent 7px);
}

/* ============================================================
   PANEL DE USUARIO (magic link) — más aireado, una decisión por pantalla
   ============================================================ */
.wrap--tenant { max-width: 760px; }

.uhero { margin-top: 44px; }
.uhero.single { min-height: calc(100vh - 150px); display: flex; flex-direction: column; justify-content: center; margin-top: 0; }
.uhero .eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--brand); }
.uhero h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 700; letter-spacing: -.02em; line-height: 1.05; margin-top: 12px; }
.uhero .sub { color: var(--muted); font-size: 14.5px; margin-top: 16px; max-width: 60ch; }
.uhero .sub strong { color: var(--text); font-weight: 600; }
.uhero .sub code { font-family: var(--mono); font-size: .92em; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px; }
.uhero .sub .mono { color: var(--brand-soft); }

.ublock { margin-top: 44px; }
.ublock__head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 12px; flex-wrap: wrap; }
.ublock__head h2 { font-family: var(--mono); font-size: 15px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.ublock__meta { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.ublock__meta strong { color: var(--brand); font-weight: 700; }

.uquotas { margin-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); }
.uquota { background: var(--surface); padding: 20px; }
.uquota__head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.uquota__label { font-weight: 600; font-size: 15px; }
.uquota__pct { font-family: var(--mono); font-size: 22px; font-weight: 700; line-height: 1; }
.uquota.hi .uquota__pct { color: var(--warn); }
.uquota.paused .uquota__pct { color: var(--paused); }
.uquota .bar { width: 100%; height: 12px; margin-top: 14px; }
.uquota__foot { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 12px; }
.uquota__foot b { color: var(--text); font-weight: 500; }

.ufoot { margin-top: 36px; }
.cta { font-family: var(--mono); font-size: 13px; color: var(--brand); text-decoration: none; border-bottom: 1px solid var(--line-y); padding-bottom: 3px; transition: .15s; }
.cta:hover { color: var(--brand-soft); border-color: var(--brand); }

/* bar chart (historial) — SVG server-side */
.bars { width: 100%; height: auto; display: block; overflow: visible; margin-top: 4px; }
.bars rect { fill: var(--brand); }
.bars .gridline { stroke: rgba(255,255,255,.05); stroke-width: 1; }
.bars .axis { stroke: var(--line); stroke-width: 1; }
.bars text { font-family: var(--mono); font-size: 9px; fill: var(--faint); }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 820px) { .fgrid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .kpi:nth-child(2) { border-right: none; }
  .filters { margin-left: 0; width: 100%; }
}
@media (max-width: 600px) {
  .wrap { padding: 0 14px 60px; }
  .table-card--list { display: none; }
  .cards { display: flex; }
  /* tablas sin alternativa de cards (audit, billing): scroll horizontal */
  .table-card table { min-width: 560px; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .hd-in { flex-wrap: wrap; row-gap: 9px; }
  .user { display: none; }
  .nav { order: 3; width: 100%; border-top: 1px solid var(--line); padding-top: 9px; margin-left: 0; }
  .nav-link { flex: 1; text-align: center; }
  .spacer { order: 2; }
  .field { flex: 1; min-width: 0; }
  .control, .control.w-num { min-width: 0; width: 100%; }
  .filters .apply { width: 100%; }
  .title-row { flex-direction: column; gap: 14px; }
  .title-row h1 { font-size: 26px; }
  .lastuse { text-align: left; }
  .fgrid { grid-template-columns: 1fr 1fr; gap: 18px; padding: 16px; }
  .actions-bar .motivo { max-width: none; width: 100%; }
  .urow { grid-template-columns: 1fr; gap: 10px; padding: 16px; }
  .urow .upct { text-align: left; }
  .uquotas { grid-template-columns: 1fr; }
  .uhero h1 { font-size: 26px; }
}

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