/* ===================================
   RESPONSIVE STYLES
   Tablet and Mobile Breakpoints
   =================================== */

/* ==================== BREAKPOINT REFERENCE ==================== */
/*
   Desktop Large:    > 1920px
   Desktop:          1280px - 1920px
   Tablet Landscape: 1024px - 1279px
   Tablet Portrait:  768px - 1023px
   Mobile:           480px - 767px
   Mobile Small:     < 480px
*/

/* ==================== LARGE DESKTOP (1921px+) ==================== */

@media (min-width: 1921px) {
    body {
        font-size: 15px;
    }

    .container {
        max-width: 1800px;
    }

    .main-content {
        padding: 40px 50px;
    }

    /* Larger cards on big screens */
    .stat-card {
        padding: 32px;
    }

    .stat-number,
    .stat-value {
        font-size: 2.8em;
    }

    /* Better use of space in forms */
    .form-row,
    .form-row-3 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ==================== DESKTOP (1200px - 1920px) ==================== */

@media (min-width: 1200px) and (max-width: 1920px) {
    body {
        font-size: 14px;
    }

    .container {
        max-width: 85%;
        padding: 25px;
    }
}

/* ==================== TABLET LANDSCAPE (1024px - 1279px) ==================== */

@media (min-width: 1024px) and (max-width: 1279px) {
    /* Sidebar adjustments */
    .sidebar {
        width: 200px;
    }

    .main-content {
        margin-left: 200px;
        padding: 24px 30px;
    }

    .sidebar-logo {
        max-height: 120px;
    }

    /* Navigation */
    .nav-item {
        padding: 9px 10px;
        font-size: 13px;
    }

    .nav-section-title {
        font-size: 10px;
    }

    /* Tables - enable horizontal scroll if needed */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Form grids */
    .form-row-4 {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Stats grid */
    .stats-grid,
    .dashboard-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ==================== TABLET PORTRAIT (768px - 1023px) ==================== */

@media (min-width: 768px) and (max-width: 1023px) {
    /* Hide sidebar by default on tablet */
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        width: 280px;
        z-index: 1000;
    }

    .sidebar.mobile-visible {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    /* Main content takes full width */
    .main-content {
        margin-left: 0;
        padding: 20px;
        padding-top: 70px; /* Space for mobile menu button */
    }

    /* Show mobile menu toggle */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Page header */
    .page-header {
        margin-bottom: 20px;
        padding-bottom: 15px;
    }

    .page-title {
        font-size: 1.8em;
    }

    /* Tabs */
    .tabs {
        gap: 4px;
        margin-bottom: 20px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab,
    .tab-button {
        padding: 10px 16px;
        font-size: 14px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Forms */
    form,
    .form-card {
        padding: 20px;
    }

    .form-row,
    .form-row-3,
    .form-row-4 {
        grid-template-columns: repeat(2, 1fr);
    }

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

    /* Tables */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -20px;
        padding: 0 20px;
    }

    table {
        min-width: 700px;
    }

    th, td {
        padding: 12px;
        font-size: 13px;
    }

    /* Stats */
    .stats-grid,
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .stat-card {
        padding: 20px;
    }

    .stat-number,
    .stat-value {
        font-size: 2em;
    }

    /* Cards */
    .repair-card {
        padding: 18px;
    }

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

    /* Modals */
    .modal-content {
        max-width: 90%;
        width: 90%;
        margin: 20px;
    }

    /* Calendar */
    .calendar {
        padding: 15px;
    }

    .calendar-header {
        flex-wrap: wrap;
        gap: 12px;
    }

    .calendar-day {
        min-height: 90px;
    }
}

/* ==================== MOBILE (480px - 767px) ==================== */

@media (max-width: 767px) {
    /* Base */
    body {
        font-size: 14px;
    }

    /* Sidebar */
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        width: 85%;
        max-width: 300px;
        z-index: 1000;
        padding-bottom: 80px; /* Space for logout */
    }

    .sidebar.mobile-visible {
        transform: translateX(0);
        box-shadow: 4px 0 30px rgba(0, 0, 0, 0.4);
    }

    .sidebar-header {
        padding: 12px;
    }

    .sidebar-logo {
        max-height: 100px;
    }

    /* Main content */
    .main-content {
        margin-left: 0;
        padding: 15px;
        padding-top: 65px;
    }

    /* Mobile menu toggle */
    .mobile-menu-toggle {
        display: flex;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 200;
        padding: 10px 14px;
        font-size: 14px;
    }

    /* Page header */
    .page-header {
        margin-bottom: 15px;
    }

    .page-title {
        font-size: 1.5em;
    }

    .page-subtitle {
        font-size: 0.95em;
    }

    /* Tabs - horizontal scroll */
    .tabs {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 6px;
        margin-bottom: 20px;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab,
    .tab-button {
        padding: 10px 14px;
        font-size: 13px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Forms */
    form,
    .form-card {
        padding: 16px;
        border-radius: 12px;
    }

    .form-row,
    .form-row-2,
    .form-row-3,
    .form-row-4 {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .form-group {
        margin-bottom: 12px;
    }

    .form-group label {
        font-size: 10px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea,
    .form-control {
        padding: 12px 14px;
        font-size: 16px; /* Prevents iOS zoom */
    }

    .form-section h4 {
        font-size: 10px;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    /* Buttons */
    .btn {
        padding: 12px 20px;
        font-size: 14px;
        width: 100%;
        margin-right: 0;
        margin-bottom: 8px;
    }

    .btn-small {
        padding: 10px 16px;
    }

    /* Button groups */
    .action-buttons {
        flex-direction: column;
        gap: 8px;
    }

    .action-buttons .btn,
    .action-buttons .status-select {
        width: 100%;
    }

    /* Tables */
    .table-container,
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
    }

    table {
        min-width: 600px;
    }

    th, td {
        padding: 10px 12px;
        font-size: 13px;
    }

    /* Hide less important columns on mobile */
    .hide-mobile {
        display: none !important;
    }

    /* Stats grid */
    .stats-grid,
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-number,
    .stat-value {
        font-size: 1.8em;
    }

    .stat-label {
        font-size: 0.85em;
    }

    /* Cards */
    .card,
    .repair-card {
        padding: 14px;
        border-radius: 12px;
    }

    .repair-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .repair-title {
        font-size: 1.1em;
    }

    .repair-details {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    /* Modals */
    .modal-overlay {
        padding: 10px;
        align-items: flex-end; /* Slide up from bottom on mobile */
    }

    .modal-content {
        max-width: 100%;
        width: 100%;
        max-height: 90vh;
        border-radius: 16px 16px 0 0;
        padding: 20px 16px;
        margin: 0;
    }

    .modal-header h2 {
        font-size: 1.2em;
    }

    .close {
        font-size: 1.8em;
        padding: 8px;
    }

    /* Calendar */
    .calendar {
        padding: 12px 8px;
    }

    .calendar-header {
        flex-direction: column;
        gap: 12px;
        padding: 12px;
    }

    .calendar-header h2 {
        font-size: 1.3em;
    }

    .calendar-nav {
        width: 100%;
        justify-content: space-between;
    }

    .calendar-weekdays > div {
        font-size: 0.7em;
        padding: 6px 2px;
    }

    .calendar-day {
        min-height: 70px;
        padding: 4px;
    }

    .day-number {
        width: 24px;
        height: 24px;
        line-height: 24px;
        font-size: 0.8em;
    }

    .calendar-event {
        padding: 4px 6px;
        margin-bottom: 3px;
    }

    .event-title {
        font-size: 0.7em;
    }

    .event-client {
        display: none;
    }

    /* Search section */
    .search-section {
        padding: 16px;
    }

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

    /* Messages */
    .message {
        padding: 14px;
        font-size: 13px;
    }

    /* User info bar */
    .user-info-bar {
        text-align: center;
        padding: 12px;
        font-size: 13px;
    }

    /* Activity feed */
    .activity-item {
        padding: 12px;
        gap: 12px;
    }

    .activity-icon {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    /* Scanner */
    .scanner-close {
        top: 10px;
        right: 10px;
        padding: 10px 18px;
        font-size: 14px;
    }

    /* Quick actions bar (if exists) */
    .quick-actions {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--color-bg-surface);
        border-top: 1px solid var(--color-border);
        padding: 12px;
        display: flex;
        justify-content: space-around;
        z-index: 90;
    }
}

/* ==================== MOBILE SMALL (< 480px) ==================== */

@media (max-width: 479px) {
    body {
        font-size: 13px;
    }

    .main-content {
        padding: 12px;
        padding-top: 60px;
    }

    .page-title {
        font-size: 1.3em;
    }

    h1 { font-size: 1.3em; }
    h2 { font-size: 1.15em; }
    h3 { font-size: 1em; }

    form,
    .form-card {
        padding: 14px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 12px;
    }

    .btn {
        padding: 12px 16px;
        font-size: 13px;
    }

    .modal-content {
        padding: 16px 12px;
    }

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

    .day-number {
        width: 22px;
        height: 22px;
        line-height: 22px;
        font-size: 0.75em;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-number,
    .stat-value {
        font-size: 1.5em;
    }

    .repair-card {
        padding: 12px;
    }
}

/* ==================== TOUCH DEVICE OPTIMIZATIONS ==================== */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn {
        min-height: 44px;
    }

    .btn-small {
        min-height: 40px;
    }

    .nav-item {
        min-height: 44px;
        padding: 12px;
    }

    .tab,
    .tab-button {
        min-height: 44px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        min-height: 44px;
    }

    /* Remove hover states that don't work well on touch */
    .btn:hover {
        transform: none;
    }

    .card:hover,
    .repair-card:hover {
        transform: none;
    }

    /* Add active states instead */
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    .card:active,
    .repair-card:active {
        transform: scale(0.99);
    }

    /* Disable hover lift effects */
    .hover-lift:hover {
        transform: none;
    }
}

/* ==================== LANDSCAPE MODE (MOBILE) ==================== */

@media (max-height: 500px) and (orientation: landscape) {
    .main-content {
        padding-top: 50px;
    }

    .mobile-menu-toggle {
        padding: 8px 12px;
    }

    .sidebar {
        padding-top: 10px;
    }

    .sidebar-logo {
        max-height: 60px;
    }

    .modal-content {
        max-height: 85vh;
    }

    /* Reduce vertical spacing */
    .form-group {
        margin-bottom: 8px;
    }

    .form-section {
        margin-bottom: 12px;
        padding-bottom: 10px;
    }
}

/* ==================== HIGH CONTRAST MODE ==================== */

@media (prefers-contrast: high) {
    :root {
        --color-border: #4a5568;
        --color-border-light: rgba(255, 255, 255, 0.15);
        --color-text-muted: #b0b8c4;
    }

    .btn {
        border: 2px solid currentColor;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        border-width: 2px;
    }
}

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

@media print {
    .sidebar,
    .mobile-menu-toggle,
    .tabs,
    .btn,
    .action-buttons {
        display: none !important;
    }

    .main-content {
        margin-left: 0;
        padding: 0;
    }

    body {
        font-size: 12pt;
        background: white;
        color: black;
    }
}

/* ==================== UTILITY CLASSES ==================== */

/* Show only on specific breakpoints */
.show-tablet {
    display: none !important;
}

.show-mobile {
    display: none !important;
}

@media (min-width: 768px) and (max-width: 1023px) {
    .show-tablet {
        display: block !important;
    }
    .hide-tablet {
        display: none !important;
    }
}

@media (max-width: 767px) {
    .show-mobile {
        display: block !important;
    }
    .hide-mobile {
        display: none !important;
    }
}

/* Responsive text alignment */
@media (max-width: 767px) {
    .mobile-text-center {
        text-align: center !important;
    }
    .mobile-text-left {
        text-align: left !important;
    }
}

/* Responsive spacing */
@media (max-width: 767px) {
    .mobile-mt-0 { margin-top: 0 !important; }
    .mobile-mb-0 { margin-bottom: 0 !important; }
    .mobile-p-0 { padding: 0 !important; }
    .mobile-full-width { width: 100% !important; }
}
