/* ================================================================
 * Foliador · Ecatepec
 * Paleta institucional Pantone:
 *   Vino   #691C32  (Pantone 7421 C)
 *   Tan    #BC955C  (Pantone 465 C)
 *   Crema  #ECD798  (Pantone 7402 C)
 * ================================================================ */

:root {
    /* ===== Paleta institucional ===== */
    --vino:         #691C32;
    --vino-oscuro:  #4a1322;
    --vino-claro:   #8b3146;
    --tan:          #BC955C;
    --tan-claro:    #d4b685;
    --tan-oscuro:   #9a7842;
    --crema:        #ECD798;
    --crema-claro:  #f7ecc9;
    --crema-bg:     #faf6ec;

    /* ===== Neutros ===== */
    --bg:        #f5f0e6;
    --surface:   #ffffff;
    --surface-2: #faf6ec;
    --border:    #e2dac8;
    --border-2:  #c8bda3;
    --text:      #2b1d18;
    --text-mute: #6b5d52;
    --text-soft: #9a8d80;

    /* ===== Estado ===== */
    --danger:    #c53030;
    --success:   #2f7d4f;
    --warning:   #b35900;

    /* ===== Tokens ===== */
    --radius:    8px;
    --radius-sm: 5px;
    --shadow:    0 1px 2px rgba(74,19,34,.08), 0 4px 14px rgba(74,19,34,.06);
    --shadow-lg: 0 4px 24px rgba(74,19,34,.12), 0 14px 48px rgba(74,19,34,.10);
    --mono:      ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
    --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
 * LOGIN
 * ============================================================ */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 30% 0%, rgba(236,215,152,.55) 0%, transparent 55%),
        radial-gradient(ellipse at 100% 100%, rgba(188,149,92,.30) 0%, transparent 55%),
        linear-gradient(160deg, #faf6ec 0%, #f0e6cf 100%);
    padding: 20px;
    position: relative;
}
.login-body::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, var(--vino) 0%, var(--vino) 33%, var(--tan) 33%, var(--tan) 66%, var(--crema) 66%, var(--crema) 100%);
    height: 5px;
    top: 0;
    bottom: auto;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 36px 32px 24px;
    border: 1px solid var(--border);
}
.login-head {
    text-align: center;
    margin-bottom: 26px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.login-head img.login-logo {
    max-width: 220px;
    height: auto;
    margin-bottom: 14px;
}
.login-head h1 {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--vino);
}
.login-head p {
    margin: 0;
    color: var(--text-mute);
    font-size: 13px;
}
#login-form { display: flex; flex-direction: column; gap: 14px; }
#login-form label { display: flex; flex-direction: column; gap: 6px; }
#login-form label span {
    font-size: 12px;
    color: var(--text-mute);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.login-foot {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-soft);
    font-size: 11px;
    font-family: var(--mono);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.login-foot .muni {
    color: var(--vino);
    font-family: var(--font);
    font-weight: 600;
    letter-spacing: 0;
}
.error {
    color: var(--danger);
    background: #fff5f5;
    border: 1px solid #fed7d7;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin: 0;
}

/* ============================================================
 * FORM BASE
 * ============================================================ */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="color"],
select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--vino);
    box-shadow: 0 0 0 3px rgba(105,28,50,.14);
}
input[type="color"] {
    padding: 2px;
    height: 36px;
    cursor: pointer;
}

/* ============================================================
 * BOTONES
 * ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 14px;
    border: 1px solid var(--border-2);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--tan); color: var(--vino); }
.btn-primary {
    background: var(--vino);
    color: white;
    border-color: var(--vino);
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(105,28,50,.20);
}
.btn-primary:hover {
    background: var(--vino-oscuro);
    border-color: var(--vino-oscuro);
    color: white;
}
.btn-tan {
    background: var(--tan);
    color: white;
    border-color: var(--tan);
}
.btn-tan:hover { background: var(--tan-oscuro); border-color: var(--tan-oscuro); color: white; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============================================================
 * APP SHELL
 * ============================================================ */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: relative;
}
.app-header::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--vino) 0%, var(--vino) 50%, var(--tan) 50%, var(--tan) 75%, var(--crema) 75%, var(--crema) 100%);
}
.app-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}
.app-brand img {
    height: 38px;
    width: auto;
}
.app-brand-divider {
    width: 1px;
    height: 32px;
    background: var(--border);
}
.app-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}
.app-brand-name {
    font-weight: 700;
    font-size: 15px;
    color: var(--vino);
    letter-spacing: -.01em;
}
.app-brand-sub {
    font-size: 11px;
    color: var(--text-mute);
    font-weight: 500;
}

.app-nav { display: flex; gap: 4px; }
.app-nav a {
    padding: 8px 14px;
    color: var(--text-mute);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: all .15s;
    text-transform: uppercase;
    letter-spacing: .02em;
}
.app-nav a:hover { background: var(--surface-2); color: var(--vino); }
.app-nav a.active {
    background: var(--vino);
    color: white;
}
.app-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}
.app-user-info { color: var(--text-mute); }
.app-user-info strong { color: var(--vino); font-weight: 700; }

.app-main {
    flex: 1;
    padding: 24px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* ============================================================
 * FOLIADOR
 * ============================================================ */
.foliar-grid {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 24px;
}
@media (max-width: 980px) {
    .foliar-grid { grid-template-columns: 1fr; }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.panel-head h2 {
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    color: var(--vino);
    letter-spacing: .02em;
    text-transform: uppercase;
}
.panel-body { padding: 18px; }

.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}
.field-group:last-child { margin-bottom: 0; }
.field-group label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.field-row { display: flex; gap: 8px; }
.field-row > * { flex: 1; }

.field-section {
    border-top: 1px solid var(--border);
    padding-top: 16px;
    margin-top: 16px;
}
.field-section:first-child { border: 0; padding-top: 0; margin-top: 0; }
.field-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--vino);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.field-section-title::before {
    content: '';
    width: 18px;
    height: 2px;
    background: var(--tan);
    border-radius: 2px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.checkbox-row input { width: auto; cursor: pointer; accent-color: var(--vino); }
.checkbox-row span { font-size: 13px; color: var(--text); font-weight: 500; }

.actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ============================================================
 * PREVIEW
 * ============================================================ */
.preview-wrap {
    padding: 28px;
    background:
        repeating-linear-gradient(45deg, transparent 0 12px, rgba(188,149,92,.06) 12px 13px),
        var(--surface-2);
    min-height: 540px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.preview-info {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-mute);
}
.preview-info span strong {
    color: var(--vino);
    font-family: var(--mono);
    margin-left: 4px;
    font-weight: 700;
}
.preview-stage {
    background: white;
    box-shadow: 0 4px 16px rgba(74,19,34,.18), 0 1px 2px rgba(74,19,34,.10);
    position: relative;
    cursor: crosshair;
    border-radius: 2px;
    overflow: hidden;
    border: 1px solid #e8e4dc;
}
.preview-folio {
    position: absolute;
    cursor: move;
    user-select: none;
    white-space: nowrap;
    transform-origin: 0 0;
    padding: 0;
    line-height: 1;
    font-family: Helvetica, Arial, sans-serif;
}
.preview-folio.dragging { opacity: .7; }
.preview-folio:hover {
    outline: 2px dashed rgba(105,28,50,.55);
    outline-offset: 2px;
}
.preview-help {
    color: var(--text-mute);
    font-size: 12px;
    text-align: center;
    max-width: 420px;
    line-height: 1.5;
}
.preview-help strong { color: var(--vino); }

/* ============================================================
 * AUDIT TABLE
 * ============================================================ */
.audit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.audit-table th {
    text-align: left;
    padding: 12px 14px;
    background: var(--vino);
    color: white;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 700;
    border-bottom: 2px solid var(--tan);
}
.audit-table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
.audit-table tr:nth-child(even) td { background: var(--surface-2); }
.audit-table tr:hover td { background: var(--crema-claro); }
.audit-table .mono { font-family: var(--mono); font-size: 12px; color: var(--text-mute); }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-soft);
}
.empty-state p { margin: 0; font-size: 13px; }

/* ============================================================
 * USUARIOS
 * ============================================================ */
.users-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 24px;
}
@media (max-width: 980px) {
    .users-grid { grid-template-columns: 1fr; }
}
.help-text {
    font-size: 12px;
    color: var(--text-mute);
    margin: 0 0 12px;
    line-height: 1.5;
}
.area-add {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}
.area-add input { flex: 1; }
.area-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.area-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: var(--crema-claro);
    border: 1px solid var(--tan-claro);
    color: var(--vino);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.area-tag button {
    background: transparent;
    border: 0;
    color: var(--tan-oscuro);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    border-radius: 50%;
    transition: all .15s;
}
.area-tag button:hover {
    background: var(--vino);
    color: white;
}
.row-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}
.row-actions .btn {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
}
.row-actions .btn-danger {
    color: var(--danger);
    border-color: transparent;
}
.row-actions .btn-danger:hover {
    background: #fff5f5;
    border-color: #fed7d7;
    color: var(--danger);
}
.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.badge-admin {
    background: var(--vino);
    color: white;
}
.badge-user {
    background: var(--crema-claro);
    color: var(--vino);
    border: 1px solid var(--tan-claro);
}

/* Modal de password generado */
.pwd-display {
    background: var(--surface-2);
    border: 2px dashed var(--tan);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
    margin: 12px 0;
}
.pwd-display .pwd-label {
    font-size: 11px;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 700;
    margin-bottom: 6px;
}
.pwd-display .pwd-value {
    font-family: var(--mono);
    font-size: 22px;
    color: var(--vino);
    font-weight: 700;
    letter-spacing: .02em;
    user-select: all;
}
.pwd-display .pwd-warn {
    font-size: 11px;
    color: var(--warning);
    margin-top: 8px;
}
.modal-card.wide { max-width: 460px; }

/* ============================================================
 * TOAST
 * ============================================================ */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--vino);
    color: white;
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    z-index: 1000;
    animation: toast-in .25s ease-out;
    border-left: 4px solid var(--tan);
}
.toast.error { background: var(--danger); border-left-color: #fed7d7; }
.toast.success { background: var(--success); border-left-color: #c6f6d5; }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
 * MODAL
 * ============================================================ */
.modal-bg {
    position: fixed;
    inset: 0;
    background: rgba(43,29,24,.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    backdrop-filter: blur(2px);
}
.modal-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 380px;
    padding: 22px;
    border-top: 4px solid var(--vino);
}
.modal-card h3 {
    margin: 0 0 14px;
    font-size: 16px;
    color: var(--vino);
}
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}
