/* ============ Tokens ============ */
:root {
  --paper: #f6f4ee;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --ink: #262524;
  --ink-muted: #5b5957;
  --ink-faint: #8d8a86;
  --border: #e3ded2;
  --border-soft: #efece3;
  --accent: #fbb900;
  --accent-strong: #8a5400;
  --accent-soft: #fdecc5;
  --accent-ink: #402900;
  --on-accent: #2a1c00;
  --good: #2d7a53;
  --good-soft: #e3f2e8;
  --warn: #a1631b;
  --warn-soft: #f8ecdb;
  --bad: #ad3b30;
  --bad-soft: #fbe8e5;
  --focus: #8a5400;
  --shadow: 0 1px 2px rgba(30, 32, 26, 0.06), 0 4px 14px rgba(30, 32, 26, 0.05);
  --shadow-lg: 0 8px 30px rgba(20, 24, 20, 0.14);
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --font-display: "Archivo", "Arial Narrow", sans-serif;
  --font-body: "Public Sans", -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #181715;
    --surface: #1f1d1a;
    --surface-raised: #262320;
    --ink: #f1efe9;
    --ink-muted: #b6b1a8;
    --ink-faint: #7d786f;
    --border: #34302a;
    --border-soft: #2a2723;
    --accent: #ffc94d;
    --accent-strong: #ffd98a;
    --accent-soft: #3a2c10;
    --accent-ink: #ffe8b8;
    --on-accent: #2a1c00;
    --good: #5fbf8a;
    --good-soft: #17281f;
    --warn: #e0a355;
    --warn-soft: #2c2214;
    --bad: #e2776b;
    --bad-soft: #2c1917;
    --focus: #ffd98a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --paper: #181715;
  --surface: #1f1d1a;
  --surface-raised: #262320;
  --ink: #f1efe9;
  --ink-muted: #b6b1a8;
  --ink-faint: #7d786f;
  --border: #34302a;
  --border-soft: #2a2723;
  --accent: #ffc94d;
  --accent-strong: #ffd98a;
  --accent-soft: #3a2c10;
  --accent-ink: #ffe8b8;
  --on-accent: #2a1c00;
  --good: #5fbf8a;
  --good-soft: #17281f;
  --warn: #e0a355;
  --warn-soft: #2c2214;
  --bad: #e2776b;
  --bad-soft: #2c1917;
  --focus: #ffd98a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; text-wrap: balance; color: var(--ink); }
p { margin: 0; }
a { color: var(--accent-strong); }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
table { border-collapse: collapse; width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }
.tnum { font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ============ App shell ============ */
.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.brand-row { display: flex; align-items: center; gap: 9px; }
.brand-badge { flex: none; }
.brand-badge circle { fill: var(--accent); }
.brand-badge text {
  fill: #fff;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 18px;
}
.brand-lockup { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-lockup .unl {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 13.5px;
  letter-spacing: 0.01em;
  color: var(--accent-strong);
}
.brand-lockup .fac {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 9.3px;
  letter-spacing: 0.01em;
  line-height: 1.25;
  color: var(--ink-muted);
  text-transform: uppercase;
}
.brand .sub {
  font-size: 11.5px;
  color: var(--ink-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  padding: 14px 10px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-s);
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 13.7px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  text-align: left;
  width: 100%;
}
.nav-item .ic { width: 17px; height: 17px; flex: none; opacity: 0.85; }
.nav-item:hover { background: var(--border-soft); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.sidebar-foot {
  margin-top: auto;
  padding: 10px;
  font-size: 11.5px;
  color: var(--ink-faint);
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
}

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { font-size: 21px; font-weight: 700; }
.topbar .eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin-bottom: 2px;
  display: block;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.view { padding: 24px 28px 60px; flex: 1; min-width: 0; }

/* status banners */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-s);
  font-size: 13px;
  margin-bottom: 18px;
  border: 1px solid transparent;
}
.banner.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.info { background: var(--accent-soft); color: var(--accent-strong); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.banner.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 13.3px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.nav-item, a.link-row { text-decoration: none; }
.btn:hover { border-color: var(--ink-faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(0.93); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--border-soft); }
.btn.sm { padding: 5px 10px; font-size: 12.3px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: var(--radius-s);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--ink-muted);
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-faint); }
.icon-btn svg { width: 15px; height: 15px; }
.btn svg { width: 15px; height: 15px; flex: none; }

/* ============ Cards / layout blocks ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow);
}
.card .card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.card .card-head h3 { font-size: 15px; font-weight: 700; }
.card .card-head .hint { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.card .card-body { padding: 18px 20px; }
.card .card-body.pad-0 { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 980px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

/* KPI */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); }
.kpi .value { font-family: var(--font-display); font-size: 30px; font-weight: 800; margin-top: 6px; color: var(--ink); }
.kpi .value .unit { font-size: 14px; font-weight: 600; color: var(--ink-muted); margin-left: 4px; }
.kpi .delta { font-size: 12px; color: var(--ink-muted); margin-top: 4px; }

/* Bars (share visualization, no chart lib) */
.barlist { display: flex; flex-direction: column; gap: 10px; }
.barrow { display: grid; grid-template-columns: 168px 1fr 52px; align-items: center; gap: 10px; }
.barrow .blabel { font-size: 12.6px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barrow .btrack { height: 8px; background: var(--border-soft); border-radius: 5px; overflow: hidden; }
.barrow .bfill { height: 100%; background: var(--accent); border-radius: 5px; }
.barrow .bval { font-size: 12.3px; color: var(--ink-muted); text-align: right; font-family: var(--font-mono); }

/* Tables */
.table-wrap { overflow-x: auto; }
.dtable { width: 100%; border-collapse: collapse; font-size: 13.2px; }
.dtable th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-faint); font-weight: 600; padding: 9px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; background: var(--surface);
}
.dtable td { padding: 10px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.dtable tbody tr:hover { background: var(--border-soft); }
.dtable td.num, .dtable th.num { text-align: right; font-family: var(--font-mono); }
.dtable .actions-col { width: 1%; white-space: nowrap; text-align: right; }
.dtable a.link-row { color: var(--ink); text-decoration: none; font-weight: 600; }
.dtable a.link-row:hover { color: var(--accent-strong); text-decoration: underline; }

/* Chips / badges */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2.5px 9px; border-radius: 100px; font-size: 11.3px; font-weight: 600;
  background: var(--border-soft); color: var(--ink-muted); white-space: nowrap;
}
.chip.blue { background: var(--accent-soft); color: var(--accent-strong); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.cargo-chip {
  display: inline-block; padding: 2px 8px; margin: 1px 4px 1px 0; border-radius: 5px;
  background: var(--accent-soft); color: var(--accent-strong); font-size: 11.6px;
}

/* Forms */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.3px; font-weight: 600; color: var(--ink-muted); }
.field .optional { font-weight: 400; color: var(--ink-faint); }
.input, .select, textarea.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-s);
  background: var(--surface); color: var(--ink); font-size: 13.6px;
}
.input:focus, .select:focus, textarea.input:focus { border-color: var(--focus); }
textarea.input { resize: vertical; min-height: 64px; font-family: var(--font-body); }
.field .err { font-size: 11.8px; color: var(--bad); min-height: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 760px) { .form-grid { grid-template-columns: 1fr; } }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-s); overflow: hidden; }
.seg button {
  padding: 7px 16px; border: none; background: var(--surface); color: var(--ink-muted);
  font-weight: 600; font-size: 12.8px; cursor: pointer; border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--accent); color: var(--on-accent); }

/* Combobox (search-select) */
.combo { position: relative; }
.combo-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m);
  box-shadow: var(--shadow-lg); max-height: 260px; overflow-y: auto; padding: 4px;
}
.combo-opt {
  padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13.2px;
  display: flex; justify-content: space-between; gap: 10px;
}
.combo-opt:hover, .combo-opt.hi { background: var(--accent-soft); }
.combo-opt .m { color: var(--ink-faint); font-size: 11.5px; }
.combo-empty { padding: 12px 10px; color: var(--ink-faint); font-size: 12.6px; }
.combo-selected {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--accent-soft);
}
.combo-selected .who { font-weight: 700; color: var(--accent-ink); font-size: 13.4px; }
.combo-selected .meta { font-size: 11.8px; color: var(--ink-muted); }

/* Search input generic */
.search-box { position: relative; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--ink-faint); }
.search-box input { padding-left: 32px; }

/* Empty state */
.empty {
  text-align: center; padding: 46px 20px; color: var(--ink-faint);
}
.empty .ic { width: 34px; height: 34px; margin: 0 auto 12px; opacity: 0.55; }
.empty .t { font-weight: 700; color: var(--ink-muted); font-size: 14px; margin-bottom: 4px; }
.empty .d { font-size: 12.6px; }

/* Toasts */
#toast-region { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--radius-s);
  font-size: 13px; box-shadow: var(--shadow-lg); max-width: 340px; display: flex; align-items: center; gap: 8px;
  animation: toast-in 0.18s ease-out;
}
.toast.warn { background: var(--warn); color: #2a1c05; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.good { background: var(--good); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Profile header (Consulta) */
.profile-head { display: flex; align-items: flex-start; gap: 16px; }
.avatar {
  width: 52px; height: 52px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-strong);
  display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 800; font-size: 18px; flex: none;
}
.profile-name { font-family: var(--font-display); font-size: 19px; font-weight: 800; }
.profile-meta { color: var(--ink-muted); font-size: 12.8px; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 12px; }

.section-title { font-family: var(--font-display); font-weight: 700; font-size: 14.5px; margin-bottom: 2px; }
.helptext { font-size: 12.4px; color: var(--ink-faint); }

.inline-confirm { display: inline-flex; align-items: center; gap: 6px; }

.pill-count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 100px; background: var(--border-soft); color: var(--ink-muted); font-size: 10.5px; font-weight: 700; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 18, 14, 0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; z-index: 60; overflow-y: auto;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius-l); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 620px; border: 1px solid var(--border);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 20px; border-bottom: 1px solid var(--border-soft);
}
.modal-head h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px; }

/* Tabs (simple) */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button {
  padding: 9px 4px; margin-right: 18px; border: none; background: none; cursor: pointer;
  color: var(--ink-muted); font-weight: 600; font-size: 13.4px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--accent-strong); border-bottom-color: var(--accent); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; height: auto; width: 100%;
    flex-direction: row; align-items: center; gap: 10px;
    padding: 10px 12px; overflow-x: auto; z-index: 8;
  }
  .brand { border-bottom: none; padding: 0 10px 0 0; flex: none; }
  .brand .sub { display: none; }
  .brand-lockup .fac { display: none; }
  .brand-badge { width: 26px; height: 26px; }
  .nav { flex-direction: row; gap: 2px; }
  .nav-group-label { display: none; }
  .nav-item { flex-direction: column; gap: 3px; padding: 6px 10px; font-size: 11px; }
  .nav-item .ic { width: 16px; height: 16px; }
  .sidebar-foot { margin-top: 0; border-top: none; padding-top: 0; flex: none; max-width: 200px; }
  .sidebar-foot .banner { padding: 6px 10px; font-size: 11.5px; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .view { padding: 16px; }
  .profile-head { flex-wrap: wrap; }
}

@media print {
  .sidebar, .topbar-actions, .no-print { display: none !important; }
  .app { display: block; }
  .view { padding: 0; }
}

/* ============ Login screen ============ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
}

/* ============ Documentación adjunta ============ */
.adjuntos-block { display: flex; flex-direction: column; gap: 5px; }
.adjuntos-block > label { font-size: 12.3px; font-weight: 600; color: var(--ink-muted); }
.adjuntos-block input[type="file"] { font-size: 12.5px; max-width: 260px; }
.adjuntos-ul { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.adjuntos-ul li { font-size: 13px; }
.adjuntos-ul .adjunto-row { display: flex; align-items: center; gap: 8px; }
.adjuntos-ul a { display: inline-flex; align-items: center; gap: 5px; color: var(--accent-strong); text-decoration: none; overflow-wrap: anywhere; }
.adjuntos-ul a:hover { text-decoration: underline; }
.adjuntos-ul a svg { width: 14px; height: 14px; flex: none; }
.adjuntos-ul .hint { color: var(--ink-faint); font-size: 11.5px; white-space: nowrap; }
.adjuntos-ul .icon-btn { margin-left: auto; }
.adjuntos-ul .adjunto-quien { margin-top: 1px; white-space: normal; }
