:root {
    --color-primary: #A6093D;
    --color-secondary: #6F4E37;
    --color-accent: #D4AF37;
    --color-sky: #3DB7E4;
    --color-light: #FFFFFF;
    --color-dark: #2B1B12;
    --color-success: #2E7D32;
    --color-danger: #C0392B;
    --color-warning: #E0A800;
    --color-info: #3DB7E4;
    --color-bg: #F7F3EE;

    --sidebar-width: 260px;
    --topbar-height: 64px;
    --radius: 10px;
    --shadow-sm: 0 1px 3px rgba(43, 27, 18, 0.08);
    --shadow-md: 0 4px 16px rgba(43, 27, 18, 0.10);
    --transition: all 0.2s ease;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-dark);
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; }

/* ============================================================
   LAYOUT GENERAL
============================================================ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ---------- SIDEBAR ---------- */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--color-secondary) 0%, #4a3324 100%);
    color: #fff;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-md);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
}

.sidebar-brand .logo-badge {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    border: 2px solid var(--color-accent);
    flex-shrink: 0;
}

.sidebar-brand .brand-text strong {
    display: block;
    font-size: 14.5px;
    line-height: 1.25;
}

.sidebar-brand .brand-text span {
    display: block;
    font-size: 11px;
    color: var(--color-accent);
    letter-spacing: .04em;
    margin-top: 2px;
}

.sidebar-nav {
    padding: 14px 10px;
    list-style: none;
    margin: 0;
}

.sidebar-nav li { margin-bottom: 4px; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius);
    color: rgba(255,255,255,0.85);
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    text-decoration: none;
}

.sidebar-nav a:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.sidebar-nav a.active {
    background: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.sidebar-nav .icon {
    width: 19px;
    height: 19px;
    flex-shrink: 0;
}

.sidebar-section-title {
    text-transform: uppercase;
    font-size: 10.5px;
    letter-spacing: .08em;
    color: rgba(255,255,255,0.45);
    padding: 16px 16px 6px;
}

/* ---------- TOPBAR ---------- */
.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid rgba(43,27,18,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.topbar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-secondary);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topbar-user .user-info {
    text-align: right;
    line-height: 1.2;
}

.topbar-user .user-info strong { font-size: 13.5px; display: block; }
.topbar-user .user-info span { font-size: 11.5px; color: #8a8a8a; }

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--color-sky);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: var(--color-secondary);
}

.menu-toggle .icon { width: 24px; height: 24px; }

/* ---------- CONTENT ---------- */
.content {
    padding: 24px;
    flex: 1;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.page-header h1 {
    font-size: 22px;
    margin: 0 0 4px;
    color: var(--color-secondary);
}

.page-header p {
    margin: 0;
    color: #8a7c70;
    font-size: 13.5px;
}

/* ============================================================
   COMPONENTES
============================================================ */

/* ---------- BOTONES ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius);
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    line-height: 1;
}
.btn .icon { width: 16px; height: 16px; }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: #8c0732; }

.btn-secondary { background: var(--color-secondary); color: #fff; }
.btn-secondary:hover { background: #5a3e2c; }

.btn-accent { background: var(--color-accent); color: var(--color-dark); }
.btn-accent:hover { background: #c19c2e; }

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--color-secondary);
    color: var(--color-secondary);
}
.btn-outline:hover { background: var(--color-secondary); color: #fff; }

.btn-success { background: var(--color-success); color: #fff; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-icon { padding: 8px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- CARDS ---------- */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 22px;
    margin-bottom: 20px;
    border: 1px solid rgba(43,27,18,0.05);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.card-header h2 {
    font-size: 16px;
    margin: 0;
    color: var(--color-secondary);
}

/* ---------- STAT CARDS ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    border-left: 5px solid var(--color-primary);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-card .stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
}
.stat-card .stat-icon .icon { width: 22px; height: 22px; }

.stat-card.primary .stat-icon { background: var(--color-primary); }
.stat-card.secondary .stat-icon { background: var(--color-secondary); }
.stat-card.accent .stat-icon { background: var(--color-accent); color: var(--color-dark); }
.stat-card.sky .stat-icon { background: var(--color-sky); }

.stat-card .stat-value { font-size: 24px; font-weight: 700; color: var(--color-dark); }
.stat-card .stat-label { font-size: 12.5px; color: #8a7c70; margin-top: 2px; }

/* ---------- TABLAS ---------- */
.table-wrapper { overflow-x: auto; }

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

table.data-table th {
    background: var(--color-bg);
    color: var(--color-secondary);
    text-align: left;
    padding: 12px 14px;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 2px solid rgba(43,27,18,0.08);
    white-space: nowrap;
}

table.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(43,27,18,0.06);
    vertical-align: middle;
}

table.data-table tbody tr:hover { background: rgba(166,9,61,0.03); }

.table-actions { display: flex; gap: 6px; flex-wrap: nowrap; }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #b0a39a;
}
.empty-state .icon { width: 48px; height: 48px; margin-bottom: 10px; color: var(--color-accent); }

/* ---------- BADGES ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.badge-success { background: rgba(46,125,50,0.12); color: var(--color-success); }
.badge-danger { background: rgba(192,57,43,0.12); color: var(--color-danger); }
.badge-warning { background: rgba(224,168,0,0.15); color: #a37800; }
.badge-info { background: rgba(61,183,228,0.15); color: #1b8aab; }
.badge-secondary { background: rgba(111,78,55,0.12); color: var(--color-secondary); }
.badge-primary { background: rgba(166,9,61,0.10); color: var(--color-primary); }

/* ---------- FORMULARIOS ---------- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.form-group { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-secondary);
}

.form-group .hint { font-size: 11.5px; color: #a09287; }

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="date"], input[type="time"], input[type="tel"], input[type="search"],
select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #e6ddd5;
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--color-dark);
    transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(166,9,61,0.10);
}

textarea { resize: vertical; min-height: 80px; }

.input-group { display: flex; }
.input-group input { border-radius: var(--radius) 0 0 var(--radius); }
.input-group-text {
    display: flex; align-items: center; padding: 0 12px;
    background: var(--color-bg); border: 1.5px solid #e6ddd5; border-left: none;
    border-radius: 0 var(--radius) var(--radius) 0; font-weight: 700; color: var(--color-secondary);
}

/* Checkbox / switch */
.switch {
    position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; cursor: pointer; inset: 0;
    background-color: #d8cfc7; transition: var(--transition); border-radius: 24px;
}
.switch .slider:before {
    position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px;
    background-color: #fff; transition: var(--transition); border-radius: 50%;
}
.switch input:checked + .slider { background-color: var(--color-success); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* ---------- ALERTAS / FLASH ---------- */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 18px;
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 4px solid;
}
.alert-success { background: rgba(46,125,50,0.08); border-color: var(--color-success); color: #1e5023; }
.alert-danger { background: rgba(192,57,43,0.08); border-color: var(--color-danger); color: #8c2a1f; }
.alert-warning { background: rgba(224,168,0,0.10); border-color: var(--color-warning); color: #8a6800; }
.alert-info { background: rgba(61,183,228,0.10); border-color: var(--color-info); color: #1b6f87; }

/* ---------- LOGIN ---------- */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--color-secondary) 0%, var(--color-dark) 100%);
    padding: 20px;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
    width: 100%;
    max-width: 400px;
    padding: 36px 32px;
    text-align: center;
}

.login-card .logo-badge {
    width: 64px; height: 64px; border-radius: 50%;
    background: var(--color-primary);
    border: 3px solid var(--color-accent);
    color: #fff; font-weight: 800; font-size: 26px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
}

.login-card h1 { font-size: 19px; color: var(--color-secondary); margin: 0 0 4px; }
.login-card p.subtitle { color: #a09287; font-size: 13px; margin: 0 0 26px; }
.login-card .form-group { text-align: left; }

.login-footer {
    margin-top: 22px; font-size: 11.5px; color: #b0a39a;
}

/* ---------- TABS ---------- */
.tabs {
    display: flex; gap: 4px; border-bottom: 2px solid rgba(43,27,18,0.08);
    margin-bottom: 20px; flex-wrap: wrap;
}
.tabs a, .tabs button {
    padding: 10px 18px; font-size: 13.5px; font-weight: 600;
    color: #a09287; background: none; border: none; cursor: pointer;
    border-bottom: 3px solid transparent; margin-bottom: -2px; text-decoration: none;
}
.tabs a.active, .tabs button.active { color: var(--color-primary); border-color: var(--color-primary); }

/* ---------- PERMISOS MATRIX ---------- */
.permisos-table th, .permisos-table td { text-align: center; }
.permisos-table th:first-child, .permisos-table td:first-child { text-align: left; }
.permisos-table input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--color-primary); }

/* ---------- MAPA ---------- */
.map-container {
    width: 100%; height: 480px; border-radius: var(--radius);
    overflow: hidden; border: 1px solid rgba(43,27,18,0.08);
}

/* ---------- UTILIDADES ---------- */
.text-muted { color: #a09287; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.d-flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex-wrap { flex-wrap: wrap; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mb-0 { margin-bottom: 0; }
.w-100 { width: 100%; }
.pill-color {
    display: inline-block; width: 16px; height: 16px; border-radius: 4px;
    vertical-align: middle; margin-right: 6px; border: 1px solid rgba(0,0,0,0.1);
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .menu-toggle { display: inline-flex; align-items: center; }
    .topbar { padding: 0 16px; }
    .content { padding: 16px; }
}
