/* ============================================================
   21Portal — Panel de gestión
   Implements the "21Portal Design System" from Claude Design:
   photography-first dark UI, signal-orange accent, Archivo
   display type + IBM Plex Mono meta, near-square radii.
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Archivo:ital,wdth,wght@0,62..125,100..900;1,62..125,100..900&family=IBM+Plex+Mono:wght@400;500;600&display=swap");

:root {
  /* ---- Base: Ink (dark, photography-first) ---- */
  --ink-0: #050607;
  --ink-1: #0c0d10;
  --ink-2: #14161a;
  --ink-3: #1d2026;
  --ink-4: #2a2e36;

  /* ---- Foreground ---- */
  --fg-1: #f4f4f2;
  --fg-2: #a7abb3;
  --fg-3: #686d77;

  /* ---- Lines ---- */
  --line-1: rgba(244, 244, 242, 0.09);
  --line-2: rgba(244, 244, 242, 0.18);
  --line-3: rgba(244, 244, 242, 0.34);

  /* ---- Accent: signal orange ---- */
  --signal: #ff4d00;
  --signal-hover: #ff6a26;
  --signal-press: #e04400;
  --signal-soft: rgba(255, 77, 0, 0.14);
  --on-signal: #0c0d10;

  /* ---- Semantic ---- */
  --ok: #2fbf71;
  --warn: #ffb020;
  --error: #ff3b30;
  --ok-soft: rgba(47, 191, 113, 0.14);
  --warn-soft: rgba(255, 176, 32, 0.14);
  --error-soft: rgba(255, 59, 48, 0.14);

  /* ---- Type ---- */
  --font-display: "Archivo", "Arial Black", sans-serif;
  --font-body: "Archivo", "Helvetica Neue", sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", monospace;

  /* ---- Radii: technical, near-square ---- */
  --radius-1: 2px;
  --radius-2: 4px;
  --radius-full: 999px;

  /* ---- Motion: fast and dry, like a shutter ---- */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 120ms;
  --dur-base: 200ms;

  /* ---- Effects ---- */
  --shadow-overlay: 0 24px 64px rgba(0, 0, 0, 0.6);
  --scrim-bottom: linear-gradient(180deg, rgba(5,6,7,0) 40%, rgba(5,6,7,0.82) 100%);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ink-0);
  color: var(--fg-1);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: flex;
  min-height: 100vh;
}

::selection { background: var(--signal); color: var(--on-signal); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--ink-4); border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

a { color: var(--fg-1); text-decoration-color: var(--signal); text-underline-offset: 3px; transition: color var(--dur-fast) var(--ease-out); }
a:hover { color: var(--signal); }

/* ---- Display type ---- */
.t-display {
  font-family: var(--font-display);
  font-weight: 900;
  font-stretch: 125%;
  text-transform: uppercase;
  line-height: 0.95;
  letter-spacing: -0.01em;
}

/* ---- Meta EXIF text ---- */
.meta {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--fg-2);
}
.meta.faint { color: var(--fg-3); font-size: 10px; }
.meta.signal { color: var(--signal); }

/* ============================================================
   Sidebar
   ============================================================ */

nav.sidebar {
  width: 264px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 24px 16px;
  background: var(--ink-1);
  border-right: 1px solid var(--line-1);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 900;
  font-stretch: 125%;
  text-transform: uppercase;
  font-size: 22px;
  letter-spacing: -0.02em;
  padding: 0 8px;
}
.wordmark .w1 { color: var(--fg-1); }
.wordmark .w2 { color: var(--signal); }

.sidebar-tag { padding: 2px 8px 20px; }

.nav-group-label { padding: 14px 14px 8px; }

nav.sidebar a.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  position: relative;
  border-radius: var(--radius-1);
  color: var(--fg-2);
  text-decoration: none;
  font-size: 15px;
  font-weight: 400;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
nav.sidebar a.nav-item:hover { background: var(--ink-3); color: var(--fg-1); }
nav.sidebar a.nav-item.active { background: var(--signal-soft); color: var(--fg-1); font-weight: 600; }
nav.sidebar a.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--signal);
  border-radius: 999px;
}
nav.sidebar a.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
nav.sidebar a.nav-item.active svg { color: var(--signal); }

.sidebar-foot {
  border-top: 1px solid var(--line-1);
  margin-top: auto;
  padding: 14px 12px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.dot-ok { width: 7px; height: 7px; border-radius: 999px; background: var(--ok); flex-shrink: 0; }

/* ============================================================
   Layout / page
   ============================================================ */

main {
  flex: 1;
  min-width: 0;
  padding: 48px 32px 80px;
  max-width: 1120px;
  width: 100%;
}

.page-header { margin-bottom: 32px; }
.page-header .eyebrow { display: block; margin-bottom: 10px; }
.page-header h1 { margin: 0; font-size: 34px; color: var(--fg-1); }
.page-header .subtitle { margin: 10px 0 0; color: var(--fg-2); font-size: 15px; max-width: 640px; }
.page-header .header-meta { margin-top: 14px; }

/* Staggered page entry — fast and dry */
@media (prefers-reduced-motion: no-preference) {
  .page-anim > * { animation: pageItem 240ms var(--ease-out) both; }
  .page-anim > *:nth-child(2) { animation-delay: 50ms; }
  .page-anim > *:nth-child(3) { animation-delay: 100ms; }
  .page-anim > *:nth-child(4) { animation-delay: 150ms; }
  .page-anim > *:nth-child(5) { animation-delay: 200ms; }
  .page-anim > *:nth-child(6) { animation-delay: 250ms; }
  .page-anim > *:nth-child(7) { animation-delay: 300ms; }
  .page-anim > *:nth-child(8) { animation-delay: 350ms; }
}
@keyframes pageItem { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ============================================================
   Cards
   ============================================================ */

.card {
  background: var(--ink-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius-1);
  padding: 24px;
  margin-bottom: 16px;
  transition: background var(--dur-fast) var(--ease-out);
}
.card.hover:hover { background: var(--ink-3); }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.card-head .ch-left { display: flex; align-items: center; gap: 12px; }
.card-head svg { width: 18px; height: 18px; color: var(--signal); flex-shrink: 0; }
.card-head .ch-title { font-weight: 600; font-size: 18px; color: var(--fg-1); line-height: 1.2; }
.card-head .ch-sub { color: var(--fg-2); font-size: 13px; margin-top: 2px; }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
  align-items: start;
}
.grid-cards .card { margin-bottom: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---- Section rule with label ---- */
.rule {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 32px 0 24px;
}
.rule::after { content: ""; flex: 1; height: 1px; background: var(--line-1); }

/* ============================================================
   Stat / KPI cards
   ============================================================ */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.tile {
  background: var(--ink-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius-1);
  padding: 16px;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  transition: background var(--dur-fast) var(--ease-out);
}
.tile:hover { background: var(--ink-3); }
.tile .tile-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tile .tile-top svg { width: 16px; height: 16px; color: var(--fg-3); }
.tile .tile-value { margin-top: auto; }
.tile .tile-num { font-size: 34px; color: var(--fg-1); }

/* ---- Hero strip (dashboard) ---- */
.hero {
  position: relative;
  border-radius: var(--radius-1);
  overflow: hidden;
  border: 1px solid var(--line-1);
  margin-bottom: 24px;
  min-height: 220px;
  background:
    radial-gradient(120% 140% at 85% 10%, rgba(255, 77, 0, 0.16), transparent 55%),
    radial-gradient(100% 120% at 10% 90%, rgba(255, 77, 0, 0.06), transparent 50%),
    var(--ink-1);
  background-size: cover;
  background-position: center;
}
.hero::after { content: ""; position: absolute; inset: 0; background: var(--scrim-bottom); pointer-events: none; }
.hero-inner {
  position: relative;
  z-index: 1;
  padding: 24px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.hero-chips { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.hero-chips .meta { background: rgba(5,6,7,.55); padding: 6px 10px; backdrop-filter: blur(6px); }
.hero-title { font-size: clamp(28px, 5vw, 44px); color: #fff; margin-top: 6px; text-shadow: 0 2px 20px rgba(0,0,0,.6); }

/* ---- Stage rows (dashboard panels) ---- */
.stage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--line-1);
}
.stage-row:last-child { border-bottom: none; }
.stage-row .stage-num { font-size: 22px; color: var(--fg-1); }
.stage-row .stage-num.ok { color: var(--ok); }
.stage-row .stage-num.warn { color: var(--warn); }

/* ============================================================
   Key/value rows
   ============================================================ */

.kv {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 20px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line-1);
}
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--fg-2); font-size: 13px; }
.kv .v { color: var(--fg-1); font-weight: 500; word-break: break-word; }
.kv .v.mono { font-family: var(--font-mono); font-size: 13px; }

/* ============================================================
   Tables
   ============================================================ */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--line-2);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--fg-2);
}
td {
  padding: 16px;
  border-bottom: 1px solid var(--line-1);
  font-size: 13px;
  color: var(--fg-1);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--dur-fast) var(--ease-out); }
tbody tr:hover { background: var(--ink-1); }
td.mono, .mono { font-family: var(--font-mono); font-size: 13px; }
th.right, td.right { text-align: right; }
td .td-sub { color: var(--fg-3); font-size: 12px; margin-top: 2px; }
td .td-num { font-size: 17px; }

/* ============================================================
   Forms
   ============================================================ */

label {
  display: block;
  margin: 16px 0 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-2);
}
label:first-child { margin-top: 0; }
label .help {
  display: block;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  color: var(--fg-3);
  margin-top: 3px;
}

input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--ink-1);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-1);
  color: var(--fg-1);
  font-size: 15px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease-out);
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { border-color: var(--signal); }
input::placeholder, textarea::placeholder { color: var(--fg-3); }

/* Operator reply box (conversaciones) */
.reply-row td { border-top: none; }
.reply-box summary {
  cursor: pointer;
  color: var(--fg-2);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px;
}
.reply-box summary svg { width: 13px; height: 13px; }
.reply-box[open] summary { color: var(--fg-1); }
.reply-body {
  margin-top: 8px;
  padding: 12px;
  background: var(--ink-1);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-1);
}
.reply-thread { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.reply-msg {
  padding: 6px 10px;
  background: var(--ink-3);
  border-radius: var(--radius-1);
  font-size: 14px;
  border-left: 2px solid var(--line-2);
}
.reply-msg.dir-in { border-left-color: var(--ok); }
.reply-msg.dir-operator { border-left-color: var(--signal); }
.reply-msg > div { margin-top: 2px; white-space: pre-wrap; }
.check-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--fg-2);
  margin: 0;
}
.check-inline input[type=checkbox] { width: auto; margin: 0; }

input[type=file] { color: var(--fg-2); font-size: 13px; margin-top: 4px; }
input[type=file]::file-selector-button {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  font-size: 11px;
  padding: 7px 14px;
  margin-right: 12px;
  background: transparent;
  color: var(--fg-1);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-1);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
input[type=file]::file-selector-button:hover { border-color: var(--line-3); background: var(--ink-3); }

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23686d77' stroke-width='1.6' stroke-linecap='square'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

/* ============================================================
   Buttons — mono, uppercase, shutter-fast
   ============================================================ */

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  font-size: 12px;
  padding: 10px 20px;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius-1);
  cursor: pointer;
  white-space: nowrap;
  margin-top: 16px;
  margin-right: 8px;
  text-decoration: none;
  background: var(--signal);
  color: var(--on-signal);
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
button:hover, .btn:hover { background: var(--signal-hover); }
button:active, .btn:active { background: var(--signal-press); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button svg, .btn svg { width: 14px; height: 14px; }

button.secondary, .btn.secondary {
  background: transparent;
  color: var(--fg-1);
  border-color: var(--line-2);
}
button.secondary:hover { border-color: var(--line-3); background: var(--ink-3); }
button.secondary:active { background: var(--ink-2); }

button.danger { background: var(--error); color: #fff; }
button.danger:hover { background: #ff544a; }

button.danger-outline {
  background: transparent;
  color: var(--error);
  border-color: rgba(255, 59, 48, 0.4);
}
button.danger-outline:hover { background: var(--error-soft); }

button.ghost {
  background: transparent;
  color: var(--fg-2);
}
button.ghost:hover { color: var(--fg-1); background: var(--ink-3); }

button.sm { font-size: 11px; padding: 7px 14px; min-height: 32px; margin-top: 0; }

/* ============================================================
   Badges
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--ink-3);
  color: var(--fg-2);
}
.badge::before { content: none; }
.badge.dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 999px;
  background: currentColor;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--error-soft); color: var(--error); }
.badge.signal { background: var(--signal-soft); color: var(--signal); }

/* ============================================================
   Banners
   ============================================================ */

.error, .message, .notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border-radius: var(--radius-1);
  padding: 14px 16px;
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.5;
}
.error { background: var(--error-soft); border: 1px solid rgba(255, 59, 48, 0.28); color: var(--fg-1); }
.error::before { content: "!"; font-family: var(--font-mono); font-weight: 600; color: var(--error); }
.message { background: var(--ok-soft); border: 1px solid rgba(47, 191, 113, 0.28); color: var(--fg-1); }
.message::before { content: "✓"; font-family: var(--font-mono); font-weight: 600; color: var(--ok); }
.notice { background: var(--warn-soft); border: 1px solid rgba(255, 176, 32, 0.28); color: var(--warn); }
.notice::before { content: "▲"; font-size: 10px; margin-top: 3px; color: var(--warn); }

.muted { color: var(--fg-2); }
.faint { color: var(--fg-3); }
.small { font-size: 13px; }

/* ============================================================
   Details / advanced settings disclosure
   ============================================================ */

details summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
  color: var(--fg-1);
  list-style: none;
}
details summary::-webkit-details-marker { display: none; }
details summary .meta { margin-left: auto; }
details summary::after {
  content: "";
  width: 8px; height: 8px;
  border-right: 1.6px solid var(--fg-3);
  border-bottom: 1.6px solid var(--fg-3);
  transform: rotate(45deg);
  transition: transform var(--dur-fast) var(--ease-out);
  flex-shrink: 0;
}
details[open] summary::after { transform: rotate(-135deg); }
details[open] summary { margin-bottom: 8px; }
details summary svg { width: 16px; height: 16px; color: var(--fg-2); }

/* ============================================================
   Log viewer
   ============================================================ */

pre.log {
  background: var(--ink-0);
  border: 1px solid var(--line-1);
  border-radius: var(--radius-1);
  padding: 14px;
  max-height: 340px;
  overflow-y: auto;
  font-size: 12px;
  font-family: var(--font-mono);
  white-space: pre-wrap;
  color: var(--fg-2);
}

/* ============================================================
   Guide steps
   ============================================================ */

.step-card { display: flex; gap: 18px; align-items: flex-start; }
.step-icon {
  color: var(--signal);
  background: var(--signal-soft);
  width: 44px; height: 44px;
  border-radius: var(--radius-1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.step-icon svg { width: 20px; height: 20px; }
.step-card .step-title { font-weight: 600; font-size: 18px; }
.step-card .step-desc { color: var(--fg-2); font-size: 13px; margin-top: 4px; }
.step-card a { color: var(--signal); }

/* ============================================================
   Splash
   ============================================================ */

#splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--ink-0);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity 360ms var(--ease-out);
}
#splash[hidden] { display: none; }
#splash.out { opacity: 0; pointer-events: none; }
#splash .splash-mark { font-size: clamp(40px, 8vw, 84px); animation: splashUp 500ms var(--ease-out) both; }
#splash .splash-line { width: 220px; height: 1px; background: var(--line-2); position: relative; overflow: hidden; }
#splash .splash-line span {
  position: absolute; inset: 0;
  background: var(--signal);
  transform-origin: left;
  animation: splashSweep 1.2s var(--ease-out) 200ms both;
}
#splash .meta { animation: splashFade 400ms var(--ease-out) 500ms both; }
#splash .meta.faint { animation-delay: 800ms; }
@keyframes splashUp { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes splashFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes splashSweep { from { transform: scaleX(0); } to { transform: scaleX(1); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  #splash { display: none; }
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 900px) {
  nav.sidebar { display: none; }
  main { padding: 24px 16px 60px; }
}

/* ============================================================
   Job progress bar (OCR)
   ============================================================ */
.progress-wrap { margin: 10px 0 14px; }
.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--ink-3);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--signal);
  transition: width 0.6s ease;
}
.progress-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  color: var(--fg-2);
}

.row-actions { display: flex; gap: 10px; align-items: center; }

.radio-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line-1);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}
.radio-chip:has(input:checked) { border-color: var(--signal); background: var(--signal-soft); }
.radio-chip input { width: auto; margin: 0; accent-color: var(--signal); }
