/* Control de Obras — misma base visual que Melasur Ops (variables, temas y shell) */
:root {
  --bg: #0f1419;
  --surface: #1a222d;
  --surface2: #243041;
  --text: #eef2f7;
  --muted: #94a3b8;
  --primary: #c2783a;
  --primary-dark: #9a5f2e;
  --primary-rgb: 194,120,58;
  --primary-light: #f0c090;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --info: #2563eb;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0,0,0,.25);
  --sidebar-w: 240px;
}
body[data-theme="clasico"] {
  --bg: #f0f2f5; --surface: #ffffff; --surface2: #d6d9de; --text: #1a1a1a; --muted: #5f6368;
  --primary-dark: #005a9e; --primary-light: #0b5cad;
  --danger: #d13438; --ok: #107c10; --warn: #ca5010; --radius: 6px; --shadow: 0 2px 8px rgba(0,0,0,.14);
}
body[data-theme="minimalista"] {
  --bg: #ffffff; --surface: #f8f9fa; --surface2: #e8eaed; --text: #202124; --muted: #5f6368;
  --primary-dark: #1557b0; --primary-light: #1a56c4;
  --danger: #d93025; --ok: #188038; --warn: #e37400; --radius: 8px;
  --shadow: 0 1px 3px rgba(60,64,67,.15), 0 4px 8px rgba(60,64,67,.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body { font-family: system-ui, -apple-system, Segoe UI, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* Shell */
.app-shell-body { overflow-x: hidden; }
.app-shell { display: flex; min-height: 100vh; width: 100%; }
.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.main-content { flex: 1; padding: 1.25rem 1.5rem 1rem; max-width: 1280px; width: 100%; }
.app-footer { padding: .75rem 1.5rem 1.25rem; font-size: .72rem; border-top: 1px solid var(--surface2); }

.sidebar { width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--surface2); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 40; }
.sidebar-brand { display: flex; align-items: center; gap: .55rem; padding: 1rem 1rem .85rem; color: var(--text); font-weight: 700; border-bottom: 1px solid var(--surface2); }
.sidebar-brand:hover { text-decoration: none; opacity: .92; }
.brand-text small { font-weight: 500; color: var(--muted); }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; display: grid; place-items: center; font-weight: 800; flex-shrink: 0; }
.sidebar-nav { flex: 1; min-height: 0; overflow-y: auto; padding: .5rem .45rem; display: flex; flex-direction: column; gap: .35rem; }
.sidebar-group { border-radius: 9px; background: rgba(0,0,0,.12); overflow: hidden; }
body[data-theme="clasico"] .sidebar-group, body[data-theme="minimalista"] .sidebar-group { background: rgba(0,0,0,.035); }
.sidebar-group-toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .6rem; border: none; border-left: 3px solid transparent; background: transparent; color: inherit; cursor: pointer; text-align: left; font: inherit; }
.sidebar-group-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.sidebar-group-chevron { width: .45rem; height: .45rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .2s; opacity: .75; margin-top: -.15rem; }
.sidebar-group.is-open .sidebar-group-chevron { transform: rotate(-135deg); margin-top: .1rem; }
.sidebar-group-panel { display: none; padding: 0 .35rem .35rem; flex-direction: column; gap: .12rem; }
.sidebar-group.is-open .sidebar-group-panel { display: flex; }
.sidebar-group--ops .sidebar-group-toggle { border-left-color: var(--primary); color: var(--primary-light); }
.sidebar-group--sgc .sidebar-group-toggle { border-left-color: #4ade80; color: #16a34a; }
.sidebar-group--sistema .sidebar-group-toggle { border-left-color: #60a5fa; color: #3b82f6; }
body[data-theme="alto_contraste"] .sidebar-group--sgc .sidebar-group-toggle { color: #bbf7d0; }
body[data-theme="alto_contraste"] .sidebar-group--sistema .sidebar-group-toggle { color: #bfdbfe; }
.sidebar-link { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .55rem .65rem; border-radius: 8px; color: var(--muted); font-size: .88rem; }
.sidebar-link:hover { color: var(--text); background: rgba(127,127,127,.08); text-decoration: none; }
.sidebar-link.active { color: var(--text); background: rgba(var(--primary-rgb),.18); font-weight: 600; }
.sidebar-badge { font-size: .68rem; font-weight: 700; padding: .1rem .35rem; border-radius: 999px; background: rgba(217,119,6,.25); color: #f59e0b; }
.sidebar-foot { flex-shrink: 0; padding: .85rem 1rem; border-top: 1px solid var(--surface2); display: flex; flex-direction: column; gap: .45rem; }
.sidebar-user-name { display: block; font-size: .85rem; font-weight: 600; }
.sidebar-user-role { display: block; font-size: .72rem; color: var(--muted); }
.sidebar-logout { font-size: .78rem; color: var(--muted); }
.sidebar-version { font-size: .65rem; color: var(--muted); opacity: .7; }
.mobile-topbar { display: none; align-items: center; gap: .75rem; padding: .65rem 1rem; background: var(--surface); border-bottom: 1px solid var(--surface2); position: sticky; top: 0; z-index: 30; }
.sidebar-toggle { background: var(--surface2); border: none; color: var(--text); width: 36px; height: 36px; border-radius: 8px; font-size: 1.1rem; cursor: pointer; }
.mobile-title { font-size: .95rem; font-weight: 600; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 35; }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; height: auto; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop:not([hidden]) { display: block; }
  .mobile-topbar { display: flex; }
  .main-content { padding: 1rem; }
  body.sidebar-open { overflow: hidden; }
}

/* Componentes */
.card { background: var(--surface); border: 1px solid var(--surface2); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card h2 { font-size: 1.05rem; margin-bottom: .65rem; }
.card h3 { font-size: .95rem; margin: .5rem 0; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-title-row h2 { margin: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { font-size: 1.4rem; }
.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: .75rem; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; border: none; border-radius: 8px; padding: .6rem 1rem; font-weight: 600; cursor: pointer; font-size: .9rem; font-family: inherit; line-height: 1.2; }
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-small { padding: .32rem .55rem; font-size: .75rem; }
.btn-danger { background: rgba(220,38,38,.18); color: var(--danger); border: 1px solid rgba(220,38,38,.4); }
.btn-success { background: var(--ok); color: #fff; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.inline-form { display: inline; }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.flash.error { background: rgba(220,38,38,.15); color: var(--danger); border: 1px solid rgba(220,38,38,.3); }
.flash.ok { background: rgba(22,163,74,.15); color: var(--ok); border: 1px solid rgba(22,163,74,.3); }
body[data-theme="alto_contraste"] .flash.error { color: #fecaca; }
body[data-theme="alto_contraste"] .flash.ok { color: #bbf7d0; }

.form-stack { display: grid; gap: .85rem; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem 1rem; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem 1rem; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem 1rem; }
@media (max-width: 700px) { .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; } }
.field { display: grid; gap: .35rem; font-size: .85rem; color: var(--muted); }
.field input, .field select, .field textarea, .mini-input {
  width: 100%; padding: .6rem .7rem; border-radius: 8px; border: 1px solid var(--surface2);
  background: var(--bg); color: var(--text); font-size: .95rem; font-family: inherit;
}
.mini-input { padding: .35rem .5rem; font-size: .85rem; width: auto; }
.field textarea { resize: vertical; min-height: 4rem; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus, .mini-input:focus { outline: none; border-color: var(--primary); }
.check { display: flex; align-items: center; gap: .45rem; font-size: .88rem; color: var(--text); cursor: pointer; }
.check input { width: 1rem; height: 1rem; accent-color: var(--primary); }
.field-hint { font-size: .78rem; color: var(--muted); }
details.card > summary { cursor: pointer; font-weight: 600; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: '+ '; color: var(--primary); }
details.card[open] > summary::before { content: '− '; }
details.card[open] > summary { margin-bottom: .85rem; }

.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.data-table th, .data-table td { text-align: left; padding: .5rem .45rem; border-bottom: 1px solid var(--surface2); vertical-align: middle; }
.data-table th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.data-table tfoot td { font-weight: 700; border-top: 2px solid var(--surface2); }
.data-table tr.row-titulo td { background: rgba(var(--primary-rgb),.07); font-weight: 600; }
.data-table tr.row-nivel-0.row-titulo td { background: rgba(var(--primary-rgb),.13); }
.data-table tr:hover td { background: rgba(127,127,127,.05); }

.filter-bar { display: flex; gap: .4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-pill { font-size: .8rem; padding: .35rem .7rem; border-radius: 999px; background: var(--surface2); color: var(--text); }
.filter-pill.active, .filter-pill:hover { background: var(--primary); color: #fff; text-decoration: none; }

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--surface2); border-radius: var(--radius); padding: .8rem .9rem; }
.stat b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat.stat-ok b { color: var(--ok); } .stat.stat-warn b { color: var(--warn); } .stat.stat-info b { color: var(--info); }

/* Barra de avance con marca de programado */
.progress { position: relative; display: inline-block; width: 100%; min-width: 70px; height: .55rem; border-radius: 999px; background: var(--surface2); overflow: visible; vertical-align: middle; }
.progress-fill { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--primary); }
.progress.done .progress-fill { background: var(--ok); }
.progress-plan { position: absolute; top: -.2rem; bottom: -.2rem; width: 2px; background: var(--text); opacity: .7; }
.progress-cell { display: flex; align-items: center; gap: .5rem; min-width: 140px; }
.progress-cell small { min-width: 3.2rem; text-align: right; font-variant-numeric: tabular-nums; }
.progress-lg { height: .9rem; }

/* Obra */
.obra-head { margin-bottom: .75rem; }
.obra-head h1 { font-size: 1.35rem; margin: .2rem 0; }
.obra-head-code { font-size: .8rem; color: var(--muted); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--surface2); margin-bottom: 1rem; overflow-x: auto; }
.tab { padding: .55rem .85rem; color: var(--muted); border-bottom: 2px solid transparent; font-size: .88rem; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.estado-pill, .tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px; background: var(--surface2); color: var(--text); }
.estado-en_ejecucion, .ep-emitido { background: rgba(37,99,235,.18); color: #3b82f6; }
.estado-adjudicada, .ep-aprobado { background: rgba(var(--primary-rgb),.2); color: var(--primary); }
.estado-detenida, .ep-borrador { background: rgba(217,119,6,.18); color: #d97706; }
.estado-terminada, .estado-cerrada, .ep-pagado { background: rgba(22,163,74,.18); color: #16a34a; }
.ep-anulado { background: rgba(220,38,38,.15); color: #dc2626; text-decoration: line-through; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; font-size: .88rem; }
.dl dt { color: var(--muted); }

/* Matriz recintos × partidas */
.matriz { border-collapse: collapse; font-size: .75rem; }
.matriz th, .matriz td { border: 1px solid var(--surface2); padding: .25rem .35rem; text-align: center; white-space: nowrap; }
.matriz thead th { position: sticky; top: 0; background: var(--surface); writing-mode: vertical-rl; transform: rotate(180deg); max-height: 160px; font-weight: 600; }
.matriz th.rec { text-align: left; position: sticky; left: 0; background: var(--surface); writing-mode: horizontal-tb; transform: none; }
.matriz td.na { background: transparent; color: var(--muted); opacity: .4; }
.matriz td.c0 { background: rgba(148,163,184,.12); }
.matriz td.cp { background: rgba(217,119,6,.25); }
.matriz td.c100 { background: rgba(22,163,74,.35); }
.matriz td button { all: unset; cursor: pointer; display: block; width: 100%; }
.matriz-legend { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .75rem; margin-top: .5rem; }
.matriz-legend span::before { content: ''; display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; margin-right: .3rem; vertical-align: -2px; }
.lg-0::before { background: rgba(148,163,184,.3); } .lg-p::before { background: rgba(217,119,6,.5); } .lg-100::before { background: rgba(22,163,74,.6); }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .3rem .75rem; max-height: 300px; overflow-y: auto; padding: .5rem; border: 1px solid var(--surface2); border-radius: 8px; }

/* Libro de obra */
.libro-entry { border-left: 3px solid var(--primary); padding: .6rem .9rem; margin-bottom: .85rem; background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; }
.libro-entry header { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; font-size: .78rem; color: var(--muted); }
.libro-entry h3 { font-size: .98rem; margin: .25rem 0; }
.libro-entry p { white-space: pre-line; font-size: .9rem; line-height: 1.5; }
.libro-incidente { border-left-color: var(--danger); }
.libro-instruccion { border-left-color: var(--info); }
.libro-entrega { border-left-color: var(--ok); }
.fotos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .4rem; margin-top: .5rem; }
.fotos a { display: block; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: var(--surface2); }
.fotos img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at top, rgba(var(--primary-rgb),.14), transparent 40%), var(--bg); }
.auth-box { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--surface2); border-radius: 14px; padding: 1.5rem; box-shadow: var(--shadow); }
.auth-logo { font-size: .8rem; letter-spacing: .15em; text-transform: uppercase; color: var(--primary); margin-bottom: .25rem; }
.auth-box h1 { font-size: 1.35rem; margin-bottom: .25rem; }

/* Público */
.public-top { display: flex; align-items: center; gap: .6rem; padding: .85rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--surface2); font-weight: 700; }
.public-tagline { margin-left: auto; font-weight: 400; color: var(--muted); font-size: .85rem; }
.wrap { max-width: 1000px; margin: 0 auto; padding: 1.25rem; }
.footer { text-align: center; color: var(--muted); font-size: .75rem; padding: 2rem 1rem; }

/* Impresión (EP) */
.print-only { display: none; }
@media print {
  .sidebar, .mobile-topbar, .app-footer, .tabs, .no-print, .flash { display: none !important; }
  .print-only { display: block; }
  body, .app-main, .card { background: #fff !important; color: #000 !important; box-shadow: none !important; }
  .card { border: none; padding: 0; }
  .main-content { padding: 0; max-width: none; }
  .data-table th, .data-table td { border-color: #bbb; color: #000; }
}
