/* Escritorio base layer — "cabina de faro": calm, editorial, flat.
   No radius, no shadows, no gradients (only Faro's beam, defined in M8).
   Token fallbacks live in a cascade layer so the unlayered CDN tokens
   (style.illanes00.cl/v5/tokens.css) always win when they load. */

@layer token-fallbacks {
  :root {
    --bg: #f6f4ee;
    --paper: #fffdf8;
    --ink: #21221e;
    --muted: #6d6b62;
    --line: #e3e0d6;
    --c-amber: #a06b0a;
    --c-green: #2e7d4f;
    --c-red: #b3261e;
  }
}

/* Accent is always local: lighthouse teal. Overrides any CDN brand accent. */
:root {
  --c-accent: #0e6e66;
  --c-accent-hover: #0a5650;
  --font-ui: "IBM Plex Sans", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --sidebar-w: 208px;
  --topbar-h: 56px;
}

/* ── Reset-ish ─────────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

a {
  color: var(--c-accent);
  text-decoration: none;
}

a:hover {
  color: var(--c-accent-hover);
}

h1,
h2,
h3,
h4 {
  margin: 0 0 0.5rem;
  font-weight: 600;
  line-height: 1.25;
}

img,
svg {
  max-width: 100%;
}

/* ── Type helpers ──────────────────────────────────────────── */

.display {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -0.01em;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

.muted {
  color: var(--muted);
}

/* ── Shell layout ──────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1rem 0.75rem;
  background: var(--paper);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.sidebar .brand {
  font-size: 1.35rem;
  color: var(--ink);
  padding: 0.25rem 0.5rem 1rem;
}

.nav-main {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}

.nav-bottom {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-top: 1px solid var(--line);
  padding-top: 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.5rem;
  color: var(--ink);
  border-left: 2px solid transparent;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--ink);
}

.nav-item.active {
  border-left-color: var(--c-accent);
  background: var(--bg);
  font-weight: 600;
}

.nav-ico {
  display: inline-block;
  width: 1.6rem;
  color: var(--muted);
  text-align: center;
}

.nav-item.active .nav-ico {
  color: var(--c-accent);
}

.content-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar-h);
  padding: 0 1.25rem;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.capture-form {
  flex: 1;
  max-width: 520px;
}

.capture-form input {
  width: 100%;
}

#capture-feedback {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  padding: 1.5rem 1.25rem 3rem;
}

.main {
  flex: 1;
  min-width: 0;
  max-width: 1100px;
}

.rightpanel {
  width: 320px;
  flex-shrink: 0;
}

.rightpanel:empty {
  display: none;
}

/* ── Cards and stats ───────────────────────────────────────── */

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.stat-num {
  font-family: var(--font-display);
  font-size: 1.9rem;
  line-height: 1.1;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

/* ── Tags ──────────────────────────────────────────────────── */

.tag {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--line);
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}

.tag-ok {
  color: var(--c-green);
  border-color: var(--c-green);
}

.tag-warn {
  color: var(--c-amber);
  border-color: var(--c-amber);
}

/* Critical = real overdue + priority 1 only. Never decorative. */
.tag-crit {
  color: var(--c-red);
  border-color: var(--c-red);
}

.tag-muted {
  color: var(--muted);
  border-color: var(--line);
}

/* ── Buttons and forms ─────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  font-family: var(--font-ui);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--c-accent);
  color: var(--c-accent);
}

.btn-primary {
  color: #fff;
  background: var(--c-accent);
  border-color: var(--c-accent);
}

.btn-primary:hover {
  color: #fff;
  background: var(--c-accent-hover);
  border-color: var(--c-accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  color: var(--c-accent);
  border-color: transparent;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
textarea,
select {
  font-family: var(--font-ui);
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0.4rem 0.6rem;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--c-accent);
}

label {
  font-size: 0.82rem;
  color: var(--muted);
}

/* ── Lists ─────────────────────────────────────────────────── */

.list-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.25rem;
  border-bottom: 1px solid var(--line);
}

.list-row:last-child {
  border-bottom: none;
}

.empty-state {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 1.05rem;
}

/* ── Flash messages ────────────────────────────────────────── */

.flash-stack {
  padding: 0.75rem 1.25rem 0;
}

.flash {
  padding: 0.5rem 0.8rem;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 3px solid var(--c-green);
}

.flash-warn {
  border-left-color: var(--c-amber);
}

.flash-error {
  border-left-color: var(--c-red);
}

/* ── "Puede esperar" collapsible sections ──────────────────── */

details {
  border: 1px solid var(--line);
  background: var(--paper);
  margin-bottom: 1rem;
}

details summary {
  cursor: pointer;
  padding: 0.6rem 1rem;
  font-size: 0.88rem;
  color: var(--muted);
  list-style: none;
}

details summary::-webkit-details-marker {
  display: none;
}

details summary::before {
  content: "+ ";
  font-family: var(--font-mono);
  color: var(--muted);
}

details[open] summary::before {
  content: "− ";
}

details > :not(summary) {
  padding: 0 1rem;
}

details > :last-child {
  padding-bottom: 0.75rem;
}

/* ── HTMX transitions ──────────────────────────────────────── */

.fade-swap {
  opacity: 1;
  transition: opacity 0.25s ease;
}

.fade-swap.htmx-added,
.fade-swap.htmx-swapping {
  opacity: 0;
}

/* ── Staggered reveal (Home) ───────────────────────────────── */

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.reveal > * {
  animation: reveal 0.4s ease both;
}

.reveal > *:nth-child(1) { animation-delay: 0.03s; }
.reveal > *:nth-child(2) { animation-delay: 0.09s; }
.reveal > *:nth-child(3) { animation-delay: 0.15s; }
.reveal > *:nth-child(4) { animation-delay: 0.21s; }
.reveal > *:nth-child(5) { animation-delay: 0.27s; }
.reveal > *:nth-child(6) { animation-delay: 0.33s; }
.reveal > *:nth-child(7) { animation-delay: 0.39s; }
.reveal > *:nth-child(8) { animation-delay: 0.45s; }

@media (prefers-reduced-motion: reduce) {
  .reveal > * {
    animation: none;
  }
  .fade-swap {
    transition: none;
  }
}

/* ── Login page ────────────────────────────────────────────── */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  width: min(360px, 90vw);
  padding: 2rem;
  background: var(--paper);
  border: 1px solid var(--line);
  text-align: center;
}

.login-title {
  font-size: 2rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

.login-card .flash-stack {
  padding: 0.75rem 0 0;
}

/* ── Responsive: sidebar collapses to glyphs under 900px ───── */

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 56px 1fr;
  }

  .sidebar {
    padding: 1rem 0.4rem;
  }

  .sidebar .brand {
    font-size: 1rem;
    padding: 0.25rem 0.25rem 1rem;
    overflow: hidden;
    white-space: nowrap;
  }

  .nav-label {
    display: none;
  }

  .nav-item {
    justify-content: center;
    padding: 0.5rem 0.25rem;
  }

  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .page {
    flex-direction: column;
  }

  .rightpanel {
    width: 100%;
  }

  #capture-feedback {
    display: none;
  }
}
