:root {
    --green-50:  #f0fdf4;
    --green-100: #dcfce7;
    --green-500: #22c55e;
    --green-600: #16a34a;
    --green-700: #15803d;
    --green-900: #14532d;
    --white:     #ffffff;
    --gray-400:  #9ca3af;
    --gray-500:  #6b7280;
    --gray-600:  #4b5563;

    --bg-color: var(--green-50);
    --secondary-bg: var(--white);
    --primary-color: var(--green-600);
    --primary-hover: var(--green-700);
    --accent-color: var(--green-500);
    --text-main: var(--green-900);
    --text-muted: var(--gray-600);
    --border-color: #e5e7eb;
    --danger-color: #ef4444;
    --success-color: var(--green-600);
    --warning-color: #f59e0b;
    --info-color: #3b82f6;
    --glass-bg: rgba(255, 255, 255, 0.95);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    --radius: 14px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }

* { box-sizing: border-box; margin: 0; padding: 0; }


body {
    background: var(--green-50);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(34,197,94,.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(22,163,74,.05) 0%, transparent 50%);
    color: var(--text-main);
    font-family: var(--font-family);
    min-height: 100vh;
    padding: 20px 10px;
    padding-bottom: 40px;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
}

.glass-header {
    text-align: center;
    margin-bottom: 24px;
    padding: 20px;
    background: var(--secondary-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--glass-shadow);
}
.glass-header h1 { font-weight: 700; color: var(--text-main); margin-bottom: 4px;}
.glass-header p { color: var(--text-muted); font-size: 0.9em; }

.glass-card {
    background: var(--secondary-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--glass-shadow);
    padding: 20px;
    margin-bottom: 24px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.full-width { grid-column: span 2; }
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; gap:12px; } .full-width { grid-column: span 1; } }

.input-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.horizontal-group {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.flex-grow { flex-grow: 1; }

input[type="text"], input[type="number"], input[type="datetime-local"], input[type="password"], input[type="tel"], input[type="date"], select, textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-main);
    font-family: var(--font-family);
    transition: all 0.3s ease;
    font-size: 1rem;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.btn {
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: transform 0.1s, background 0.3s;
    font-size: 1rem;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--primary-color); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--green-100); color: var(--green-900); }
.btn-icon { background: rgba(16, 185, 129, 0.2); padding: 12px; display: flex; align-items: center; justify-content: center;}

.btn-plus {
    background-color: var(--accent-color);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8em;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(52, 211, 153, 0.4);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: 8px;
    line-height: 0;
}
.btn-plus:hover {
    background-color: #6ee7b7; /* Brighter emerald */
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 14px rgba(52, 211, 153, 0.6);
}

.btn-block { width: 100%; display: block; padding: 16px;}

.checkbox-group { display: flex; gap: 16px; flex-wrap: wrap; }
.checkbox-container {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--text-muted);
}
.checkbox-container input { width: auto; scale: 1.3;}

.results-box {
    background: rgba(16, 185, 129, 0.1);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.result-item { display: flex; justify-content: space-between; font-weight: 600; font-size: 1.1rem; }
.result-item .value { color: #10b981; }

.history-list { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.history-card {
    background: var(--secondary-bg);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.history-stats { display: flex; flex-direction: column; gap: 4px; }
.history-date { font-size: 0.8rem; color: var(--text-muted); }
.history-total { font-weight: bold; color: #10b981; font-size: 1.2rem; }
.rendimiendo-badge {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    margin-top: 4px;
    display: inline-block;
}

/* Modals */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    display: flex; justify-content: center; align-items: center;
    z-index: 1000;
}
.modal.hidden { display: none; }
.modal-content { width: 90%; max-width: 400px; }
.modal-content h3 { margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Custom Searchable Dropdown */
.searchable-select { position: relative; width: 100%; font-family: var(--font-family); }
.select-header { 
    padding: 12px; background: var(--bg-color); border: 1px solid var(--border-color);
    border-radius: 8px; color: var(--text-main); cursor: pointer; display: flex; justify-content: space-between; align-items: center;
    transition: border-color 0.3s;
}
.select-header:hover { border-color: var(--primary-color); }
.select-options { 
    position: absolute; top: calc(100% + 4px); left: 0; width: 100%; background: var(--secondary-bg); 
    border: 1px solid var(--primary-color); border-radius: 8px; z-index: 50;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5); max-height: 250px; overflow-y: auto; display: flex; flex-direction: column;
}
.select-options.hidden { display: none; }
#selectSearch, #vehiculoSearch { 
    margin: 8px; width: calc(100% - 16px); padding: 8px; background: var(--bg-color);
    border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-main); font-size: 0.9em;
}
#selectSearch:focus, #vehiculoSearch:focus { border-color: var(--primary-color); outline: none;}
.option-item { padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--border-color); font-size: 0.95em; }
.option-item:hover { background: var(--primary-color); color: #fff; }
.option-item:last-child { border-bottom: none; }

/* Sidebar & Hamburger Menu */
.btn-hamburger {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1.8rem;
    cursor: pointer;
    transition: color 0.3s;
}
.btn-hamburger:hover { color: var(--primary-color); }

.sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.5); z-index: 1000;
    opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.sidebar-overlay.open { opacity: 1; pointer-events: all; }

.sidebar {
    position: fixed; top: 0; left: -280px; width: 280px; height: 100vh;
    background: var(--bg-color);
    z-index: 1001;
    transition: left 0.3s ease;
    box-shadow: 2px 0 10px rgba(0,0,0,0.5);
    padding: 30px 20px;
    display: flex; flex-direction: column;
}
.sidebar.open { left: 0; }

.sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; border-bottom: 1px solid var(--border-color); padding-bottom: 15px;}
.sidebar-header h2 { color: var(--primary-color); font-size: 1.2rem; margin: 0; font-weight: 700; }
.btn-close { background: transparent; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; transition: color 0.3s; }
.btn-close:hover { color: var(--danger-color); }

.sidebar-menu { list-style: none; padding: 0; margin: 0; }
.sidebar-menu li { margin-bottom: 15px; }
.sidebar-menu a {
    color: var(--text-main);
    text-decoration: none;
    font-size: 1.1rem;
    font-weight: 500;
    transition: color 0.3s;
    display: flex; align-items: center; gap: 10px;
    padding: 10px;
    border-radius: 8px;
}
.sidebar-menu a:hover { background: var(--green-100); color: var(--primary-color); }

@keyframes pulseHighlight {
    0% { box-shadow: 0 0 0 0 rgba(89, 130, 52, 0.6); border-color: var(--primary-color); }
    70% { box-shadow: 0 0 0 15px rgba(89, 130, 52, 0); border-color: var(--border-color); }
    100% { box-shadow: 0 0 0 0 rgba(89, 130, 52, 0); border-color: var(--border-color); }
}
.highlight-form {
    animation: pulseHighlight 1s ease 2;
}

/* SPA Screen Transitions (Native App Feel) */
.view-section {
    display: none;
    opacity: 0;
}
.view-section.active {
    display: block;
    animation: slideFadeIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes slideFadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}
/* Dashboard Grid & Tiles */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat-tile {
    background: var(--secondary-bg);
    padding: 12px;
    text-align: center;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--glass-shadow);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 80px;
}

.stat-tile span {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 4px;
}

.stat-tile div {
    font-size: 1.1rem;
    font-weight: 700;
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
    align-items: stretch;
}

.chart-container {
    background: var(--glass-bg);
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    margin-bottom: 12px;
    min-width: 0; /* Fix for chartjs overflow in grid */
    display: flex;
    flex-direction: column;
    height: 300px; /* New fixed height to prevent vertical growth */
}

.chart-container h3 {
    font-size: 0.9rem;
    margin-bottom: 12px;
    color: var(--text-muted);
    text-align: center;
}

.period-tabs {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
}

.period-select-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

#periodDetailSelector {
    width: 100%;
    max-width: 280px;
    background: var(--secondary-bg);
    border-color: var(--primary-color);
}

/* Responsiveness Fixes */
@media (max-width: 580px) {
    .glass-header h1 { font-size: 1.5rem; }
    .glass-header p { font-size: 0.8rem; }
    .btn-hamburger { font-size: 1.5rem; left: 12px; }
}

@media (max-width: 480px) {
    body { padding: 10px; }
    .stats-grid { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
    .stat-tile { min-height: 70px; padding: 10px; }
    .stat-tile div { font-size: 1rem; }
    .chart-container { padding: 10px; height: 260px; }
    .period-tabs { flex-wrap: wrap; }
    .period-tabs .btn { flex: 1; min-width: 80px; font-size: 0.85rem; padding: 8px; }
}

@media (max-width: 360px) {
    .glass-header { padding: 15px 10px; }
    .glass-header h1 { font-size: 1.3rem; }
}
