
/* ========================================
   RESPONSIVE
   ======================================== */

/* Hide carousel arrows on desktop by default */
.custom-nav-arrow {
    display: none !important;
}

/* Tablet (max-width: 1024px) */
@media (max-width: 1024px) {
    body {
        padding: 0.5rem;
    }

    .biggest-container {
        padding: 0.5rem;
    }

    .btn,
    .menu-btn,
    .control-btn,
    .filter-btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
    :root {
        --font-size-base: 1.125rem;
        --font-size-sm: 1rem;
        --font-size-lg: 1.375rem;
        --font-size-xl: 1.625rem;
        --font-size-2xl: 2.25rem;
    }

    body {
        padding: 0;
        padding-bottom: 5.5rem;
    }

    .biggest-container {
        padding: 0.5rem;
        padding-bottom: 6rem;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Layout Overrides */
    .mobile-header {
        display: block !important; /* Restored */
    }

    .header {
        display: none !important; /* Hide desktop header container */
    }

    .title-container {
        display: none !important;
    }

    .menu-toggle {
        display: none !important;
    }

    .full-view-header {
        display: block;
        top: 4.5rem; /* Adjust for mobile header height */
    }

    /* Side Menu & Toggle */
    .side-menu {
        display: none;
    }

    /* Containers */
    .big-container {
        flex-direction: column;
        gap: 1.5rem;
        padding: 0;
    }

    .timetable-wrapper {
        order: 1;
        width: 100%;
        border-radius: var(--border-radius-xs);
        margin: 0;
        box-shadow: 0 4px 12px var(--shadow-color);
        margin-top: 0;
        margin-bottom: 2rem;
        /* Ensure scrolling works smoothly */
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        position: relative; /* Context for sticky */
    }

    .timetable {
        border-radius: var(--border-radius-xs);
        /* Use auto layout to fit content width */
        table-layout: auto;
        width: max-content; /* Allow table to be as wide as needed */
        min-width: 100%;
    }

    .timetable th,
    .timetable td {
        padding: 0.6rem 0.8rem;
        font-size: 1rem;
        width: auto;
        min-width: 140px; /* Healthy minimum */
        max-width: none;
        height: auto !important;
        line-height: 1.5;
        white-space: nowrap; /* Prevent wrapping to fit content width */
        vertical-align: middle;
        box-sizing: border-box;
    }

    /* Sticky Time Column */
    .timetable th:first-child,
    .timetable td:first-child {
        position: sticky;
        left: 0;
        z-index: 10;
        background-color: var(--card-bg); /* Opaque background over scrolling content */
        border-right: 1px solid var(--border-color);
        width: auto !important;
        min-width: auto !important;
        white-space: nowrap;
        font-weight: 700;
        padding: 0.6rem 1rem;
        text-align: center;
        box-shadow: 2px 0 5px -2px rgba(0,0,0,0.1);
    }

    /* Ensure header time cell is on top */
    .timetable thead th:first-child {
        z-index: 11; 
    }

    #emojis {
        font-size: 1.2rem;
    }

    /* Increased from previous small size */

    canvas {
        display: none;
    }

    #scroll-indicator-bg,
    #scroll-indicator {
        display: none;
    }

    /* Overlays on Mobile - Full Screen Logic */
    .manuals-popup {
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
        padding: 1rem;
        top: 0;
        left: 0;
        transform: none;
        padding-top: 4rem;
        position: fixed;
        inset: 0;
        max-height: none;
        background: var(--bg-color);
    }

    .manuals-popup h2 {
        font-size: var(--font-size-2xl);
        margin: 1rem 0 1.5rem;
        padding-right: 0;
    }

    .manuals-popup .close-btn {
        top: 1rem;
        right: 1rem;
    }

    #manualSearch {
        width: 95%;
        font-size: var(--font-size-lg);
        padding: 0.85rem 1rem;
    }

    .manuals-popup .boss-container {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 1rem;
        height: calc(100% - 140px);
        width: 100%;
        max-width: none;
        border: none;
        box-shadow: none;
    }

    .manuals-popup .container {
        padding: 0.75rem;
    }

    .manuals-popup .container h2 {
        font-size: var(--font-size-lg);
        margin: 0.75rem 0 0;
    }

    .manuals-popup .container img {
        max-height: 220px;
    }

    #time {
        font-size: clamp(4rem, 15vw, 8rem);
    }

    #date {
        font-size: clamp(1.3rem, 4vw, 2rem);
    }

    #infoOverlay {
        padding: 0;
    }

    .info-overlay-container {
        width: 100vw;
        max-width: 100%;
        height: 100dvh;
        max-height: 100%;
        border-radius: 0;
        padding: 1.5rem;
        padding-top: 4rem;
        overflow-y: auto;
    }

    .info-overlay-header h2 {
        font-size: var(--font-size-2xl);
        padding-right: 0;
    }

    .release-notes-section>h2 {
        font-size: var(--font-size-xl);
        flex-direction: column;
        gap: 0.5rem;
    }

    .release-note {
        padding: 1.25rem;
    }

    .release-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .release-version {
        font-size: var(--font-size-sm);
        padding: 0.35rem 0.85rem;
    }

    .release-date {
        font-size: var(--font-size-sm);
    }

    .release-note h4 {
        font-size: 1.15rem;
    }

    .release-note li {
        font-size: var(--font-size-sm);
    }

    /* Customization Mobile - Full Screen */
    .customization-container {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
        max-height: 100%;
        border-radius: 0;
        margin: 0;
        flex-direction: column;
        /* Column layout for ordering */
        background: var(--bg-color);
        display: flex;
    }

    /* 
       Order 1: Content (Top)
       Order 2: Sidebar (Bottom)
    */

    .custom-content {
        flex: 1;
        order: 1;
        width: 100%;
        padding: 1.5rem 1rem;
        padding-top: 4rem;
        /* Space for close btn */
        padding-bottom: 1rem;
        overflow-y: auto;
        height: auto;
        max-height: none;
    }

    .custom-sidebar {
        order: 2;
        width: 100%;
        height: auto;
        min-height: 4.5rem;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        background: color-mix(in srgb, var(--card-bg) 95%, transparent);
        backdrop-filter: blur(var(--overlay-blur));
        -webkit-backdrop-filter: blur(var(--overlay-blur));
        overflow: visible;
        /* Allow overrides */
        z-index: 20;
        padding: 0 2rem; /* Add horizontal padding for arrows */
        display: flex !important; /* Ensure flex for centering arrows/nav */
        align-items: center;
        box-shadow: 0 -4px 20px var(--shadow-color);
        flex-shrink: 0;
        position: relative; /* Context for arrows */
    }

    /* Gradient fade overlay for carousel */
    .custom-sidebar::before {
        content: '';
        position: absolute;
        left: 2rem;
        top: 0;
        bottom: 0;
        width: 2rem;
        background: linear-gradient(90deg, var(--card-bg) 0%, transparent 100%);
        pointer-events: none;
        z-index: 11;
    }

    .custom-sidebar::after {
        content: '';
        position: absolute;
        right: 2rem;
        top: 0;
        bottom: 0;
        width: 2rem;
        background: linear-gradient(270deg, var(--card-bg) 0%, transparent 100%);
        pointer-events: none;
        z-index: 11;
    }

    /* Force Hide Sidebar Header on Mobile (Customization overlay only) */
    .custom-sidebar .sidebar-header {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: hidden !important;
    }

    /* Target OverlayScrollbars structure if present, or direct child */
    .custom-sidebar .os-viewport,
    .custom-sidebar .os-content,
    .custom-sidebar {
        height: auto !important;
        overflow: visible !important;
    }

    .sidebar-nav {
        display: flex;
        flex-direction: row;
        width: 100%;
        height: 100%;
        padding: 0;
        margin: 0;
        align-items: center;
        overflow-x: auto;
        scroll-behavior: smooth;
        scrollbar-width: none;
    }
    
    .sidebar-nav::-webkit-scrollbar {
        display: none;
    }

    /* Carousel Arrows Styles for Mobile */
    .custom-nav-arrow {
        display: flex !important;
        position: absolute;
        top: 0;
        bottom: 0;
        height: 100%;
        width: 2rem;
        background: color-mix(in srgb, var(--card-bg) 90%, transparent);
        border: none;
        color: var(--accent-color);
        align-items: center;
        justify-content: center;
        z-index: 10;
        cursor: pointer;
        font-size: 1.2rem;
        backdrop-filter: blur(4px);
        margin: 0;
        padding: 0;
    }

    .custom-nav-arrow.left {
        left: 0;
        border-right: 1px solid var(--border-color);
    }

    .custom-nav-arrow.right {
        right: 0;
        border-left: 1px solid var(--border-color);
    }

    .sidebar-item {
        flex: 0 0 auto; /* Allow scrolling */
        width: 25%; /* Show 4 items roughly */
        height: 4.5rem;
        padding: 0.25rem;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.25rem;
        border: none;
        background: transparent;
        color: var(--text-muted);
        transition: all 0.2s ease;
        border-radius: 0;
    }

    .sidebar-item i {
        font-size: var(--font-size-lg);
        margin: 0;
        width: auto;
        color: inherit;
    }

    .sidebar-item span {
        font-size: var(--font-size-xs);
        font-weight: 500;
        letter-spacing: 0.3px;
    }

    .sidebar-item.active {
        background: transparent;
        border: none;
        color: var(--accent-color);
        box-shadow: inset 0 -3px 0 0 var(--accent-color);
        /* Bottom border indicator */
    }

    .sidebar-item.active i {
        transform: scale(1.1);
        color: var(--accent-color);
    }

    /* Other Styles */

    .theme-options {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .theme-card {
        padding: 1.25rem 0.75rem;
    }

    .theme-icon {
        font-size: var(--font-size-2xl);
    }

    .color-picker-wrapper {
        gap: 0.75rem;
        flex-direction: column;
        align-items: stretch;
    }

    .color-input-box {
        width: 50px;
        height: 50px;
    }

    .color-hex-input {
        width: 100%;
        font-size: var(--font-size-sm);
    }

    .color-presets-grid {
        grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
        gap: 0.75rem;
    }

    .preset-item {
        width: 50px;
        height: 50px;
    }

    .preset-delete {
        width: 22px;
        height: 22px;
        font-size: var(--font-size-xs);
        top: -6px;
        right: -6px;
    }

    .font-select {
        padding: 0.75rem;
        font-size: var(--font-size-sm);
    }

    .presets-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .preset-action-btn {
        width: 100%;
        justify-content: center;
    }

    .saved-presets {
        grid-template-columns: 1fr;
    }

    .contrast-warning {
        font-size: var(--font-size-sm);
        padding: 0.85rem 1rem;
    }

    .add-custom-font-btn {
        padding: 1rem 1.5rem;
        font-size: var(--font-size-lg);
    }

    .custom-select-wrapper .select-arrow {
        right: 0.75rem;
    }

    .randomize-btn {
        width: 100%;
        margin-top: 0.5rem;
        margin-left: 0;
    }

    .add-preset-btn {
        width: 100%;
        justify-content: center;
    }

    /* Weather Mobile - Strict Full Screen */
    #weatherOverlay {
        padding: 0 !important;
        align-items: flex-start !important;
    }

    .weather-overlay-container {
        width: 100vw;
        max-width: 100%;
        height: 100dvh;
        max-height: 100%;
        border-radius: 0;
        padding: 1.5rem;
        padding-top: 4rem;
        position: fixed;
        inset: 0;
        margin: 0;
    }

    .weather-overlay-header h2 {
        font-size: var(--font-size-xl);
        flex-direction: column;
        gap: 0.5rem;
        padding-right: 0;
    }

    .weather-main-info {
        padding: 1.5rem;
    }

    .weather-large-emoji {
        font-size: 5rem;
    }

    .weather-large-temp {
        font-size: 2.5rem;
    }

    .weather-large-desc {
        font-size: var(--font-size-lg);
    }

    .weather-details-grid {
        grid-template-columns: 1fr;
    }

    .weather-detail-card {
        padding: 1.25rem;
    }

    .weather-detail-card i {
        font-size: 1.8rem;
    }

    .weather-detail-value {
        font-size: 1.2rem;
    }

    .weather-location-info {
        font-size: var(--font-size-lg);
    }

    .menu-weather-emoji {
        font-size: 1.6rem;
    }

    .menu-weather-temp {
        font-size: 1rem;
    }

    .weather-btn-content {
        gap: 0.75rem;
        background: var(--card-bg) !important;
    }

    .weather-btn-label {
        font-size: var(--font-size-xs);
    }

    .color-presets {
        gap: 0.5rem;
    }

    .color-presets .preset {
        width: 45px;
        height: 45px;
    }

    /* Todo Mobile - Full Screen */
    .advanced-todo-container {
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
        flex-direction: column;
    }

    .todo-sidebar {
        width: 100%;
        height: auto;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        overflow-y: visible;
        margin-top: 4rem;
    }

    .todo-sidebar.collapsed {
        height: 60px;
    }

    .todo-sidebar.collapsed .todo-stats-compact,
    .todo-sidebar.collapsed .sidebar-section {
        display: none;
    }

    .sidebar-header {
        padding: 1rem 1.5rem;
    }

    .todo-stats-compact {
        padding: 0.75rem 1rem;
        gap: 0.35rem;
    }

    .stat-compact {
        padding: 0.5rem 0.25rem;
    }

    .stat-number {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: var(--font-size-xs);
    }

    .sidebar-section {
        padding: 0.75rem 1rem;
    }

    .todo-content-header {
        padding: 1rem 1.5rem;
        flex-direction: column;
        align-items: stretch;
        margin-top: 0;
    }

    .close-btn-todo {
        top: 1rem;
        right: 1rem;
    }

    .header-left {
        order: 1;
    }

    .header-left h1 {
        font-size: 1.5rem;
    }

    .header-actions {
        order: 2;
        flex-direction: column;
        width: 100%;
    }

    .search-container,
    .view-switcher,
    .dropdown-container,
    .add-task-btn {
        width: 100%;
    }

    #taskSearch {
        width: 100%;
    }

    #taskSearch:focus {
        width: 100%;
    }

    /* Fix #9 — align view-switcher left, consistent with the other stacked controls */
    .view-switcher {
        justify-content: flex-start;
    }

    /* Fix #5 — FAB becomes a full-width in-flow button; no longer floats over content */
    .add-task-btn {
        position: static;
        border-radius: var(--border-radius-sm);
        font-size: var(--font-size-base);
        padding: 0.85rem 1.25rem;
        justify-content: center;
        box-shadow: 0 4px 12px color-mix(in srgb, var(--accent-color) 35%, transparent);
        animation: none; /* scaleIn looks odd on a full-width bar */
    }
    .add-task-btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 6px 16px color-mix(in srgb, var(--accent-color) 45%, transparent);
    }

    .list-view,
    .calendar-view {
        padding: 1rem;
        /* No extra padding-bottom needed — FAB is now in the header, not floating */
        padding-bottom: 1.5rem;
    }

    .task-edit-container,
    .folder-edit-container {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        padding-top: 4rem;
    }

    .task-edit-content,
    .folder-edit-content {
        padding: 1rem 1.5rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .priority-flags {
        flex-wrap: wrap;
    }

    .priority-flag {
        flex: 1;
        min-width: 60px;
    }

    .color-picker-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .icon-picker-grid {
        grid-template-columns: repeat(6, 1fr);
    }

    .calendar-grid {
        gap: 0.5rem;
    }

    .calendar-day {
        min-height: 60px;
        padding: 0.35rem;
    }

    .calendar-day-number {
        font-size: var(--font-size-xs);
    }

    .task-edit-footer,
    .folder-edit-footer {
        flex-direction: column-reverse;
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
        justify-content: center;
    }

    .task-item {
        padding: 1rem;
    }

    .folder-item {
        padding: 0.5rem 0.65rem;
    }

    .quick-filter {
        font-size: var(--font-size-sm);
        padding: 0.5rem 0.65rem;
    }

    .bottom-navbar {
        display: flex;
    }

    .today-view {
        padding-top: calc(4.5rem + max(0.75rem, env(safe-area-inset-top))); /* Adjusted for header */
    }
}

/* Tablet (Landscape) */
@media (max-width: 768px) and (orientation: landscape) {
    .side-menu {
        width: 50%;
        max-width: 400px;
    }

    .task-modal-content {
        width: 90%;
        max-width: 700px;
        height: 90%;
        max-height: 90vh;
        border-radius: var(--border-radius);
    }

    .manuals-popup {
        width: 95%;
        height: 95%;
        border-radius: var(--border-radius);
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .manuals-popup .boss-container {
        grid-template-columns: repeat(3, 1fr);
    }

    .weather-overlay-container {
        width: 90%;
        max-width: 700px;
        height: 90%;
        max-height: 90vh;
        border-radius: var(--border-radius);
    }

    .weather-details-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {

    .title-container,
    .main-title,
    .time-display {
        animation: none;
    }

    .main-title::before {
        animation: none;
    }

    .time-display::after {
        display: none;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Touch Devices */
@media (hover: none) and (pointer: coarse) {

    .btn:active,
    .menu-btn:active,
    .control-btn:active,
    .filter-btn:active,
    .modal-btn:active {
        transform: scale(0.95);
        opacity: 0.8;
    }
}

/* Safe Area Insets */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0.5rem, env(safe-area-inset-left));
        padding-right: max(0.5rem, env(safe-area-inset-right));
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    }

    .side-menu {
        padding-left: max(1.5rem, env(safe-area-inset-left));
        padding-right: max(1.5rem, env(safe-area-inset-right));
    }

    .menu-toggle {
        left: max(1rem, env(safe-area-inset-left));
        top: max(1rem, env(safe-area-inset-top));
    }
}

/* Small Mobile (max-width: 480px) specific tweaks */
@media (max-width: 480px) {
    #emojis {
        font-size: 1.1rem;
    }

    /* Update: Make emojis larger on small screens */
    .manuals-popup .container img {
        max-height: 280px;
    }

    .menu-toggle {
        border-radius: var(--border-radius);
    }

    .filter-btn {
        font-size: var(--font-size-xs);
        padding: 0.5rem 0.8rem;
    }
}
