/* BibliotecaEmpresas · estilos comunes de los mockups.
   HTML y CSS estáticos, sin frameworks: se traducen a Blazor.
   Sistema: .interface-design/system.md */

/* ---------- Tokens ---------- */
:root {
  --bg: #F6F5F2;            /* lienzo cálido */
  --surface: #FFFFFF;
  --surface-2: #FAF9F7;     /* banda de cabecera de tabla, pies */
  --side: #EEF0F7;          /* sidebar */
  --side-hover: #E3E7F3;
  --line: #E4E2DD;
  --line-strong: #D2CFC8;

  --ink: #1F2433;
  --ink-2: #555C6E;
  --ink-3: #80869A;

  --accent: #3E5BD8;
  --accent-ink: #2C46B8;
  --accent-soft: #E6EBFC;
  --accent-soft-2: #D3DCFA;

  --warn: #D69E2E;          /* barras */
  --warn-ink: #85560C;      /* texto */
  --warn-soft: #FBF1DD;
  --danger: #C2413A;
  --danger-ink: #A8332D;
  --danger-soft: #FBE8E6;
  --ok: #2F855A;
  --ok-ink: #276749;
  --ok-soft: #E3F3EA;
  --off: #9AA0AE;
  --off-soft: #EEEEF0;

  --r: 10px;
  --r-sm: 7px;
  --shadow: 0 1px 2px rgba(31, 36, 51, .05), 0 1px 1px rgba(31, 36, 51, .03);
  --shadow-pop: 0 10px 30px rgba(31, 36, 51, .12), 0 2px 6px rgba(31, 36, 51, .06);

  --font: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --side-w: 248px;
  color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 500 14px/1.5 var(--font);
  font-feature-settings: "tnum" 1, "lnum" 1;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 15px; height: 15px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }

/* ---------- Esqueleto: sidebar + contenido ---------- */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.main { min-width: 0; padding: 28px 32px 72px; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
  background: var(--side); border-right: 1px solid var(--line);
  padding: 20px 14px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; color: var(--ink); font-weight: 800; font-size: 16px; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.brand-mark .i { width: 18px; height: 18px; stroke-width: 2; }

.nav-fold { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.nav-fold > summary { list-style: none; cursor: pointer; }
.nav-fold > summary::-webkit-details-marker { display: none; }
.nav-body { display: flex; flex-direction: column; gap: 18px; height: 100%; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-title { font-size: 12px; font-weight: 700; color: var(--ink-3); padding: 0 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; min-height: 38px;
  padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 600;
}
.nav a .i { color: var(--ink-3); }
.nav a:hover { background: var(--side-hover); color: var(--ink); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow); }
.nav a[aria-current="page"] .i { color: var(--accent); }

/* Cupo del mes en el sidebar: lo pinta el layout (sin ids, como el usuario) */
.side-quota { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 12px 10px; box-shadow: var(--shadow); }
.side-quota-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 12px; font-weight: 700; color: var(--ink-2); }
.side-quota-free { font-size: 20px; font-weight: 800; color: var(--ink); letter-spacing: -.01em; margin: 2px 0 8px; }
.side-quota-free span { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-left: 4px; }
.side-quota-foot { font-size: 12px; color: var(--ink-2); margin-top: 6px; }

.who { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--line-strong); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: 13px; flex: none; }
.who-text { min-width: 0; flex: 1; line-height: 1.3; }
.who-text b { display: block; font-size: 13px; }
.who-text span { display: block; font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-text .role-tag { display: inline-block; margin-top: 2px; padding: 0 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: 11px; }
.logout { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r-sm); color: var(--ink-2); }
.logout:hover { background: var(--side-hover); color: var(--ink); }

/* En escritorio el menú siempre está abierto (details forzado) */
@supports selector(::details-content) {
  @media (min-width: 861px) {
    .nav-fold > summary { display: none; }
    .nav-fold::details-content { content-visibility: visible; display: block; flex: 1; }
  }
}

/* ---------- Cabecera de página ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title { font-size: 26px; line-height: 1.2; font-weight: 800; letter-spacing: -.02em; }
.page-sub { margin-top: 6px; color: var(--ink-2); font-size: 14px; }
.page-sub b { color: var(--ink); }
.head-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.stat-pill { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--ink-2); }
.stat-pill b { color: var(--ink); font-weight: 800; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); flex: none; }
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-danger { background: var(--danger); }

/* ---------- Paneles ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.panel-pad { padding: 18px 20px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 36px; padding: 7px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); text-decoration: none; }
.btn:disabled { color: var(--ink-3); background: var(--surface-2); border-color: var(--line); cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: rgba(31, 36, 51, .06); border-color: transparent; color: var(--ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-ink); border-color: var(--danger-ink); }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn-icon { width: 36px; padding: 0; }
.link-btn { border: 0; background: none; padding: 2px 4px; color: var(--accent-ink); font-weight: 700; font-size: 13px; cursor: pointer; border-radius: 4px; }
.link-btn:hover { text-decoration: underline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > * { min-width: 0; }
.field + .field { margin-top: 14px; }
.label, .field > label { font-size: 13px; font-weight: 700; color: var(--ink); }
.hint { font-size: 12.5px; color: var(--ink-2); }
.err { font-size: 13px; font-weight: 600; color: var(--danger-ink); display: flex; gap: 6px; align-items: center; }
.input {
  width: 100%; min-height: 38px; padding: 7px 11px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface);
  font-weight: 500;
}
.input::placeholder { color: var(--ink-3); }
.input:hover { border-color: var(--ink-3); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
select.input { min-width: 0; max-width: 100%; text-overflow: ellipsis; appearance: none; padding-right: 32px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23555C6E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 16px; }
.input-icon { position: relative; }
.input-icon > .i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.input-icon > .input { padding-left: 36px; }
.input-row { display: flex; flex-wrap: wrap; gap: 8px; }
.input-row > * { min-width: 0; }
.input-row > .input { flex: 1 1 140px; width: auto; }
.input-row > .btn { flex: 0 1 auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-2 > .field + .field { margin-top: 0; }

.check { display: flex; align-items: center; gap: 9px; min-height: 30px; font-size: 14px; font-weight: 500; cursor: pointer; }
.check input, .switch input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); flex: none; cursor: pointer; }
.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
.checks-1 { grid-template-columns: minmax(0, 1fr); }
.switch { display: flex; align-items: center; gap: 9px; font-weight: 600; cursor: pointer; }

/* ---------- Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; min-height: 30px;
  padding: 3px 4px 3px 11px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: 13px;
}
.chip-k { font-weight: 600; color: var(--ink-2); }
.chip button { display: grid; place-items: center; width: 24px; height: 24px; border: 0; border-radius: 50%; background: transparent; color: var(--accent-ink); cursor: pointer; }
.chip button:hover { background: var(--accent-soft-2); }
.chip button .i { width: 14px; height: 14px; stroke-width: 2.2; }

/* ---------- Etiquetas ---------- */
.tag { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 99px; font-size: 12.5px; font-weight: 700; white-space: nowrap; background: var(--off-soft); color: var(--ink-2); }
.tag-ok { background: var(--ok-soft); color: var(--ok-ink); }
.tag-warn { background: var(--warn-soft); color: var(--warn-ink); }
.tag-danger { background: var(--danger-soft); color: var(--danger-ink); }
.tag-accent { background: var(--accent-soft); color: var(--accent-ink); }
.tag .i { width: 14px; height: 14px; }

/* ---------- Tablas ---------- */
.table-panel { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; }
table.data th {
  text-align: left; padding: 11px 14px; background: var(--surface-2);
  font-size: 13px; font-weight: 700; color: var(--ink-2); white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
table.data th.num { text-align: right; }
table.data td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #FBFAF8; }
table.data tbody tr[aria-selected="true"] td { background: var(--accent-soft); }
table.data tfoot td { background: var(--surface-2); border-top: 1px solid var(--line); border-bottom: 0; font-weight: 700; }
table.data .sel { width: 46px; padding-right: 0; }
table.data .sel input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); cursor: pointer; display: block; }
table.data .name { font-weight: 700; }
table.data .name a { color: var(--ink); }
table.data .name a:hover { color: var(--accent-ink); }
table.data .row-actions { text-align: right; white-space: nowrap; }
@media (min-width: 861px) { table.data td.row-actions { display: table-cell; } } /* el framework define .row-actions como inline-flex */
.sub { display: block; margin-top: 3px; font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.table-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border-top: 1px solid var(--line); background: var(--surface-2); }
.spacer { flex: 1; }

/* ---------- Medidor de cupo (elemento firma) ----------
   Tramos: usado (añil), esta exportación (añil rayado), libre (vacío).
   Lo que no cabe rebosa por la derecha (.m-over), fuera de la pista. */
.meter { position: relative; }
.meter-track { position: relative; display: flex; height: 10px; border-radius: 99px; background: #E9E8EE; overflow: visible; }
.meter-track > span { display: block; height: 100%; }
.meter-track > span:first-child { border-radius: 99px 0 0 99px; }
.m-used { background: var(--accent); }
.m-this { background: repeating-linear-gradient(-45deg, var(--accent) 0 4px, #8FA2EC 4px 8px); }
.m-over {
  position: absolute; left: 100%; top: -3px; height: 16px !important; border-radius: 0 99px 99px 0;
  background: repeating-linear-gradient(-45deg, var(--danger) 0 4px, #E59A95 4px 8px);
}
.meter-track::after { content: ""; position: absolute; right: -1px; top: -4px; bottom: -4px; width: 2px; border-radius: 2px; background: var(--ink); opacity: .55; }
.meter.has-over { margin-right: var(--over-room, 30%); }
.meter-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12.5px; color: var(--ink-2); }
.meter-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.k-used { background: var(--accent); }
.k-this { background: repeating-linear-gradient(-45deg, var(--accent) 0 3px, #8FA2EC 3px 6px); }
.k-free { background: #E9E8EE; }
.k-over { background: repeating-linear-gradient(-45deg, var(--danger) 0 3px, #E59A95 3px 6px); }
/* Medidor pequeño (filas de tablas, sidebar) */
.meter-sm .meter-track { height: 6px; }
.meter-sm .meter-track::after { top: -3px; bottom: -3px; }
.meter.near .m-used { background: var(--warn); }
.meter.full .m-used { background: var(--danger); }
.meter.off .meter-track { background: var(--off-soft); }
.mini { display: grid; grid-template-columns: minmax(70px, 1fr) auto; align-items: center; gap: 10px; min-width: 170px; }
.mini-n { font-size: 13px; color: var(--ink-2); white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.mini-n b { color: var(--ink); font-weight: 800; }
.mini.near .mini-n b { color: var(--warn-ink); }
.mini.full .mini-n b { color: var(--danger-ink); }

/* ---------- Avisos ---------- */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r); background: var(--accent-soft); color: var(--ink); font-size: 14px; }
.notice > .i { margin-top: 1px; color: var(--accent-ink); }
.notice b { display: block; margin-bottom: 2px; }
.notice .actions { margin-top: 10px; }
.notice-ok { background: var(--ok-soft); } .notice-ok > .i { color: var(--ok-ink); }
.notice-warn { background: var(--warn-soft); } .notice-warn > .i { color: var(--warn-ink); }
.notice-danger { background: var(--danger-soft); } .notice-danger > .i { color: var(--danger-ink); }

/* Lo que el plan no permite: se ve, con candado y sin acción (D-22) */
.not-in-plan {
  display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 6px 12px;
  border-radius: var(--r-sm); border: 1px dashed var(--line-strong); background: var(--surface-2);
  color: var(--ink-2); font-size: 13px; font-weight: 600;
}
.not-in-plan .i { color: var(--ink-3); width: 16px; height: 16px; }

/* Vacíos */
.empty { text-align: center; padding: 36px 24px; }
.empty-icon { width: 48px; height: 48px; margin: 0 auto 14px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; }
.empty-icon .i { width: 24px; height: 24px; }
.empty h3 { font-size: 17px; font-weight: 800; }
.empty p { margin-top: 6px; color: var(--ink-2); max-width: 52ch; margin-inline: auto; }
.empty .actions { justify-content: center; margin-top: 16px; }

/* Diálogo dibujado (en la app es un <dialog>) */
.dialog { text-align: left; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-pop); border: 1px solid var(--line); max-width: 560px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; }
.dialog-head h3 { font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.dialog-body { padding: 16px 20px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 14px 14px; }

/* ---------- Estados alternativos (D-26) ---------- */
.states { margin-top: 56px; padding-top: 28px; border-top: 2px dashed var(--line-strong); }
.states-title { font-size: 18px; font-weight: 800; }
.states-intro { color: var(--ink-2); margin-top: 4px; }
.state { margin-top: 26px; }
.state-label { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.state-label::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--ink-3); }
.state-stage { padding: 24px; border-radius: var(--r); background: repeating-linear-gradient(45deg, #EFEDE8 0 10px, #F2F0EC 10px 20px); }

/* ---------- Móvil (390 px): misma página adaptada (D-25) ---------- */
.mobile-only { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .main { padding: 18px 16px 56px; }
  .mobile-only { display: revert; }
  .desktop-only { display: none !important; }

  /* El sidebar pasa a barra superior; el menú se despliega con <details> */
  .sidebar {
    position: sticky; top: 0; z-index: 30; height: auto; overflow: visible;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px 8px;
    padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; grid-column: 1; grid-row: 1; }
  .nav-fold { grid-column: 2; grid-row: 1; display: block; }
  .nav-fold > summary {
    display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px;
    border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line-strong); font-weight: 700;
  }
  .nav-fold[open] > summary { background: var(--accent-soft); border-color: var(--accent-soft-2); color: var(--accent-ink); }
  .nav-body {
    position: absolute; left: 0; right: 0; top: 100%; z-index: 40; height: auto;
    background: var(--side); border-bottom: 1px solid var(--line-strong); box-shadow: var(--shadow-pop);
    padding: 10px 16px 14px;
  }
  .nav a { min-height: 44px; }
  .side-quota { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 12px; padding: 8px 12px; box-shadow: none; }
  .side-quota-head { grid-column: 1; grid-row: 1; }
  .side-quota-free { grid-column: 1; grid-row: 2; font-size: 16px; margin: 0; }
  .side-quota .meter { grid-column: 2; grid-row: 1 / 3; }
  .side-quota-foot { display: none; }
  .who { padding-top: 12px; margin-top: 4px; }

  .page-title { font-size: 22px; }
  .panel-pad { padding: 16px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .state-stage { padding: 12px; }

  /* Tablas: filas apiladas */
  table.stackable thead { display: none; }
  table.stackable, table.stackable tbody, table.stackable tfoot, table.stackable tr, table.stackable td { display: block; }
  table.stackable tr { position: relative; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.stackable tbody tr:last-child { border-bottom: 0; }
  table.stackable td { padding: 0; border: 0; background: none !important; }
  table.stackable tbody tr[aria-selected="true"] { background: var(--accent-soft); }
  table.stackable td.inline { display: inline; font-size: 13px; color: var(--ink-2); }
  table.stackable td.inline + td.inline::before { content: " · "; color: var(--ink-3); }
  table.stackable td[data-label] { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; font-size: 13px; }
  table.stackable td[data-label]::before { content: attr(data-label); color: var(--ink-2); font-weight: 600; flex: none; }
  table.stackable td.row-actions { margin-top: 10px; text-align: left; }
  table.stackable tfoot tr { background: var(--surface-2); }
  table.stackable tfoot td { font-weight: 700; }
  table.data td.name { margin-bottom: 2px; }
  .input-row > .btn { flex: 1 1 auto; }
}
