:root {
    --primary: #2e7d32;
    --secondary: #4caf50;
    --bg-body: #f4f6f8;
    --bg-card: #ffffff;
    --bg-sidebar: #1a1a1a;
    --text-main: #333333;
    --text-muted: #666666;
    --border: #e0e0e0;
    --input-bg: #ffffff;
    --hover-nav: rgba(255,255,255,0.1);
    --shadow: rgba(0,0,0,0.05);
}

[data-theme="dark"] {
    --primary: #4caf50;
    --secondary: #81c784;
    --bg-body: #121212;
    --bg-card: #1e1e1e;
    --bg-sidebar: #000000;
    --text-main: #e0e0e0;
    --text-muted: #a0a0a0;
    --border: #333333;
    --input-bg: #2d2d2d;
    --hover-nav: #333333;
    --shadow: rgba(0,0,0,0.5);
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    display: flex;
    height: 100vh;
    background-color: var(--bg-body);
    color: var(--text-main);
    transition: background-color 0.3s, color 0.3s;
    overflow: hidden;
}

/* =========================================================
   SIDEBAR
   ========================================================= */
.sidebar {
    width: 250px;
    min-width: 250px;
    background: var(--bg-sidebar);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 20px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 200;
}

.logo-area {
    margin-bottom: 40px;
    text-align: center;
    border-bottom: 1px solid #333;
    padding-bottom: 20px;
}

.nav-btn {
    background: none;
    border: none;
    color: #aaa;
    padding: 15px;
    text-align: left;
    cursor: pointer;
    font-size: 15px;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: 8px;
    margin-bottom: 5px;
    width: 100%;
}

.nav-btn:hover {
    background-color: var(--hover-nav);
    color: #fff;
}

.nav-btn.active {
    color: white;
    background: var(--primary);
}

.spacer { flex: 1; }

/* =========================================================
   HAMBURGER - solo visible en movil
   ========================================================= */
.hamburger {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 300;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    width: 42px;
    height: 42px;
    font-size: 18px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 150;
}

/* =========================================================
   MAIN CONTENT
   ========================================================= */
.main-content {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    min-width: 0;
}

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity:0; transform: translateY(5px); } to { opacity:1; transform: translateY(0); } }

/* =========================================================
   HEADER BAR
   ========================================================= */
.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

/* =========================================================
   CARDS
   ========================================================= */
.card {
    background: var(--bg-card);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px var(--shadow);
    border: 1px solid var(--border);
    transition: background-color 0.3s, border-color 0.3s;
    margin-bottom: 20px;
}

.card h3 {
    margin-top: 0;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 15px;
    margin-bottom: 20px;
    font-size: 1.1rem;
    font-weight: 600;
}

/* =========================================================
   FORMULARIOS
   ========================================================= */
.form-row {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.form-row .input-group {
    flex: 1;
    min-width: 200px;
}

.input-group {
    margin-bottom: 15px;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-muted);
}

input, select, textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    background-color: var(--input-bg);
    color: var(--text-main);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(46, 125, 50, 0.1);
}

/* =========================================================
   BOTONES
   ========================================================= */
.btn-primary {
    background: var(--primary);
    color: white;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: transform 0.1s;
}
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
    background: var(--border);
    color: var(--text-main);
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 10px;
    font-size: 13px;
}

/* =========================================================
   UPLOAD AREA
   ========================================================= */
.upload-area {
    border: 2px dashed var(--border);
    background-color: var(--bg-body);
    padding: 30px;
    text-align: center;
    cursor: pointer;
    border-radius: 10px;
    transition: 0.2s;
    color: var(--text-muted);
}
.upload-area:hover { border-color: var(--primary); color: var(--primary); }

/* =========================================================
   GALERIA
   ========================================================= */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    margin-top: 20px;
}

.thumb-wrapper { position: relative; }

.thumb-img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.thumb-del {
    position: absolute; top: -5px; right: -5px;
    background: #ff5252; color: white; border: none;
    border-radius: 50%; width: 22px; height: 22px;
    cursor: pointer; font-size: 12px; display: flex;
    align-items: center; justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* =========================================================
   TABLAS
   ========================================================= */
.mat-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }

.mat-table th {
    text-align: left;
    background: var(--bg-body);
    padding: 12px;
    font-size: 13px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.mat-table td { padding: 8px; border-bottom: 1px solid var(--border); }

.mat-table input, .mat-table select {
    border: 1px solid transparent;
    background: transparent;
    padding: 5px;
}

.mat-table input:hover, .mat-table select:hover {
    border-color: var(--border);
    background-color: var(--input-bg);
}


/* =========================================================
   LOADING OVERLAY & CRONÓMETRO (NUEVO)
   ========================================================= */
.loading-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8); z-index: 9999; justify-content: center; align-items: center;
    backdrop-filter: blur(3px); /* Difumina el fondo sutilmente */
}
.loading-overlay.active { display: flex; }

.loading-box {
    background: var(--bg-card);
    padding: 30px 40px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    border: 2px solid var(--primary);
    max-width: 90%;
    animation: fadeIn 0.3s ease-out;
}
.loading-box h3 { margin: 20px 0 5px 0; color: var(--text-main); font-size: 18px; }
.loading-box p { margin: 0 0 20px 0; color: var(--text-muted); font-size: 13px; }

.loading-spinner {
    width: 50px; height: 50px; border: 4px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto; /* FUNDAMENTAL: Centra el spinner */
}

.timer-box {
    background: var(--bg-body);
    padding: 8px 15px;
    border-radius: 20px;
    font-family: monospace;
    font-size: 16px;
    color: var(--primary);
    font-weight: bold;
    display: inline-block;
    border: 1px solid var(--border);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   RESPONSIVE — MOVIL (max 768px)
   ========================================================= */
@media (max-width: 768px) {

    /* Hamburger visible */
    .hamburger { display: flex; }

    /* Sidebar se oculta fuera de pantalla por defecto */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    /* Contenido ocupa todo el ancho */
    .main-content {
        width: 100%;
        padding: 70px 16px 20px 16px;
    }

    .card {
        padding: 16px;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-row .input-group {
        min-width: unset;
    }

    .btn-primary, .btn-secondary {
        width: 100%;
        text-align: center;
        margin-top: 8px;
    }

    .header-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-bar > div:last-child,
    .header-bar > button {
        width: 100%;
    }
}