/*
   ==========================================================================
   MOBILE-FIRST RESPONSIVE DESIGN
   ==========================================================================
   Breakpoints:
   - Mobile: 0 - 640px
   - Tablet: 641px - 1024px
   - Desktop: 1025px+
*/

/* ========================================
   1. MOBILE MENU TOGGLE
   ======================================== */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 200;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s, background 0.3s;
}

.mobile-menu-toggle:hover {
    transform: scale(1.1);
}

.mobile-menu-toggle.active {
    background: #ef4444;
}

.mobile-menu-toggle ion-icon {
    transition: transform 0.3s;
}

.mobile-menu-toggle.active ion-icon {
    transform: rotate(90deg);
}

/* ========================================
   2. SIDEBAR OVERLAY
   ======================================== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s;
}

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

/* ========================================
   3. BASE MOBILE STYLES (Default)
   ======================================== */

/* Hide scrollbars but keep functionality */
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* Dropdown overlay - hidden by default on desktop */
.dropdown-overlay {
    display: none;
}

/* Mobile page title - hidden by default */
.mobile-page-title {
    display: none;
}

/* ========================================
   4. MOBILE (max-width: 640px)
   ======================================== */
@media (max-width: 640px) {
    /* Body & Layout */
    body {
        font-size: 14px;
    }

    .dashboard-layout {
        padding: 0.75rem;
        gap: 0;
        flex-direction: column;
    }

    /* Sidebar - Hidden slide-in menu */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: 280px;
        height: 100vh;
        border-radius: 0 24px 24px 0;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 100;
        padding: 1.5rem 1rem;
        flex-direction: column;
        justify-content: flex-start;
        gap: 0.5rem;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar .nav-item {
        width: 100%;
        height: auto;
        padding: 0.75rem 1rem;
        border-radius: 12px;
        justify-content: flex-start;
        gap: 0.75rem;
    }

    .sidebar .nav-item::after {
        display: none;
    }

    .sidebar .logo-bubble {
        margin-bottom: 1rem;
    }

    /* Show mobile menu toggle */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Main Content */
    .main-content {
        padding: 0;
        width: 100%;
        min-width: 0;
    }

    /* Topbar adjustments */
    .topbar-layout {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.75rem 0;
        margin-bottom: 1rem;
    }

    /* Mobile page title */
    .mobile-page-title {
        display: block;
        order: 0;
    }

    .mobile-page-title h1 {
        font-size: 1.5rem;
        font-weight: 700;
        color: var(--text-main, #1e293b);
        margin: 0;
        line-height: 1.2;
    }

    /* Hide pill-menu on mobile - navigation is in sidebar */
    .top-nav {
        display: none;
    }

    /* Header actions - compact row */
    .header-actions {
        order: 1;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.5rem;
    }

    /* Mobile search - expandable */
    .search-pill {
        flex: 1;
        width: auto;
        min-width: 0;
        padding: 0.5rem 1rem;
        background: white;
        border-radius: 25px;
    }

    .search-pill input {
        font-size: 0.9rem;
    }

    .search-pill input::placeholder {
        font-size: 0.85rem;
    }

    /* Circle buttons - touch friendly */
    .circle-btn {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
        font-size: 1.2rem;
    }

    /* Hide residence name on mobile */
    .residence-name {
        display: none !important;
    }

    .residence-selector-btn {
        padding: 0.6rem;
        border-radius: 50%;
        width: 44px;
        height: 44px;
        justify-content: center;
    }

    .residence-selector-btn .chevron {
        display: none;
    }

    /* Notification wrapper */
    .notification-wrapper {
        position: static;
    }

    /* Bottom sheet dropdowns */
    .notification-dropdown,
    .profile-dropdown,
    .residence-dropdown {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 24px 24px 0 0 !important;
        max-height: 80vh;
        transform: translateY(100%) !important;
        opacity: 1 !important;
        visibility: hidden;
    }

    .notification-dropdown.show,
    .profile-dropdown.show,
    .residence-dropdown.show {
        transform: translateY(0) !important;
        visibility: visible;
    }

    /* Bottom sheet handle */
    .notification-dropdown::before,
    .profile-dropdown::before,
    .residence-dropdown::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #e2e8f0;
        border-radius: 2px;
        margin: 12px auto 8px;
    }

    /* Overlay for bottom sheets */
    .dropdown-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s;
    }

    .dropdown-overlay.show {
        opacity: 1;
        visibility: visible;
    }

    /* Page Headers */
    .header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    .header-row .header-actions,
    .header-row > div:last-child {
        width: 100%;
    }

    .page-title {
        font-size: 1.5rem !important;
    }

    /* Stats Grid */
    .stats-row {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }

    .stat-bubble-card {
        padding: 1rem;
        border-radius: 16px;
    }

    .stat-icon-circle {
        width: 44px;
        height: 44px;
        font-size: 1.2rem;
    }

    .stat-info .value {
        font-size: 1.25rem;
    }

    .stat-info .label {
        font-size: 0.75rem;
    }

    /* Cards */
    .clay-card {
        padding: 1rem;
        border-radius: 20px;
        margin-bottom: 1rem;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .card-header h2,
    .card-header h3 {
        font-size: 1.1rem;
    }

    .card-header .card-actions {
        width: 100%;
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    /* Grids - Single column on mobile */
    .rooms-grid-soft,
    .residences-grid-soft,
    .reports-grid,
    .settings-grid,
    .grid-cols-2,
    .grid-cols-3,
    .lg\:grid-cols-2,
    .lg\:grid-cols-3,
    .md\:grid-cols-2,
    .md\:grid-cols-3 {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    /* Stats grid - 2 columns on mobile for compact view */
    .stats-row {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }

    .stat-bubble-card {
        padding: 0.875rem;
        border-radius: 16px;
        flex-direction: column;
        text-align: center;
    }

    .stat-bubble-card .stat-icon-circle {
        margin-bottom: 0.5rem;
    }

    .stat-bubble-card .stat-info {
        text-align: center;
    }

    .stat-bubble-card .stat-info .value {
        font-size: 1.25rem;
    }

    .stat-bubble-card .stat-info .label {
        font-size: 0.7rem;
    }

    /* Room Cards - Compact */
    .room-card-soft {
        padding: 1rem;
        border-radius: 16px;
    }

    .room-card-soft .room-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }

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

    .room-type-badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.5rem;
    }

    .room-pricing {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .price-tag {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }

    .room-status {
        margin-top: 0.75rem;
    }

    /* Residence Cards */
    .residence-card-soft {
        padding: 1rem;
    }

    .residence-card-soft .residence-header {
        gap: 0.75rem;
    }

    .residence-card-soft .residence-logo {
        width: 48px;
        height: 48px;
    }

    /* Client Cards */
    .client-card {
        padding: 1rem;
    }

    .client-avatar {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    /* Invoice Cards */
    .invoice-card {
        padding: 1rem;
    }

    .invoice-amount {
        font-size: 1.1rem;
    }

    /* Alert Cards */
    .alert-card {
        padding: 0.875rem;
        border-radius: 12px;
    }

    /* Empty State Cards */
    .empty-state-card {
        padding: 2rem 1rem;
    }

    .empty-icon-bubble {
        width: 60px;
        height: 60px;
        font-size: 1.8rem;
    }

    .empty-state-card p {
        font-size: 0.9rem;
    }

    /* Timeline and list items */
    .timeline-item,
    .history-item {
        padding: 0.875rem;
    }

    /* Flex utilities on mobile */
    .flex-col-mobile {
        flex-direction: column !important;
    }

    .gap-sm-mobile {
        gap: 0.5rem !important;
    }

    /* Spacing utilities */
    .mb-6 {
        margin-bottom: 1.5rem !important;
    }

    .mt-6 {
        margin-top: 1.5rem !important;
    }

    .p-6 {
        padding: 1rem !important;
    }

    .gap-6 {
        gap: 1rem !important;
    }

    /* Text sizes */
    .text-2xl {
        font-size: 1.25rem !important;
    }

    .text-xl {
        font-size: 1.1rem !important;
    }

    .text-lg {
        font-size: 1rem !important;
    }

    /* Tables - Horizontal scroll with indicators */
    .table-responsive,
    .soft-table-wrapper,
    .data-table-wrapper {
        position: relative;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
        scrollbar-width: thin;
        scrollbar-color: #cbd5e1 transparent;
    }

    /* Scroll shadow indicators */
    .table-responsive::before,
    .soft-table-wrapper::before,
    .data-table-wrapper::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 20px;
        background: linear-gradient(to right, rgba(255,255,255,0.9), transparent);
        pointer-events: none;
        z-index: 1;
        opacity: 0;
        transition: opacity 0.2s;
    }

    .table-responsive::after,
    .soft-table-wrapper::after,
    .data-table-wrapper::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 20px;
        background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
        pointer-events: none;
        z-index: 1;
    }

    .soft-table,
    .data-table {
        min-width: 600px;
        border-collapse: separate;
        border-spacing: 0;
    }

    .soft-table th,
    .soft-table td,
    .data-table th,
    .data-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    /* Sticky first column for important data */
    .table-sticky-first .soft-table th:first-child,
    .table-sticky-first .soft-table td:first-child,
    .table-sticky-first .data-table th:first-child,
    .table-sticky-first .data-table td:first-child {
        position: sticky;
        left: 0;
        background: white;
        z-index: 2;
        box-shadow: 2px 0 4px rgba(0,0,0,0.05);
    }

    .table-sticky-first .soft-table th:first-child,
    .table-sticky-first .data-table th:first-child {
        background: #f8fafc;
    }

    /* Table actions column - compact */
    .soft-table .actions-cell,
    .data-table .actions-cell {
        display: flex;
        gap: 0.25rem;
    }

    .soft-table .actions-cell .icon-btn-soft,
    .data-table .actions-cell .icon-btn-soft {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }

    /* Mobile Card View for tables (optional class) */
    .table-as-cards .soft-table,
    .table-as-cards .data-table {
        min-width: 0;
    }

    .table-as-cards .soft-table thead,
    .table-as-cards .data-table thead {
        display: none;
    }

    .table-as-cards .soft-table tbody,
    .table-as-cards .data-table tbody {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .table-as-cards .soft-table tr,
    .table-as-cards .data-table tr {
        display: flex;
        flex-direction: column;
        background: white;
        border-radius: 16px;
        padding: 1rem;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
        border: 1px solid #f1f5f9;
    }

    .table-as-cards .soft-table td,
    .table-as-cards .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border-bottom: 1px solid #f1f5f9;
        white-space: normal;
    }

    .table-as-cards .soft-table td:last-child,
    .table-as-cards .data-table td:last-child {
        border-bottom: none;
    }

    .table-as-cards .soft-table td::before,
    .table-as-cards .data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.75rem;
        color: #64748b;
        text-transform: uppercase;
    }

    /* Icon buttons in mobile tables */
    .icon-btn-soft {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 1rem;
    }

    /* Buttons */
    .action-btn-pill {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }

    .action-btn-pill.small {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }

    .btn-pill {
        padding: 0.6rem 1.2rem;
        font-size: 0.85rem;
    }

    /* Forms */
    .form-control {
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
        height: 44px;
    }

    .form-group {
        margin-bottom: 1rem;
    }

    .form-row,
    .filter-grid {
        flex-direction: column;
        gap: 0.75rem;
    }

    .filter-grid .col {
        width: 100%;
        min-width: 0;
    }

    /* Filter Pills */
    .filter-pills-row {
        padding-bottom: 0.75rem;
        margin-bottom: 1rem;
    }

    .filter-pill {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }

    /* Empty States */
    .empty-state-card {
        padding: 2rem 1rem;
    }

    .empty-icon-bubble {
        width: 60px;
        height: 60px;
        font-size: 1.8rem;
    }

    /* Modals & Dropdowns */
    .notification-dropdown,
    .profile-dropdown,
    .residence-dropdown {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 24px 24px 0 0 !important;
        max-height: 80vh;
    }

    /* Invoice Print - hide on mobile */
    @media print {
        .sidebar, .topbar-layout, .mobile-menu-toggle {
            display: none !important;
        }
    }
}

/* ========================================
   5. TABLET (641px - 1024px)
   ======================================== */
@media (min-width: 641px) and (max-width: 1024px) {
    .dashboard-layout {
        display: flex !important;
        flex-direction: row !important;
        padding: 1rem;
        gap: 1rem;
    }

    /* Sidebar - Compact rail - VISIBLE on tablet */
    .sidebar {
        display: flex !important;
        position: sticky !important;
        top: 1rem;
        left: auto !important;
        width: 70px !important;
        height: calc(100vh - 2rem);
        padding: 1rem 0.5rem;
        transform: none !important;
        flex-shrink: 0 !important;
        background: var(--bg-surface, #ffffff);
        border-radius: var(--radius-pill, 100px);
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Hide mobile elements on tablet */
    .mobile-menu-toggle {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }

    /* Main content takes remaining space */
    .main-content {
        flex: 1;
        min-width: 0;
    }

    .sidebar .nav-item {
        width: 44px;
        height: 44px;
    }

    .logo-bubble {
        width: 42px;
        height: 42px;
        font-size: 1.2rem;
    }

    /* Topbar */
    .topbar-layout {
        grid-template-columns: 1fr auto;
        gap: 0.75rem;
    }

    .top-nav {
        grid-column: 1 / -1;
        order: 2;
    }

    .header-actions {
        grid-column: 2;
        order: 1;
    }

    .search-pill {
        width: 180px;
    }

    /* Grids */
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .rooms-grid-soft,
    .residences-grid-soft {
        grid-template-columns: repeat(2, 1fr);
    }

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

    /* Cards */
    .clay-card {
        padding: 1.5rem;
    }

    /* Tables */
    .soft-table th,
    .soft-table td {
        padding: 1rem 0.75rem;
    }
}

/* ========================================
   6. DESKTOP (1025px+)
   ======================================== */
@media (min-width: 1025px) {
    .dashboard-layout {
        display: flex !important;
        flex-direction: row !important;
        padding: 1.5rem;
        gap: 2rem;
    }

    /* Full sidebar visible - EXPLICIT desktop styles */
    .sidebar {
        display: flex !important;
        position: sticky !important;
        top: 1.5rem;
        left: auto !important;
        width: var(--sidebar-width, 80px) !important;
        height: calc(100vh - 3rem);
        transform: none !important;
        flex-shrink: 0 !important;
        background: var(--bg-surface, #ffffff);
        border-radius: var(--radius-pill, 100px);
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Main content takes remaining space */
    .main-content {
        flex: 1;
        min-width: 0;
    }

    /* Full topbar */
    .topbar-layout {
        grid-template-columns: 1fr auto 1fr;
    }

    /* Stats row - 3 or 4 columns */
    .stats-row {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }

    /* Hide mobile elements on desktop */
    .mobile-menu-toggle {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }
}

/* ========================================
   7. UTILITY RESPONSIVE CLASSES
   ======================================== */

/* Hide/Show by breakpoint */
.hide-mobile {
    display: block;
}
.show-mobile {
    display: none;
}

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

.hide-tablet {
    display: block;
}
.show-tablet {
    display: none;
}

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

/* Stack on mobile */
.stack-mobile {
    display: flex;
    gap: 1rem;
}

@media (max-width: 640px) {
    .stack-mobile {
        flex-direction: column;
    }
}

/* Full width on mobile */
.full-mobile {
    width: auto;
}

@media (max-width: 640px) {
    .full-mobile {
        width: 100% !important;
    }
}

/* Text alignment on mobile */
@media (max-width: 640px) {
    .text-center-mobile {
        text-align: center !important;
    }
}

/* ========================================
   8. TOUCH OPTIMIZATIONS
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .nav-item,
    .icon-btn-soft,
    .circle-btn,
    .filter-pill {
        min-width: 44px;
        min-height: 44px;
    }

    /* Remove hover effects on touch */
    .room-card-soft:hover,
    .stat-bubble-card:hover,
    .clay-card:hover {
        transform: none;
    }

    /* SIDEBAR NAV ITEMS - Fix hover/active on touch */
    .sidebar .nav-item {
        transform: none !important;
        transition: background 0.15s ease;
    }

    .sidebar .nav-item:hover {
        transform: none !important;
        background: rgba(99, 102, 241, 0.08);
    }

    .sidebar .nav-item:active {
        background: rgba(99, 102, 241, 0.15) !important;
        transform: scale(0.98) !important;
    }

    .sidebar .nav-item.active {
        background: linear-gradient(135deg, #eef2ff, #e0e7ff) !important;
        color: var(--primary) !important;
    }

    .sidebar .nav-item.active .nav-label {
        color: var(--primary);
        font-weight: 600;
    }

    /* Ensure text is always readable */
    .sidebar .nav-item .nav-label {
        color: inherit;
        opacity: 1;
    }

    /* Tap highlight */
    a, button {
        -webkit-tap-highlight-color: rgba(99, 102, 241, 0.1);
    }
}

/* ========================================
   9. SAFE AREAS (Notch/Home indicator)
   ======================================== */
@supports (padding: max(0px)) {
    .dashboard-layout {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }

    .mobile-menu-toggle {
        bottom: max(1.5rem, calc(env(safe-area-inset-bottom) + 0.5rem));
        right: max(1.5rem, env(safe-area-inset-right));
    }

    .sidebar {
        padding-bottom: max(2rem, calc(env(safe-area-inset-bottom) + 1rem));
    }
}

/* ========================================
   10. ANIMATIONS (Reduced motion)
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
