/* =========================================
   VARIABLES Y CONFIGURACIÓN BASE
   ========================================= */
:root {
    --bg-color: #0d0d0d;
    --panel-bg: #111111;
    --border-color: #2a2a2a;
    --text-main: #f0f0f0;
    --text-muted: #888888;
    --accent-color: #d11a2a; /* Rojo tipo progreso */
    --hover-bg: #1a1a1a;
    
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

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

/* Fondo animado oscuro con tonos rojos */
@keyframes redMatrixBg {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

body {
    background: linear-gradient(-45deg, #0d0d0d, #1a0505, #0a0000, #220000);
    background-size: 400% 400%;
    animation: redMatrixBg 15s ease infinite;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 14px;
    height: 100vh;
    overflow-x: hidden;
}

/* Contenedor principal para dar márgenes */
.app-container {
    padding: 20px;
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* =========================================
   ENCABEZADO (HEADER)
   ========================================= */
.header {
    display: flex;
    align-items: center;
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    height: 80px;
}

.header-section {
    padding: 0 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-right: 1px solid var(--border-color);
    height: 100%;
}

.header-section:last-of-type {
    border-right: none;
    flex-grow: 1;
}

/* Custom Selectors (Mes y Año) */
.custom-selectors-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    position: relative;
}

.custom-dropdown {
    position: relative;
    user-select: none;
}

.dropdown-header {
    font-family: var(--font-heading);
    font-size: 32px;
    letter-spacing: 2px;
    font-weight: 800;
    cursor: pointer;
    color: var(--text-main);
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dropdown-header:hover {
    color: var(--accent-color);
}

.dropdown-header::after {
    content: "▼";
    font-size: 14px;
    opacity: 0.5;
    transition: transform 0.2s;
}

.dropdown-header.small-header {
    font-size: 16px;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.custom-dropdown.active .dropdown-header::after {
    transform: rotate(180deg);
}

.dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    list-style: none;
    padding: 10px 0;
    margin-top: 5px;
    min-width: 150px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 200;
    box-shadow: 0 4px 15px rgba(0,0,0,0.7);
    
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.custom-dropdown.active .dropdown-list {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.dropdown-list li {
    padding: 10px 20px;
    font-size: 16px;
    font-family: var(--font-heading);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.dropdown-list li:hover, .dropdown-list li.selected {
    background-color: var(--hover-bg);
    color: var(--accent-color);
}

/* Custom Scrollbar para los dropdowns */
.dropdown-list::-webkit-scrollbar {
    width: 6px;
}
.dropdown-list::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 3px;
}

.header-section .label {
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 5px;
}

.header-section .value {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 700;
}

.progress-section {
    flex-direction: row !important;
    align-items: center;
    gap: 20px;
    border-right: none !important;
    flex-grow: 1;
}

.progress-section .label, .progress-section .value {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.progress-bar-container {
    flex-grow: 1;
    min-width: 150px;
    height: 20px;
    background-color: #222;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--accent-color);
    transition: width 0.3s ease;
}

/* Acciones del Encabezado (Botones) */
.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    padding-right: 20px;
}

/* Botón de Ajustes (Engranaje) */
.settings-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-size: 22px;
    width: 50px;
    height: 50px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-btn:hover {
    background: var(--hover-bg);
    border-color: var(--text-muted);
}

/* Menú de Ajustes Desplegable */
.settings-menu {
    position: absolute;
    top: 90px;
    right: 20px;
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 100;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    min-width: 200px;
    transition: opacity 0.2s, transform 0.2s;
}

.settings-menu.hidden {
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
}

.settings-menu-header {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 5px;
    text-align: center;
}

.action-btn {
    background: #1a1a1a;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-size: 14px;
    font-weight: 600;
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    width: 100%;
}

.action-btn:hover {
    background: #2a2a2a;
}

.action-btn.danger {
    color: #ff4d4d;
    border-color: rgba(255, 77, 77, 0.3);
}

.action-btn.danger:hover {
    background: rgba(255, 77, 77, 0.1);
}

/* =========================================
   CUADRÍCULA PRINCIPAL (MAIN GRID)
   ========================================= */
.main-grid {
    display: grid;
    grid-template-columns: 250px 1fr 250px;
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 60vh;
}

/* Custom Scrollbar para el main-grid */
.main-grid::-webkit-scrollbar {
    width: 8px;
}
.main-grid::-webkit-scrollbar-thumb {
    background-color: #333;
    border-radius: 4px;
}
.main-grid::-webkit-scrollbar-track {
    background-color: var(--panel-bg);
}

.sticky-headers {
    position: sticky;
    top: 0;
    background-color: var(--panel-bg);
    z-index: 10;
    height: 85px; /* Altura fija para que las 3 columnas se alineen perfectamente */
    display: flex;
    flex-direction: column;
    justify-content: flex-end; /* Alinear contenido hacia abajo */
}

.sticky-footer {
    position: sticky;
    bottom: 0;
    background-color: var(--panel-bg);
    z-index: 10;
    border-top: 1px solid var(--border-color);
}

.section-header {
    text-align: center;
    font-weight: 700;
    padding: 10px 0; /* Reducido para encajar en el flex */
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* --- Columna Izquierda: Hábitos --- */
.habits-list-section {
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.habits-list {
    list-style: none;
    flex-grow: 1;
}

.habit-item {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid var(--border-color);
    height: 40px;
}

.habit-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    margin-right: 10px;
    font-size: 16px;
}

.habit-delete:hover {
    color: var(--accent-color);
}

.habit-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.add-habit-container {
    padding: 10px;
}

#new-habit-input {
    width: 100%;
    background-color: #222;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 4px;
    font-family: var(--font-body);
}

#new-habit-input:focus {
    outline: 1px solid var(--text-muted);
}

/* --- Centro: Cuadrícula de Días --- */
.days-grid-section {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    overflow-x: auto;
}

.weeks-header, .days-header {
    /* La grilla ahora se maneja dinámica en JS pero por defecto son 31 */
    display: grid;
    grid-template-columns: repeat(31, 1fr);
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 11px;
}

.weeks-header {
    display: flex;
    justify-content: space-between;
    padding: 15px 20px;
}

.days-header .day-num {
    padding: 5px 0;
    border-right: 1px solid var(--border-color);
}

.days-header .day-num.current-day {
    color: var(--accent-color);
    font-weight: 800;
    font-size: 14px;
    background-color: rgba(209, 26, 42, 0.1);
}

.checkboxes-grid {
    display: flex;
    flex-direction: column;
}

.checkbox-row {
    display: grid;
    grid-template-columns: repeat(31, 1fr);
    height: 40px;
    border-bottom: 1px solid var(--border-color);
}

.checkbox-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--border-color);
}

.checkbox-cell.current-day {
    background-color: rgba(209, 26, 42, 0.05);
}

/* Chulito rojo moderno */
.custom-checkbox {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 1px solid #444;
    border-radius: 4px;
    background-color: transparent;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.custom-checkbox:hover {
    border-color: #666;
}

.custom-checkbox:checked {
    background-color: #1a0505;
    border-color: var(--accent-color);
}
/* =========================================
   ANIMACIONES Y ESTILOS DEL GRÁFICO (CHART)
   ========================================= */
.chart-line-anim {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: drawLine 1.5s ease-out forwards;
}

.chart-area-anim {
    opacity: 0;
    animation: fadeInArea 1s ease-out 0.5s forwards;
}

@keyframes drawLine {
    to { stroke-dashoffset: 0; }
}

@keyframes fadeInArea {
    to { opacity: 1; }
}

.chart-dot {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: var(--panel-bg);
    border: 2px solid var(--accent-color);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s, box-shadow 0.2s;
    z-index: 5;
    opacity: 0;
    animation: popInDot 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Efecto de pop in secuencial usando nth-child en JS o un delay general */
.chart-dot { animation-delay: 1s; }

.chart-dot:hover {
    transform: translate(-50%, -50%) scale(1.5);
    background-color: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-color);
    z-index: 10;
}

@keyframes popInDot {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.chart-tooltip {
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--accent-color);
    color: #fff;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
}

.chart-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 4px;
    border-style: solid;
    border-color: var(--accent-color) transparent transparent transparent;
}

.chart-dot:hover .chart-tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}
.custom-checkbox:checked::after {
    content: '✓';
    color: #ff3333;
    font-size: 14px;
    font-weight: 800;
}

/* =========================================
   MODAL PERSONALIZADO
   ========================================= */
.custom-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
    transition: opacity 0.3s;
}

.custom-modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.custom-modal {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 30px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.custom-modal-overlay.hidden .custom-modal {
    transform: scale(0.8);
}

.custom-modal-title {
    font-family: var(--font-heading);
    font-size: 20px;
    margin-bottom: 15px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.custom-modal-text {
    font-size: 16px;
    color: var(--text-muted);
    margin-bottom: 25px;
    line-height: 1.5;
}

.custom-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.custom-modal-actions .action-btn {
    width: auto;
    padding: 10px 20px;
}

/* --- Columna Derecha: Resumen --- */
.habit-stats-section {
    display: flex;
    flex-direction: column;
}

.stats-header {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 11px;
    text-align: center;
}

.total-col {
    width: 60px;
    padding: 5px 0;
    border-right: 1px solid var(--border-color);
}

.progress-col {
    flex-grow: 1;
    padding: 5px 0;
}

.stat-row {
    display: flex;
    align-items: center;
    height: 40px;
    border-bottom: 1px solid var(--border-color);
}

.stat-total {
    width: 60px;
    text-align: center;
    font-family: var(--font-heading);
    font-weight: 700;
    border-right: 1px solid var(--border-color);
}

.stat-progress-container {
    flex-grow: 1;
    padding: 0 15px;
}

.stat-progress-bar {
    height: 12px;
    background-color: #222;
    border-radius: 2px;
    overflow: hidden;
}

.stat-progress-fill {
    height: 100%;
    background-color: #555;
    transition: width 0.3s;
}

/* =========================================
   SECCIÓN SUEÑO
   ========================================= */
.sleep-section {
    display: flex;
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    height: 50px;
    align-items: center;
}

.sleep-label {
    width: 250px;
    padding: 0 20px;
    font-weight: 700;
    border-right: 1px solid var(--border-color);
}

.sleep-inputs {
    display: grid;
    grid-template-columns: repeat(31, 1fr);
    flex-grow: 1;
}

.sleep-input-cell {
    border-right: 1px solid var(--border-color);
    text-align: center;
}

.sleep-input-cell select {
    background: transparent;
    color: var(--accent-color);
    border: none;
    font-family: var(--font-heading);
    font-weight: 700;
    text-align: center;
    appearance: none;
    cursor: pointer;
}

.sleep-input-cell select:focus {
    outline: none;
}

/* =========================================
   PANELES INFERIORES
   ========================================= */
.bottom-panels {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
}

.daily-progress-panel, .global-progress-panel {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
}

.panel-header {
    font-weight: 700;
    margin-bottom: 20px;
}

/* Gráficos de barras */
.daily-bars-container, .sleep-bars-container {
    display: grid;
    grid-template-columns: repeat(31, 1fr);
    gap: 2px;
    height: 100px;
    align-items: end;
}

.bar-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.daily-bar {
    background-color: var(--accent-color);
    width: 100%;
    border-radius: 2px 2px 0 0;
    transition: height 0.3s;
}

.sleep-bar {
    background-color: #4a4a4a;
    width: 100%;
    border-radius: 2px 2px 0 0;
    transition: height 0.3s;
}

/* Gráfico circular */
.global-progress-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.circular-progress {
    position: relative;
    width: 180px;
    height: 180px;
    margin-top: 10px;
}

.circular-progress svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.circle-bg {
    fill: none;
    stroke: #222;
    stroke-width: 8;
}

.circle-fill {
    fill: none;
    stroke: var(--accent-color);
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.5s ease;
}

.circle-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.circle-text .percent {
    display: block;
    font-family: var(--font-heading);
    font-size: 32px;
    font-weight: 800;
}

.circle-text .label {
    color: var(--accent-color);
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 1px;
}

/* =========================================
   SISTEMA DE AUTENTICACIÓN (LOGIN UI)
   ========================================= */
#auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 99999;
}

.auth-modal {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}

.auth-modal h2 {
    margin-bottom: 25px;
    font-size: 24px;
    color: var(--text-main);
    letter-spacing: 2px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.auth-modal input {
    background: var(--hover-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 12px 15px;
    border-radius: 6px;
    font-family: var(--font-body);
    font-size: 16px;
}

.auth-modal input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.auth-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
    font-family: var(--font-body);
}

.auth-btn:hover {
    background: #e62222;
}

.payment-btn {
    background: #009ee3; /* Color de MercadoPago */
    display: block;
    text-decoration: none;
    margin-top: 15px;
}

.payment-btn:hover {
    background: #007eb5;
}

.auth-switch {
    margin-top: 15px;
    font-size: 14px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

.auth-switch:hover {
    color: var(--text-main);
    text-decoration: underline;
}

.auth-support {
    margin-top: 30px;
    font-size: 12px;
    color: #888;
    border-top: 1px solid var(--border-color);
    padding-top: 15px;
}

.hidden {
    display: none !important;
}
