/* =====================================================================
   LIBRO DE OBRA · Bits and Bytes — hoja de estilos
   Paleta corporativa azul/blanco · móvil primero
   ===================================================================== */
:root {
  --bits: #0067B1;
  --bits-dark: #00508A;
  --tech: #009FE3;
  --noche: #123047;
  --noche-2: #1B3F5C;
  --celeste: #DCEFF8;
  --bg: #F7F9FB;
  --card: #FFFFFF;
  --text: #263238;
  --muted: #6B7785;
  --line: #E3E8EE;
  --ok: #27AE60;
  --ok-bg: #E6F6EC;
  --warn: #F2B134;
  --warn-bg: #FEF5E1;
  --warn-text: #8A5A00;
  --danger: #E5484D;
  --danger-bg: #FDECEC;
  --info-bg: #E8F3FB;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(18, 48, 71, .06), 0 4px 16px rgba(18, 48, 71, .06);
  --sidebar: 256px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg); }
a { color: var(--bits); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; color: var(--noche); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: .9rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
p { margin: 0 0 .7em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.neg { color: var(--danger) !important; }
.pos { color: var(--ok) !important; }
.warn-text { color: var(--warn-text); font-weight: 600; }
.ico { flex: none; vertical-align: middle; }
[hidden] { display: none !important; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Estructura ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 40;
  background: var(--noche); color: #CFE0EE; display: flex; flex-direction: column;
  transition: transform .25s ease;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 18px; color: #fff; text-decoration: none !important; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand b { display: block; font-size: 1.05rem; }
.brand small { display: block; color: #8FB3CF; font-size: .78rem; }
.side-nav { padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px; color: #CFE0EE; font-weight: 500; text-decoration: none; }
.side-nav a:hover { background: var(--noche-2); color: #fff; }
.side-nav a.active { background: var(--bits); color: #fff; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 14px 14px 18px; border-top: 1px solid rgba(255,255,255,.08); }
.side-user .who { flex: 1; min-width: 0; }
.side-user b { display: block; color: #fff; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user small { color: #8FB3CF; font-size: .76rem; }
.side-user .icon-btn { color: #CFE0EE; }
.side-user .icon-btn:hover { background: var(--noche-2); color: #fff; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--tech); color: #fff; display: inline-grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none; }
.avatar.sm { width: 28px; height: 28px; font-size: .72rem; vertical-align: middle; margin-right: 6px; }

.main { margin-left: var(--sidebar); min-height: 100vh; display: flex; flex-direction: column; }
.main-full { margin-left: 0; }
.content { padding: 22px 28px 40px; max-width: 1280px; width: 100%; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 18px 28px 10px; background: var(--card); }
.topbar-title { min-width: 0; }
.topbar-title small { color: var(--muted); font-size: .82rem; display: block; }
.topbar-title h1 { font-size: 1.4rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .menu-btn { display: none; }
.scrim { display: none; }
.foot { margin-top: auto; padding: 18px 28px; color: var(--muted); font-size: .78rem; }

.tabs { display: flex; gap: 4px; padding: 0 22px; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; position: sticky; top: 0; z-index: 20; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: flex; align-items: center; gap: 7px; padding: 12px 14px; color: var(--muted); font-weight: 600; font-size: .9rem; border-bottom: 3px solid transparent; white-space: nowrap; text-decoration: none !important; }
.tab:hover { color: var(--bits); }
.tab.active { color: var(--bits); border-bottom-color: var(--bits); }

/* ---------- Componentes ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.card-head a { font-size: .85rem; font-weight: 600; white-space: nowrap; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin-bottom: 2px; }
.page-head p { margin: 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row-inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid-2, .grid-3, .grid-4 { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.gap-lg { gap: 18px; }
.gap-lg > .card { margin-bottom: 0; }
.grid-2.gap-lg { margin-bottom: 18px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--bits); background: var(--bits); color: #fff; font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer; text-decoration: none !important; white-space: nowrap; transition: background .15s; }
.btn:hover { background: var(--bits-dark); }
.btn-ghost { background: #fff; color: var(--bits); border-color: var(--line); }
.btn-ghost:hover { background: var(--celeste); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #c93a3f; }
.btn-sm { padding: 6px 11px; font-size: .84rem; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; border: 0; background: transparent; color: var(--muted); cursor: pointer; position: relative; text-decoration: none !important; }
.icon-btn:hover { background: var(--celeste); color: var(--bits); }
.icon-btn sup { position: absolute; top: 2px; right: 2px; font-size: .62rem; font-weight: 700; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: .74rem; font-weight: 600; background: #EEF1F4; color: var(--muted); white-space: nowrap; }
.chip-ok { background: var(--ok-bg); color: #1D7F46; }
.chip-warn { background: var(--warn-bg); color: var(--warn-text); }
.chip-danger { background: var(--danger-bg); color: #B42328; }
.chip-info { background: var(--info-bg); color: var(--bits); }
.estado-en_ejecucion { background: var(--info-bg); color: var(--bits); }
.estado-terminado { background: var(--ok-bg); color: #1D7F46; }
.estado-pausado { background: var(--warn-bg); color: var(--warn-text); }
.estado-planificacion { background: #EEF1F4; color: var(--muted); }

.bar { height: 8px; border-radius: 99px; background: #EBEFF3; overflow: hidden; margin: 6px 0 4px; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--bits); transition: width .4s; }
.bar-info > span { background: linear-gradient(90deg, var(--bits), var(--tech)); }
.bar-ok > span { background: var(--bits); }
.bar-alerta > span { background: var(--warn); }
.bar-completo > span { background: var(--ok); }
.bar-excedido > span { background: var(--danger); }
.bar-anulado > span { background: #C5CDD5; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; font-size: .92rem; border-left: 4px solid; }
.flash-ok { background: var(--ok-bg); border-color: var(--ok); color: #1D5E37; }
.flash-error { background: var(--danger-bg); border-color: var(--danger); color: #8E1E22; }
.flash-warn { background: var(--warn-bg); border-color: var(--warn); color: #6E4700; }
.flash-info { background: var(--info-bg); border-color: var(--bits); color: var(--noche); }

.empty { text-align: center; padding: 44px 20px; }
.empty-ico { color: var(--tech); display: grid; place-items: center; margin-bottom: 10px; font-size: 36px; }
.empty .btn { margin-top: 8px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; border-top: 3px solid var(--bits); min-width: 0; }
.kpi small { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.kpi b { font-size: 1.45rem; color: var(--noche); font-variant-numeric: tabular-nums; }
.kpi.neg { border-top-color: var(--danger); } .kpi.neg b { color: var(--danger); }
.kpi.pos { border-top-color: var(--ok); } .kpi.pos b { color: #1D7F46; }
.kpi.warn { border-top-color: var(--warn); }
.kpis-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis-sm .kpi b { font-size: 1.2rem; }
.kpis.flat { margin-bottom: 8px; }
.kpis.flat .kpi { box-shadow: none; border: 1px solid var(--line); border-top: 3px solid var(--bits); }

/* Proyectos */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.project-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; color: inherit; text-decoration: none !important; display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s; }
.project-card:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(18,48,71,.12); }
.pc-cover { position: relative; aspect-ratio: 16/9; background: var(--celeste); }
.pc-cover img { width: 100%; height: 100%; object-fit: cover; }
.pc-placeholder { width: 100%; height: 100%; display: grid; place-items: center; color: var(--bits); background: linear-gradient(135deg, var(--celeste), #fff); }
.pc-cover .chip-estado { position: absolute; top: 12px; left: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.pc-cover .pc-alert { position: absolute; top: 12px; right: 12px; }
.pc-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.pc-body h3 { margin: 0; }
.pc-body p { margin: 0; }
.pc-progress { margin-top: 8px; }
.pc-money { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); margin-top: 6px; }
.pc-money small { display: block; color: var(--muted); font-size: .72rem; }
.pc-money b { font-size: .92rem; font-variant-numeric: tabular-nums; }
.pc-foot { display: flex; justify-content: space-between; margin-top: auto; padding-top: 8px; }
.pc-foot span { display: inline-flex; align-items: center; gap: 5px; }

.hero-strip { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; padding: 14px 20px; }
.hs-item small { display: block; color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.hs-grow { flex: 1; min-width: 200px; }

.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.qa { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--bits); color: #fff; border-radius: var(--radius); font-weight: 600; text-decoration: none !important; box-shadow: var(--shadow); }
.qa:nth-child(2) { background: var(--tech); }
.qa:nth-child(3) { background: var(--noche); }
.qa:nth-child(4) { background: #fff; color: var(--bits); }
.qa:hover { filter: brightness(1.07); }

.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 10px; font-size: .9rem; }
.alert .ico { margin-top: 1px; }
.alert-warn { background: var(--warn-bg); color: #6E4700; }
.alert-danger { background: var(--danger-bg); color: #8E1E22; }
.alert-ok { background: var(--ok-bg); color: #1D5E37; }
.alert-info { background: var(--info-bg); color: var(--noche); }
.explain { padding: 12px 20px; }
.explain summary { cursor: pointer; font-weight: 600; color: var(--bits); font-size: .9rem; }
.explain ul { margin: 10px 0 0; padding-left: 18px; }

.mini-timeline { list-style: none; margin: 0; padding: 0; }
.mini-timeline li { display: flex; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mini-timeline li:last-child { border: 0; }
.mt-date { flex: none; width: 46px; text-align: center; background: var(--celeste); border-radius: 10px; padding: 4px 0; color: var(--bits); font-size: .72rem; text-transform: uppercase; font-weight: 700; line-height: 1.1; }
.mt-date b { display: block; font-size: 1.2rem; color: var(--noche); }
.cat-bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.photo-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.photo-strip a, .gallery a, .tl-photos a { display: block; overflow: hidden; border-radius: 10px; background: var(--celeste); }
.photo-strip img { width: 100%; aspect-ratio: 1; object-fit: cover; transition: transform .3s; }
.photo-strip a:hover img, .gallery a:hover img { transform: scale(1.04); }

/* Tablas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 2px solid var(--line); white-space: nowrap; background: #FAFBFC; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:hover { background: #FAFCFE; }
.table tfoot td { border-top: 2px solid var(--line); border-bottom: 0; background: #FAFBFC; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-sm td, .table-sm th { padding: 7px 10px; }
.table-card { padding: 0; overflow: hidden; }
.table .actions { text-align: right; }
.w-check { width: 34px; }
.cat { white-space: nowrap; font-size: .86rem; }
tr.is-void, .is-void { opacity: .55; }
.bulk-bar { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; background: #FAFBFC; }
form.inline { display: inline; }

/* Formularios */
.form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .86rem; color: var(--noche); margin-bottom: 14px; }
.form .grid-2 > label, .form .grid-3 > label, .form .grid-4 > label { margin-bottom: 0; }
.form .grid-2, .form .grid-3, .form .grid-4 { margin-bottom: 14px; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--text); width: 100%; padding: 10px 12px; border: 1px solid #CFD8E0; border-radius: var(--radius-sm); background: #fff; transition: border-color .15s, box-shadow .15s; min-height: 42px; }
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--tech); box-shadow: 0 0 0 3px rgba(0,159,227,.18); }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--bits); flex: none; margin: 2px 0 0; }
input[type=file] { padding: 8px; }
.hint { font-weight: 400; color: var(--muted); font-size: .78rem; }
.form-section { display: flex; align-items: center; gap: 8px; margin: 22px 0 12px; padding-top: 16px; border-top: 1px solid var(--line); font-size: .95rem; color: var(--bits); }
.form > .form-section:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }
.form label.check, label.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; cursor: pointer; }
label.check span b { display: block; font-weight: 600; }
label.check span small { display: block; color: var(--muted); }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; margin-bottom: 14px; }
.check-grid .check { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.narrow { max-width: 480px; }
.danger-zone { border: 1px solid #F5C2C4; }
.danger-zone h3 { color: var(--danger); }
.inline-danger { display: flex; justify-content: flex-end; margin-top: -6px; margin-bottom: 18px; }
.nuevo-proveedor { background: var(--celeste); padding: 14px; border-radius: 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px; }
.filters input[type=search] { flex: 1 1 220px; width: auto; }
.filters select { width: auto; flex: 0 1 200px; }
.filters label.inline { display: flex; align-items: center; gap: 6px; font-size: .84rem; color: var(--muted); font-weight: 600; }
.filters label.inline input { width: auto; }

.dropzone { position: relative; border: 2px dashed #B8CCDD; border-radius: var(--radius); background: #FAFCFE; margin-bottom: 14px; transition: border-color .15s, background .15s; }
.dropzone.drag { border-color: var(--tech); background: var(--celeste); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.dz-label { display: flex !important; flex-direction: column; align-items: center; gap: 4px !important; padding: 24px 16px; text-align: center; color: var(--bits) !important; margin: 0 !important; pointer-events: none; }
.dz-label small { color: var(--muted); font-weight: 400; }
.dz-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; padding: 0 14px; }
.dz-preview:not(:empty) { padding: 0 14px 14px; }
.dz-preview .pv { position: relative; border-radius: 8px; overflow: hidden; background: #fff; border: 1px solid var(--line); aspect-ratio: 1; display: grid; place-items: center; font-size: .7rem; color: var(--muted); text-align: center; padding: 2px; }
.dz-preview .pv img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.upload-progress { margin-top: 10px; }
.upload-progress .bar span { width: 0; }
.edit-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.ep { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; padding-bottom: 6px; }
.ep img { width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.ep input:not([type=checkbox]) { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; font-size: .82rem; min-height: 34px; }
.ep label.check { padding: 6px 8px 0; margin: 0; }

/* Línea de tiempo (bitácora) */
.timeline { position: relative; padding-left: 4px; }
.timeline::before { content: ""; position: absolute; left: 31px; top: 10px; bottom: 10px; width: 2px; background: linear-gradient(var(--tech), var(--celeste)); }
.tl-month { position: relative; margin: 8px 0 14px; }
.tl-month span { display: inline-block; background: var(--noche); color: #fff; padding: 5px 14px; border-radius: 99px; font-weight: 700; font-size: .82rem; position: relative; z-index: 1; }
.tl-item { display: flex; gap: 16px; margin-bottom: 18px; scroll-margin-top: 70px; }
.tl-date { flex: none; width: 56px; height: 56px; border-radius: 14px; background: var(--bits); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; z-index: 1; box-shadow: 0 0 0 4px var(--bg); line-height: 1.05; }
.tl-date b { font-size: 1.35rem; }
.tl-date span { font-size: .7rem; text-transform: uppercase; font-weight: 700; opacity: .85; }
.tl-card { flex: 1; min-width: 0; margin: 0; }
.tl-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.tl-head h3 { margin: 2px 0 6px; font-size: 1.1rem; }
.tl-tags { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.tl-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 10px; }
.tl-meta span { display: inline-flex; align-items: center; gap: 5px; }
.tl-body p:last-child { margin-bottom: 0; }
.tl-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: .9rem; }
.tl-cols ul { margin: 0; padding-left: 18px; }
.tl-nov { background: var(--warn-bg); border-radius: 10px; padding: 10px 12px; }
.tl-nov h4 { color: var(--warn-text); }
.tl-photos { display: grid; gap: 6px; margin-top: 14px; grid-template-columns: repeat(3, 1fr); }
.tl-photos.n1 { grid-template-columns: 1fr; }
.tl-photos.n2 { grid-template-columns: 1fr 1fr; }
.tl-photos.n4 { grid-template-columns: repeat(4, 1fr); }
.tl-photos.n5 { grid-template-columns: repeat(5, 1fr); }
.tl-photos a { position: relative; }
.tl-photos img { width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.tl-photos.n1 img { aspect-ratio: 16/9; max-height: 420px; }
.tl-photos .more-hidden { display: none; }
.tl-photos .more { position: absolute; inset: 0; background: rgba(18,48,71,.6); color: #fff; display: grid; place-items: center; font-size: 1.4rem; font-weight: 700; }

/* Galería */
.gallery-month { margin-bottom: 26px; scroll-margin-top: 60px; }
.gallery-month h3 small { font-weight: 400; font-size: .82rem; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.g-item { margin: 0; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; position: relative; }
.g-item img { width: 100%; aspect-ratio: 4/3; object-fit: cover; transition: transform .3s; }
.g-item a { border-radius: 0; }
.g-item figcaption { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 8px 10px; font-size: .8rem; color: var(--muted); }
.g-item.is-internal img { opacity: .7; }
.g-actions { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.g-item:hover .g-actions, .g-item:focus-within .g-actions { opacity: 1; }
.g-actions form { margin: 0; }
.g-actions button, .g-actions a { width: 30px; height: 30px; border: 0; border-radius: 8px; background: rgba(255,255,255,.94); color: var(--noche); cursor: pointer; display: grid; place-items: center; font-size: .9rem; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.g-actions button:hover, .g-actions a:hover { background: var(--bits); color: #fff; }

/* Detalle / adjuntos */
.dl-grid { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 0 0 16px; }
.dl-grid dt { color: var(--muted); font-size: .86rem; }
.dl-grid dd { margin: 0; }
.attach-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.attach { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; font-size: .78rem; color: var(--text); display: flex; flex-direction: column; }
.attach a { color: inherit; display: flex; flex-direction: column; text-decoration: none; }
.attach img, .attach .pdf { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #F1F4F7; }
.attach .pdf { display: grid; place-items: center; font-weight: 800; font-size: 1.3rem; color: var(--danger); }
.attach span { padding: 6px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.attach label.check { padding: 0 8px 6px; margin: 0; }

/* Acuerdos */
.contract-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; }
.contract { margin: 0; border-left: 5px solid var(--bits); }
.contract.nivel-alerta { border-left-color: var(--warn); background: linear-gradient(90deg, #FFFBF1, #fff 40%); }
.contract.nivel-excedido { border-left-color: var(--danger); background: linear-gradient(90deg, #FFF6F6, #fff 40%); }
.contract.nivel-completo { border-left-color: var(--ok); }
.contract.nivel-anulado { border-left-color: #C5CDD5; }
.contract header { align-items: flex-start; }
.contract h3 { margin: 0; }
.contract header p { margin: 2px 0 0; font-size: .9rem; }
.contract-nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 6px; }
.contract-nums small { display: block; font-size: .72rem; color: var(--muted); text-transform: uppercase; font-weight: 600; }
.contract-nums b { font-variant-numeric: tabular-nums; }
.contract-bar { position: relative; }
.contract-bar .bar { height: 10px; }
.mark75 { position: absolute; top: 2px; width: 2px; height: 14px; background: var(--noche); opacity: .45; border-radius: 2px; }
.contract footer { margin-top: 12px; }
.contract-pagos { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; overflow-x: auto; }

.stack-bar { display: flex; height: 14px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 6px 0 10px; }
.sb-cobrado { background: var(--ok); }
.sb-planillado { background: var(--warn); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); }

/* ---------- Lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(9, 22, 33, .94); display: flex; align-items: center; justify-content: center; }
.lightbox figure { margin: 0; max-width: 92vw; max-height: 90vh; text-align: center; }
.lightbox img { max-width: 92vw; max-height: 82vh; object-fit: contain; border-radius: 6px; margin: 0 auto; }
.lightbox figcaption { color: #DCE7F0; margin-top: 10px; font-size: .9rem; }
.lightbox button { position: absolute; background: rgba(255,255,255,.1); color: #fff; border: 0; width: 48px; height: 48px; border-radius: 50%; font-size: 2rem; line-height: 1; cursor: pointer; }
.lightbox button:hover { background: rgba(255,255,255,.22); }
.lb-close { top: 16px; right: 16px; }
.lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 16px; top: 50%; transform: translateY(-50%); }

/* ---------- Login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--noche) 0%, #0B4C7F 60%, var(--bits) 100%); padding: 20px; }
.login-wrap { display: grid; grid-template-columns: 1.1fr 1fr; max-width: 900px; width: 100%; background: #fff; border-radius: 20px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-hero { background: var(--noche); color: #CFE0EE; padding: 40px; display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; }
.login-hero::after { content: ""; position: absolute; right: -80px; bottom: -80px; width: 260px; height: 260px; border-radius: 50%; border: 40px solid rgba(0,159,227,.12); }
.login-hero h1 { color: #fff; font-size: 1.9rem; margin-top: 10px; }
.login-hero ul { padding-left: 18px; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.login-hero small { margin-top: auto; padding-top: 24px; color: #8FB3CF; }
.login-card { padding: 40px; }
.login-card h2 { font-size: 1.5rem; }
.login-card form { margin-top: 18px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .86rem; color: var(--noche); margin-bottom: 14px; }

/* ---------- Álbum / memoria ---------- */
.album-body { background: #E9EEF2; }
.album-toolbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 20px; background: #fff; box-shadow: var(--shadow); }
.album { max-width: 900px; margin: 24px auto; background: #fff; box-shadow: var(--shadow); }
.album-cover { position: relative; min-height: 640px; display: flex; align-items: flex-end; background: var(--noche); color: #fff; overflow: hidden; }
.cover-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.album-cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(18,48,71,0) 30%, rgba(18,48,71,.92) 85%); }
.cover-text { position: relative; z-index: 1; padding: 48px; width: 100%; }
.cover-text img { margin-bottom: 16px; }
.cover-text small { text-transform: uppercase; letter-spacing: .2em; color: #9FD3F0; font-weight: 700; }
.cover-text h1 { color: #fff; font-size: 2.6rem; margin: 6px 0 8px; }
.cover-text p { font-size: 1.1rem; margin: 0 0 4px; color: #DCEBF5; }
.cover-dates { font-weight: 600; }
.cover-brand { display: inline-block; margin-top: 18px; padding: 4px 12px; border: 1px solid rgba(255,255,255,.4); border-radius: 99px; font-size: .82rem; }
.album-intro { padding: 48px; }
.album-intro .lead { font-size: 1.05rem; color: #3E4C57; }
.album-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 24px 0; }
.album-stats div { background: var(--celeste); border-radius: 14px; padding: 16px; text-align: center; }
.album-stats b { display: block; font-size: 1.8rem; color: var(--bits); }
.album-stats span { font-size: .8rem; color: var(--noche); }
.antes-despues { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.antes-despues figure, .ae-photos figure { margin: 0; }
.antes-despues img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 10px; }
.antes-despues figcaption { text-align: center; font-weight: 700; color: var(--bits); margin-top: 6px; }
.album-money { margin-top: 26px; }
.album-month { margin: 0; padding: 22px 48px 6px; color: var(--bits); font-size: 1.5rem; border-top: 1px solid var(--line); }
.album-entry { padding: 16px 48px 22px; break-inside: avoid; page-break-inside: avoid; }
.ae-date { color: var(--muted); font-size: .85rem; font-weight: 600; }
.album-entry h3 { margin: 2px 0 8px; }
.ae-text { color: #3E4C57; }
.ae-photos { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; margin-top: 10px; }
.ae-photos.n1 { grid-template-columns: 1fr; }
.ae-photos.n3 { grid-template-columns: repeat(3, 1fr); }
.ae-photos img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; }
.ae-photos.n1 img { aspect-ratio: 16/9; }
.ae-photos figcaption { font-size: .78rem; color: var(--muted); margin-top: 3px; }
.album-end { text-align: center; padding: 70px 40px; background: var(--noche); color: #CFE0EE; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.album-end h2 { color: #fff; }
.debug { text-align: left; background: #111; color: #eee; padding: 12px; border-radius: 8px; overflow: auto; font-size: .8rem; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  body.menu-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(9,22,33,.45); }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: 12px 14px 8px; }
  .topbar-title h1 { font-size: 1.15rem; }
  .tabs { padding: 0 8px; }
  .content { padding: 16px 14px 30px; }
  .foot { padding: 14px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-hero { padding: 28px; }
  .login-hero ul { display: none; }
  .login-card { padding: 28px; }
  .contract-list { grid-template-columns: 1fr; }
  .tl-cols { grid-template-columns: 1fr; }
  .album-stats { grid-template-columns: 1fr 1fr; }
  .album-intro, .album-entry { padding-left: 22px; padding-right: 22px; }
  .album-month { padding-left: 22px; }
  .cover-text { padding: 28px; }
  .cover-text h1 { font-size: 1.9rem; }
  .album-cover { min-height: 460px; }
  .album { margin: 0; }
}
@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .kpis, .kpis-6 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi b { font-size: 1.12rem; }
  .card { padding: 16px; }
  .page-head .btn { flex: 1; }
  .page-head > div:first-child { width: 100%; }
  .quick-actions { grid-template-columns: 1fr 1fr; }
  .qa { padding: 12px; font-size: .88rem; }
  .timeline::before { left: 21px; }
  .tl-item { gap: 10px; }
  .tl-date { width: 44px; height: 44px; border-radius: 11px; }
  .tl-date b { font-size: 1.05rem; }
  .tl-photos, .tl-photos.n4, .tl-photos.n5 { grid-template-columns: repeat(3, 1fr); }
  .tl-head { flex-direction: column-reverse; }
  .gallery { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .g-actions { opacity: 1; }
  .contract-nums { grid-template-columns: 1fr 1fr; }
  .dl-grid { grid-template-columns: 1fr; gap: 2px; }
  .dl-grid dd { margin-bottom: 8px; }
  .filters select, .filters label.inline { flex: 1 1 45%; }
  .hero-strip { gap: 12px 18px; }
  .pc-money b { font-size: .84rem; }
  /* Tabla de gastos como tarjetas en celular */
  .table-gastos thead { display: none; }
  .table-gastos tbody tr { display: grid; grid-template-columns: 30px 1fr auto; gap: 2px 10px; padding: 12px; border-bottom: 1px solid var(--line); }
  .table-gastos td { border: 0; padding: 0; }
  .table-gastos td.w-check { grid-row: span 3; }
  .table-gastos td:nth-child(2) { grid-column: 2; font-size: .8rem; color: var(--muted); }
  .table-gastos td:nth-child(3) { grid-column: 2 / span 2; }
  .table-gastos td:nth-child(4), .table-gastos td:nth-child(5) { grid-column: 2; font-size: .8rem; }
  .table-gastos td:nth-child(6) { grid-column: 3; grid-row: 1; }
  .table-gastos td:nth-child(7) { grid-column: 3; grid-row: 2 / span 2; text-align: right; }
  .table-gastos td:nth-child(8) { grid-column: 3; text-align: right; }
  .table-gastos tfoot tr { display: flex; justify-content: space-between; padding: 12px; }
  .table-gastos tfoot td { border: 0; padding: 0; }
  .table-gastos tfoot td:empty { display: none; }
}
/* Cuando el usuario no tiene casillas (cliente) la tabla tiene una columna menos */
@media (max-width: 560px) {
  .rol-cliente .table-gastos tbody tr { grid-template-columns: 1fr auto; }
  .rol-cliente .table-gastos td:nth-child(1) { grid-column: 1; font-size: .8rem; color: var(--muted); }
  .rol-cliente .table-gastos td:nth-child(2) { grid-column: 1 / span 2; font-size: inherit; color: inherit; }
  .rol-cliente .table-gastos td:nth-child(3), .rol-cliente .table-gastos td:nth-child(4) { grid-column: 1; font-size: .8rem; }
  .rol-cliente .table-gastos td:nth-child(5) { grid-column: 2; grid-row: 1; }
  .rol-cliente .table-gastos td:nth-child(6) { grid-column: 2; grid-row: 3; text-align: right; }
  .rol-cliente .table-gastos td:nth-child(7) { grid-column: 2; grid-row: 4; text-align: right; }
}

/* ---------- Impresión ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 11pt; }
  .no-print, .sidebar, .topbar .menu-btn, .tabs, .quick-actions, .foot, .g-actions, .filters, .bulk-bar, .form-actions { display: none !important; }
  .main { margin: 0; }
  .card, .kpi { box-shadow: none; border: 1px solid #ddd; }
  .album { margin: 0; box-shadow: none; max-width: none; }
  .album-cover { min-height: 260mm; page-break-after: always; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .album-intro { page-break-after: always; }
  .album-stats div, .album-end, .tl-date { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .page-break { page-break-before: always; }
  .album-month { page-break-after: avoid; }
  a { color: inherit; text-decoration: none; }
}
