:root {
    --navy: #123454;
    --navy-dark: #09233a;
    --blue: #1f5f8b;
    --gold: #c89b3c;
    --gold-soft: #f5ead0;
    --green: #1f6b4f;
    --red: #9d2b35;
    --ink: #182431;
    --muted: #5c6b78;
    --line: #d8e0e7;
    --surface: #ffffff;
    --canvas: #f4f7f9;
    --radius: 12px;
    --shadow: 0 10px 28px rgba(15, 41, 64, .08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--canvas);
    color: var(--ink);
    line-height: 1.55;
}

a { color: var(--blue); }
a:hover { color: var(--navy-dark); }
img { max-width: 100%; }
h1, h2, h3 { color: var(--navy); line-height: 1.2; }
h1 { font-size: clamp(1.8rem, 4vw, 2.65rem); margin: 0 0 .65rem; }
h2 { margin-top: 0; }
p { margin: .45rem 0 1rem; }

.skip-link {
    position: fixed;
    left: 1rem;
    top: -5rem;
    z-index: 100;
    padding: .7rem 1rem;
    color: #fff;
    background: var(--navy-dark);
}
.skip-link:focus { top: 1rem; }

.container {
    width: min(1380px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2rem 0;
}

.public-container { min-height: 62vh; }
.admin-body .container { width: min(1440px, calc(100% - 2rem)); }

.admin-header,
.public-header {
    position: relative;
    z-index: 20;
    color: #fff;
    background: var(--navy-dark);
    box-shadow: 0 4px 18px rgba(0, 0, 0, .15);
}

.admin-header {
    min-height: 74px;
    padding: .75rem max(1rem, calc((100% - 1440px) / 2));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}

.brand-area {
    display: inline-flex;
    align-items: center;
    gap: .8rem;
    color: #fff;
    text-decoration: none;
}
.brand-area span { display: grid; }
.brand-area strong { font-size: 1rem; line-height: 1.2; }
.brand-area small { color: #dbe7ef; }
.logo-menu { width: 50px; height: 50px; object-fit: contain; padding: 3px; border-radius: 8px; background: #fff; }

.menu-links,
.public-menu {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .25rem;
}
.menu-links a,
.menu-links .link-button,
.public-menu > a,
.public-menu summary {
    display: inline-flex;
    padding: .55rem .7rem;
    border-radius: 7px;
    color: #fff;
    font: inherit;
    font-size: .9rem;
    text-decoration: none;
    cursor: pointer;
}
.menu-links a:hover,
.menu-links .link-button:hover,
.public-menu > a:hover,
.public-menu summary:hover { color: #fff; background: rgba(255, 255, 255, .12); }
.logout-form { margin: 0; }
.link-button { border: 0; background: transparent; }

.menu-toggle {
    display: none;
    border: 1px solid rgba(255,255,255,.45);
    padding: .5rem .8rem;
    color: #fff;
    background: transparent;
}

.public-brand-row {
    width: min(1280px, calc(100% - 2rem));
    margin: 0 auto;
    min-height: 104px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.logo-publico { width: 78px; height: 78px; object-fit: contain; padding: 4px; border-radius: 10px; background: #fff; }
.public-brand-row .brand-area strong { font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.25rem, 3vw, 2rem); }
.public-menu {
    min-height: 52px;
    padding: .25rem max(1rem, calc((100% - 1280px) / 2));
    border-top: 1px solid rgba(255,255,255,.12);
    background: var(--navy);
}
.public-menu details { position: relative; }
.public-menu summary { list-style: none; }
.public-menu summary::-webkit-details-marker { display: none; }
.public-menu summary::after { content: "⌄"; margin-left: .35rem; }
.submenu {
    position: absolute;
    top: calc(100% + .3rem);
    left: 0;
    width: 250px;
    padding: .45rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    box-shadow: var(--shadow);
}
.submenu-wide { width: 310px; columns: 2; }
.submenu a {
    display: block;
    break-inside: avoid;
    padding: .55rem .65rem;
    border-radius: 6px;
    color: var(--ink);
    text-decoration: none;
}
.submenu a:hover { background: var(--gold-soft); }

.hero {
    position: relative;
    overflow: hidden;
    padding: clamp(2rem, 6vw, 5rem);
    border-radius: 20px;
    color: #fff;
    background: linear-gradient(125deg, var(--navy-dark) 0%, var(--navy) 65%, #2b6382 100%);
    box-shadow: var(--shadow);
}
.hero::after {
    content: "";
    position: absolute;
    right: -80px;
    bottom: -120px;
    width: 360px;
    height: 360px;
    border: 55px solid rgba(200, 155, 60, .18);
    border-radius: 50%;
}
.hero > * { position: relative; z-index: 1; }
.hero h1 { max-width: 820px; color: #fff; font-family: Georgia, "Times New Roman", serif; }
.hero p { max-width: 750px; color: #e5edf3; font-size: 1.08rem; }
.eyebrow { margin-bottom: .55rem; color: var(--gold); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.hero-search { display: flex; max-width: 800px; gap: .6rem; margin-top: 1.5rem; }
.hero-search input { margin: 0; background: #fff; }

.section-heading { margin: 2.5rem 0 1rem; display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.section-heading p { margin: 0; color: var(--muted); }

.cards,
.stats-grid,
.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}
.card,
.panel,
.formulario,
.publication-card,
.stat-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.card,
.stat-card { padding: 1.25rem; }
.card { border-top: 4px solid var(--gold); }
.link-card { color: inherit; text-decoration: none; transition: transform .18s ease, box-shadow .18s ease; }
.link-card:hover { transform: translateY(-2px); box-shadow: 0 16px 36px rgba(15,41,64,.13); }
.card span,
.stat-card span { display: block; color: var(--muted); font-size: .9rem; }
.card strong,
.stat-card strong { display: block; margin-top: .4rem; color: var(--navy); font-size: 1.8rem; }

.panel,
.formulario { padding: clamp(1rem, 3vw, 1.5rem); margin: 1rem 0; }
.formulario { max-width: 1000px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.field-full { grid-column: 1 / -1; }

label { display: block; margin: .2rem 0 .3rem; color: var(--navy-dark); font-weight: 700; }
input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    margin: 0 0 1rem;
    padding: .68rem .75rem;
    border: 1px solid #b9c6d0;
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    font: inherit;
}
textarea { min-height: 110px; resize: vertical; }
input:focus,
select:focus,
textarea:focus { outline: 3px solid rgba(31, 95, 139, .18); border-color: var(--blue); }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: auto; margin-right: .35rem; }
.help { margin-top: -.7rem; color: var(--muted); font-size: .86rem; }

button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    min-height: 42px;
    padding: .62rem 1rem;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #fff !important;
    background: var(--navy);
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}
button:hover, .btn:hover { background: var(--navy-dark); }
.btn-secondary { color: var(--navy) !important; border-color: var(--line); background: #fff; }
.btn-secondary:hover { background: var(--gold-soft); }
.btn-success { background: var(--green); }
.btn-danger { background: var(--red); }
.btn-small { min-height: 34px; padding: .35rem .6rem; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; }

.search-panel {
    padding: 1.25rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
}
.search-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: .75rem; }
.search-grid .wide { grid-column: span 2; }
.search-grid label { font-size: .86rem; }
.search-grid input, .search-grid select { margin: 0; }
.search-actions { display: flex; align-items: end; gap: .5rem; }

.publication-list { display: grid; gap: 1rem; margin-top: 1rem; }
.publication-card { padding: 1.25rem; }
.publication-card header { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.publication-card h2 { margin: 0; font-size: 1.25rem; }
.publication-card .meta { display: flex; flex-wrap: wrap; gap: .35rem 1rem; margin: .6rem 0; color: var(--muted); font-size: .9rem; }
.publication-card p { margin-bottom: .7rem; }

.config-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 1rem;
    align-items: start;
}
.config-record {
    min-width: 0;
    padding: 1.2rem;
    border: 1px solid var(--line);
    border-top: 4px solid var(--gold);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.config-record-compact { min-height: 0; }
.config-record-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}
.config-record-header > div { min-width: 0; }
.config-record-header h2,
.config-record-header h3 { margin: .2rem 0 .35rem; overflow-wrap: anywhere; }
.config-record-header p { margin: 0; color: var(--muted); }
.record-code {
    color: var(--gold);
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
}
.record-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem 1rem;
    margin: 1rem 0;
    padding: .75rem;
    border-radius: 8px;
    color: var(--muted);
    background: #f5f8fa;
    font-size: .86rem;
}
.record-editor {
    margin-top: 1rem;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #fbfcfd;
}
.record-editor summary {
    padding: .7rem .85rem;
    color: var(--navy);
    font-weight: 800;
    cursor: pointer;
}
.record-editor[open] summary { border-bottom: 1px solid var(--line); }
.embedded-form { padding: 1rem; }
.embedded-form input,
.embedded-form select,
.embedded-form textarea { background: #fff; }
.record-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-top: 1rem;
}
.record-actions form { margin: 0; }
.record-help { margin: .65rem 0 0; }
button:disabled,
.btn:disabled {
    opacity: .52;
    cursor: not-allowed;
    filter: grayscale(.25);
}
button:disabled:hover { background: inherit; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: .28rem .58rem;
    border-radius: 999px;
    color: var(--navy);
    background: #e5eff6;
    font-size: .76rem;
    font-weight: 800;
    white-space: nowrap;
}
.badge.vigente, .badge.publicado { color: #14513b; background: #dff3e9; }
.badge.derogado, .badge.anulado { color: #7b2029; background: #f8e1e3; }
.badge.modificado { color: #76540b; background: #faefcf; }

.table-wrap { width: 100%; overflow-x: auto; margin-top: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; background: #fff; font-size: .9rem; }
table th { padding: .8rem; color: #fff; background: var(--navy); text-align: left; white-space: nowrap; }
table td { padding: .75rem .8rem; border-top: 1px solid var(--line); vertical-align: top; }
table tr:hover td { background: #f8fafb; }

.alert,
.success,
.notice {
    padding: .85rem 1rem;
    margin: 1rem 0;
    border: 1px solid;
    border-radius: 9px;
}
.alert { color: #7b2029; border-color: #efb8bd; background: #fff0f1; }
.success { color: #14513b; border-color: #a9d9c2; background: #ecf9f2; }
.notice { color: #664b0a; border-color: #ead28f; background: #fff8e4; }
.empty-state { padding: 2rem; border: 1px dashed #aebbc5; border-radius: var(--radius); text-align: center; background: #fff; }

.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 2rem; }
.detail-item { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.detail-item dt { color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.detail-item dd { margin: .25rem 0 0; }
.document-box { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 1rem; padding: 1.25rem; border-radius: var(--radius); color: #fff; background: var(--navy); }
.document-box h2 { color: #fff; }
.qr-image { width: 180px; height: 180px; padding: 8px; object-fit: contain; background: #fff; }
.permanent-url { display: flex; gap: .5rem; }
.permanent-url input { margin: 0; }
.hash { overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .82rem; }

.chart-list { display: grid; gap: .7rem; }
.chart-row { display: grid; grid-template-columns: minmax(130px, 240px) 1fr auto; align-items: center; gap: .75rem; }
.chart-track { height: 12px; overflow: hidden; border-radius: 999px; background: #e7edf1; }
.chart-bar { height: 100%; min-width: 3px; border-radius: inherit; background: linear-gradient(90deg, var(--gold), #e0bc68); }

.site-footer {
    margin-top: 2rem;
    padding: 1.5rem max(1rem, calc((100% - 1280px) / 2));
    color: #dce7ee;
    background: var(--navy-dark);
}
.public-footer { display: flex; justify-content: space-between; gap: 2rem; }
.site-footer a { color: #fff; }
.site-footer p { margin: .25rem 0; }
.admin-footer { display: flex; justify-content: space-between; }

.login-body {
    display: grid;
    place-items: center;
    padding: 1rem;
    background: radial-gradient(circle at 80% 10%, #2c6487, transparent 35%), linear-gradient(140deg, var(--navy-dark), var(--navy));
}
.login-box { width: min(440px, 100%); padding: 2rem; border-radius: 18px; background: #fff; box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.login-box h1 { font-size: 1.8rem; }
.logo-login { display: block; width: 230px; max-height: 110px; margin: 0 auto 1.2rem; object-fit: contain; }
.login-box button { width: 100%; }
.back-link { display: block; margin-top: 1rem; text-align: center; }
.danger { border-left: 5px solid var(--red); }
.firma-box { border: 2px dashed var(--blue); }

@media (max-width: 1050px) {
    .menu-toggle { display: inline-flex; }
    .admin-header { flex-wrap: wrap; }
    .menu-links,
    .public-menu { display: none; width: 100%; align-items: stretch; flex-direction: column; }
    .menu-links.is-open,
    .public-menu.is-open { display: flex; }
    .menu-links a,
    .menu-links .link-button,
    .public-menu > a,
    .public-menu summary { width: 100%; }
    .logout-form, .logout-form button { width: 100%; text-align: left; }
    .public-toggle { margin: 0 1rem 1rem; }
    .public-menu { padding: .5rem 1rem 1rem; }
    .public-menu details { width: 100%; }
    .submenu, .submenu-wide { position: static; width: 100%; margin-top: .25rem; columns: 1; box-shadow: none; }
    .search-grid { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
}

@media (max-width: 680px) {
    .container, .admin-body .container { width: min(100% - 1rem, 1380px); padding: 1rem 0; }
    .public-brand-row { width: calc(100% - 1rem); min-height: 88px; }
    .public-brand-row > .btn { display: none; }
    .logo-publico { width: 60px; height: 60px; }
    .hero { padding: 1.5rem; border-radius: 14px; }
    .hero-search, .public-footer, .admin-footer, .permanent-url { flex-direction: column; }
    .form-grid, .detail-grid, .search-grid, .config-list { grid-template-columns: 1fr; }
    .search-grid .wide { grid-column: auto; }
    .publication-card header, .section-heading, .document-box, .config-record-header { align-items: stretch; flex-direction: column; display: flex; }
    .chart-row { grid-template-columns: 1fr auto; }
    .chart-track { grid-column: 1 / -1; grid-row: 2; }
    .actions .btn, .actions button { flex: 1 1 100%; }
}

@media print {
    .admin-header, .public-header, .site-footer, button, .btn, .actions, .search-panel { display: none !important; }
    body { background: #fff; color: #000; }
    .container { width: 100%; margin: 0; padding: 0; }
    .panel, .publication-card { border: 0; box-shadow: none; }
}
