/* --- Apple Design System Variables (iOS/macOS Style) --- */
:root {
    --background-color: #F2F2F7;
    --widget-bg: rgba(255, 255, 255, 0.72);
    --text-color: #1D1D1F;
    --secondary-text-color: #6E6E73;
    --primary-color: #D70015;
    --glass-border: rgba(255, 255, 255, 0.4);
    --bezel-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
    --spring-ease: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ios-radius: 44px;
    --dynamic-padding: clamp(12px, 4vw, 25px);
}

body.dark-mode {
    --background-color: #000000;
    --widget-bg: rgba(28, 28, 30, 0.75);
    --text-color: #FFFFFF;
    --secondary-text-color: #AEAEB2;
    --glass-border: rgba(255, 255, 255, 0.1);
    --bezel-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
    --shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-font-smoothing: antialiased; }

html, body {
    height: 100%; height: 100dvh; width: 100%; overflow: hidden;
    overflow-y: auto;
    touch-action: pan-y;
    user-select: none;
    background-color: var(--background-color);
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", sans-serif;
    color: var(--text-color);
    display: flex; display: -webkit-flex; flex-direction: column; -webkit-flex-direction: column; 
    padding: var(--dynamic-padding);
    transition: background-color 0.8s var(--spring-ease);
    min-height: 100%; min-height: 100dvh;
}

#splash-screen {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--background-color); z-index: 99999;
    display: flex; display: -webkit-flex; flex-direction: column; -webkit-flex-direction: column; justify-content: center; -webkit-justify-content: center; align-items: center; -webkit-align-items: center;
}

.loader-icon { width: 64px; height: 64px; margin-bottom: 20px; color: var(--primary-color); }
.loader-icon svg { animation: spin 2s linear infinite; stroke-width: 1.5; }

@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }

.spinner-icon { animation: spin 1s linear infinite; }
.spinner-icon path { animation: pulse 1.5s ease-in-out infinite; }
.spinner-icon path:nth-child(2) { animation-delay: 0.1s; }
.spinner-icon path:nth-child(3) { animation-delay: 0.2s; }
.spinner-icon path:nth-child(4) { animation-delay: 0.3s; }
.spinner-icon path:nth-child(5) { animation-delay: 0.4s; }
.spinner-icon path:nth-child(6) { animation-delay: 0.5s; }
.spinner-icon path:nth-child(7) { animation-delay: 0.6s; }
.spinner-icon path:nth-child(8) { animation-delay: 0.7s; }

#sun-info.loading { opacity: 0.5; }
#sun-info.loading .sun-moon-icon svg { animation: spin 1.5s linear infinite; }

.top-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    padding: var(--dynamic-padding);
    padding-top: max(var(--dynamic-padding), env(safe-area-inset-top));
    display: flex; display: -webkit-flex;
    justify-content: space-between; -webkit-justify-content: space-between;
    align-items: center; -webkit-align-items: center;
    z-index: 1000;
    pointer-events: none;
}

.top-left-info, .top-right-controls {
    pointer-events: auto;
    background: var(--widget-bg); border: 1px solid var(--glass-border);
    height: 48px; border-radius: 24px;
    color: var(--secondary-text-color);
    box-shadow: var(--shadow); -webkit-backdrop-filter: blur(25px); backdrop-filter: blur(25px);
    transition: all 0.5s var(--spring-ease);
    display: flex; display: -webkit-flex; align-items: center; -webkit-align-items: center;
    -webkit-flex-shrink: 0; flex-shrink: 0;
    max-width: 50%;
    overflow: hidden;
}

.top-left-info { padding: 0 20px; max-width: 55%; }
.top-right-controls { padding: 0 10px; gap: 5px; max-width: 45%; }

/* Mobile: ocultar iconos de plataforma y nombre de autor para liberar espacio */
@media (max-width: 768px) {
    .platform-icons { display: none !important; }
    .author-name, .author-separator { display: none !important; }
    #version-tag > .v-label { margin-right: 0; }
    .top-left-info { max-width: 35%; padding: 0 14px; }
    .top-right-controls { max-width: 65%; }
}

@media (max-width: 768px) and (orientation: portrait) {
    .top-bar {
        padding: 15px;
        padding-top: max(15px, env(safe-area-inset-top));
        flex-direction: row; -webkit-flex-direction: row;
        justify-content: space-between; -webkit-justify-content: space-between;
        gap: 8px;
        align-items: center; -webkit-align-items: center;
    }
    .top-left-info, .top-right-controls {
        height: 40px;
        border-radius: 20px;
        width: auto;
    }
    .top-right-controls { padding: 0 6px; gap: 1px; }
    .control-button { width: 34px; height: 34px; min-width: 44px; min-height: 44px; }
}

@media (max-width: 400px) and (orientation: portrait) {
    .top-left-info { padding: 0 10px; }
    .v-label { font-size: 13px; }
}

#version-tag {
    display: flex; display: -webkit-flex; flex-direction: row; -webkit-flex-direction: row; 
    align-items: center; -webkit-align-items: center; justify-content: center; -webkit-justify-content: center;
    gap: 12px; width: 100%;
    flex-wrap: nowrap; -webkit-flex-wrap: nowrap;
    white-space: nowrap;
}

/* Fallback para navegadores antiguos sin soporte de gap */
#version-tag > .v-label { margin-right: 12px; }

.v-label {
    font-size: 16px; line-height: 20px; height: 20px;
    font-weight: 700; opacity: 0.9;
    font-variant-numeric: tabular-nums;
    display: flex; display: -webkit-flex; align-items: center; -webkit-align-items: center;
}

.platform-icons {
    display: flex; display: -webkit-flex; align-items: center; -webkit-align-items: center;
    height: 20px; gap: 8px;
}
/* Fallback para iconos en Android 4/6 */
.platform-icons .p-icon:not(:last-child) { margin-right: 8px; }

/* Enlace del autor integrado en top-bar */
.top-left-info { color: var(--secondary-text-color); }

/* Enlace dilware.net y separador (visibles solo en pantallas grandes) */
.author-separator {
    font-size: 13px;
    opacity: 0.4;
    margin: 0 5px;
    white-space: nowrap;
}
.author-name {
    font-size: 13px;
    font-weight: 500;
    opacity: 0.7;
    white-space: nowrap;
    letter-spacing: 0.02em;
    text-decoration: none;
    color: inherit;
}
.author-name:hover { opacity: 1; text-decoration: underline; }

/* Iconos Globales (SF Symbols Style) */
svg {
    width: 20px; height: 20px; /* Forzado para Android Legacy (colapsa con auto) */
    display: block;
    fill: currentColor; 
    stroke: none;
    transition: color 0.3s var(--spring-ease);
}

/* Iconos que usan solo contorno (SF Symbols Puro) */
.loader-icon svg, 
.nav-arrow svg, 
.sun-moon-icon svg,
.p-icon svg[viewBox="0 0 24 24"],
#dark-mode-button svg,
#fullscreen-button svg {
    fill: none !important;
    stroke: currentColor !important;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.loader-icon svg { width: 64px; height: 64px; }
.sun-moon-icon svg { width: 32px; height: 32px; }
.nav-arrow svg { width: 22px; height: 22px; }

.p-icon { 
    width: 20px; height: 20px; display: flex; display: -webkit-flex; 
    opacity: 0.9; justify-content: center; -webkit-justify-content: center; align-items: center; -webkit-align-items: center;
}
.p-icon:hover { opacity: 1; }

.control-button {
    width: 38px; height: 38px; border-radius: 50%;
    background: transparent; border: none;
    color: var(--text-color); cursor: pointer;
    display: flex; display: -webkit-flex; justify-content: center; -webkit-justify-content: center; align-items: center; -webkit-align-items: center; 
    transition: transform 0.2s var(--spring-ease), background-color 0.2s;
}
.control-button:hover { background-color: rgba(128, 128, 128, 0.1); }
.control-button:active { transform: scale(0.85); background-color: rgba(128, 128, 128, 0.2); }
.control-button svg { width: 20px; height: 20px; }

/* Casos Especiales */
.nav-arrow svg { stroke-width: 2.5; }
.sun-moon-icon svg { width: 32px; height: 32px; }

.dashboard-container {
    flex: 1; -webkit-flex: 1; display: flex; display: -webkit-flex; flex-direction: row; -webkit-flex-direction: row; justify-content: center; -webkit-justify-content: center; align-items: stretch; -webkit-align-items: stretch;
    width: 100%; padding: clamp(65px, 10vh, 90px) 0 20px 0; gap: clamp(15px, 3vw, 35px);
    animation: fadeIn 1s var(--spring-ease);
}

@media (max-width: 768px) and (orientation: portrait) {
    .dashboard-container {
        flex-direction: column; -webkit-flex-direction: column;
        padding-top: 60px;
        gap: 20px;
    }
}

/* Fallback para navegadores que no soportan gap (Android 4.4.4) */
.dashboard-container > .widget:not(:last-child) { margin-right: 25px; }

@media (orientation: landscape) and (max-height: 500px) {
    body { padding: 8px; }
    .top-bar { padding: 8px; padding-top: max(8px, env(safe-area-inset-top)); }
    .top-left-info, .top-right-controls { height: 34px; }
    .top-left-info { padding: 0 10px; }
    .top-right-controls { padding: 0 4px; gap: 1px; }
    .control-button { width: 30px; height: 30px; min-width: 34px; min-height: 34px; }
    .control-button svg { width: 16px; height: 16px; }
    .v-label { font-size: 12px; height: 14px; line-height: 14px; }
    .author-name, .author-separator { display: none !important; }
    .dashboard-container { padding-top: 46px; gap: 10px; }
    .dashboard-container > .widget:not(:last-child) { margin-right: 10px; }
    .widget { padding: 10px; border-radius: 25px; }
    #sun-info { font-size: 18px; margin-top: 5px; }
}

.widget {
    flex: 1; -webkit-flex: 1; display: flex; display: -webkit-flex; flex-direction: column; -webkit-flex-direction: column; justify-content: center; -webkit-justify-content: center; align-items: center; -webkit-align-items: center;
    background: var(--widget-bg); border-radius: var(--ios-radius); border: 1px solid var(--glass-border);
    box-shadow: var(--shadow), var(--bezel-shadow); padding: clamp(20px, 5%, 45px); position: relative;
    overflow: hidden; -webkit-backdrop-filter: blur(25px); backdrop-filter: blur(25px);
    transition: all 0.6s var(--spring-ease);
}

@media (orientation: portrait) {
    .dashboard-container { flex-direction: column; -webkit-flex-direction: column; padding-top: 60px; gap: 15px; }
    .dashboard-container > .widget:not(:last-child) { margin-right: 0; margin-bottom: 15px; }
    .widget { width: 100%; flex: 1; padding: 25px; }
    #calendar-container { flex: 1.4; }

    .top-left-info { padding: 0 14px; }
    .top-right-controls { padding: 0 8px; gap: 2px; }

    #version-tag { gap: 4px 8px; }
    #version-tag > .v-label { margin-right: 0; }
    .v-label { font-size: 14px; height: 16px; line-height: 16px; }

    .control-button { width: 32px; height: 32px; min-width: 44px; min-height: 44px; }
    .control-button svg { width: 16px; height: 16px; }
}

#clock-time { 
    font-variant-numeric: tabular-nums; 
    font-weight: 800; 
    line-height: 1; 
    letter-spacing: -0.05em; 
    display: flex; display: -webkit-flex; 
    justify-content: center; -webkit-justify-content: center; 
    align-items: center; -webkit-align-items: center; 
    width: 100%;
    transition: all 0.3s ease;
}

/* Modo Clásico (Horizontal) - Forzado por JS según contenedor */
.clock-mode-classic {
    flex-direction: row !important; -webkit-flex-direction: row !important;
}
.clock-mode-classic .clock-sep { display: inline-block !important; opacity: 0.8; margin: 0 0.05em; }

/* Modo Nike (Vertical) - Forzado por JS según contenedor */
.clock-mode-nike {
    flex-direction: column !important; -webkit-flex-direction: column !important;
    line-height: 0.8 !important;
    letter-spacing: -0.08em !important;
}
.clock-mode-nike .clock-sep { display: none !important; }
.clock-mode-nike .clock-h, .clock-mode-nike .clock-m { 
    height: 0.85em; 
    display: flex; display: -webkit-flex; 
    align-items: center; -webkit-align-items: center; 
}

@media (orientation: landscape) { 
    #clock-time { 
        text-shadow: 0 0 40px rgba(0,0,0,0.1);
        overflow: visible;
    } 
    .clock-s-container { display: none !important; }
    #sun-info { margin-top: 10px; font-size: 18px; }
}

/* Optimización para Pantallas Cortas (iPhone landscape, tablets antiguas) */
@media (orientation: landscape) and (max-height: 450px) {
    .dashboard-container { padding-top: 42px; gap: 10px; overflow: hidden; }
    .widget { padding: 12px; border-radius: 25px; }
    #sun-info { margin-top: 2px; font-size: 14px; }
    .sun-moon-icon svg { width: 18px; height: 18px; }
    .top-bar { padding: 8px; }
    .top-left-info, .top-right-controls { height: 30px; border-radius: 15px; }
    .top-left-info { padding: 0 10px; }
    .top-right-controls { padding: 0 4px; gap: 0; }
    .control-button { width: 26px; height: 26px; min-width: 30px; min-height: 30px; }
    .control-button svg { width: 14px; height: 14px; }
    .v-label { font-size: 11px; height: 12px; line-height: 12px; }
}
@media (orientation: portrait) { #clock-time { flex-direction: row; -webkit-flex-direction: row; } }

/* Estilos para el Sol y la Luna */
#sun-info { 
    margin-top: 15px; display: flex; display: -webkit-flex; align-items: center; -webkit-align-items: center; 
    font-size: 24px; font-weight: 700; color: var(--secondary-text-color); opacity: 0; transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: -0.02em;
}
.sun-moon-icon svg { width: 32px; height: 32px; margin-right: 14px; display: block; }
.sun-time-text { font-variant-numeric: tabular-nums; }

.status-info { 
    margin-top: auto; width: 100%; 
    display: flex; display: -webkit-flex; justify-content: space-between; -webkit-justify-content: space-between; align-items: center; -webkit-align-items: center; 
    font-size: 14px; font-weight: 700; color: var(--secondary-text-color); padding-top: 15px;
    letter-spacing: 0.02em; text-transform: uppercase;
}
.status-left { display: flex; display: -webkit-flex; align-items: center; -webkit-align-items: center; }
.led { width: 9px; height: 9px; border-radius: 50%; margin-right: 12px; position: relative; }
.led.online { background: #34C759; box-shadow: 0 0 12px rgba(52, 199, 89, 0.6); animation: pulseGreen 2.5s infinite; }
.led.offline { background: #FF3B30; box-shadow: 0 0 12px rgba(255, 59, 48, 0.6); animation: pulseRed 2.5s infinite; }

@keyframes pulseGreen { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }
@keyframes pulseRed { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

/* Estilos del Calendario */
.calendar-content { width: 100%; height: 100%; display: flex; display: -webkit-flex; flex-direction: column; -webkit-flex-direction: column; }
#calendar-header { 
    display: flex; display: -webkit-flex; justify-content: space-between; -webkit-justify-content: space-between; align-items: center; -webkit-align-items: center; 
    margin-bottom: 20px; width: 100%;
}
.calendar-title { 
    font-size: 26px; font-weight: 800; color: var(--text-color); border: none; background: none; cursor: pointer; letter-spacing: -0.04em;
    transition: opacity 0.2s;
}
.calendar-title:active { opacity: 0.6; }

#calendar-grid { 
    display: flex; display: -webkit-flex; flex-wrap: wrap; -webkit-flex-wrap: wrap; width: 100%; flex: 1; -webkit-flex: 1;
    align-content: stretch;
}
.calendar-cell { 
    width: 14.285%; width: -webkit-calc(100% / 7); width: calc(100% / 7); 
    height: 16.666%; height: -webkit-calc(100% / 6); height: calc(100% / 6); 
    display: flex; display: -webkit-flex; justify-content: center; -webkit-justify-content: center; align-items: center; -webkit-align-items: center;
    font-size: 1.35rem; font-weight: 700; position: relative;
    letter-spacing: -0.02em;
}
.calendar-cell.day-name { font-weight: 800; color: var(--secondary-text-color); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.1em; }
.calendar-cell.weekend .content { color: #FF3B30; }
.calendar-cell.weekend.today .content { background: var(--primary-color); color: #FFFFFF; }
body.dark-mode .calendar-cell.weekend .content { color: #FF6961; }
.calendar-cell.today .content { 
    background: var(--primary-color); color: #FFFFFF; width: 46px; height: 46px; 
    display: flex; display: -webkit-flex; justify-content: center; -webkit-justify-content: center; align-items: center; -webkit-align-items: center; border-radius: 50%; 
    box-shadow: 0 6px 15px rgba(255, 59, 48, 0.35);
}

.nav-arrow { 
    width: 44px; height: 44px; border-radius: 50%; background: rgba(128, 128, 128, 0.12); 
    color: var(--primary-color); border: none; cursor: pointer; display: flex; display: -webkit-flex; justify-content: center; -webkit-justify-content: center; align-items: center; -webkit-align-items: center;
    transition: transform 0.3s var(--spring-ease), background-color 0.2s;
}
.nav-arrow:active { transform: scale(0.8); background-color: rgba(128, 128, 128, 0.25); }
.nav-arrow svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 3; }

/* Debug Log - Apple Console Style */
#debug-log { 
    display: none; position: fixed; bottom: 0; left: 0; width: 100%; 
    background: #000000 !important; color: #FFFFFF !important; padding: 25px; 
    font-family: "SF Mono", "SFMono-Regular", ui-monospace, monospace; font-size: 13px; max-height: 45vh; overflow-y: auto; z-index: 100001; 
    border-top: 1px solid rgba(255,255,255,0.1);
}
body.dark-mode #debug-log { background: #FFFFFF !important; color: #000000 !important; border-top: 1px solid rgba(0,0,0,0.1); }
#debug-log.debug-log-visible { display: block !important; animation: slideUp 0.5s var(--spring-ease); }
#debug-log p { border-bottom: 1px solid rgba(128,128,128,0.15); padding: 10px 0; display: block !important; }
#debug-log .log-info { color: #FFFFFF; }
#debug-log .log-warning { color: #FFD60A; }
#debug-log .log-error { color: #FF453A; font-weight: 700; cursor: pointer; }
#debug-log .log-error:hover { text-decoration: underline; }

body.dark-mode #debug-log .log-info { color: #000000; }
body.dark-mode #debug-log .log-warning { color: #8B6E00; }
body.dark-mode #debug-log .log-error { color: #AE0000; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* Banner de Actualización - Apple Modal Style */
.info-banner {
    position: fixed; top: 50%; left: 50%; 
    transform: translate(-50%, -50%) scale(0.9); -webkit-transform: translate(-50%, -50%) scale(0.9);
    width: 90%; max-width: 360px; background: var(--widget-bg); color: var(--text-color);
    padding: 35px; border-radius: 38px; display: none; flex-direction: column; -webkit-flex-direction: column;
    align-items: center; -webkit-align-items: center; gap: 20px; z-index: 100000; 
    box-shadow: 0 40px 120px rgba(0,0,0,0.6); -webkit-backdrop-filter: blur(40px); backdrop-filter: blur(40px);
    opacity: 0; transition: all 0.5s var(--spring-ease); border: 1px solid var(--glass-border);
}
.info-banner.banner-visible { 
    display: flex; opacity: 1; 
    transform: translate(-50%, -50%) scale(1); -webkit-transform: translate(-50%, -50%) scale(1);
}
.banner-buttons { display: flex; display: -webkit-flex; gap: 15px; width: 100%; }
.info-banner button { flex: 1; -webkit-flex: 1; padding: 18px; border-radius: 20px; font-weight: 700; border: none; cursor: pointer; font-size: 16px; transition: transform 0.2s; }
.info-banner button:active { transform: scale(0.95); }
.btn-accept { background: #007AFF; color: #FFFFFF; }
.btn-cancel { background: rgba(128, 128, 128, 0.15); color: #007AFF; }
body.dark-mode .btn-cancel { background: rgba(255, 255, 255, 0.1); color: #0A84FF; }

/* Focus States - Accesibilidad y Apple HIG */
.control-button:focus-visible,
.nav-arrow:focus-visible,
.calendar-title:focus-visible,
.info-banner button:focus-visible {
    outline: 3px solid #007AFF;
    outline-offset: 2px;
}

/* Reducción de movimiento para usuarios que lo prefieren */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
