:root {
    --vino: #7a1530;
    --vino-oscuro: #4a0d1e;
    --vino-claro: #a12f4d;
    --vino-tint: #fbeef1;
    --oro: #b8863b;
    --bg: #f5f3f1;
    --card: #ffffff;
    --text: #241a1c;
    --text-secondary: #7a6b6d;
    --text-muted: #a6989a;
    --borde: #ebe2e2;
    --borde-fuerte: #ddd0d1;
    --verde: #1a7a4c;
    --verde-tint: #e8f6ee;
    --rojo: #c0293f;
    --rojo-tint: #fbeaec;
    --amarillo: #a3690a;
    --amarillo-tint: #fdf3e0;
    --azul: #1e5f8f;
    --azul-tint: #e8f2fa;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(36, 20, 22, .06);
    --shadow-md: 0 4px 16px rgba(36, 20, 22, .08);
    --shadow-lg: 0 12px 32px rgba(36, 20, 22, .16);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--vino); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; margin: 0 0 18px; display: flex; align-items: center; gap: 10px; }
h1 .icon { color: var(--vino); }
h2 { font-size: 16px; font-weight: 700; margin: 0 0 4px; }
h3 { font-size: 15px; font-weight: 700; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }

.icon { flex-shrink: 0; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 15% 15%, rgba(255,255,255,.06), transparent 40%),
        linear-gradient(160deg, var(--vino-oscuro), var(--vino) 60%, var(--vino-claro));
    padding: 16px;
}
.login-box {
    background: var(--card);
    border-radius: 20px;
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}
.login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 4px;
}
.login-brand .icon { color: var(--vino); width: 30px; height: 30px; }
.login-title { font-size: 24px; font-weight: 800; text-align: center; color: var(--vino); letter-spacing: -0.02em; }
.login-sub { text-align: center; color: var(--text-secondary); font-size: 13px; margin-bottom: 26px; }

/* ── Formularios ───────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--borde-fuerte);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--card);
    color: var(--text);
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--vino-claro);
    box-shadow: 0 0 0 3px rgba(122, 21, 48, .12);
}
input[type=checkbox] { width: auto; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: 1.5px solid transparent;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    font-family: inherit;
    transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--vino); color: #fff; }
.btn-primary:hover { background: var(--vino-oscuro); text-decoration: none; }
.btn-secondary { background: var(--card); color: var(--text); border-color: var(--borde-fuerte); }
.btn-secondary:hover { background: var(--bg); text-decoration: none; border-color: var(--text-muted); }
.btn-danger { background: var(--rojo-tint); color: var(--rojo); }
.btn-danger:hover { background: var(--rojo); color: #fff; text-decoration: none; }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ── Alertas / flash ───────────────────────────────────────────────────── */
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 12px; line-height: 1.4; }
.alert .icon { flex-shrink: 0; margin-top: 1px; }
.alert-danger  { background: var(--rojo-tint); color: var(--rojo); }
.alert-success { background: var(--verde-tint); color: var(--verde); }
.alert-warning { background: var(--amarillo-tint); color: var(--amarillo); }
.alert-info    { background: var(--azul-tint); color: var(--azul); }

/* ── Layout con sidebar ────────────────────────────────────────────────── */
.header {
    position: sticky; top: 0; z-index: 30;
    height: 58px;
    background: var(--vino);
    color: #fff;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px;
    box-shadow: var(--shadow-md);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 16px; letter-spacing: -0.01em; }
.header-brand .icon { color: var(--oro); }
.header-title { font-weight: 600; font-size: 13px; opacity: .85; padding-left: 10px; border-left: 1px solid rgba(255,255,255,.25); }
.menu-btn { background: none; border: none; color: #fff; cursor: pointer; padding: 6px; border-radius: 8px; display: flex; }
.menu-btn:hover { background: rgba(255,255,255,.12); }
.user-badge { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; background: rgba(255,255,255,.15); padding: 6px 12px; border-radius: 999px; }
.icon-link { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 9px; color: #fff; }
.icon-link:hover { background: rgba(255,255,255,.15); text-decoration: none; }
.header-logo { height: 28px; width: 28px; object-fit: contain; border-radius: 6px; background: #fff; padding: 2px; }

.sidebar {
    position: fixed; top: 58px; left: 0; bottom: 0;
    width: 232px;
    background: var(--vino-oscuro);
    color: #f0dde1;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform .2s;
    z-index: 25;
    padding-bottom: 20px;
}
.sidebar.open { transform: translateX(0); }
.nav-list { list-style: none; margin: 0; padding: 14px 10px; }
.nav-section { display: block; padding: 16px 10px 6px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #c99; font-weight: 700; }
.nav-list a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; color: #f0dde1; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; margin-bottom: 1px; }
.nav-list a .icon { color: #d9a8b3; flex-shrink: 0; }
.nav-list a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav-list a.active { background: rgba(255,255,255,.14); color: #fff; }
.nav-list a.active .icon { color: var(--oro); }

.main-content { margin-left: 0; padding: 22px 18px 60px; max-width: 1150px; }
@media (min-width: 900px) {
    .sidebar { transform: translateX(0); }
    .main-content { margin-left: 232px; }
}

.card { background: var(--card); border: 1px solid var(--borde); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow-sm); }
.card-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--borde); }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-secondary); font-weight: 700; }
tbody tr:hover { background: var(--vino-tint); }
tbody tr:last-child td { border-bottom: none; }
td a { font-weight: 600; }
.table-empty { text-align: center; color: var(--text-muted); padding: 28px 12px !important; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-verde  { background: var(--verde-tint); color: var(--verde); }
.badge-rojo   { background: var(--rojo-tint); color: var(--rojo); }
.badge-amarillo { background: var(--amarillo-tint); color: var(--amarillo); }
.badge-gris { background: var(--borde); color: var(--text-secondary); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card {
    background: var(--card); border: 1px solid var(--borde); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow-sm); display: flex; align-items: center; gap: 14px;
    color: var(--text); transition: box-shadow .15s, transform .1s;
}
a.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); text-decoration: none; }
.stat-icon {
    width: 44px; height: 44px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
    background: var(--vino-tint); color: var(--vino); flex-shrink: 0;
}
.stat-card .valor { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.stat-card .etiqueta { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .icon { color: var(--borde-fuerte); margin-bottom: 10px; }

.credential-box {
    background: var(--vino-tint); border: 1.5px dashed var(--vino-claro); border-radius: var(--radius);
    padding: 18px; display: flex; flex-direction: column; gap: 10px; margin: 14px 0;
}
.credential-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--card); border-radius: var(--radius-sm); padding: 10px 14px; border: 1px solid var(--borde); }
.credential-row .valor { font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; font-size: 14px; font-weight: 700; }
.copy-btn { background: none; border: none; color: var(--vino); cursor: pointer; padding: 4px; display: flex; border-radius: 6px; }
.copy-btn:hover { background: var(--vino-tint); }

.doc-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; border-bottom: 2px solid var(--vino); padding-bottom: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.doc-header .logo { height: 46px; max-width: 160px; object-fit: contain; }
.doc-title { font-size: 20px; font-weight: 800; color: var(--vino); display: flex; align-items: center; gap: 8px; }
.doc-meta { font-size: 12.5px; color: var(--text-secondary); }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.doc-party-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 700; margin-bottom: 4px; }
.doc-totales { margin-top: 16px; display: flex; justify-content: flex-end; }
.doc-totales-box { min-width: 240px; background: var(--vino-tint); border-radius: var(--radius); padding: 16px 18px; }
.doc-totales-box .fila { display: flex; justify-content: space-between; font-size: 13.5px; padding: 3px 0; color: var(--text-secondary); }
.doc-totales-box .fila.total { border-top: 1px solid var(--vino-claro); margin-top: 8px; padding-top: 10px; font-size: 17px; font-weight: 800; color: var(--vino); }

.avatar-logo { height: 26px; width: 26px; object-fit: contain; border-radius: 6px; background: #fff; }
