/**
 * Mobile-specific styles and responsive design
 * Mobile-first approach with breakpoints
 */

/* ========================================
   Mobile Optimizations (< 768px)
   ======================================== */
@media (max-width: 767px) {
    /* Typography */
    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }

    /* Header - Keep horizontal layout for hamburger menu */
    .app-header .container {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: var(--spacing-sm);
    }

    .header-left {
        flex: 1;
        min-width: 0; /* Allows text to truncate if needed */
    }

    .app-title {
        font-size: var(--font-size-lg);
    }

    /* Navigation */
    .app-nav {
        top: auto;
    }

    .nav-btn {
        font-size: var(--font-size-sm);
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    /* View Header */
    .view-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-md);
    }

    .view-header h2 {
        font-size: var(--font-size-xl);
    }

    /* Stats Grid */
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: var(--spacing-md);
    }

    .stat-value {
        font-size: var(--font-size-2xl);
    }

    /* Forms */
    .form-row {
        grid-template-columns: 1fr;
    }

    /* Buttons */
    .button-group {
        flex-direction: column;
    }

    .button-group .btn {
        width: 100%;
    }

    /* Tables - Make scrollable */
    .table-responsive {
        margin: 0 calc(var(--spacing-md) * -1);
        padding: 0 var(--spacing-md);
    }

    table {
        font-size: var(--font-size-sm);
    }

    th,
    td {
        padding: var(--spacing-sm);
    }

    .trip-destination {
        max-width: 120px;
    }

    /* Cards */
    .card {
        padding: var(--spacing-md);
    }

    /* Vehicles Grid */
    .vehicles-grid {
        grid-template-columns: 1fr;
    }

    /* Modal */
    .modal-content {
        max-height: 95vh;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: var(--spacing-md);
    }

    .modal-footer {
        flex-direction: column-reverse;
    }

    .modal-footer .btn {
        width: 100%;
    }

    /* FAB - Larger touch target on mobile */
    .fab {
        width: 64px;
        height: 64px;
        font-size: 32px;
        bottom: var(--spacing-md);
        right: var(--spacing-md);
    }

    /* Dashboard */
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-md);
    }

    .year-selector {
        align-self: stretch;
        justify-content: space-between;
    }

    .purpose-row {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }

    .purpose-stats {
        width: 100%;
        justify-content: space-between;
    }

    .recent-trip {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }

    .trip-stats {
        width: 100%;
        justify-content: space-between;
    }

    .quick-actions {
        flex-direction: column;
    }

    .quick-actions .btn {
        width: 100%;
    }

    /* Filters */
    .filters {
        flex-direction: column;
    }

    .filter-select,
    .filter-input,
    .filter-date-group {
        width: 100%;
    }

    .date-presets {
        flex-direction: column;
    }

    .date-presets .btn {
        width: 100%;
        justify-content: center;
    }

    /* Reports */
    .report-options {
        grid-template-columns: 1fr;
    }

    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Toast */
    .toast {
        left: var(--spacing-md);
        right: var(--spacing-md);
        transform: translateX(0) translateY(100px);
        min-width: auto;
    }

    .toast.show {
        transform: translateX(0) translateY(0);
    }

    /* Impersonation Banner */
    .impersonation-banner .container {
        flex-direction: column;
        gap: var(--spacing-sm);
        align-items: flex-start;
    }

    /* Login Screen */
    .login-container {
        width: 100%;
        padding: var(--spacing-md);
    }

    /* Make touch targets larger */
    button,
    input,
    select,
    textarea {
        min-height: 44px;
    }

    input[type="checkbox"] {
        width: 22px;
        height: 22px;
    }
}

/* ========================================
   Tablet (768px - 1024px)
   ======================================== */
@media (min-width: 768px) and (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .vehicles-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .summary-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ========================================
   Desktop (> 1024px)
   ======================================== */
@media (min-width: 1025px) {
    /* Hide FAB on larger screens where top "Add Trip" button is easily accessible */
    .fab {
        display: none;
    }

    /* Larger container */
    .container {
        max-width: 1400px;
    }

    /* Multi-column layouts */
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }

    /* Table improvements */
    tbody tr:hover {
        cursor: pointer;
    }
}

/* ========================================
   Login & Init Screens
   ======================================== */
#login-screen,
#db-init-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--spacing-md);
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: var(--spacing-lg);
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: var(--spacing-xl);
}

.login-header h1 {
    color: var(--color-primary);
    margin-bottom: var(--spacing-sm);
}

.login-header p {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

#login-form {
    margin-top: var(--spacing-lg);
}

/* ========================================
   Touch Optimizations
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets */
    .btn {
        min-height: 44px;
        padding: var(--spacing-md) var(--spacing-lg);
    }

    .btn-small {
        min-height: 36px;
    }

    .nav-btn {
        min-height: 44px;
    }

    /* Remove hover effects */
    .btn:hover,
    .nav-btn:hover,
    .modal-close:hover {
        transform: none;
    }

    /* Use tap highlighting */
    button,
    a,
    .clickable {
        -webkit-tap-highlight-color: rgba(74, 158, 255, 0.3);
    }
}

/* ========================================
   Landscape Mobile (< 768px height)
   ======================================== */
@media (max-height: 500px) and (orientation: landscape) {
    .modal-content {
        max-height: 85vh;
    }

    .app-header {
        padding: var(--spacing-sm) 0;
    }

    .app-nav .container {
        padding: var(--spacing-xs) var(--spacing-md);
    }

    .fab {
        width: 48px;
        height: 48px;
        font-size: 24px;
    }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    body {
        background-color: white;
        color: black;
    }

    .app-header,
    .app-nav,
    .fab,
    .btn,
    .view-controls,
    .modal,
    .toast {
        display: none !important;
    }

    .card {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    table {
        font-size: 10pt;
    }

    th,
    td {
        padding: 4px 8px;
    }
}

/* ========================================
   Reduced Motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========================================
   Dark Mode (System Preference)
   Already dark by default, but respect system preference
   ======================================== */
@media (prefers-color-scheme: light) {
    /* User explicitly wants dark mode for this app,
       so we keep it dark regardless of system preference */
}

/* ========================================
   Safe Areas (for notched devices)
   ======================================== */
@supports (padding: env(safe-area-inset-top)) {
    .app-header {
        padding-top: max(var(--spacing-md), env(safe-area-inset-top));
    }

    .fab {
        bottom: max(var(--spacing-lg), env(safe-area-inset-bottom));
        right: max(var(--spacing-lg), env(safe-area-inset-right));
    }
}
