:root {
    --green-950: #163d2d;
    --green-800: #265b43;
    --green-700: #347052;
    --green-100: #eaf3ed;
    --gold: #b89b58;
    --ink: #17231d;
    --muted: #65746d;
    --line: #dfe7e2;
    --paper: #ffffff;
    --surface: #f4f7f5;
    --danger: #a33b3b;
    --shadow: 0 18px 55px rgba(23, 48, 36, .11);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--surface);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
a { color: inherit; }

.app-header {
    height: 72px;
    padding: 0 clamp(18px, 4vw, 58px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #fff;
    background: linear-gradient(118deg, #153d2d, #2c6b4d);
    box-shadow: 0 8px 30px rgba(19, 54, 39, .18);
}

.header-brand, .card-brand, .back-heading {
    display: flex;
    align-items: center;
}

.header-brand { gap: 12px; }
.header-brand strong, .header-brand span { display: block; }
.header-brand strong { font-size: 1rem; letter-spacing: .01em; }
.header-brand span { margin-top: 2px; color: #cfe2d6; font-size: .78rem; }

.app-logo, .login-logo {
    display: grid;
    place-items: center;
    color: var(--green-950);
    background: #fff;
    border: 2px solid rgba(255,255,255,.4);
    border-radius: 13px;
    font-weight: 900;
    letter-spacing: -.05em;
}

.app-logo { width: 42px; height: 42px; }
.login-logo { width: 58px; height: 58px; margin: 0 auto 22px; background: var(--green-950); color: #fff; }

.app-shell {
    width: min(1480px, calc(100% - 34px));
    margin: 32px auto 60px;
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(520px, 1.05fr) minmax(440px, .95fr);
    gap: 24px;
    align-items: start;
}

.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 12px 40px rgba(23, 48, 36, .06);
}

.form-panel, .preview-panel, .records-panel { padding: clamp(20px, 3vw, 32px); }
.preview-panel { position: sticky; top: 20px; overflow: hidden; }
.records-panel { margin-top: 24px; }

.panel-heading {
    margin-bottom: 26px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
}

.panel-heading.compact { margin-bottom: 18px; }
.panel-heading h1, .panel-heading h2 { margin: 2px 0 0; line-height: 1.1; }
.panel-heading h1 { font-size: clamp(1.45rem, 2.4vw, 2rem); }
.panel-heading h2 { font-size: 1.3rem; }

.eyebrow {
    margin: 0;
    color: var(--green-700);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .14em;
    text-transform: uppercase;
}

.muted { color: var(--muted); }

fieldset {
    margin: 0 0 26px;
    padding: 0;
    border: 0;
}

legend {
    width: 100%;
    margin-bottom: 14px;
    padding-bottom: 9px;
    color: var(--green-950);
    border-bottom: 1px solid var(--line);
    font-size: .86rem;
    font-weight: 800;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
}

.field { display: grid; gap: 7px; color: #314039; font-size: .8rem; font-weight: 700; }
.field.full { grid-column: 1 / -1; }
.field small { color: var(--muted); font-size: .7rem; font-weight: 500; }

input, textarea {
    width: 100%;
    padding: 11px 12px;
    color: var(--ink);
    background: #fbfcfb;
    border: 1px solid #cfdad4;
    border-radius: 10px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

input:focus, textarea:focus {
    background: #fff;
    border-color: var(--green-700);
    box-shadow: 0 0 0 4px rgba(52, 112, 82, .12);
}

.uppercase { text-transform: uppercase; }
textarea { resize: vertical; }

.advanced-options {
    margin: 0 0 24px;
    padding: 14px 16px;
    background: #f8faf9;
    border: 1px solid var(--line);
    border-radius: 12px;
}

.advanced-options summary { color: var(--green-800); cursor: pointer; font-size: .84rem; font-weight: 800; }
.advanced-options p { margin: 10px 0 14px; color: var(--muted); font-size: .76rem; }
.advanced-options .field + .field { margin-top: 13px; }

.form-actions, .toolbar-actions, .row-actions { display: flex; align-items: center; gap: 10px; }

.btn {
    display: inline-flex;
    min-height: 40px;
    padding: 0 16px;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    font-size: .8rem;
    font-weight: 800;
    text-decoration: none;
    transition: transform .15s ease, filter .15s ease, background .15s ease;
}

.btn:hover { filter: brightness(.97); transform: translateY(-1px); }
.btn.primary { color: #fff; background: var(--green-800); box-shadow: 0 8px 22px rgba(38, 91, 67, .22); }
.btn.secondary { color: var(--green-800); background: var(--green-100); border-color: #cddfd4; }
.btn.print { color: #4f3e17; background: #f2e7c9; border-color: #ddc98f; }
.btn.ghost { min-height: 36px; color: #fff; background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.24); }
.btn.wide { width: 100%; margin-top: 18px; }

.alert {
    margin-bottom: 18px;
    padding: 13px 15px;
    border: 1px solid;
    border-radius: 12px;
    font-size: .84rem;
    font-weight: 700;
}

.alert.success { color: #20583c; background: #e8f5ed; border-color: #b9dec7; }
.alert.error { color: #873434; background: #fff0f0; border-color: #efc4c4; }

.size-badge, .count-badge {
    display: inline-flex;
    padding: 7px 10px;
    color: var(--green-800);
    background: var(--green-100);
    border-radius: 999px;
    font-size: .67rem;
    font-weight: 800;
    white-space: nowrap;
}

.preview-stage {
    min-height: 410px;
    padding: 22px 10px;
    display: grid;
    place-items: center;
    background-color: #e8eeea;
    background-image: linear-gradient(45deg, rgba(255,255,255,.48) 25%, transparent 25%), linear-gradient(-45deg, rgba(255,255,255,.48) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, rgba(255,255,255,.48) 75%), linear-gradient(-45deg, transparent 75%, rgba(255,255,255,.48) 75%);
    background-size: 24px 24px;
    background-position: 0 0, 0 12px, 12px -12px, -12px 0;
    border-radius: 14px;
    overflow: auto;
}

.preview-note { margin: 13px 4px 0; color: var(--muted); font-size: .72rem; line-height: 1.5; }

/* Tarjeta: medidas físicas exactas ISO/IEC 7810 ID-1 en orientación vertical. */
.credential-pair {
    display: flex;
    gap: 5mm;
    align-items: flex-start;
    justify-content: center;
}

.credential-card {
    position: relative;
    width: 54mm;
    min-width: 54mm;
    height: 85.6mm;
    min-height: 85.6mm;
    color: #17221d;
    background: #fff;
    border: .5mm solid #2f6548;
    box-shadow: 0 8px 24px rgba(23, 48, 36, .18);
    overflow: hidden;
    font-family: Arial, Helvetica, sans-serif;
}

.credential-card.official-template {
    border: 0;
    background-color: #fff;
    background-position: center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

.credential-card.official-template.card-front { background-image: url("templates/curp-front.jpg"); }
.credential-card.official-template.card-back { background-image: url("templates/curp-back.jpg"); }

.official-template .security-pattern,
.official-template .card-brand,
.official-template .card-title,
.official-template .back-heading,
.official-template .mexico-flag {
    display: none;
}

.official-template .card-inner {
    inset: 0;
    padding: 0;
    background: transparent;
}

.official-template .card-inner::before { display: none; }

.official-template .front-data {
    position: absolute;
    top: 30.4mm;
    left: 4.9mm;
    right: 4.5mm;
}

.official-template .front-data > div { margin-bottom: 2.3mm; }
.official-template .front-data dt { color: #4d704f; font-size: 2.15mm; }
.official-template .front-data dd { margin-top: .55mm; color: #050705; font-size: 2.5mm; line-height: 1.05; }
.official-template .front-data .curp-value { color: #0745d3; font-size: 2.55mm; letter-spacing: .08mm; }

.official-template .front-footer {
    left: auto;
    right: 4.4mm;
    bottom: 5.1mm;
}

.official-template .front-footer .qr-code { width: 18.7mm; height: 18.7mm; }

.official-template .back-qr {
    position: absolute;
    top: 17.8mm;
    left: 50%;
    width: 13.5mm;
    height: 13.5mm;
    margin: 0;
    transform: translateX(-50%);
}

.acta-title {
    display: none;
}

.official-template .acta-title {
    position: absolute;
    top: 32.2mm;
    left: 4.5mm;
    right: 4.5mm;
    display: block;
    color: #050705;
    font-size: 2.4mm;
    font-weight: 900;
    text-align: center;
}

.official-template .back-data {
    position: absolute;
    top: 37.4mm;
    left: 5.1mm;
    right: 4.5mm;
}

.official-template .back-data > div { margin-bottom: 2.65mm; }
.official-template .back-data dt { color: #050705; font-size: 2.18mm; }
.official-template .back-data dd { color: #050705; font-size: 2.25mm; }

.official-template .official-check {
    left: 5mm;
    right: 5mm;
    bottom: 5.5mm;
    padding-top: 1mm;
    color: #384a40;
    border-top-color: rgba(61, 101, 75, .28);
    font-size: 1.55mm;
}

.official-template .watermark {
    top: 53%;
    color: rgba(153, 37, 37, .145);
    font-size: 4.7mm;
    letter-spacing: .5mm;
}

.official-template .validity-note {
    bottom: 1.85mm;
    font-size: 1.28mm;
    letter-spacing: .08mm;
}

.security-pattern {
    position: absolute;
    inset: .7mm;
    border: .8mm double #5e8a70;
    background:
        repeating-linear-gradient(45deg, transparent 0, transparent 1.2mm, rgba(48, 100, 72, .16) 1.3mm, rgba(48, 100, 72, .16) 1.55mm),
        repeating-linear-gradient(-45deg, transparent 0, transparent 1.2mm, rgba(184, 155, 88, .13) 1.3mm, rgba(184, 155, 88, .13) 1.55mm);
    pointer-events: none;
}

.card-inner {
    position: absolute;
    inset: 2.25mm;
    padding: 1.6mm 1.8mm;
    background:
        radial-gradient(circle at 50% 48%, rgba(42, 103, 73, .08), transparent 28%),
        linear-gradient(rgba(255,255,255,.94), rgba(255,255,255,.94));
    overflow: hidden;
}

.card-inner::before {
    content: "SG";
    position: absolute;
    left: 50%;
    top: 51%;
    width: 25mm;
    height: 25mm;
    display: grid;
    place-items: center;
    color: rgba(38, 91, 67, .055);
    border: .7mm solid rgba(38, 91, 67, .045);
    border-radius: 50%;
    font-size: 10mm;
    font-weight: 900;
    transform: translate(-50%, -50%);
}

.card-brand { position: relative; gap: 1.8mm; color: var(--green-950); }
.brand-mark {
    width: 9mm;
    height: 9mm;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(145deg, #173f2e, #46775a);
    border: .35mm solid #c2ad71;
    border-radius: 50%;
    font-size: 3mm;
    font-weight: 900;
    letter-spacing: -.1mm;
}

.brand-mark.small { width: 7.2mm; height: 7.2mm; font-size: 2.45mm; }
.card-brand strong { display: block; font-size: 6.1mm; line-height: .85; letter-spacing: -.35mm; }
.card-brand span { display: block; margin-top: .8mm; color: #8b753d; font-size: 1.75mm; font-weight: 700; letter-spacing: .08mm; text-transform: uppercase; }

.card-title {
    position: relative;
    margin: 4mm 0 2.4mm;
    color: var(--green-800);
    font-size: 2.45mm;
    font-weight: 800;
    line-height: 1.18;
    text-align: center;
}

.card-data { position: relative; margin: 0; }
.card-data > div { margin: 0 0 2.15mm; }
.card-data dt { color: #55755f; font-size: 2.05mm; font-weight: 800; letter-spacing: .06mm; }
.card-data dd { margin: .7mm 0 0; color: #111915; font-size: 2.35mm; font-weight: 800; line-height: 1.1; overflow-wrap: anywhere; }
.card-data .curp-value { color: #164cc0; font-size: 2.5mm; letter-spacing: .09mm; }

.front-footer {
    position: absolute;
    left: 1.8mm;
    right: 1.8mm;
    bottom: 3.4mm;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
}

.mexico-flag { width: 12mm; height: 6.2mm; display: flex; border: .2mm solid #d5d5d5; }
.mexico-flag i { flex: 1; }
.mexico-flag i:nth-child(1) { background: #0b7048; }
.mexico-flag i:nth-child(2) { position: relative; background: #fff; }
.mexico-flag i:nth-child(2)::after { content: "•"; position: absolute; inset: 0; display: grid; place-items: center; color: #a3803d; font-size: 3mm; }
.mexico-flag i:nth-child(3) { background: #c92636; }

.qr-code { width: 18mm; height: 18mm; background: #fff; }
.qr-code svg { display: block; width: 100%; height: 100%; shape-rendering: crispEdges; }
.qr-fallback { display: grid; place-items: center; border: .3mm solid #111; color: #111; font-size: 3mm; font-weight: 900; }

.watermark {
    position: absolute;
    left: 50%;
    top: 52%;
    width: 70mm;
    color: rgba(154, 44, 44, .105);
    font-size: 5.1mm;
    font-weight: 900;
    letter-spacing: .6mm;
    text-align: center;
    transform: translate(-50%, -50%) rotate(-57deg);
    pointer-events: none;
}

.validity-note {
    position: absolute;
    left: 1.6mm;
    right: 1.6mm;
    bottom: .7mm;
    color: #8d3030;
    font-size: 1.45mm;
    font-weight: 900;
    letter-spacing: .12mm;
    text-align: center;
}

.back-heading {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 1.7mm;
    color: var(--green-800);
}

.back-heading .brand-mark { grid-row: 1 / 3; }
.back-heading strong { align-self: end; font-size: 2.65mm; line-height: 1; }
.back-heading span { align-self: start; margin-top: .6mm; color: #8b753d; font-size: 1.55mm; font-weight: 700; letter-spacing: .1mm; text-transform: uppercase; }
.back-qr { position: relative; width: 13.5mm; height: 13.5mm; margin: 2.3mm auto 2mm; }

.back-data > div { margin-bottom: 1.7mm; }
.back-data dt, .back-data dd { display: inline; }
.back-data dt { color: #243c30; font-size: 2.15mm; }
.back-data dd { margin-left: .8mm; font-size: 2.2mm; }

.official-check {
    position: absolute;
    left: 1.8mm;
    right: 1.8mm;
    bottom: 5.2mm;
    padding-top: 1.5mm;
    color: #52685d;
    border-top: .2mm solid #cfdbd4;
    font-size: 1.75mm;
    line-height: 1.35;
    text-align: center;
}

.official-check strong { color: var(--green-800); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 12px; border-bottom: 1px solid var(--line); font-size: .78rem; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; }
td:first-child { white-space: normal; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; color: #274f3b; }
.row-actions { justify-content: flex-end; }
.row-actions form { margin: 0; }
.icon-link, .link-danger { padding: 0; border: 0; background: none; cursor: pointer; font-size: .73rem; font-weight: 800; text-decoration: none; }
.icon-link { color: var(--green-700); }
.print-link { color: #826a2f; }
.link-danger { color: var(--danger); }

.empty-state { min-height: 130px; display: grid; place-content: center; text-align: center; }
.empty-state strong, .empty-state span { display: block; }
.empty-state span { margin-top: 5px; color: var(--muted); font-size: .8rem; }

.login-page { display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 30% 20%, #437458, transparent 31%), linear-gradient(145deg, #0f3022, #295f46); }
.login-card { width: min(430px, 100%); padding: 38px; background: #fff; border: 1px solid rgba(255,255,255,.55); border-radius: 22px; box-shadow: var(--shadow); text-align: center; }
.login-card h1 { margin: 5px 0 10px; }
.login-card .muted { margin: 0 0 22px; font-size: .86rem; line-height: 1.5; }
.login-card label { display: grid; gap: 8px; text-align: left; font-size: .8rem; font-weight: 800; }
.login-help { display: block; margin-top: 18px; color: var(--muted); font-size: .7rem; }

.print-page { background: #dfe5e1; }
.print-toolbar { min-height: 72px; padding: 13px clamp(18px, 4vw, 52px); display: flex; align-items: center; justify-content: space-between; gap: 20px; color: #fff; background: var(--green-950); }
.print-toolbar strong, .print-toolbar span { display: block; }
.print-toolbar span { margin-top: 3px; color: #c8dbd1; font-size: .75rem; }
.print-sheet { width: 210mm; min-height: 297mm; margin: 28px auto; padding: 18mm; background: #fff; box-shadow: 0 15px 50px rgba(20, 44, 32, .2); }
.print-caption { margin-bottom: 8mm; color: #607068; font-size: 2.6mm; font-weight: 800; letter-spacing: .35mm; text-align: center; }
.crop-area { position: relative; display: flex; justify-content: center; }
.crop-area::before { content: ""; position: absolute; inset: -3mm; pointer-events: none; }
.print-instructions { width: 118mm; margin: 12mm auto 0; padding: 4mm; color: #52635a; background: #f3f6f4; border: .2mm solid #dfe7e2; font-size: 2.7mm; line-height: 1.5; text-align: center; }

@media (max-width: 1080px) {
    .workspace-grid { grid-template-columns: 1fr; }
    .preview-panel { position: static; }
}

@media (max-width: 660px) {
    .app-shell { width: min(100% - 20px, 1480px); margin-top: 18px; }
    .app-header { height: 64px; padding: 0 12px; }
    .header-brand span { display: none; }
    .form-panel, .preview-panel, .records-panel { padding: 18px; border-radius: 15px; }
    .field-grid { grid-template-columns: 1fr; }
    .field.full { grid-column: auto; }
    .credential-pair { gap: 3mm; }
    .preview-stage { justify-content: start; }
    .panel-heading { align-items: flex-start; }
    .size-badge { display: none; }
    .form-actions { align-items: stretch; flex-direction: column; }
    .row-actions { flex-wrap: wrap; }
}

@page { size: A4 portrait; margin: 14mm; }

@media print {
    html, body { width: 210mm; min-height: 297mm; background: #fff !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
    .print-toolbar { display: none !important; }
    .print-sheet { width: auto; min-height: auto; margin: 0; padding: 4mm 0 0; box-shadow: none; }
    .credential-card { box-shadow: none; outline: .18mm dashed #8b958f; outline-offset: 1mm; }
    .print-caption { margin-bottom: 7mm; }
    .print-instructions { margin-top: 10mm; }
}
