/* =========================================================================
   Comunidad Sevilla13 · Interfaz web
   Paleta y jerarquía según docs/GUIA_ESTILO_VISUAL.md.
   Puntos de corte: ≥1100px menú lateral fijo · <1100px menú desplegable
   · <720px móvil (barra inferior, tablas como tarjetas, formularios a una columna).
   ========================================================================= */

:root {
    color-scheme: light;
    --navy: #082a62;
    --navy-deep: #041d43;
    --navy-hover: #0d3a7c;
    --blue: #0878d1;
    --blue-dark: #066ab9;
    --cyan: #10bceb;
    --bg: #f2f7fc;
    --surface: #fff;
    --surface-alt: #f6f9fd;
    --border: #d8e6f5;
    --border-soft: #e8f0f8;
    --text: #173b69;
    --text-strong: #0a3475;
    --muted: #5d789f;
    --green: #0c9876;
    --green-bg: #e6f7f1;
    --amber: #9a6400;
    --amber-bg: #fff4dc;
    --red: #bc4a55;
    --red-bg: #fff1ef;
    --grey: #61748c;
    --grey-bg: #eef2f6;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 8px 24px rgba(15, 55, 105, .07);
    --sidebar-w: 264px;
    --appbar-h: 60px;
    --tabbar-h: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea, summary { touch-action: manipulation; }
:focus-visible { outline: 3px solid #7cc4f4; outline-offset: 2px; }
img, svg { max-width: 100%; }

.icon {
    width: 20px; height: 20px; flex: none;
    fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
    position: absolute; left: 12px; top: -60px; z-index: 100;
    padding: 10px 14px; border-radius: var(--radius-sm); background: var(--navy); color: #fff; font-weight: 700;
}
.skip-link:focus { top: 12px; text-decoration: none; }

/* ---------- Menú lateral ---------- */
.sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    width: var(--sidebar-w);
    display: flex; flex-direction: column;
    background: linear-gradient(180deg, var(--navy-deep), var(--navy));
    color: #dcecff;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 20px 18px 14px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark {
    display: grid; place-items: center; width: 40px; height: 40px; flex: none;
    border-radius: 12px; background: linear-gradient(145deg, #23c5ed, var(--blue));
    color: #fff; font-size: 21px; font-weight: 800; box-shadow: 0 4px 12px #001c4670;
}
.brand strong, .brand small { display: block; line-height: 1.1; }
.brand strong { font-size: 17px; }
.brand small { margin-top: 4px; font-size: 10px; letter-spacing: .14em; color: #a8d7f2; white-space: nowrap; }
.sidebar .sidebar-close { display: none; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 4px 12px 16px; scrollbar-width: thin; scrollbar-color: #ffffff30 transparent; }
.nav-group { margin: 18px 10px 6px; color: #7fa6d1; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.nav-link {
    position: relative; display: flex; align-items: center; gap: 12px;
    min-height: 44px; padding: 0 12px; margin: 2px 0;
    border-radius: var(--radius-sm); color: #cfe2f8; font-weight: 600;
}
.nav-link:hover { background: #ffffff12; color: #fff; text-decoration: none; }
.nav-link.active { background: #ffffff1c; color: #fff; }
.nav-link.active::before {
    content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px;
    width: 4px; border-radius: 0 4px 4px 0; background: var(--cyan);
}
.nav-link .icon { opacity: .9; }

.sidebar-user {
    display: flex; align-items: center; gap: 11px;
    margin: 0 12px 14px; padding: 12px; border-radius: var(--radius-sm); background: #ffffff10;
}
.avatar {
    display: grid; place-items: center; width: 36px; height: 36px; flex: none;
    border-radius: 50%; background: #10bceb33; color: #fff; font-weight: 800;
}
.sidebar-user-text { flex: 1; min-width: 0; }
.sidebar-user-text strong, .sidebar-user-text small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-text strong { color: #fff; font-size: 14px; }
.sidebar-user-text small { color: #9dc0e4; font-size: 12px; }
.sidebar-user form { margin: 0; }

.icon-button {
    display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
    border: 0; border-radius: var(--radius-sm); background: transparent; color: inherit; cursor: pointer;
}
.icon-button:hover { background: #ffffff1c; }

/* ---------- Selector de ejercicio ---------- */
.year-switch {
    display: flex; align-items: center; gap: 10px; margin: 0 12px 6px; padding: 10px 12px;
    border: 1px solid #ffffff26; border-radius: var(--radius-sm); background: #ffffff0d; color: #fff;
    text-align: left; cursor: pointer;
}
.year-switch:hover { background: #ffffff1a; }
.year-switch .icon { color: var(--cyan); }
.year-switch-text { flex: 1; min-width: 0; }
.year-switch-text small, .year-switch-text strong { display: block; }
.year-switch-text small { color: #9dc0e4; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.year-switch-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.year-switch-action { color: #a8d7f2; font-size: 12px; font-weight: 700; }
.appbar-year { display: none; }

.year-banner {
    display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap; margin: 0 0 20px; padding: 11px 16px;
    border: 1px solid #f1dca6; border-radius: 12px; background: #fff9ea; color: #6b5212; font-size: 13px;
}
.link-button { padding: 0; border: 0; background: none; color: var(--blue); font: inherit; font-weight: 700; cursor: pointer; }
.link-button:hover { text-decoration: underline; }

.year-dialog {
    width: min(440px, calc(100vw - 24px)); max-height: min(640px, calc(100vh - 32px)); padding: 0;
    border: 0; border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: 0 24px 70px #041d4359;
}
.year-dialog::backdrop { background: #041d4380; backdrop-filter: blur(2px); }
.year-dialog[open] { display: flex; flex-direction: column; overflow: hidden; }
.year-form { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.year-form > .form-actions { flex: none; padding-top: 4px; }
.year-dialog-head { display: flex; align-items: center; justify-content: space-between; }
.year-dialog-head h2 { margin: 0; color: var(--navy); font-size: 20px; }
.year-dialog-head .icon-button { color: var(--muted); }
.year-dialog-head .icon-button:hover { background: var(--surface-alt); }
.year-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 2px; }
.year-row { flex: none; }
.year-row {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 6px 4px 12px;
    border: 1px solid var(--border-soft); border-radius: var(--radius-sm); background: var(--surface-alt);
}
.year-row.is-selected { border-color: #9fcdf0; background: #eaf5fe; }
.year-check, .year-main { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.year-check { flex: 1; font-size: 16px; font-weight: 700; color: var(--navy); }
.year-main { padding: 0 10px; border-radius: 8px; color: var(--muted); font-size: 13px; font-weight: 650; }
.year-check input, .year-main input { width: 19px; height: 19px; accent-color: var(--blue); }
.year-main:has(input:checked) { background: var(--blue); color: #fff; }
.year-main:has(input:checked) input { accent-color: #fff; }

/* Bloque de un ejercicio cuando se consultan varios */
.year-block-title {
    display: flex; align-items: center; gap: 10px; margin: 30px 0 14px; color: var(--navy); font-size: 21px;
}
.year-block-title:first-of-type { margin-top: 0; }
.year-block-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.year-tag { padding: 2px 9px; border-radius: 99px; background: var(--blue); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .04em; }

.menu-backdrop { position: fixed; inset: 0; z-index: 35; background: #041d4366; backdrop-filter: blur(2px); }
.menu-backdrop[hidden] { display: none; }

/* ---------- Estructura principal ---------- */
.shell { min-height: 100vh; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.appbar { display: none; }
.app-main { flex: 1; width: min(1280px, 100% - 64px); margin: 32px auto 40px; }
.app-main:focus { outline: none; }
.app-footer {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 16px 32px; border-top: 1px solid var(--border); color: #7890aa; font-size: 12px;
}
.tabbar { display: none; }

/* ---------- Cabecera de página ---------- */
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin: 0 0 24px; flex-wrap: wrap; }
.page-heading > div:first-child { min-width: 0; }
.page-heading h1 { margin: 3px 0 4px; color: var(--navy); font-size: clamp(26px, 2.6vw, 32px); line-height: 1.15; letter-spacing: -.03em; }
.eyebrow { margin: 0; color: #5582ae; font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.muted { margin: 0; color: var(--muted); }
.helper-note { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.text-danger { color: var(--red); font-weight: 700; }
.subsection-title { margin: 22px 0 10px; color: var(--navy); font-size: 15px; }

/* ---------- Botones ---------- */
.button {
    min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 16px; border: 1px solid transparent; border-radius: var(--radius-sm);
    font-weight: 700; line-height: 1.2; text-align: center; cursor: pointer;
    transition: background .15s, box-shadow .15s, transform .15s;
}
.button:hover { text-decoration: none; }
.button:active { transform: translateY(1px); }
.button-primary { background: var(--blue); color: #fff; box-shadow: 0 4px 12px #0878d129; }
.button-primary:hover { background: var(--blue-dark); color: #fff; }
.button-secondary { background: var(--surface); color: var(--navy); border-color: var(--border); }
.button-secondary:hover { background: var(--surface-alt); border-color: #c3d7ee; }
.button-danger { background: var(--red-bg); color: #a63f48; border-color: #f2cbc6; }
.button-danger:hover { background: #ffe5e1; }
.button-small { min-height: 36px; padding: 6px 11px; font-size: 13px; }
.button-full { width: 100%; }
.text-link { font-weight: 700; cursor: pointer; }

/* ---------- Avisos ---------- */
.alert { margin: 0 0 18px; padding: 13px 16px; border: 1px solid; border-radius: var(--radius-sm); }
.alert-error { background: var(--red-bg); border-color: #f2c7c1; color: #9f3e38; }
.alert-success { background: var(--green-bg); border-color: #bee8d8; color: #087a5e; }
.alert-info { background: #eaf5fe; border-color: #b9dcf4; color: #174c77; }
.consultation-banner {
    display: flex; align-items: center; gap: 12px; margin: 0 0 22px; padding: 13px 16px;
    border: 1px solid #b9dcf4; border-radius: 12px; background: linear-gradient(100deg, #e8f5ff, #f5fbff); color: #174c77;
}
.consultation-icon { width: 24px; height: 24px; color: var(--blue); }
.consultation-banner strong, .consultation-banner small { display: block; }
.consultation-banner strong { font-size: 13px; }
.consultation-banner small { margin-top: 2px; color: #527895; font-size: 12px; line-height: 1.4; }

/* ---------- Indicadores ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.three-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-card {
    min-height: 136px; padding: 20px; display: flex; flex-direction: column; align-items: flex-start;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat-primary { background: linear-gradient(135deg, var(--navy), #0a4f94); border: 0; color: #fff; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 650; }
.stat-primary .stat-label, .stat-primary .stat-foot { color: #c7e3fb; }
.stat-card strong { margin: 10px 0 6px; color: var(--navy); font-size: clamp(21px, 2.2vw, 28px); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat-primary strong { color: #fff; }
.stat-foot { margin-top: auto; color: var(--muted); font-size: 12px; }
.stat-foot a { font-weight: 700; }
.stat-primary .stat-foot a { color: #fff; }
.integrity-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.integrity-grid div { padding: 16px; background: var(--surface-alt); border-radius: var(--radius-sm); }
.integrity-grid strong, .integrity-grid span { display: block; }
.integrity-grid strong { color: var(--navy); font-size: 22px; }
.integrity-grid span { margin-top: 4px; color: var(--muted); font-size: 12px; }

/* ---------- Tarjetas y secciones ---------- */
.content-card {
    margin: 0 0 20px; padding: 22px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.compact-card { padding: 14px 18px; }
.form-card { scroll-margin-top: 80px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.section-heading > div:first-child { min-width: 0; flex: 1 1 260px; }
.section-heading h2 { margin: 3px 0 0; color: var(--navy); font-size: 18px; }
.section-heading form { margin: 0; }
.empty-state { padding: 34px 18px; text-align: center; color: var(--muted); background: var(--surface-alt); border-radius: var(--radius-sm); }

/* Accesos rápidos del resumen */
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.quick-link {
    display: flex; align-items: center; gap: 11px; min-height: 56px; padding: 12px 14px;
    background: var(--surface-alt); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
    color: var(--navy); font-weight: 650;
}
.quick-link:hover { background: #eaf3fc; border-color: var(--border); text-decoration: none; }
.quick-link .icon { width: 22px; height: 22px; color: var(--blue); }

/* ---------- Tablas ---------- */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; text-align: left; }
thead { background: #f5f9fd; }
th { height: 42px; padding: 10px 14px; color: #5c7898; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; white-space: nowrap; }
td { padding: 11px 14px; border-top: 1px solid #eaf0f7; color: #365779; vertical-align: middle; }
tbody tr:nth-child(even) { background: #fbfdff; }
tbody tr:hover { background: #f4f9fe; }
td strong { color: var(--navy); }
td small { display: block; color: #7890aa; font-size: 12px; }
.number { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.positive { color: var(--green); font-weight: 700; }
.negative { color: var(--red); font-weight: 700; }
.result-count { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
.result-line { margin: 0 0 12px; }

/* ---------- Etiquetas de estado ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge-income, .badge-pagado, .badge-activa { background: var(--green-bg); color: #087a5e; }
.badge-expense, .badge-pendiente { background: var(--red-bg); color: #b44c45; }
.badge-parcial { background: var(--amber-bg); color: var(--amber); }
.badge-anulado, .badge-inactiva { background: var(--grey-bg); color: var(--grey); }
.badge-traspasado { background: #e6f1fc; color: #0d5ea8; }

/* ---------- Barras de herramientas y filtros ---------- */
.toolbar { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-toolbar { flex-wrap: wrap; }
.page-heading .toolbar { margin-bottom: 0; }
.search-box {
    min-height: 44px; display: flex; align-items: center; gap: 9px; flex: 1 1 280px; max-width: 560px;
    padding: 0 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; color: #7390ae;
}
.search-box:focus-within { border-color: #72bbeb; box-shadow: 0 0 0 3px #10bceb22; }
.search-box span { font-size: 19px; }
.search-box input { width: 100%; min-width: 0; height: 42px; border: 0; outline: 0; background: transparent; color: var(--text); }
.field-inline { display: grid; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 700; }
.field-inline input, .field-inline select {
    height: 44px; min-width: 110px; padding: 7px 10px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; color: var(--text);
}
.year-picker { margin: 0; }
.year-picker input { width: 110px; }
.export-toolbar { margin: 18px 0 0; }
.upload-toolbar { align-items: flex-end; }
.upload-toolbar .field { flex: 1; }
.import-actions { margin-top: 16px; }
.inline-setting { padding-top: 14px; border-top: 1px solid #eaf0f7; }

/* ---------- Formularios ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field label, .field > span { color: #4f6e91; font-size: 12px; font-weight: 700; }
.field input, .field select, .field textarea {
    width: 100%; min-height: 44px; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; color: var(--text);
}
.field input[type="checkbox"], .field input[type="radio"] { width: 18px; min-height: 0; height: 18px; accent-color: var(--blue); }
.field input[type="file"] { padding: 8px; background: var(--surface-alt); }
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus,
.field-inline input:focus, .field-inline select:focus,
.inline-form input:focus, .inline-form select:focus,
.inline-editor input:focus, .inline-editor select:focus, .inline-editor textarea:focus { outline: none; border-color: #72bbeb; box-shadow: 0 0 0 3px #10bceb22; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.check-field { display: flex; align-items: center; gap: 9px; color: #4f6e91; font-size: 13px; }
.check-field input { width: 18px; height: 18px; accent-color: var(--blue); }
.field-error { color: var(--red); font-size: 12px; }

.inline-form { display: flex; align-items: center; gap: 7px; margin-top: 6px; flex-wrap: wrap; }
.inline-form select, .inline-form input,
.assign-form select, .assign-form input {
    min-width: 0; max-width: 230px; height: 38px; padding: 6px 9px;
    border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); font-size: 13px;
}
.assign-form { display: grid; gap: 6px; min-width: 190px; }
.assign-form select { max-width: none; width: 100%; }
.assign-form input { max-width: none; width: 110px; }
.inline-editor {
    display: grid; gap: 8px; min-width: 220px; margin-top: 9px; padding: 12px;
    background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.inline-editor label { display: grid; gap: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }
.inline-editor input, .inline-editor select, .inline-editor textarea {
    width: 100%; min-height: 38px; padding: 6px 9px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}

.allocation-lines, .assignment-lines { display: grid; gap: 9px; }
.allocation-line, .assignment-line {
    display: flex; align-items: end; gap: 10px; padding: 10px; flex-wrap: wrap;
    background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.allocation-line label, .assignment-line .field { display: grid; gap: 4px; flex: 1 1 160px; min-width: 0; color: var(--muted); font-size: 12px; font-weight: 700; }
.allocation-line select, .allocation-line input, .assignment-line select, .assignment-line input {
    width: 100%; min-width: 0; min-height: 40px; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}

/* Desplegables (details/summary) usados para editar dentro de las tablas */
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
details > summary.text-link::after {
    content: ""; display: inline-block; width: 6px; height: 6px; margin: 0 2px 3px 8px;
    border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg);
}
details[open] > summary.text-link::after { margin-bottom: -1px; transform: rotate(-135deg); }
.junta-details { padding: 12px 0; border-top: 1px solid var(--border-soft); }

/* ---------- Juntas: convocatoria y acta ---------- */
.junta-editor { border-top: 3px solid var(--navy); }
.doc-tabs { display: flex; gap: 10px; margin: 0 0 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border-soft); flex-wrap: wrap; }
.doc-tab {
    display: flex; align-items: center; gap: 10px; flex: 1 1 200px; padding: 10px 14px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}
.doc-tab:hover { text-decoration: none; border-color: #9fcdf0; background: var(--surface-alt); }
.doc-tab > span:last-child { display: grid; line-height: 1.25; }
.doc-tab small { color: var(--muted); font-size: 12px; }
.doc-tab-step {
    display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%;
    background: var(--surface-alt); border: 1px solid var(--border); color: var(--muted); font-size: 13px; font-weight: 800;
}
.doc-tab.is-active { border-color: var(--navy); background: #eef4fb; box-shadow: inset 0 -2px 0 var(--navy); }
.doc-tab.is-active .doc-tab-step { background: var(--navy); border-color: var(--navy); color: #fff; }
.doc-tab.is-disabled { opacity: .55; cursor: not-allowed; }
.field-hint { margin-left: 6px; color: var(--muted); font-weight: 500; }
.junta-resumen { margin: 0 0 20px; padding: 14px 18px; background: var(--surface-alt); border-left: 3px solid var(--navy); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.junta-resumen-datos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.junta-resumen-datos span, .junta-resumen-titulo { display: block; margin: 0; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.junta-resumen-titulo { margin-top: 14px; }
.orden-dia { margin: 6px 0 0; padding-left: 22px; }
.orden-dia li { padding: 3px 0; }
.informes-anexos { margin: 0; padding: 14px 16px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.informes-anexos legend { padding: 0 6px; color: var(--navy); font-size: 13px; font-weight: 800; }
.informes-anexos-lista { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.field .informe-opcion {
    display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; cursor: pointer;
    border: 1px solid var(--border-soft); border-radius: var(--radius-sm); background: #fff; color: var(--text); font-size: 13px; font-weight: 500;
}
.field .informe-opcion:hover { border-color: #9fcdf0; }
.field .informe-opcion:has(input:checked) { border-color: #72bbeb; background: #eef6fd; }
.informe-opcion input { margin-top: 2px; flex: none; }
.informe-opcion > span { display: grid; gap: 2px; }
.informe-opcion small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ver-como-form { display: inline; margin-left: 10px; }
.vista-propietario-banner {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    margin: 0 0 20px; padding: 12px 16px; border-radius: var(--radius-sm);
    background: var(--amber-bg); border: 1px solid #f0d49a; color: #6b4600;
}
.vista-propietario-banner form { margin: 0; }
tr.is-selected td { background: #eef6fd; }
tr[data-fila], [data-fila] { scroll-margin-top: 90px; }
tr:target td { background: #fff4dc; transition: background 1.5s ease; }
.tipo-gasto { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.3; }
.tipo-gasto-pendiente { color: var(--amber); font-weight: 700; }
.metodo-form { margin: 0 0 6px; flex-wrap: nowrap; }
.metodo-form select { min-width: 0; max-width: 220px; min-height: 36px; padding: 6px 8px; font-size: 13px; }
@media (max-width: 719px) {
    .junta-resumen-datos { grid-template-columns: 1fr; gap: 8px; }
    .doc-tab { flex-basis: 100%; }
}

/* ---------- Inicio de sesión ---------- */
.login-page {
    min-height: 100vh;
    background: radial-gradient(ellipse at 15% 5%, #dceeff 0, transparent 40%), linear-gradient(150deg, var(--bg), #e6f0fa);
}
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
    width: min(100%, 420px); padding: 36px;
    background: #fff; border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 22px 70px #092c601c;
}
.login-card .brand-mark { width: 52px; height: 52px; margin-bottom: 22px; font-size: 26px; }
.login-card h1 { margin: 4px 0 5px; color: var(--navy); font-size: 30px; letter-spacing: -.03em; }
.login-card > .muted { margin-bottom: 24px; }
.form-stack { display: flex; flex-direction: column; gap: 8px; }
.form-stack label { margin-top: 7px; color: #4f6e91; font-size: 13px; font-weight: 700; }
.form-stack input { height: 48px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.form-stack input:focus { outline: none; border-color: #72bbeb; box-shadow: 0 0 0 3px #10bceb22; }
.form-stack .button { margin-top: 14px; }
.login-note { margin: 20px 0 0; padding-top: 16px; border-top: 1px solid #edf2f7; color: #8195ad; text-align: center; font-size: 12px; }

/* =========================================================================
   Tableta y móvil: menú lateral desplegable
   ========================================================================= */
@media (max-width: 1099px) {
    .sidebar {
        width: min(86vw, 300px);
        transform: translateX(-102%);
        transition: transform .22s ease;
        box-shadow: 8px 0 30px #041d4340;
    }
    .menu-abierto .sidebar { transform: none; }
    .menu-abierto { overflow: hidden; }
    .sidebar .sidebar-close { display: inline-grid; color: #cfe2f8; }
    .shell { margin-left: 0; }
    .appbar {
        position: sticky; top: 0; z-index: 30;
        height: var(--appbar-h); display: flex; align-items: center; gap: 10px; padding: 0 12px;
        background: linear-gradient(110deg, var(--navy-deep), var(--navy)); color: #fff;
        box-shadow: 0 3px 14px #031d4330;
    }
    .appbar .icon-button:hover { background: #ffffff1c; }
    .appbar-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; font-weight: 700; }
    .appbar-year {
        display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px;
        border: 1px solid #ffffff40; border-radius: 99px; background: #ffffff14; color: #fff; font-weight: 700; cursor: pointer; white-space: nowrap;
    }
    .appbar-year .icon { width: 17px; height: 17px; color: var(--cyan); }
    .appbar-year:hover { background: #ffffff26; }
    .appbar-badge { padding: 3px 10px; border: 1px solid #ffffff3c; border-radius: 99px; color: #c7eaff; font-size: 12px; white-space: nowrap; }
    .app-main { width: min(100% - 40px, 960px); margin: 24px auto 32px; }
    .app-footer { padding: 14px 20px; }
    .stats-grid, .integrity-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .three-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* =========================================================================
   Móvil
   ========================================================================= */
@media (max-width: 719px) {
    body { font-size: 14px; }
    .app-main { width: calc(100% - 24px); margin: 16px auto calc(var(--tabbar-h) + var(--safe-bottom) + 20px); }
    .app-footer { display: none; }
    .appbar-badge { display: none; }

    .tabbar {
        position: fixed; inset: auto 0 0 0; z-index: 30;
        display: grid; grid-template-columns: repeat(5, 1fr);
        height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
        background: #fff; border-top: 1px solid var(--border); box-shadow: 0 -4px 16px #0f37690f;
    }
    .tab {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        min-width: 0; border: 0; background: transparent; color: var(--muted);
        font-size: 11px; font-weight: 650; cursor: pointer;
    }
    .tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .tab .icon { width: 23px; height: 23px; }
    .tab:hover { text-decoration: none; color: var(--navy); }
    .tab.active { color: var(--blue); }
    .tab.active .icon { stroke-width: 2.2; }

    .page-heading { flex-direction: column; align-items: stretch; gap: 14px; margin-bottom: 16px; }
    .page-heading h1 { font-size: 26px; }
    .page-heading > .button, .page-heading > a.button { width: 100%; }

    .stats-grid, .three-stats, .integrity-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
    .stat-card { min-height: 112px; padding: 14px; border-radius: 12px; }
    .stat-primary { grid-column: 1 / -1; min-height: 0; }
    /* Si tras la tarjeta principal queda una tarjeta suelta, ocupa todo el ancho. */
    .stats-grid > .stat-primary:first-child ~ .stat-card:last-child:nth-child(even) { grid-column: 1 / -1; min-height: 0; }
    .stat-label { font-size: 12px; }
    .stat-card strong { margin: 8px 0 4px; font-size: 21px; }
    .stat-foot { font-size: 11px; }

    .content-card { padding: 14px; margin-bottom: 14px; border-radius: 12px; }
    .compact-card { padding: 12px 14px; }
    .section-heading { align-items: flex-start; }
    .section-heading h2 { font-size: 17px; }
    .section-heading > .button, .section-heading > a.button, .section-heading > form, .section-heading > form .button { width: 100%; }

    /* Tablas → tarjetas apiladas (cada celda muestra su etiqueta con data-label) */
    .table-wrap { overflow: visible; border: 0; border-radius: 0; }
    table, tbody { display: block; width: 100%; }
    thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
    tbody tr { display: block; margin: 0 0 10px; padding: 4px 14px; border: 1px solid var(--border-soft); border-radius: 12px; background: #fff; box-shadow: 0 2px 8px #0f37690a; }
    tbody tr:nth-child(even), tbody tr:hover { background: #fff; }
    /* Etiqueta a la izquierda; todo el contenido de la celda se apila a la derecha. */
    tbody td {
        display: grid; grid-template-columns: minmax(84px, 38%) minmax(0, 1fr); column-gap: 14px;
        align-items: start; justify-items: end;
        padding: 9px 0; border: 0; border-top: 1px solid #f0f4f9; text-align: right; white-space: normal; overflow-wrap: anywhere;
    }
    tbody td:first-child { border-top: 0; }
    tbody td::before { content: attr(data-label); grid-column: 1; grid-row: 1 / span 12; justify-self: start; color: #7890aa; text-align: left; font-size: 12px; font-weight: 700; overflow-wrap: normal; }
    tbody td > * { grid-column: 2; }
    tbody td > * + * { margin-top: 6px; }
    tbody td:not([data-label]) { grid-template-columns: minmax(0, 1fr); }
    tbody td:not([data-label])::before { content: none; }
    tbody td:not([data-label]) > * { grid-column: 1; }
    tbody td > details { justify-self: stretch; }
    tbody td > details > summary { text-align: right; }
    /* Un panel de edición abierto ocupa todo el ancho de la tarjeta, debajo de la etiqueta. */
    tbody td > details[open] { grid-column: 1 / -1; grid-row: 13; margin-top: 8px; text-align: left; }
    tbody td > details[open] > summary { display: block; margin-bottom: 4px; }
    tbody td > details[open] > form { width: 100%; text-align: left; }
    tbody td > details[open] .inline-form { justify-content: flex-start; }
    tbody td > form { max-width: 100%; }
    td small { text-align: right; }
    .number { white-space: nowrap; }
    .inline-form { justify-content: flex-end; }
    .inline-form select, .inline-form input { max-width: 100%; flex: 1 1 140px; }
    .inline-editor { min-width: 0; text-align: left; }
    details > summary.text-link { display: inline-block; padding: 4px 0; }

    .toolbar { align-items: stretch; gap: 10px; }
    .toolbar > * { flex: 1 1 100%; }
    .toolbar .search-box { max-width: none; }
    .toolbar .result-count { flex: none; margin-left: 0; }
    .filter-toolbar .field-inline { flex: 1 1 calc(50% - 5px); }
    .filter-toolbar .field-inline input, .filter-toolbar .field-inline select { width: 100%; min-width: 0; }
    .filter-toolbar .button { flex: 1 1 calc(50% - 5px); }
    .year-picker, .year-picker .field-inline { width: 100%; }
    .year-picker input { width: 100%; }
    .upload-toolbar .field { flex: 1 1 100%; }
    .export-toolbar .button { width: 100%; }

    .form-grid { grid-template-columns: 1fr; gap: 12px; }
    .form-actions { align-items: stretch; }
    .form-actions .button { width: 100%; }
    .allocation-line, .assignment-line { flex-direction: column; align-items: stretch; }
    .allocation-line label, .assignment-line .field { flex: none; }

    .consultation-banner { align-items: flex-start; margin-bottom: 14px; padding: 12px; }
    .login-card { padding: 28px 22px; border-radius: 18px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

@media print {
    .sidebar, .appbar, .tabbar, .menu-backdrop, .app-footer, .skip-link, form .button { display: none !important; }
    .shell { margin: 0; }
    .app-main { width: 100%; margin: 0; }
    .content-card, .stat-card { box-shadow: none; break-inside: avoid; }
}

/* ---------- Portal del propietario ---------- */
.data-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0; }
.data-list div { padding: 12px 14px; background: var(--surface-alt); border-radius: var(--radius-sm); min-width: 0; }
.data-list dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.data-list dd { margin: 3px 0 0; color: var(--navy); font-weight: 600; overflow-wrap: anywhere; }
.narrow-card { max-width: 560px; }
.form-grid.single-column { grid-template-columns: 1fr; }
@media (max-width: 719px) { .data-list { grid-template-columns: 1fr; } }

/* Celdas editables dentro de tablas (presupuesto propuesto) */
.cell-input { width: 100%; min-width: 120px; min-height: 38px; padding: 6px 9px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); }
.cell-input.cell-number { min-width: 100px; text-align: right; }
.cell-input:focus { outline: none; border-color: #72bbeb; box-shadow: 0 0 0 3px #10bceb22; }
