﻿/* ============================================
   TIMER MOBILE OVERRIDES
   Global mobile-first fixes loaded AFTER all page CSS.
   Enforces touch-friendly, phone-optimized layouts.

   Breakpoints:
   - 768px  = tablet / small laptop
   - 480px  = phone
   - 375px  = small phone (iPhone SE, etc.)
   ============================================ */

/* ====== 768px  -  TABLET & BELOW ====== */
@media (max-width: 768px) {

    /* --- TOUCH TARGETS: enforce 44px minimum on all interactive elements --- */
    .timer-btn,
    .timer-btn-sm,
    .timer-btn-icon,
    button[type="button"],
    .timer-action-btn,
    .timer-chip,
    .timer-tag {
        min-height: 44px;
        min-width: 44px;
    }

    .timer-btn-sm {
        padding: 8px 16px;
        font-size: 13px;
    }

    /* --- TABLES: horizontal scroll instead of broken overflow --- */
    .timer-table-container,
    .timer-table-wrapper,
    .table-responsive,
    .timer-data-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    .timer-table {
        min-width: 500px; /* Force scroll rather than squish */
    }

    /* --- GRIDS: collapse to single column --- */
    .timer-stats-grid,
    .timer-card-grid,
    .timer-grid-3,
    .timer-grid-4 {
        grid-template-columns: 1fr !important;
    }

    .timer-grid-2 {
        grid-template-columns: 1fr !important;
    }

    /* --- MODALS: fit viewport --- */
    .timer-modal-content,
    .timer-modal-dialog {
        max-width: calc(100vw - 24px) !important;
        margin: 12px auto;
    }

    .timer-modal-footer {
        flex-direction: column;
        gap: 8px;
    }

    .timer-modal-footer .timer-btn {
        width: 100%;
    }

    /* --- DRAWERS: full width on mobile --- */
    .timer-drawer-panel {
        width: calc(100vw - 16px) !important;
        max-width: 100vw !important;
        right: 8px !important;
    }

    /* --- BUTTON GROUPS: wrap on mobile --- */
    .timer-btn-group,
    .timer-actions,
    .timer-page-actions,
    .timer-hero-actions,
    .timer-toolbar-actions {
        flex-wrap: wrap;
        gap: 8px;
    }

    .timer-btn-group .timer-btn,
    .timer-page-actions .timer-btn {
        flex: 1 1 auto;
        min-width: 120px;
    }

    /* --- FLEX ROWS: stack vertically --- */
    .timer-hero-split,
    .timer-hero-row {
        flex-direction: column !important;
        gap: 16px;
    }

    /* --- INPUTS: touch-friendly sizing --- */
    .timer-input,
    .timer-select,
    .timer-textarea,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    select,
    textarea {
        min-height: 44px;
        font-size: 16px !important; /* Prevents iOS zoom on focus */
    }

    /* --- TABS: scrollable with touch --- */
    .timer-tabs,
    .timer-role-tabs,
    .timer-pipeline-tabs,
    .timer-filter-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
    }

    .timer-tabs::-webkit-scrollbar,
    .timer-role-tabs::-webkit-scrollbar,
    .timer-pipeline-tabs::-webkit-scrollbar,
    .timer-filter-tabs::-webkit-scrollbar {
        display: none;
    }

    .timer-tab,
    .timer-role-tab,
    .timer-filter-tab {
        flex-shrink: 0;
        min-height: 44px;
        white-space: nowrap;
    }

    /* --- KANBAN: horizontal scroll with proper column width --- */
    .timer-kanban-board,
    .timer-pipeline-board {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }

    .timer-kanban-column,
    .timer-pipeline-column {
        flex: 0 0 calc(100vw - 48px) !important;
        min-width: 0 !important;
        scroll-snap-align: center;
    }

    /* --- REMOVE HOVER-ONLY PATTERNS --- */
    /* Actions hidden behind hover must be always visible on touch */
    .timer-row-actions,
    .timer-card-actions,
    .timer-item-actions {
        opacity: 1 !important;
        visibility: visible !important;
        position: static !important;
        padding-right: 0 !important;
    }

    /* --- PAGE PADDING: tighter on mobile --- */
    .timer-content-area {
        padding: 16px 12px !important;
    }

    .timer-page-header {
        padding: 16px 12px;
    }

    /* --- REMOVE FIXED MIN-WIDTHS that cause overflow --- */
    .timer-row-guest,
    .timer-row-date,
    .timer-row-duration,
    .timer-past-guest,
    .timer-past-title,
    .timer-past-date {
        min-width: 0 !important;
    }

    /* Past items: remove padding-right reserved for hover actions */
    .timer-past-item {
        padding-right: 12px !important;
    }

    /* --- CARDS: ensure grid min-widths don't overflow --- */
    .timer-cards-standard,
    .timer-cards-grid {
        grid-template-columns: 1fr !important;
    }

    /* --- DATE SELECTORS / FILTER ROWS: stack --- */
    .timer-date-range,
    .date-range-selector,
    .timer-filter-row,
    .timer-filters {
        flex-wrap: wrap;
        gap: 8px;
    }

    .timer-date-range .timer-select,
    .date-range-selector .timer-select,
    .timer-date-range .timer-input,
    .timer-filter-row .timer-select {
        min-width: 0 !important;
        flex: 1 1 calc(50% - 4px);
    }
}

/* ====== 480px  -  PHONE ====== */
@media (max-width: 480px) {

    /* --- PAGE LAYOUT: tighter --- */
    .timer-content-area {
        padding: 12px 8px !important;
    }

    .timer-page-header {
        padding: 12px 8px;
    }

    /* --- HERO: compact --- */
    .timer-hero-section,
    .timer-page-hero {
        padding: 16px 12px;
    }

    .timer-hero-title,
    .timer-page-title {
        font-size: 20px !important;
    }

    .timer-hero-subtitle {
        font-size: 13px;
    }

    /* --- STAT CARDS: compact --- */
    .timer-stat-card,
    .timer-mini-stat {
        padding: 12px;
    }

    .timer-stat-value {
        font-size: 22px;
    }

    .timer-stat-label {
        font-size: 11px;
    }

    /* --- CARDS: tighter padding --- */
    .timer-card,
    .timer-premium-section {
        padding: 12px;
        border-radius: 12px;
    }

    .timer-section-header {
        padding: 10px 12px;
    }

    /* --- GRIDS: force single column, smaller minimums --- */
    .hero-metrics,
    .quick-stats-grid,
    .analytics-stats {
        grid-template-columns: 1fr !important;
    }

    .dashboard-grid,
    .analytics-content {
        grid-template-columns: 1fr !important;
    }

    .dashboard-grid [class*="section-"] {
        grid-column: span 1 !important;
    }

    /* --- HEATMAP: reduce columns for phone --- */
    .heatmap-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    /* --- CHARTS: reduce height --- */
    .chart-container {
        height: 200px !important;
    }

    /* --- COMPANIES GRID: force single column --- */
    .timer-companies-grid {
        grid-template-columns: 1fr !important;
    }

    /* --- SPOTLIGHT: 3 visible slots max --- */
    .timer-spotlight-slot:nth-child(n+4) {
        display: none;
    }

    /* --- USAGE GAUGE: stack vertically --- */
    .usage-gauge-container {
        flex-direction: column !important;
    }

    /* --- DRAWER: edge to edge --- */
    .timer-drawer-panel {
        right: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        border-radius: 0 !important;
    }

    /* --- MODAL: nearly full screen --- */
    .timer-modal-content,
    .timer-modal-dialog {
        max-width: calc(100vw - 16px) !important;
        max-height: calc(100vh - 80px);
        margin: 8px;
    }

    /* --- FILTER SELECTORS: full width stack --- */
    .timer-date-range .timer-select,
    .date-range-selector .timer-select,
    .timer-date-range .timer-input,
    .timer-filter-row .timer-select {
        flex: 1 1 100%;
    }

    /* --- TOOLTIP: hide on touch - useless --- */
    .timer-tooltip,
    .rail-tooltip,
    [data-tooltip]::after,
    [data-tooltip]::before {
        display: none !important;
    }
}

/* ====== 375px  -  SMALL PHONE (iPhone SE, etc.) ====== */
@media (max-width: 375px) {

    /* --- Even tighter padding --- */
    .timer-content-area {
        padding: 10px 6px !important;
    }

    .timer-page-header {
        padding: 10px 6px;
    }

    /* --- Smaller fonts where needed --- */
    .timer-hero-title,
    .timer-page-title {
        font-size: 18px !important;
    }

    .timer-btn {
        padding: 8px 12px;
        font-size: 13px;
    }

    /* --- Cards: minimal padding --- */
    .timer-card,
    .timer-premium-section {
        padding: 10px;
    }

    .timer-stat-card,
    .timer-mini-stat {
        padding: 10px 8px;
    }

    /* --- Tables: force tighter --- */
    .timer-table {
        font-size: 12px;
    }

    .timer-table th,
    .timer-table td {
        padding: 8px 6px;
    }

    /* --- Modal/Drawer buttons: stack full width --- */
    .timer-drawer-footer,
    .timer-modal-footer {
        flex-direction: column !important;
        gap: 8px;
        padding: 12px;
    }

    .timer-drawer-footer .timer-btn,
    .timer-modal-footer .timer-btn {
        width: 100% !important;
    }
}

/* ====== TOUCH DEVICE OPTIMIZATIONS ====== */
@media (hover: none) and (pointer: coarse) {

    /* Ensure all interactive elements have adequate tap targets */
    a,
    button,
    [role="button"],
    .timer-btn,
    .timer-tab,
    .timer-chip,
    .timer-tag,
    .timer-card[onclick],
    .timer-row[onclick] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Remove hover effects that flash on touch */
    .timer-card:hover,
    .timer-row:hover,
    .timer-btn:hover {
        transform: none !important;
    }

    /* Visible tap feedback */
    .timer-btn:active,
    .timer-card:active,
    .timer-row:active {
        opacity: 0.85;
        transition: opacity 0.1s ease;
    }

    /* Smooth momentum scrolling everywhere */
    .timer-table-container,
    .timer-kanban-board,
    .timer-tabs,
    .timer-role-tabs {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* ====== iOS SAFE AREA ====== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .timer-drawer-footer,
        .timer-modal-footer {
            padding-bottom: calc(12px + env(safe-area-inset-bottom));
        }
    }
}

/* ====== LANDSCAPE PHONE ====== */
@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce vertical spacing in landscape */
    .timer-hero-section,
    .timer-page-hero {
        padding: 8px 16px;
    }

    .timer-hero-title,
    .timer-page-title {
        font-size: 18px !important;
    }

    /* Drawers: constrain height */
    .timer-drawer-body {
        max-height: 50vh;
    }

    .timer-modal-content,
    .timer-modal-dialog {
        max-height: 80vh;
    }
}
