/* =====================================================================
   Renovar SCE · v1 — hoja de estilos (sin dependencias externas)
   Paleta: verde estilo Excel (temas: verde/azul/naranja vía data-theme)
   Tipografía: estilo Excel (Calibri)
   ===================================================================== */

:root {
    --brand-900: #0b2e1c;
    --brand-800: #12502e;
    --brand-700: #186a3d;
    --brand-600: #217346;  /* verde marca Excel */
    --brand-100: #d7ecdf;
    --brand-50:  #eef6f1;
    --slate-900: #0f172a;
    --slate-700: #334155;
    --slate-500: #64748b;
    --slate-400: #94a3b8;
    --slate-200: #e2e8f0;
    --slate-100: #f1f5f9;
    --bg:    #f8fafc;
    --card:  #ffffff;
    --green-700: #15803d;
    --green-100: #dcfce7;
    --red-700:   #b91c1c;
    --red-100:   #fee2e2;
    --amber-800: #92400e;
    --amber-100: #fef3c7;
    --blue-800:  #1e40af;
    --blue-100:  #dbeafe;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
    --font: Calibri, "Segoe UI", Carlito, "Helvetica Neue", Arial, sans-serif;
}

/* --- Temas de color (el activo se elige en Configuración) ---------------- */
[data-theme="azul"] {
    --brand-900: #072a4e;
    --brand-800: #0b3f73;
    --brand-700: #0f5dab;
    --brand-600: #1b75c4;
    --brand-100: #d6e9f8;
    --brand-50:  #eef5fc;
}
[data-theme="naranja"] {
    --brand-900: #5e1f0c;
    --brand-800: #8a2c12;
    --brand-700: #b8431f;
    --brand-600: #d35230;  /* naranja marca PowerPoint */
    --brand-100: #fbdcd2;
    --brand-50:  #fdf0ea;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--slate-900);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-600); }
h1, h2, h3 { line-height: 1.25; }

/* --- Estructura app --------------------------------------------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px;
    background: linear-gradient(180deg, var(--brand-800) 0%, var(--brand-900) 100%);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    z-index: 50;
}
.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 18px 16px;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.brand-logo {
    max-width: 190px;
    height: 44px;
    object-fit: contain;
    background: #ffffff;
    border-radius: 10px;
    padding: 5px 12px;
}
.brand-mark {
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--brand-600);
    color: #fff;
    font-weight: 800; font-size: 20px;
    border-radius: 10px;
    flex: none;
}
.nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #cbd5e1;
    text-decoration: none;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-link.active { background: var(--brand-600); color: #fff; }
.nav-icon { width: 20px; height: 20px; flex: none; display: inline-flex; }
.nav-icon svg { width: 100%; height: 100%; }

/* --- Submenú del sidebar ------------------------------------------------- */
.nav-toggle {
    width: 100%;
    background: none;
    border: 0;
    font: inherit;
    cursor: pointer;
    text-align: left;
}
.nav-toggle .nav-chevron {
    margin-left: auto;
    width: 16px;
    height: 16px;
    flex: none;
    transition: transform .18s ease;
}
.nav-item.open .nav-toggle .nav-chevron { transform: rotate(180deg); }
.nav-sub {
    display: none;
    list-style: none;
    margin: 2px 0 6px;
    padding: 0 0 0 20px;
}
.nav-item.open .nav-sub { display: block; }
.nav-sub .nav-link { padding: 8px 12px; font-size: 14px; }
.nav-sub .nav-link.active { background: rgba(255, 255, 255, .12); }

/* --- Tablas y formularios ------------------------------------------------ */
.th-num, .td-num { text-align: right; font-variant-numeric: tabular-nums; }
.form-hint { display: block; margin-top: 6px; font-size: 13px; color: var(--slate-500); font-style: normal; }
.form-hint a { color: var(--brand-600); }
.brand-link { display: inline-flex; border-radius: 10px; }
.brand-link:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* --- Brazaletes: filas de rangos ------------------------------------------------ */
.rango-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.rango-tag { font-weight: 700; color: var(--slate-700); }
.rango-desde {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    background: var(--slate-100);
    padding: 11px 13px;
    border-radius: 8px;
    color: var(--slate-700);
}
.rango-sep { color: var(--slate-400); font-weight: 700; }
.rango-select {
    padding: 11px 13px;
    border: 1px solid var(--slate-200);
    border-radius: 8px;
    font-size: 15px;
    font-family: var(--font);
    background: #fff;
    color: var(--slate-800);
}
.rango-select:focus { outline: 2px solid var(--brand-100); border-color: var(--brand-600); }
.rango-hasta { min-width: 110px; font-variant-numeric: tabular-nums; }
.rango-com { flex: 1; min-width: 180px; }
.sidebar-foot {
    padding: 14px 18px;
    font-size: 12px;
    color: var(--slate-400);
    border-top: 1px solid rgba(255, 255, 255, .08);
}

.main { margin-left: 240px; flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 14px;
    padding: 12px 24px;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--slate-200);
}
.topbar-title { font-size: 18px; font-weight: 700; margin: 0; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; }
.user-name { font-weight: 600; font-size: 14px; }
.user-email { font-size: 12px; color: var(--slate-500); }
.logout-form { margin: 0; }
.menu-toggle {
    display: none;
    border: 1px solid var(--slate-200);
    background: #fff;
    border-radius: 8px;
    font-size: 18px;
    padding: 6px 11px;
    cursor: pointer;
    color: var(--slate-700);
}

.content { padding: 28px; max-width: 1200px; width: 100%; margin: 0 auto; flex: 1; }

/* --- Componentes ------------------------------------------------------ */
.page-head { margin-bottom: 20px; }
.page-head h1 { margin: 0 0 4px; font-size: 26px; }
.muted { color: var(--slate-500); }
.empty { color: var(--slate-500); font-style: italic; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex; flex-direction: column; gap: 6px;
    border-top: 3px solid var(--brand-600);
}
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--slate-500); font-weight: 600; }
.stat-value { font-size: 30px; font-weight: 800; }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; margin-top: 16px; }

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; }
.card + .card { margin-top: 18px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
    text-align: left;
    font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--slate-500); font-weight: 600;
    padding: 8px 10px;
    border-bottom: 2px solid var(--slate-200);
}
.table td { padding: 10px; border-bottom: 1px solid var(--slate-100); }
.table tr:last-child td { border-bottom: none; }

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--brand-50);
    color: var(--brand-800);
    font-size: 12px; font-weight: 600;
}

.checklist { margin: 12px 0; padding-left: 20px; color: var(--slate-700); }
.checklist li { margin-bottom: 4px; }

.placeholder-card { text-align: center; padding: 48px 24px; max-width: 560px; margin: 24px auto; }
.placeholder-icon { font-size: 48px; margin-bottom: 12px; }
.placeholder-card h2 { margin: 0 0 8px; }
.placeholder-card .btn { margin-top: 12px; }

/* --- Botones y formularios -------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 10px 18px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-weight: 600; font-size: 15px;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--brand-600); color: #fff; }
.btn-primary:hover { background: var(--brand-800); }
.btn-ghost { background: transparent; color: var(--slate-700); border-color: var(--slate-200); padding: 8px 14px; font-size: 14px; }
.btn-ghost:hover { border-color: var(--slate-400); }
.btn-block { width: 100%; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field input {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--slate-200);
    border-radius: 8px;
    font-size: 15px;
    font-family: var(--font);
    background: #fff;
}
.field input:focus { outline: 2px solid var(--brand-100); border-color: var(--brand-600); }
.field select {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--slate-200);
    border-radius: 8px;
    font-size: 15px;
    font-family: var(--font);
    background: #fff;
    color: var(--slate-800);
}
.field select:focus { outline: 2px solid var(--brand-100); border-color: var(--brand-600); }
.badge-green { background: var(--brand-50); color: var(--brand-800); }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-slate { background: #f1f5f9; color: #475569; }

/* --- Flashes ----------------------------------------------------------- */
.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: 500;
}
.flash-success { background: var(--green-100); color: var(--green-700); border: 1px solid #bbf7d0; }
.flash-error   { background: var(--red-100);   color: var(--red-700);   border: 1px solid #fecaca; }
.flash-info    { background: var(--blue-100);  color: var(--blue-800);  border: 1px solid #bfdbfe; }

/* --- Login -------------------------------------------------------------- */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, var(--brand-800) 0%, var(--brand-900) 60%, var(--brand-700) 100%);
}
.login-card {
    background: #fff;
    width: min(400px, 94vw);
    padding: 36px 32px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.login-brand { display: flex; align-items: center; justify-content: center; }
.login-logo { max-width: 240px; height: 52px; object-fit: contain; }
.login-sub { color: var(--slate-500); margin: 6px 0 20px; }

/* --- Módulos: tablas, formularios y acciones -------------------------------- */
.toolbar { display: flex; justify-content: flex-end; gap: 10px; margin-bottom: 16px; }
.card-narrow { max-width: 560px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-danger { color: #b91c1c; border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; border-color: #fca5a5; color: #991b1b; }
.th-actions, .td-actions { text-align: right; white-space: nowrap; }
.inline-form { display: inline; }
.form-error { display: block; color: #b91c1c; font-size: 13px; font-style: normal; margin-top: 5px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-105%); transition: transform .25s ease; box-shadow: 0 0 40px rgba(0,0,0,.3); }
    .sidebar.open { transform: none; }
    .main { margin-left: 0; }
    .menu-toggle { display: inline-flex; }
    .content { padding: 18px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .user-email { display: none; }
}
@media (max-width: 520px) {
    .stats-grid { grid-template-columns: 1fr; }
    .topbar { padding: 10px 14px; }
}

/* --- Tablas como tarjetas en móvil (vista del comisionista) ----------------- */
@media (max-width: 640px) {
    .table-mobile-cards thead { display: none; }
    .table-mobile-cards,
    .table-mobile-cards tbody,
    .table-mobile-cards tr,
    .table-mobile-cards td { display: block; width: 100%; }
    .table-mobile-cards tr {
        background: var(--card);
        border: 1px solid var(--slate-200);
        border-radius: var(--radius);
        margin-bottom: 12px;
        padding: 4px 0;
    }
    .table-mobile-cards td {
        border-bottom: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 8px 14px;
        text-align: right;
    }
    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--slate-500);
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: .04em;
        text-align: left;
        flex-shrink: 0;
    }
    .table-mobile-cards td.td-num { text-align: right; }
}

/* --- Selector de temas (Configuración) ---------------------------------- */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin: 18px 0 24px;
}
.theme-card { position: relative; }
.theme-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.theme-card label {
    display: block;
    border: 2px solid var(--slate-200);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    background: var(--card);
    transition: border-color .15s, box-shadow .15s;
}
.theme-card label:hover { border-color: var(--slate-400); }
.theme-card input:checked + label {
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3px var(--brand-100);
}
.theme-card input:focus-visible + label { outline: 2px solid var(--brand-600); outline-offset: 2px; }
.theme-stripes { display: flex; height: 72px; }
.theme-stripes span { flex: 1; }
.theme-name {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    font-weight: 600;
    color: var(--slate-700);
}
.theme-now {
    font-size: 12px;
    font-weight: 700;
    color: var(--brand-700);
    background: var(--brand-100);
    border-radius: 999px;
    padding: 2px 10px;
}

/* --- Detalle: lista de datos y grid de 3 ---------------------------------- */
.detail-list { margin: 0; display: grid; gap: 10px; }
.detail-list > div { display: grid; grid-template-columns: 110px 1fr; gap: 12px; }
.detail-list dt { font-weight: 600; color: var(--slate-500); font-size: 14px; }
.detail-list dd { margin: 0; }
.stats-3 { grid-template-columns: repeat(3, 1fr); margin-bottom: 18px; }
@media (max-width: 900px) {
    .stats-3 { grid-template-columns: 1fr; }
}

/* --- Informes: filtros ------------------------------------------------------ */
.filter-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.pill {
    display: inline-block;
    padding: 7px 14px;
    border-radius: 999px;
    border: 1px solid var(--slate-200);
    color: var(--slate-700);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    background: #fff;
}
.pill:hover { border-color: var(--brand-600); color: var(--brand-700); }
.pill.active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.filter-custom {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}
.filter-custom label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--slate-500); }
.filter-custom input[type="date"] {
    padding: 8px 10px;
    border: 1px solid var(--slate-200);
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--font);
}

/* --- Insignia del rango del usuario ----------------------------------------- */
.user-role {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--brand-700);
    background: var(--brand-100);
    padding: 2px 8px;
    border-radius: 999px;
    margin-top: 2px;
}

/* --- Checkbox en formularios -------------------------------------------------- */
.field-check { flex-direction: row !important; align-items: center; gap: 10px; cursor: pointer; }
.field-check input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand-600); }
.field-check span { font-weight: 600; }

/* --- Encabezados de tabla centrados ------------------------------------------- */
.th-center { text-align: center; }
.td-center { text-align: center; }
