@font-face {
  font-family: 'Uniwars';
  src: url('../fonts/uniwars-semibold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

/* Layout con sidebar + topbar --------------------------------------- */
:root {
  --sidebar-w-rail: 64px;
  --sidebar-w-open: 240px;
  --sidebar-w: var(--sidebar-w-rail);
  --topbar-h: 60px;
}
/* IMPORTANTE: el sidebar expandido es OVERLAY (flota sobre el contenido).
   No cambiamos --sidebar-w globalmente para evitar el reflow del <main>. */

.portal-nav {
  position: sticky; top: 0; z-index: 60;
  background: var(--nav-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.portal-nav__inner {
  display: grid; align-items: center; gap: 16px;
  grid-template-columns: 1fr minmax(0, 520px) 1fr;
  padding: 10px; padding-right: 20px; height: var(--topbar-h);
}
.portal-nav__left {
  display: flex; align-items: center; gap: 10px;
  justify-self: start;
}
.portal-nav__center { justify-self: stretch; }
.portal-nav__user { justify-self: end; }
.portal-nav__burger {
  background: transparent; border: none; cursor: pointer;
  color: var(--text); border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; flex: 0 0 44px;
}
.portal-nav__burger:hover { background: var(--hover); }
.portal-nav__brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: 'Uniwars', var(--font);
  font-weight: 600; letter-spacing: -.02em; font-size: 1.35rem;
}
.portal-nav__brand .accent { color: var(--blue); }
.portal-nav__brand .chip { color: #fff; background: var(--blue); border-color: var(--blue); }

.portal-nav__search { width: 100%; max-width: 520px; margin: 0 auto; }
.portal-nav__search .input {
  padding: 8px 14px; font-size: .85rem; border-radius: 100px;
  background: var(--surface-2); height: 38px; width: 100%;
}
.portal-nav__user { display: flex; align-items: center; gap: 10px; font-size: .82rem; color: var(--gray-5); }
.portal-nav__user .who { padding: 4px 10px; border: 1px solid var(--border); border-radius: 100px; }

/* Sidebar ------------------------------------------------------------ */
.portal-sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
  width: var(--sidebar-w-rail); z-index: 55;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: width .18s ease, transform .2s ease, box-shadow .18s ease;
  overflow: hidden;
}
body.sidebar-expanded .portal-sidebar {
  width: var(--sidebar-w-open);
  box-shadow: 4px 0 24px rgba(0,0,0,.18);
}
.side-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 14px 8px; }
.side-section { padding: 6px 0; }
.side-section + .side-section { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; }
.side-section__title {
  font-size: .7rem; letter-spacing: .15em; text-transform: uppercase;
  color: var(--text-muted); padding: 6px 12px 8px;
  white-space: nowrap; overflow: hidden;
}
.side-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  font-size: .9rem; font-weight: 500; color: var(--gray-5);
  transition: color var(--transition), background var(--transition);
  white-space: nowrap; overflow: hidden;
}
.side-link:hover { color: var(--text); background: var(--hover); }
.side-link.active { color: var(--blue); background: var(--hover); font-weight: 600; }
.side-link.active .side-link__ico { color: var(--blue); }
.side-link__ico {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 22px; width: 22px; color: var(--text-muted);
}
.side-link__lbl {
  opacity: 1; transition: opacity .12s ease;
}
.side-foot {
  padding: 12px 14px; border-top: 1px solid var(--border);
  font-size: .78rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden;
}

/* Rail (colapsado): solo iconos centrados */
body:not(.sidebar-expanded) .side-link__lbl,
body:not(.sidebar-expanded) .side-section__title,
body:not(.sidebar-expanded) .side-foot { display: none; }
body:not(.sidebar-expanded) .side-nav { padding: 10px 6px; }
body:not(.sidebar-expanded) .side-link {
  justify-content: center; gap: 0; padding: 10px 0;
  width: 44px; height: 44px; margin: 2px auto;
}
body:not(.sidebar-expanded) .side-section { padding: 4px 0; }
body:not(.sidebar-expanded) .side-section + .side-section { margin-top: 6px; padding-top: 8px; }

.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 54;
  background: rgba(0,0,0,.5);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
/* Backdrop visible en cualquier tamaño cuando el sidebar está expandido (overlay).
   En desktop usamos un overlay más sutil. */
body.sidebar-expanded .sidebar-backdrop { opacity: 1; pointer-events: auto; }
@media (min-width: 961px) {
  body.sidebar-expanded .sidebar-backdrop { background: rgba(0,0,0,.25); }
}

/* Main content: padding fijo del rail. NO cambia al expandir (sidebar es overlay). */
body.has-sidebar .portal-main {
  padding-left: calc(var(--sidebar-w-rail) + 20px);
}

@media (max-width: 960px) {
  /* En mobile el rail no ocupa espacio; sidebar slide-in overlay completo */
  body.has-sidebar .portal-main { padding-left: 20px; }
  .portal-sidebar { width: var(--sidebar-w-open); transform: translateX(-100%); box-shadow: 8px 0 32px rgba(0,0,0,.25); }
  body.sidebar-expanded .portal-sidebar { transform: translateX(0); }
  /* En mobile siempre mostrar labels cuando el panel está visible */
  body.sidebar-expanded .side-link__lbl,
  body.sidebar-expanded .side-section__title,
  body.sidebar-expanded .side-foot { opacity: 1; height: auto; }
  body.sidebar-expanded .side-section__title { padding: 6px 12px 8px; }
  body.sidebar-expanded .side-foot { padding: 12px 14px; }
  body.sidebar-expanded .side-link { justify-content: flex-start; padding: 10px 12px; }
  .portal-nav__search { max-width: none; margin: 0; }
}
@media (max-width: 640px) {
  .portal-nav__user .who { display: none; }
}

.portal-main { padding: 28px 20px 100px; max-width: 1200px; margin: 0 auto; }

.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-header h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.03em; color: var(--text); }
.page-header__sub { color: var(--text-muted); font-size: .9rem; }

/* Login --------------------------------------------------------------- */
.auth-shell {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 32px 16px;
  background: radial-gradient(ellipse at top, rgba(10,132,255,.08), transparent 60%), var(--dark);
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--dark-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: 0 30px 80px rgba(0,0,0,.55);
}
.auth-card h1 { font-size: 1.35rem; font-weight: 700; margin-bottom: 4px; }
.auth-card p.sub { color: var(--gray-4); font-size: .88rem; margin-bottom: 24px; }
.tabs { display: flex; gap: 6px; background: var(--dark-3); padding: 4px; border-radius: 100px; margin-bottom: 20px; }
.tab-btn { flex: 1; padding: 9px 10px; border-radius: 100px; color: var(--gray-4); font-size: .82rem; font-weight: 600; }
.tab-btn.active { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.auth-logo { font-size: 1.4rem; font-weight: 800; letter-spacing: -.06em; margin-bottom: 20px; }
.auth-logo .accent { color: var(--blue); }

/* Dashboard ---------------------------------------------------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; margin-bottom: 22px; }

/* Tabs horizontales de estado */
.estado-tabs {
  display: flex; flex-wrap: wrap; gap: 2px;
  margin-bottom: 14px; padding: 0 2px;
  border-bottom: 1px solid var(--border);
}
.estado-tab {
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: .82rem; font-weight: 500;
  white-space: nowrap;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.estado-tab:hover { color: var(--text); }
.estado-tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.estado-tab .count {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
}
.estado-tab.active .count {
  background: rgba(10,132,255,.15);
  border-color: rgba(10,132,255,.35);
  color: var(--blue);
}

/* Edición inline en la tabla */
.inline-state {
  appearance: none; -webkit-appearance: none;
  padding: 4px 22px 4px 10px;
  border-radius: 100px;
  font-size: .72rem; font-weight: 600;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 12px) 52%, calc(100% - 7px) 52%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  max-width: 170px;
}
.inline-state option { color: var(--text); background: var(--surface); }
.inline-date {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: .78rem;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  max-width: 150px;
}
.inline-date:hover, .inline-state:hover { border-color: var(--border-hover); }
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px; margin-bottom: 18px;
  background: var(--dark-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

/* Nueva orden — layout 2 columnas independientes -------------------- */
.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  align-items: start;
}
.form-col { display: flex; flex-direction: column; gap: 16px; }
.stacked { display: flex; flex-direction: column; gap: 16px; }
.form-grid .stacked { gap: 12px; }
form.stacked { gap: 16px; }
@media (max-width: 860px) {
  .form-grid { grid-template-columns: 1fr; }
}

.page-header__meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-header__meta .chip--muted { opacity: .7; }
@media (max-width: 640px) {
  .page-header h1 { font-size: 1.3rem; }
  .page-header__meta { width: 100%; }
}

/* Checks de funcionamiento */
.check-row {
  display: grid; grid-template-columns: 1fr auto; gap: 10px;
  align-items: center; padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.check-row:last-child { border-bottom: none; }
.check-row .name { font-weight: 500; font-size: .88rem; }
.check-row .pill-group { gap: 6px; }
.check-row .pill { padding: 5px 10px; font-size: .75rem; }
.check-row:has(input:disabled) { opacity: .5; pointer-events: none; }
@media (max-width: 520px) {
  .check-row { grid-template-columns: 1fr; gap: 6px; }
  .check-row .pill-group { justify-content: flex-start; }
}

/* Toggle "no enciende" */
.noenciende-toggle {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border: 1.5px dashed rgba(255,159,10,.4);
  border-radius: 12px; margin-bottom: 12px;
  background: rgba(255,159,10,.05);
}
.noenciende-toggle.active { border-style: solid; background: rgba(255,159,10,.12); border-color: var(--amber); }
.noenciende-toggle input { width: 18px; height: 18px; accent-color: var(--amber); }
.noenciende-toggle .hint { color: var(--amber); }

/* Fotos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px,1fr)); gap: 10px; }
.photo-thumb {
  position: relative; aspect-ratio: 1;
  background: var(--dark-3); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .rm {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.7); color: #fff; font-size: .9rem;
  display: grid; place-items: center;
}
.photo-add {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  aspect-ratio: 1;
  border: 1.5px dashed var(--border-hover);
  border-radius: 10px; color: var(--gray-4);
  font-size: .85rem; cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.photo-add:hover { border-color: var(--blue); color: var(--blue); background: rgba(10,132,255,.06); }
.photo-add input { display: none; }

/* Firma */
.signature-box {
  background: #fff; border-radius: 12px;
  border: 1.5px solid var(--border);
  overflow: hidden;
  position: relative;
  width: 100%;
  min-width: 0;
  height: 200px;
}
.signature-box canvas { width: 100%; height: 100%; display: block; touch-action: none; background: #fff; }
fieldset.card { min-width: 0; }

/* Patrón de desbloqueo (3x3) */
.pattern-box {
  width: 240px; max-width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  margin-top: 8px;
}
.pattern-box svg { width: 100%; height: auto; display: block; touch-action: none; }
.pattern-box svg circle.dot { fill: var(--text-muted); }
.pattern-box svg circle.dot.active { fill: var(--blue); }
.pattern-box svg circle.dot.start  { fill: var(--green); }
.pattern-box svg circle.dot.end    { fill: var(--red); }
.pattern-box svg circle.hit { fill: transparent; }
.pattern-box svg line { stroke: var(--blue); stroke-width: 4; stroke-linecap: round; }
.pattern-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.signature-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }

/* Barra sticky acciones */
.sticky-actions {
  position: sticky; bottom: 0;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end;
  margin: 28px -20px -100px;
  z-index: 5;
}

/* Timeline */
.timeline { border-left: 2px solid var(--border); margin-left: 10px; padding-left: 18px; display: flex; flex-direction: column; gap: 14px; }
.timeline__item { position: relative; font-size: .85rem; }
.timeline__item::before {
  content: ""; position: absolute; left: -26px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--blue); box-shadow: 0 0 0 3px rgba(10,132,255,.18);
}
.timeline__time { font-size: .72rem; color: var(--gray-4); }
.timeline__to   { font-weight: 600; color: var(--text); }
.timeline__note { color: var(--gray-4); font-size: .8rem; margin-top: 2px; }

/* Layout orden detalle */
.detail-grid { display: grid; grid-template-columns: 1.3fr .7fr; gap: 20px; }
@media (max-width: 960px) { .detail-grid { grid-template-columns: 1fr; } }

.kv { display: grid; grid-template-columns: 140px 1fr; row-gap: 10px; column-gap: 12px; font-size: .9rem; align-items: center; }
.kv dt { color: var(--gray-4); font-size: .8rem; }
.kv dd { color: var(--text); }

/* Approval card */
.approval-card {
  background: linear-gradient(180deg, rgba(255,159,10,.1), rgba(255,159,10,.03));
  border: 1.5px solid rgba(255,159,10,.45);
  border-radius: var(--radius-lg);
  padding: 22px; margin-bottom: 16px;
}
.approval-card h3 { color: var(--amber); margin-bottom: 8px; font-size: 1rem; letter-spacing: .04em; text-transform: uppercase; }
.approval-card .budget { font-size: 1.8rem; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 14px; }
.approval-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Auth pages fine details */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

/* Range tabs (Reportes: Hoy / Semana / Mes / Rango) */
.range-tabs {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px;
}
.range-tab {
  padding: 7px 14px; border-radius: 8px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-muted); font-size: .85rem; font-weight: 500;
  transition: color var(--transition), background var(--transition);
}
.range-tab:hover { color: var(--text); }
.range-tab.active { background: var(--blue); color: #fff; }

/* Items de presupuesto + totales */
.items-table { width: 100%; font-size: .88rem; }
.items-table th { font-size: .72rem; letter-spacing: .12em; }
.items-table td { padding: 8px 10px; vertical-align: middle; }
.items-table td:last-child button { padding: 2px 10px; color: var(--red); }

.item-add-row {
  display: grid; grid-template-columns: 1fr 90px auto; gap: 8px;
  align-items: end; margin: 10px 0;
}
.item-add-row--free { grid-template-columns: 1.5fr 1fr 1fr auto; }
@media (max-width: 640px) {
  .item-add-row,
  .item-add-row--free { grid-template-columns: 1fr; }
}

.totals-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px; margin-top: 14px;
  font-variant-numeric: tabular-nums;
}
.totals-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 4px 0; font-size: .9rem; color: var(--text-muted);
}
.totals-row strong { color: var(--text); font-weight: 600; }
.totals-row--total {
  border-top: 1px solid var(--border);
  padding-top: 10px; margin-top: 6px;
  font-size: 1.05rem; color: var(--text);
}
.totals-row--total strong { font-size: 1.15rem; font-weight: 700; }
.totals-row--saldo {
  border-top: 2px solid var(--blue);
  padding-top: 10px; margin-top: 6px;
  font-size: 1.1rem; color: var(--text);
}
.totals-row--saldo strong { color: var(--blue); font-size: 1.25rem; font-weight: 800; }

/* Pagination */
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 16px; font-size: .85rem; color: var(--gray-4); }
.pager button { padding: 6px 12px; border: 1px solid var(--border); border-radius: 100px; color: var(--gray-4); }
.pager button:hover { color: var(--text); border-color: var(--border-hover); }
.pager button[disabled] { opacity: .4; cursor: not-allowed; }
.pager .current { color: var(--text); }
