/* Portal de presupuestos — Sistemas de Oficina
   Paleta y tipografía extraídas de los recursos oficiales de sistemasoficina.com
   (tema Avada: --awb-color4 #fa8d24, --awb-color5 #041431, Work Sans). */
@font-face {
  font-family: 'Work Sans';
  src: url('/assets/work-sans-latin.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --navy: #041431;
  --navy-2: #0b2350;
  --orange: #fa8d24;
  --orange-ink: #a85300; /* naranja oscurecido para texto (contraste AA) */
  --ink: #1e1e1e;
  --muted: #4a4e57;
  --line: #e2e2e2;
  --soft: #f7faff;
  --bg: #f4f6fa;
  --white: #ffffff;
  --ok: #157f3b;
  --ok-bg: #e7f6ec;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --crit: #b42318;
  --crit-bg: #fdecea;
  --info: #1d4ed8;
  --info-bg: #eaf1ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(4, 20, 49, 0.06), 0 4px 16px rgba(4, 20, 49, 0.06);
  --font: 'Work Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--navy-2); }
h1, h2, h3, h4 { color: var(--navy); line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--white); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------- Botones y formularios ---------- */
.btn { font: inherit; font-weight: 600; font-size: .9rem; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); background: var(--white); color: var(--navy); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; min-height: 38px; }
.btn:hover { border-color: var(--navy); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: var(--white); }
.btn.primary:hover { background: var(--navy-2); }
.btn.accent { background: var(--orange); border-color: var(--orange); color: var(--navy); }
.btn.danger { color: var(--crit); border-color: #f1b4ae; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: .8rem; }
label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { font: inherit; font-size: .92rem; width: 100%; padding: 8px 10px; border: 1px solid #c9ced8; border-radius: 8px; background: var(--white); color: var(--ink); }
textarea { min-height: 84px; resize: vertical; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { border-color: var(--navy-2); outline: 2px solid rgba(250, 141, 36, .5); outline-offset: 0; }
.field { margin-bottom: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--ink); font-size: .9rem; }

/* ---------- Tarjetas, etiquetas, tablas ---------- */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card h2, .card h3 { margin-bottom: 12px; }
.kpi .label { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .value { font-size: 1.6rem; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #eef1f6; color: var(--navy); white-space: nowrap; }
.badge.demo { background: #fff0e0; color: var(--orange-ink); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.crit { background: var(--crit-bg); color: var(--crit); }
.badge.info { background: var(--info-bg); color: var(--info); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--soft); }
.alert { border-radius: 8px; padding: 10px 12px; font-size: .88rem; border-left: 4px solid; margin-bottom: 8px; }
.alert.critical { background: var(--crit-bg); border-color: var(--crit); }
.alert.warning { background: var(--warn-bg); border-color: #e0a100; }
.alert.info { background: var(--info-bg); border-color: var(--info); }
.alert.ok { background: var(--ok-bg); border-color: var(--ok); }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* ---------- Layout backoffice ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #c8d1e3; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { display: block; padding: 4px 8px 18px; }
.sidebar .brand img { width: 150px; height: auto; display: block; }
.sidebar .brand span { display: block; font-size: .72rem; color: var(--orange); font-weight: 700; letter-spacing: .08em; margin-top: 6px; text-transform: uppercase; }
.nav a { display: flex; align-items: center; gap: 10px; color: #c8d1e3; text-decoration: none; padding: 9px 10px; border-radius: 8px; font-size: .9rem; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); color: var(--white); }
.nav a[aria-current=page] { background: rgba(250,141,36,.16); color: var(--white); box-shadow: inset 3px 0 0 var(--orange); }
.nav .group { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #7d8aa5; padding: 14px 10px 4px; }
.nav .count { margin-left: auto; background: var(--orange); color: var(--navy); border-radius: 999px; font-size: .7rem; font-weight: 700; padding: 0 7px; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--white); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar .who { margin-left: auto; text-align: right; font-size: .85rem; }
.content { padding: 24px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.menu-toggle { display: none; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: 210px minmax(0, 1fr) 310px; gap: 16px; align-items: start; }
.tree { position: sticky; top: 76px; }
.tree ol { list-style: none; padding: 0; margin: 0; }
.tree li a { display: block; padding: 6px 8px; border-radius: 6px; text-decoration: none; color: var(--ink); font-size: .87rem; }
.tree li a:hover { background: var(--soft); }
.tree li.opt a::after { content: 'opcional'; font-size: .65rem; margin-left: 6px; color: var(--orange-ink); font-weight: 700; }
.side { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow-y: auto; }
.section-card { margin-bottom: 16px; }
.section-card .sec-head { display: grid; grid-template-columns: 70px 1fr auto; gap: 8px; align-items: end; margin-bottom: 10px; }
.lines input, .lines select { padding: 6px 8px; font-size: .88rem; }
.line { border-top: 1px solid var(--line); padding: 10px 6px 10px 10px; }
.line-top { display: grid; grid-template-columns: 64px minmax(0, 1fr) 118px auto; gap: 8px; align-items: start; }
.line-tags { margin-top: 4px; gap: 6px; }
.line-amt { font-weight: 700; color: var(--navy); padding-top: 7px; }
.line-nums { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin: 8px 0 0 72px; }
.line-nums label { font-size: .7rem; margin-bottom: 2px; }
.line-detail { background: var(--soft); border-radius: 8px; padding: 12px; margin: 10px 0 0 72px; }
.line-detail .grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.line.has-crit { box-shadow: inset 3px 0 0 var(--crit); }
.line.has-warn { box-shadow: inset 3px 0 0 #e0a100; }
@media (max-width: 640px) {
  .line-top { grid-template-columns: 56px minmax(0, 1fr); }
  .line-nums, .line-detail { margin-left: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.totals dl { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0; font-size: .9rem; }
.totals dt { color: var(--muted); } .totals dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.totals .big { font-size: 1.15rem; color: var(--navy); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { font: inherit; font-size: .9rem; font-weight: 600; background: none; border: 0; padding: 10px 14px; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; }
.tabs button[aria-selected=true] { color: var(--navy); border-bottom-color: var(--orange); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; font-size: .87rem; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--orange); }
.status-bar { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 16px; }
.status-bar .step { font-size: .72rem; padding: 4px 10px; border-radius: 999px; background: #eef1f6; color: var(--muted); font-weight: 600; }
.status-bar .step.done { background: var(--ok-bg); color: var(--ok); }
.status-bar .step.now { background: var(--navy); color: var(--white); }
.saving { font-size: .8rem; color: var(--muted); }

/* ---------- Diálogos y avisos ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(4,20,49,.3); }
dialog::backdrop { background: rgba(4, 20, 49, .55); }
dialog .dlg { padding: 22px; }
dialog .dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--navy); color: var(--white); padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 1000; max-width: 420px; font-size: .9rem; }
.toast.error { background: var(--crit); }
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 100%); padding: 16px; }
.login .card { width: min(400px, 100%); }
.login .logo { background: var(--navy); border-radius: 10px; padding: 18px; margin: -18px -18px 18px; border-radius: 10px 10px 0 0; }
.login .logo img { width: 170px; display: block; }
.demo-banner { background: #fff0e0; color: var(--orange-ink); font-weight: 700; font-size: .8rem; text-align: center; padding: 6px; }

@media (max-width: 1500px) {
  .editor { grid-template-columns: minmax(0, 1fr) 300px; }
  .tree { display: none; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .editor { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* Qué hacer ahora */
.todo { border-left: 4px solid var(--orange); }
.todo-list { list-style: none; margin: 0; padding: 0; }
.todo-list li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.todo-list li:first-child { border-top: 0; }
.todo-list .badge { min-width: 48px; text-align: center; }
@media (max-width: 640px) { .todo-list li { flex-wrap: wrap; } }
