:root {
    --bg: #f6f2ed;
    --card: #fffdf9;
    --text: #1f1b16;
    --muted: #6b5f54;
    --primary: #b6452c;
    --border: #e5d9ce;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Work Sans", "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}
a:visited { color: inherit; }

/* Safety baseline: keep mobile bottom nav hidden unless mobile ADN overrides it */
.mobile-only { display: none; }
.mobile-bottom-nav { display: none !important; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 18px;
    background: #201913;
    color: #f8efe6;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.help-btn {
    margin-left: auto;
    margin-right: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: #f8efe6;
    background: transparent;
    padding: 4px;
}
.help-btn svg { width: 18px; height: 18px; fill: currentColor; }

.brand { font-weight: 700; letter-spacing: 1px; }
.brand { text-transform: uppercase; }

.back-btn {
    display: none;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: none;
    color: #f8efe6;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    padding: 4px 6px;
}
.back-btn svg {
    width: 11px;
    height: 11px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.nav {
    display: flex;
    align-items: center;
    gap: 16px;
}
.nav a,
.nav-link {
    color: #cbbeb2;
    text-decoration: none;
    margin-left: 0;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    padding: 6px 8px;
    border-radius: 6px;
    min-height: 32px;
}
.nav a:hover,
.nav-link:hover,
.nav-title:hover,
.nav-title-link:hover {
    color: #f0d9c7;
    background: rgba(248,239,230,0.08);
}
.nav-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    color: #f8efe6;
    text-decoration: none;
    padding: 8px;
    border-radius: 8px;
    background: rgba(248,239,230,0.08);
    border: 1px solid rgba(248,239,230,0.18);
}
.nav-logout svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.nav-logout:hover {
    opacity: 0.7;
}
.nav-group {
    position: relative;
}
.nav-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #cbbeb2;
    font-weight: 500;
    list-style: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 6px;
    min-height: 32px;
}
.nav a.nav-title-link {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #cbbeb2;
    font-weight: 500;
}
.nav-title::-webkit-details-marker { display: none; }
.nav-title::after {
    content: "▾";
    font-size: 10px;
    color: #cbbeb2;
    transition: transform 0.15s ease;
}
.nav-title-link::after {
    content: "";
}
.nav-group[open] .nav-title::after { transform: rotate(180deg); }
.nav-links {
    display: none;
}

.nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 999;
}

.menu-toggle {
    display: none;
    background: transparent;
    border: 1px solid #f8efe6;
    color: #f8efe6;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
}

.container {
    padding: 18px;
    max-width: 1100px;
    margin: 0 auto;
}

.card {
    background: var(--dna-card, var(--card));
    border: 1px solid var(--dna-border, var(--border));
    padding: 16px;
    border-radius: var(--dna-radius-xl, 10px);
    box-shadow: var(--dna-shadow, none);
    margin-bottom: 16px;
}

.card.narrow { max-width: 420px; margin: 40px auto; }

h1, h2 { margin-top: 0; }

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th, .table td {
    padding: 10px;
    border-bottom: 1px solid var(--dna-border, var(--border));
    text-align: left;
}

.table th { font-size: 13px; color: var(--muted); }

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 10px;
}

.search input { min-width: 220px; }

.grid {
    display: grid;
    gap: 12px;
}

.form-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

label { display: grid; gap: 6px; font-size: 11px; }

label.inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

input, select {
    padding: 8px 10px;
    border: 1px solid var(--dna-border, var(--border));
    border-radius: var(--dna-radius-md, 6px);
    font-size: 11px;
}

/* Remove number input spinners */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.btn {
    display: inline-block;
    padding: 8px 12px;
    border: 1px solid var(--dna-border, var(--border));
    border-radius: var(--dna-radius-md, 6px);
    text-decoration: none;
    color: var(--text);
    background: var(--dna-card, #fff);
    cursor: pointer;
}

.btn.primary {
    background: var(--dna-primary, var(--primary));
    color: #fff;
    border-color: var(--dna-primary, var(--primary));
}

.toolbar .btn { margin-right: 8px; }
.btn.danger {
    background: #b00020;
    color: #fff;
    border-color: #b00020;
}

.form-actions {
    display: flex;
    align-items: end;
}

.inline-form {
    display: inline-flex;
    gap: 8px;
    align-items: center;
}

.inline-input {
    width: 110px;
}

.pill {
    background: var(--dna-status-neutral-bg, #f1e7dc);
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid var(--dna-status-neutral-br, transparent);
    color: var(--dna-status-neutral-tx, var(--muted));
    font-size: 12px;
}

.alert {
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 12px;
}

.alert.success { background: #eaf7ee; border: 1px solid #bfe6c9; }
.alert.error { background: #fdecea; border: 1px solid #f5c2c0; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    background: #1b1b1b;
    color: #fff;
    padding: 10px 11px;
    border-radius: 12px;
    font-size: 13px;
    z-index: 9999;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    transition: opacity 0.3s ease, transform 0.3s ease;
    max-width: min(92vw, 430px);
}
.toast.hide {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-50%) translateY(8px);
}

@media (max-width: 860px) {
    .toast {
        top: calc(env(safe-area-inset-top, 0px) + 72px);
        bottom: auto;
    }
    .toast.hide { transform: translateX(-50%) translateY(-8px); }
}

.actions { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.actions a { margin-right: 0; }
.actions .danger:not(.btn) { color: #b00020; }
.actions .btn.danger { color: #fff; }
.warn { color: #b00020; font-weight: 700; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    text-decoration: none;
    color: var(--muted);
    background: #fff;
}
.icon-btn svg { width: 16px; height: 16px; fill: currentColor; }
.icon-btn.danger { color: var(--muted); border-color: var(--border); }

.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { text-decoration: underline; }

.pagination {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
}

/* Wizard alta rápida móvil */
.mobile-wizard {
    max-width: 520px;
    margin: 0 auto;
    padding: 10px 12px 92px;
    min-height: calc(100vh - 70px);
}
.wizard-shell {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: calc(100vh - 120px);
}
.wizard-top {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg);
    padding: 6px 0 0;
}
.wizard-step {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 8px;
}
.wizard-progress {
    height: 6px;
    border-radius: 999px;
    background: #eadfd3;
    overflow: hidden;
}
.wizard-progress > span {
    display: block;
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.25s ease;
}
.wizard-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 11px;
    min-height: 260px;
    display: grid;
    gap: 12px;
    align-content: start;
}
.wizard-title {
    font-size: 18px;
    margin: 0;
}
.wizard-input,
.wizard-select {
    width: 100%;
    height: 48px;
    padding: 10px 12px;
    font-size: 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}
.wizard-actions {
    display: grid;
    gap: 10px;
}
.wizard-actions.two {
    grid-template-columns: 1fr 1fr;
}
.wizard-btn {
    height: 52px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
.wizard-btn.primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.wizard-btn.ghost {
    background: #f7efe7;
}
.wizard-chip-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, 1fr);
}
.wizard-chip {
    height: 56px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
}
.wizard-chip.active {
    border-color: var(--primary);
    box-shadow: inset 0 0 0 2px var(--primary);
    color: var(--primary);
}
.wizard-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fdf8f3;
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    display: grid;
    gap: 8px;
}
.wizard-footer .wizard-btn {
    width: 100%;
}
.wizard-summary {
    display: grid;
    gap: 8px;
    font-size: 15px;
}
.wizard-summary .row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    border-bottom: 1px dashed var(--border);
    padding-bottom: 6px;
}
.wizard-summary .label {
    color: var(--muted);
}
.wizard-hidden {
    display: none;
}

@media (min-width: 1024px) {
    .mobile-wizard {
        max-width: 640px;
    }
}
.page-info { color: var(--muted); font-size: 11px; }

.stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px;
    text-decoration: none;
    color: inherit;
    display: block;
}

.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; }

@media (max-width: 720px) {
    .menu-toggle { display: inline-flex; }
    .nav {
        position: fixed;
        top: 56px;
        right: -100%;
        height: calc(100vh - 80px);
        max-height: 82vh;
        width: 80vw;
        background: #201913;
        padding: 10px 12px 12px;
        border-left: 1px solid #3a2f26;
        overflow: hidden;
        transition: right 0.2s ease;
        z-index: 1000;
        display: grid;
        gap: 8px;
        align-content: start;
        border-radius: 12px 0 0 12px;
    }
    .nav.open { right: 0; }
    .nav-brand {
        display: grid;
        grid-template-columns: 48px 1fr;
        align-items: center;
        column-gap: 10px;
        padding: 2px 2px 6px;
    }
    .nav-brand img { width: 48px; height: 48px; object-fit: contain; }
    .nav-brand-text {
        font-family: "Georgia", "Times New Roman", serif;
        font-size: 18px;
        letter-spacing: 0.4px;
        color: #f8efe6;
        white-space: nowrap;
    }
    .nav-divider {
        height: 1px;
        background: #3a2f26;
        margin-bottom: 6px;
    }
    .nav-quick {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        margin-bottom: 4px;
    }
    .nav-quick-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        height: 32px;
        border-radius: 10px;
        border: 1px solid #3a2f26;
        background: #2a211a;
        color: #f8efe6;
        font-size: 11px;
        text-decoration: none;
        text-align: center;
        white-space: nowrap;
    }
    .nav-group {
        padding-bottom: 8px;
        border-bottom: 1px solid #3a2f26;
    }
    .nav-group:last-child { border-bottom: 0; padding-bottom: 0; }
    .nav-title,
    .nav-title-link { font-size: 11px; letter-spacing: 0.5px; }
    .nav-links {
        display: grid;
        gap: 3px;
        padding-top: 3px;
    }
    .nav-group:not([open]) .nav-links { display: none; }
    .nav a {
        font-size: 11px;
        min-height: 32px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        font-weight: 500;
        color: #cbbeb2;
    }
    .nav-logout {
        width: 44px;
        height: 44px;
        margin-top: 8px;
    }
    .toolbar { flex-direction: column; align-items: stretch; }
}

.nav-overlay.open { display: block; }

@media (max-width: 768px) {
    .back-btn { display: inline-flex; }
    .topbar { position: sticky; }
    .topbar .brand { display: block; text-transform: uppercase; margin-right: auto; }
    .topbar { justify-content: center; }
    .menu-toggle { position: absolute; right: 18px; }
    .back-btn {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        color: #f8efe6;
        font-size: 13px;
        text-transform: uppercase;
        text-decoration: none;
    }
}

@media (min-width: 721px) {
    .menu-toggle { display: none !important; }
    .nav {
        position: static !important;
        width: auto !important;
        height: auto !important;
        right: auto !important;
        padding: 0 !important;
        border: 0 !important;
        background: transparent !important;
        display: flex !important;
        flex-wrap: wrap;
    }
    .nav-group {
        display: inline-flex;
        align-items: center;
        position: relative;
    }
    .nav-links {
        position: absolute;
        top: calc(100% + 10px);
        left: 0;
        min-width: 180px;
        background: #201913;
        border: 1px solid rgba(255,255,255,0.08);
        border-radius: 8px;
        padding: 8px 10px;
        display: none;
        gap: 4px;
        z-index: 1001;
    }
    .nav-links a {
        text-transform: none;
        letter-spacing: 0;
    }
    .nav-group[open] .nav-links { display: grid; }
    .nav a { font-size: 13px; }
.nav-overlay { display: none !important; }
    .nav-brand,
    .nav-divider,
    .nav-quick { display: none !important; }
}

.wa-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(28, 21, 16, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1200;
    padding: 16px;
}
.wa-modal-backdrop.open { display: flex; }
.wa-modal {
    width: min(520px, 94vw);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    padding: 18px 18px 14px;
}
.wa-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.wa-modal-title {
    font-weight: 700;
    font-size: 16px;
}
.wa-modal-close {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 10px;
    width: 32px;
    height: 32px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}
.wa-modal-note {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 10px;
}
.wa-modal-label {
    display: block;
    font-weight: 600;
    font-size: 13px;
}
.wa-modal textarea {
    margin-top: 6px;
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 10px 12px;
    font-size: 13px;
    resize: vertical;
}
.wa-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}
body.modal-open { overflow: hidden; }
