/* ═══════════════════════════════════════════════════════════════
   App Dashboard  ·  v2.0
   ───────────────────────────────────────────────────────────────
   @import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');
   ═══════════════════════════════════════════════════════════════ */


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §1 · DESIGN TOKENS
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
:root {
    /* ── Brand ── */
    --color-bg-main: #EBE1D9;
    --color-bg-soft: #F7F3EF;
    --color-bg-panel: #DCC3A6;
    --color-primary-dark: #110B09;
    --color-primary: #322216;
    --color-secondary: #4F3724;
    --color-accent: #A46B3E;
    --color-accent-soft: #B68757;
    --color-border: #CBA377;
    --color-technical: #21424C;
    --color-text-main: #1A120D;
    --color-text-secondary: #82684D;
    --color-text-inverse: #F7F3EF;
    --shadow-soft: 0 8px 24px rgba(17, 11, 9, 0.12);

    --primary:        var(--color-accent);
    --primary-h:      var(--color-accent-soft);   /* hover */
    --primary-s:      var(--color-secondary);   /* pressed */
    --primary-light:  rgba(166, 107, 62, .12);
    --primary-light-2:rgba(182, 135, 87, .22);
    --primary-glow:   rgba(166, 107, 62, .20);
    --primary-text:   var(--color-primary);

    /* ── Surfaces ── */
    --bg:             var(--color-bg-main);
    --bg-soft:        var(--color-bg-soft);
    --bg-2:           #E7D8C8;
    --panel:          var(--color-bg-soft);
    --panel-2:        #EFE4D7;
    --panel-inv:      var(--color-primary-dark);

    /* ── Text ── */
    --text:           var(--color-text-main);
    --text-2:         var(--color-primary);
    --text-3:         var(--color-secondary);
    --muted:          var(--color-text-secondary);
    --muted-2:        #9A7A5A;
    --text-inv:       var(--color-text-inverse);

    /* ── Borders ── */
    --line:           #D9C2AA;
    --line-2:         var(--color-border);
    --line-3:         var(--color-accent-soft);

    /* ── Semantic ── */
    --danger:         #8C2A22;
    --danger-bg:      #F7E9E6;
    --danger-bd:      #D8A69E;
    --danger-text:    #6F201A;

    --success:        #2D5C45;
    --success-bg:     #EAF2EE;
    --success-bd:     #B9D2C5;
    --success-text:   #224535;

    --warning:        #A46B3E;
    --warning-bg:     #F6EEE5;
    --warning-bd:     #D5B08A;
    --warning-text:   #5E4028;

    --info:           var(--color-technical);
    --info-bg:        #E8EEF0;
    --info-bd:        #A9BFC6;
    --info-text:      #1F3E47;

    /* ── Radius scale ── */
    --r-xs:  6px;
    --r-sm:  8px;
    --r-md:  10px;
    --r-lg:  12px;
    --r-xl:  14px;   /* = original --radius */
    --r-2xl: 18px;
    --r-full: 9999px;

    /* ── Shadows ── */
    --shadow-xs:  0 1px 3px rgba(17, 11, 9, .07);
    --shadow-sm:  0 3px 8px  rgba(17, 11, 9, .09);
    --shadow-md:  var(--shadow-soft);
    --shadow-lg:  0 12px 32px rgba(17, 11, 9, .16);
    --shadow-xl:  0 20px 44px rgba(17, 11, 9, .20);
    --shadow-primary: 0 8px 24px rgba(164, 107, 62, .32);

    /* ── Transitions (property-specific, cheaper than `all`) ── */
    --t-1: .10s cubic-bezier(.4, 0, .2, 1);
    --t-2: .18s cubic-bezier(.4, 0, .2, 1);
    --t-3: .28s cubic-bezier(.4, 0, .2, 1);

    /* ── Topbar ── */
    --topbar-h: 62px;
}

/* Dark mode override */
@media (prefers-color-scheme: dark) {
    :root {
        --bg:        var(--color-bg-main);
        --bg-soft:   var(--color-bg-soft);
        --bg-2:      #E7D8C8;
        --panel:     var(--color-bg-soft);
        --panel-2:   #EFE4D7;
        --panel-inv: var(--color-primary-dark);
        --text:      var(--color-text-main);
        --text-2:    var(--color-primary);
        --text-3:    var(--color-secondary);
        --muted:     var(--color-text-secondary);
        --muted-2:   #9A7A5A;
        --text-inv:  var(--color-text-inverse);
        --line:      #D9C2AA;
        --line-2:    var(--color-border);
        --line-3:    var(--color-accent-soft);
        --primary:   var(--color-accent);
        --primary-h: var(--color-accent-soft);
        --primary-s: var(--color-secondary);
        --primary-light:   rgba(166, 107, 62, .12);
        --primary-light-2: rgba(182, 135, 87, .22);
        --primary-glow:    rgba(166, 107, 62, .20);
        --primary-text:    var(--color-primary);
    }
}

/* Disable all animations for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    :root { --t-1: 0s; --t-2: 0s; --t-3: 0s; }
    * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §2 · RESET & BASE
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    color-scheme: light;
    scroll-behavior: smooth;
    width: 100%;
    max-width: 100%;
}

body {
    font-family: 'Manrope', ui-sans-serif, system-ui, sans-serif;
    font-size: .9375rem;
    color: var(--text);
    line-height: 1.55;
    /* overflow-x: hidden removed — it breaks position:sticky on iOS */
    background:
        radial-gradient(circle at 8% 0%, var(--primary-glow), transparent 38%),
        radial-gradient(circle at 92% 18%, rgba(33, 66, 76, .08), transparent 42%),
        var(--bg);
    min-height: 100dvh;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

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

img, svg { display: block; max-width: 100%; }

/* Focus ring — keyboard only */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--r-xs);
}
:focus:not(:focus-visible) { outline: none; }

/* Thin scrollbar */
::-webkit-scrollbar              { width: 5px; height: 5px; }
::-webkit-scrollbar-track        { background: transparent; }
::-webkit-scrollbar-thumb        { background: var(--line-2); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover  { background: var(--line-3); }
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §3 · APP SHELL
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.app-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
}


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §4 · TOPBAR
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 22px;
    height: var(--topbar-h);
    width: 100%;
    border-bottom: 1px solid rgba(203, 163, 119, .45);
    background: rgba(17 11 9 / .96);
    backdrop-filter: blur(12px) saturate(160%);
    -webkit-backdrop-filter: blur(12px) saturate(160%);
    position: sticky;
    top: 0;
    z-index: 10;
    /* overflow: visible — required for mobile dropdown */
}

.brand {
    font-family: 'Manrope', ui-sans-serif, sans-serif;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: -.2px;
    color: var(--text-inv);
    min-width: 0;
    flex-shrink: 0;
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.brand-logo {
    width: 34px;
    height: 34px;
    object-fit: contain;
    border-radius: 8px;
    flex-shrink: 0;
}

.brand-text {
    line-height: 1.1;
}

/* ── Top navigation ── */
.topnav {
    display: flex;
    gap: 4px;
    align-items: center;
    color: var(--text-inv);
    font-weight: 600;
    font-size: .875rem;
}

.topnav a {
    padding: 7px 12px;
    border-radius: var(--r-sm);
    color: color-mix(in srgb, var(--text-inv) 84%, transparent);
    font-size: clamp(0.75rem, 2.8vw, 0.9rem); /* FIXED: tamaño mínimo legible en celular */
    min-height: 44px; /* FIXED: touch target mínimo accesible */
    overflow: hidden; /* FIXED: evita desborde de texto */
    text-overflow: ellipsis; /* FIXED: truncado elegante en pantallas angostas */
    white-space: nowrap; /* FIXED: evita saltos que rompen el nav */
    transition:
        color var(--t-1),
        background var(--t-1);
}

.topnav a:hover {
    color: var(--text-inv);
    background: var(--primary-light);
}

.topnav a.is-active {
    color: var(--text-inv);
    background: var(--primary-light-2);
    font-weight: 700;
}

/* ── Hamburger button ── */
.menu-toggle {
    /* Hidden on desktop, shown via media query */
    display: none;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line-2);
    background: rgba(247, 243, 239, .12);
    border-radius: var(--r-sm);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
    padding: 0;
    transition:
        background var(--t-1),
        border-color var(--t-1);
    flex-shrink: 0;
}

.menu-toggle:hover {
    background: var(--bg-soft);
    border-color: var(--line-3);
}

.menu-toggle span {
    width: 16px;
    height: 2px;
    background: var(--text-inv);
    border-radius: 2px;
    transition: transform var(--t-2), opacity var(--t-2), background var(--t-1);
    display: block;
}

.menu-toggle:hover span { background: var(--color-accent-soft); }

/* X animation when open */
.menu-toggle.is-open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-toggle.is-open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.menu-toggle.is-open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §5 · LAYOUT
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.main-content {
    width: min(980px, calc(100% - 32px));
    margin: 28px auto;
    display: grid;
    gap: 16px;
    max-width: 100%;
}

.hidden { display: none !important; }


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §6 · PANEL (card container)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-md);
    max-width: 100%;
    min-width: 0;
}

/* ── Login ── */
.login-wrap {
    min-height: calc(100dvh - var(--topbar-h));
    display: grid;
    place-items: center;
    padding: 24px 16px;
}

.login-card {
    width: min(460px, 100%);
    padding: 32px;
}

.login-title {
    font-size: clamp(1.25rem, 4vw, 1.5rem);
    font-weight: 800;
    margin-bottom: 6px;
    color: var(--text);
}

.login-subtitle {
    color: var(--muted);
    margin-bottom: 22px;
    font-size: .9rem;
}

/* ── Dashboard card ── */
.dashboard-card { padding: 24px; }

.dashboard-card h1 {
    font-size: clamp(1.1rem, 3vw, 1.35rem);
    font-weight: 800;
    color: var(--text);
}

.dashboard-card p {
    margin-top: 8px;
    color: var(--muted);
    font-size: .9rem;
}

/* ── Block card ── */
.block-card { padding: 18px; }

.block-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.3;
    margin-bottom: 14px;
}

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

.block-tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

.small-note {
    font-size: .875rem;
    color: var(--muted);
    margin-top: 16px;
}

/* ── Grids ── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 16px;
    max-width: 100%;
}

.dashboard-grid > * { min-width: 0; }

.admin-checklist-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.project-state-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §7 · ALERTS
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.alert {
    border-radius: var(--r-lg);
    padding: 11px 14px;
    font-size: .9rem;
    line-height: 1.5;
    border: 1px solid transparent;
    /* Left accent visible on the border itself */
    border-left-width: 3px;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-color: var(--danger-bd);
    border-left-color: var(--danger);
}

.alert-success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: var(--success-bd);
    border-left-color: var(--success);
}

.alert-warning {
    background: var(--warning-bg);
    color: var(--warning-text);
    border-color: var(--warning-bd);
    border-left-color: var(--warning);
}

.alert-info {
    background: var(--info-bg);
    color: var(--info-text);
    border-color: var(--info-bd);
    border-left-color: var(--info);
}


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §8 · FORMS
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.form-grid { display: grid; gap: 14px; }

.field { display: grid; gap: 6px; }

.field label {
    font-size: .875rem;
    font-weight: 600;
    color: var(--text-2);
}

.field input:not([type="checkbox"]):not([type="radio"]),
.field textarea,
.field select {
    width: 100%;
    border: 1.5px solid var(--line);
    border-radius: var(--r-md);
    padding: 10px 12px;
    font: inherit;
    font-size: .9rem;
    background: var(--panel);
    color: var(--text);
    transition:
        border-color var(--t-2),
        background var(--t-2),
        box-shadow var(--t-2);
    appearance: none;
    -webkit-appearance: none;
}

.field input:not([type="checkbox"]):not([type="radio"])::placeholder,
.field textarea::placeholder { color: var(--muted-2); }

.field input:not([type="checkbox"]):not([type="radio"]):hover,
.field textarea:hover,
.field select:hover { border-color: var(--line-3); }

.field input:not([type="checkbox"]):not([type="radio"]):focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--panel);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.field input:not([type="checkbox"]):not([type="radio"]):disabled,
.field textarea:disabled,
.field select:disabled {
    opacity: .5;
    cursor: not-allowed;
    background: var(--bg-2);
}

/* Select arrow */
.field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2382684D' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    padding-right: 34px;
    cursor: pointer;
}

.field textarea { min-height: 90px; resize: vertical; line-height: 1.55; }

.form-actions { display: flex; gap: 10px; }

.filters-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 10px;
    margin-bottom: 10px;
    align-items: end;
}

.filters-actions { display: flex; gap: 8px; }


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §9 · BUTTONS
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.btn {
    /* border: 1px solid transparent — prevents layout shift on focus ring */
    border: 1.5px solid transparent;
    border-radius: var(--r-md);
    padding: 10px 16px;
    font: inherit;
    font-size: .9rem;
    font-weight: 700;
    cursor: pointer;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    white-space: nowrap;
    text-decoration: none;
    transition:
        background var(--t-1),
        border-color var(--t-1),
        color var(--t-1),
        box-shadow var(--t-1),
        transform var(--t-1);
    user-select: none;
    -webkit-appearance: none;
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn:active { transform: translateY(1px); }

.btn:disabled,
.btn.is-disabled {
    opacity: .55;
    cursor: not-allowed;
    pointer-events: none;
}

/* Prevent interaction while loading */
.btn.is-loading { pointer-events: none; }

/* ── Variants ── */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--text-inv);
    box-shadow: var(--shadow-primary);
}

.btn-primary:hover {
    background: var(--primary-h);
    border-color: var(--primary-h);
    box-shadow: 0 10px 28px rgba(164, 107, 62, .34);
    color: var(--text-inv);
}

.btn-secondary {
    background: var(--panel);
    border-color: var(--line-2);
    color: var(--text-2);
    box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
    background: var(--bg-soft);
    border-color: var(--line-3);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

/* ── Link button (inline, no bg) ── */
.btn-link {
    border: none;
    background: transparent;
    color: var(--primary-text);
    font-weight: 700;
    cursor: pointer;
    padding: 0;
    font: inherit;
    font-size: inherit;
    display: inline;
    transition: color var(--t-1);
}

.btn-link:hover { color: var(--primary-h); text-decoration: underline; text-underline-offset: 3px; }

.btn-link:disabled {
    opacity: .5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-link.danger { color: var(--danger); }
.btn-link.danger:hover { color: var(--danger-text); }

/* ── Loading spinner (pseudo-element) ── */
.btn.is-loading::before {
    content: '';
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255 255 255 / .35);
    border-top-color: rgba(255 255 255 / .9);
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}

.btn-secondary.is-loading::before {
    border-color: var(--line-2);
    border-top-color: var(--primary);
}


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §10 · TABLE
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.table-wrap {
    width: 100%;
    /* overflow-x here — NOT on table-wrap ancestor, fixes sticky th */
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--panel-2);
    max-width: 100%;
}

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
    background: var(--panel);
    /* table-layout: fixed prevents content blowout on narrow cols */
}

.table th {
    text-align: left;
    padding: 10px 10px;
    background: var(--color-technical);
    color: var(--text-inv);
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid color-mix(in srgb, var(--color-technical) 70%, var(--line));
    /* sticky th works only when table-wrap has overflow-x — correct here */
    white-space: nowrap;
}

.table td {
    text-align: left;
    padding: 10px 10px;
    border-bottom: 1px solid var(--line);
    font-size: .9rem;
    color: var(--text-2);
    vertical-align: top;
}

.table tbody tr { transition: background var(--t-1); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--bg-soft); }

.table-actions { display: flex; gap: 8px; align-items: center; }

.parental-row {
    cursor: pointer;
}

.parental-row .parental-check {
    width: 18px;
    height: 18px;
    cursor: pointer;
    appearance: auto;
    -webkit-appearance: checkbox;
}

.loading-row td {
    color: var(--muted);
    padding: 20px 10px;
    text-align: center;
}

.empty-row td {
    color: var(--muted);
    padding: 20px 10px;
    text-align: center;
    background: var(--bg-soft);
    font-size: .9rem;
}


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §11 · CHECKLIST
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.checklist-list {
    list-style: none;
    display: grid;
    gap: 8px;
}

.check-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--panel);
    transition: border-color var(--t-2), background var(--t-2);
}

.check-item:hover {
    border-color: var(--line-2);
    background: var(--bg-soft);
}

.check-indicator {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex: 0 0 14px;
    margin-top: 3px;
}

.check-item-done .check-indicator {
    background: var(--success);
    box-shadow: 0 0 0 3px var(--success-bg);
}

.check-item-pending .check-indicator {
    background: var(--warning);
    box-shadow: 0 0 0 3px var(--warning-bg);
}

.pending-note {
    display: inline-block;
    margin-top: 3px;
    color: var(--warning-text);
    font-size: .84rem;
    font-weight: 600;
}


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §12 · STATE CARDS (KPI)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.state-card {
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 14px 16px;
    background: var(--panel);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--t-2), border-color var(--t-2);
    position: relative;
    overflow: hidden;
}

/* Top accent line */
.state-card::before {
    content: '';
    position: absolute;
    inset-inline: 0;
    top: 0;
    height: 2px;
    background: var(--primary-light-2);
    transition: background var(--t-2);
}

.state-card:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--line-2);
}

.state-card:hover::before { background: var(--primary); }

.state-label {
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
}

.state-value {
    font-size: clamp(1.35rem, 4vw, 1.65rem);
    font-weight: 800;
    color: var(--text);
    margin-top: 6px;
    line-height: 1.1;
    letter-spacing: -.02em;
}

.state-value-small { font-size: clamp(1rem, 3vw, 1.15rem); }

.state-note {
    margin-top: 12px;
    color: var(--muted);
    font-size: .875rem;
}


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §13 · CHART
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.chart-panel {
    margin-top: 16px;
    border-top: 1px solid var(--line);
    padding-top: 14px;
}

.chart-title {
    font-size: .95rem;
    font-weight: 700;
    color: var(--text-2);
    margin-bottom: 10px;
}

.chart-wrap { height: 300px; width: 100%; }


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §14 · CHAT — FAB & PANEL
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.chat-card { margin-top: 0; }

/* ── Floating action button ── */
.chat-fab {
    position: fixed;
    right: calc(12px + env(safe-area-inset-right, 0px));
    bottom: 18px;
    z-index: 40;
    border: none;
    border-radius: var(--r-full);
    background: var(--primary);
    color: var(--text-inv);
    font: inherit;
    font-size: .9rem;
    font-weight: 700;
    padding: 12px 20px;
    box-shadow: var(--shadow-primary);
    cursor: pointer;
    transition:
        background var(--t-1),
        box-shadow var(--t-1),
        transform var(--t-2);
}

.chat-fab:hover {
    background: var(--primary-h);
    box-shadow: 0 14px 32px rgba(164, 107, 62, .36);
    transform: translateY(-2px);
}

.chat-fab:active { transform: translateY(0); }

/* ── Chat panel ── */
.chat-fab-panel {
    position: fixed;
    right: calc(12px + env(safe-area-inset-right, 0px));
    bottom: 78px;
    width: min(420px, calc(100vw - 36px));
    max-height: calc(100dvh - 100px);   /* was undefined on desktop */
    overflow-y: auto;
    z-index: 41;
    box-shadow: var(--shadow-xl);
    display: none;
    border-radius: var(--r-xl);
    border: 1px solid rgba(79, 55, 36, 0.35);
    background:
        radial-gradient(circle at 90% 0%, rgba(33, 66, 76, 0.16), transparent 38%),
        radial-gradient(circle at 0% 100%, rgba(164, 107, 62, 0.12), transparent 34%),
        var(--bg-soft);
}

.field-grid-2,
.field-grid-3,
.field-grid-4 {
    display: grid;
    gap: 12px;
}

.field-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.inline-form {
    display: inline;
}

.detail-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 12px;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.photo-preview img {
    width: min(460px, 100%);
    border-radius: 12px;
    border: 1px solid rgba(15, 23, 42, 0.12);
}

.photo-upload {
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--panel-2);
    padding: 12px;
    display: grid;
    gap: 10px;
    max-width: 560px;
}

.photo-upload-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.photo-upload-dropzone {
    width: 100%;
    border: 1.5px dashed var(--line-2);
    border-radius: var(--r-md);
    background: var(--panel);
    padding: 16px;
    text-align: left;
    cursor: pointer;
    display: grid;
    gap: 4px;
    transition: border-color var(--t-2), background var(--t-2), box-shadow var(--t-2);
}

.photo-upload-dropzone:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.photo-upload-title {
    font-weight: 700;
    color: var(--text);
}

.photo-upload-subtitle {
    color: var(--muted);
    font-size: .85rem;
}

.photo-upload-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.photo-upload-preview-wrap {
    display: grid;
    gap: 8px;
}

.photo-upload-preview {
    width: 100%;
    max-width: 400px;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: var(--r-md);
    border: 1px solid var(--line-2);
    background: var(--panel);
}

.photo-upload-crop {
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1 / 1;
    border-radius: var(--r-md);
    border: 1px solid var(--line-2);
    background: var(--color-primary-dark);
    cursor: grab;
}

.photo-upload-preview-wrap,
.photo-upload-controls {
    max-width: 400px;
}

.photo-upload-crop:active {
    cursor: grabbing;
}

.photo-upload-meta {
    font-size: .84rem;
    color: var(--muted);
}

.photo-upload-error {
    font-size: .84rem;
    color: var(--danger);
    font-weight: 600;
}

.photo-upload-progress {
    width: 100%;
    height: 10px;
    background: var(--bg-2);
    border-radius: var(--r-full);
    overflow: hidden;
    border: 1px solid var(--line);
}

.photo-upload-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--primary), var(--color-technical));
    transition: width .18s linear;
}

.photo-upload-progress-text {
    font-size: .84rem;
    color: var(--text-2);
    font-weight: 600;
}

.qr-view-wrap {
    margin: 14px 0;
}

.qr-view-wrap canvas {
    width: min(320px, 100%);
    height: auto;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 8px;
}

.qr-view-wrap img {
    width: min(320px, 100%);
    height: auto;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 8px;
}

.alert-warning {
    background: var(--warning-bg);
    border: 1px solid var(--warning-bd);
    color: var(--warning-text);
}

@media (max-width: 900px) {
    .field-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .field-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .field-grid-2,
    .field-grid-3,
    .field-grid-4,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .photo-upload-controls {
        grid-template-columns: 1fr;
    }
}

.chat-fab-panel.is-open { display: block; }

.chat-fab-panel .block-title {
    color: var(--color-primary);
    letter-spacing: 0.2px;
}

.chat-close-btn {
    padding: 7px 12px;
    border-color: rgba(79, 55, 36, 0.25);
    background: rgba(247, 243, 239, 0.9);
    color: var(--color-primary);
}

.chat-note {
    margin: 0 0 8px;
    font-size: .875rem;
    color: var(--color-text-secondary);
    font-weight: 600;
}

/* ── Messages container ── */
.chat-messages {
    max-height: 340px;
    overflow-y: auto;
    background: rgba(247, 243, 239, 0.9);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 14px;
    display: grid;
    gap: 10px;
}

/* ── Bubble base ── */
.chat-msg { max-width: 88%; }

.chat-msg p {
    margin: 0;
    padding: 9px 13px;
    border-radius: var(--r-lg);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: .9rem;
}

/* ── User bubble (right-aligned, brand color) ── */
.chat-msg-user { margin-left: auto; }

.chat-msg-user p {
    background: var(--primary);
    color: var(--text-inv);
    border-top-right-radius: var(--r-xs);
    box-shadow: 0 2px 8px rgba(79, 55, 36, .26);
}

/* ── Assistant bubble (left-aligned) ── */
.chat-msg-assistant p {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-top-left-radius: var(--r-xs);
}

/* ── Loading state bubble ── */
.chat-msg-loader p {
    color: var(--muted);
    background: var(--bg-2);
    border: 1px dashed var(--line-2);
    border-top-left-radius: var(--r-xs);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* ── Input form ── */
.chat-form {
    margin-top: 12px;
    display: grid;
    gap: 8px;
}

.chat-label {
    font-size: .875rem;
    font-weight: 600;
    color: var(--text-2);
}

.chat-form textarea {
    width: 100%;
    border: 1.5px solid var(--line);
    border-radius: var(--r-md);
    padding: 10px 12px;
    font: inherit;
    font-size: .9rem;
    resize: vertical;
    min-height: 68px;
    background: var(--panel);
    color: var(--text);
    transition:
        border-color var(--t-2),
        box-shadow var(--t-2),
        background var(--t-2);
}

.chat-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.chat-actions { display: flex; justify-content: flex-end; }


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §15 · LOADER
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.inline-loader {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--line-2);
    border-top-color: var(--primary);
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }


/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   §16 · RESPONSIVE
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
@media (max-width: 768px) {
    html,
    body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    body {
        font-size: 16px;
        line-height: 1.6;
    }

    .app-shell {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    /* Topbar */
    .topbar {
        padding: 0 calc(14px + env(safe-area-inset-right, 0px)) 0 calc(14px + env(safe-area-inset-left, 0px)); /* FIXED: safe areas laterales */
        width: 100%; /* FIXED: evita recorte por uso de 100vw */
        max-width: 100%; /* FIXED: topbar no excede viewport */
        margin: 0;
        left: 0;
        right: 0;
    }

    .brand { font-size: 1.05rem; }
    .brand-logo { width: 30px; height: 30px; }

    .menu-toggle { display: inline-flex; }

    /*
     * Mobile nav: rendered as dropdown below topbar.
     * topbar has overflow: visible so the dropdown is not clipped.
     * Position relative to topbar (which is position: sticky).
     */
    .topnav {
        position: absolute;
        left: 14px;
        right: 14px;
        top: calc(var(--topbar-h) + 6px);
        display: none;
        flex-direction: column;
        background: rgba(17, 11, 9, .98);
        border: 1px solid rgba(203, 163, 119, .45);
        border-radius: var(--r-xl);
        padding: 8px;
        box-shadow: var(--shadow-lg);
        z-index: 30;
    }

    .topnav.is-open { display: flex; }

    .topnav a {
        padding: 10px 13px;
        border-radius: var(--r-sm);
        width: 100%;
    }

    /* Layout */
    .main-content {
        width: calc(100% - 20px);
        margin: 16px auto;
        gap: 12px;
        max-width: calc(100% - 20px);
        overflow-x: hidden;
    }

    .login-card { padding: 22px 18px; }

    .dashboard-grid { grid-template-columns: 1fr; }
    .dashboard-grid > * { min-width: 0; }

    /* Block title row */
    .block-title-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .block-tools {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    /* Forms */
    .form-actions { flex-direction: column; }

    .filters-row { grid-template-columns: 1fr; }

    .filters-actions { flex-direction: column; }
    .filters-actions .btn { width: 100%; }

    /* FIXED: evita que tablas del dashboard fuercen zoom/escala horizontal */
    .table-wrap {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    .table {
        width: 100%;
        min-width: 0;
        table-layout: fixed;
    }

    .table th,
    .table td {
        white-space: normal;
        word-break: break-word;
    }

    .table-actions {
        flex-wrap: wrap;
        row-gap: 4px;
    }

    .block-title { font-size: 1.2rem; }

    .field label { font-size: 1rem; }

    .field input,
    .field textarea,
    .field select,
    .btn { font-size: 1rem; }

    /* Chart */
    .chart-wrap { height: 240px; }

    /* Chat */
    .chat-messages { max-height: 280px; }
    .chat-msg      { max-width: 96%; }
    .chat-actions  { justify-content: stretch; }
    .chat-actions .btn { width: 100%; }

    .chat-fab {
        right: calc(10px + env(safe-area-inset-right, 0px));
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        padding: 12px 16px;
        font-size: 1rem;
        z-index: 80;
    }

    .chat-fab-panel {
        right: calc(10px + env(safe-area-inset-right, 0px));
        left: 10px;
        bottom: calc(62px + env(safe-area-inset-bottom, 0px));
        width: auto;
        max-height: calc(100dvh - 86px);
        z-index: 81;
    }

    .admin-checklist-grid,
    .project-state-grid {
        grid-template-columns: 1fr;
    }
}
