/* ========================================
   MOBILE-FIRST RESPONSIVE DESIGN
   ======================================== */

/* Base mobile styles (320px and up) */
:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --text-color: #333;
    --bg-color: #f8f9fa;
    --border-color: #ddd;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
    --touch-target: 44px;
}

* {
    -webkit-tap-highlight-color: transparent;
}

/* Global mobile fix - prevent horizontal scrolling */
html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
}

body {
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-color);
}

/* Typography - Mobile optimized (scoped to .container for
   legacy pages; design-system components handle their own) */
.container h1 {
    font-size: 28px;
    margin-bottom: 12px;
}

.container h2 {
    font-size: 24px;
    margin-bottom: 10px;
}

.container h3 {
    font-size: 20px;
    margin-bottom: 8px;
}

.container h4 {
    font-size: 18px;
    margin-bottom: 8px;
}

.container h5 {
    font-size: 16px;
    margin-bottom: 6px;
}

.container h6 {
    font-size: 14px;
    margin-bottom: 6px;
}

.container p {
    margin-bottom: 12px;
}

/* Navigation - Mobile hamburger menu */
.mobile-menu-toggle {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
}

.mobile-menu-toggle span {
    width: 24px;
    height: 2px;
    background: white;
    transition: var(--transition);
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(10px, 10px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

/* Navigation - Stack vertically on mobile */
.main-nav {
    display: none;
    flex-direction: column;
    width: 100%;
    position: absolute;
    top: 100%;
    left: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.main-nav.active {
    display: flex;
}

.nav-link {
    min-height: var(--touch-target);
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* Buttons - Touch friendly (only un-classed fallback buttons) */
button:not([class]),
input[type="submit"]:not([class]),
input[type="button"]:not([class]) {
    min-height: var(--touch-target);
    min-width: var(--touch-target);
    padding: 12px 16px;
    font-size: 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    background-color: var(--primary-color);
    color: white;
    -webkit-appearance: none;
}

button:not([class]):hover,
input[type="submit"]:not([class]):hover,
input[type="button"]:not([class]):hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

button:not([class]):active {
    transform: translateY(0);
}

/* Forms - Mobile optimized (scoped to avoid overriding
   design-system inputs like .ps-input, .ps-select, chat
   widget inputs, etc.) */
.container input[type="text"],
.container input[type="email"],
.container input[type="password"],
.container input[type="number"],
.container input[type="tel"],
.container input[type="date"],
.container input[type="time"],
.container select,
.container textarea {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 12px;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.container input:focus,
.container select:focus,
.container textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.container label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 14px;
}

/* Tables - Responsive (scoped to .container for legacy pages;
   component tables like .td-table / .ps-table define their own) */
.container table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.container tbody tr {
    border-bottom: 1px solid var(--border-color);
}

.container th,
.container td {
    padding: 12px;
    text-align: left;
}

.container th {
    background-color: #f5f5f5;
    font-weight: 600;
    font-size: 14px;
}

/* Cards and panels */
.card,
.panel {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

/* Flex utilities */
.flex {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.flex-row {
    flex-direction: row;
}

.flex-col {
    flex-direction: column;
}

/* Grid - Mobile first */
.grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

/* Spacing utilities */
.mb-0 {
    margin-bottom: 0;
}

.mb-1 {
    margin-bottom: 8px;
}

.mb-2 {
    margin-bottom: 16px;
}

.mb-3 {
    margin-bottom: 24px;
}

/* Prevent unwanted horizontal scrolling in app frames (owners / admins)
   - Force main layout to use vertical scrolling
   - Hide horizontal overflow while allowing specific components to enable
     horizontal scrolling via explicit `.overflow-x-auto` when needed */
.ps-layout,
.ps-page-wrapper,
.td-page,
body > div,
main,
section {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
}

.ps-main {
    /* keep vertical scroll for main content areas */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
}

/* Align main content with navbar margins and account for sidebar */
/* On large screens where sidebar is visible (280px), offset main content */
@media (min-width: 992px) {
    .ps-sidebar {
        position: relative;
        width: 280px;
        flex-shrink: 0;
    }

    .ps-main {
        margin-left: 0;
        flex: 1;
        /* match header/nav horizontal spacing (logo-link uses 8px/16px) */
        padding: 24px 16px;
        box-sizing: border-box;
    }
}

/* On small screens no sidebar offset; use consistent horizontal padding */
@media (max-width: 991px) {
    .ps-main {
        margin-left: 0;
        padding: 16px 16px;
        box-sizing: border-box;
    }
}

/* Ensure sidebar inner content aligns with header spacing */
.ps-sidebar {
    padding-left: 16px;
    padding-right: 16px;
}

/* Utility to explicitly allow horizontal scrolling where required */
.allow-horizontal,
.overflow-x-auto {
    overflow-x: auto !important;
}

.mb-4 {
    margin-bottom: 32px;
}

.mt-0 {
    margin-top: 0;
}

.mt-1 {
    margin-top: 8px;
}

.mt-2 {
    margin-top: 16px;
}

.mt-3 {
    margin-top: 24px;
}

/* Images - Lazy loading */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

img[loading="lazy"] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Alerts and messages */
.alert {
    padding: 16px;
    margin-bottom: 16px;
    border-radius: 6px;
    border-left: 4px solid;
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
    border-color: #28a745;
}

.alert-danger {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #dc3545;
}

.alert-warning {
    background-color: #fff3cd;
    color: #856404;
    border-color: #ffc107;
}

.alert-info {
    background-color: #d1ecf1;
    color: #0c5460;
    border-color: #17a2b8;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 20px 0;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-target);
    height: var(--touch-target);
    padding: 0 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    text-decoration: none;
    color: var(--primary-color);
    transition: var(--transition);
}

.pagination a:hover {
    background-color: var(--primary-color);
    color: white;
}

.pagination .active span {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Loading state */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* ========================================
   SMALL TABLET STYLES (600px and up)
   ======================================== */

@media (min-width: 600px) {
    .container h1 {
        font-size: 30px;
    }

    .container h2 {
        font-size: 26px;
    }

    .container h3 {
        font-size: 22px;
    }

    /* Grid layouts - 2 columns on small tablets */
    .property-info-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Forms - side-by-side on small tablets */
    .container form .row {
        display: flex;
        gap: 15px;
    }

    .container form .row > div {
        flex: 1;
    }

    /* Buttons - slightly larger touch targets */
    button:not([class]),
    input[type="submit"]:not([class]),
    input[type="button"]:not([class]) {
        padding: 14px 20px;
    }
}

/* ========================================
   TABLET STYLES (768px and up)
   ======================================== */

@media (min-width: 768px) {
    .container h1 {
        font-size: 32px;
    }

    .container h2 {
        font-size: 28px;
    }

    .container h3 {
        font-size: 24px;
    }

    /* Navigation - Show horizontally on tablet */
    .mobile-menu-toggle {
        display: none;
    }

    .main-nav {
        display: flex !important;
        flex-direction: row !important;
        position: static !important;
        width: auto !important;
        background: none !important;
        border: none !important;
    }

    .nav-link {
        border: none !important;
        padding: 8px 14px !important;
        min-height: auto;
    }

    /* Ensure dropdowns don't cover other nav items */
    .language-menu,
    .country-menu {
        position: absolute !important;
        z-index: 1000 !important;
        background: white !important;
        border: 1px solid #ddd !important;
        border-radius: 8px !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
        margin-top: 5px !important;
        max-height: 70vh !important;
        overflow-y: auto !important;
        right: 0 !important;
        min-width: 200px !important;
        max-width: 250px !important;
    }

    /* Ensure dropdown items are visible */
    .language-menu a,
    .country-menu a {
        display: block !important;
        padding: 10px 15px !important;
        color: #333 !important;
        text-decoration: none !important;
        border-bottom: 1px solid #eee !important;
        white-space: nowrap !important;
        font-size: 14px !important;
        line-height: 1.4 !important;
    }

    .language-menu a:hover,
    .country-menu a:hover {
        background: #f5f5f5 !important;
    }

    /* Prevent dropdown from going off screen */
    .language-menu {
        position: fixed !important;
        top: 60px !important;
        bottom: auto !important;
        right: 20px !important;
        max-height: 50vh !important;
        overflow-y: auto !important;
        min-width: 200px !important;
        max-width: 250px !important;
    }

    /* Also apply to country menu */
    .country-menu {
        position: fixed !important;
        top: 60px !important;
        bottom: auto !important;
        right: 20px !important;
        max-height: 50vh !important;
        overflow-y: auto !important;
        min-width: 200px !important;
        max-width: 250px !important;
    }

    /* Grid - 2 columns on tablet */
    .grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid.grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid.grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Tables - scoped to legacy .container */
    .container table {
        font-size: 14px;
    }

    .container th,
    .container td {
        padding: 14px;
    }
}

/* ========================================
   DESKTOP STYLES (1024px and up)
   ======================================== */

@media (min-width: 1024px) {
    .container h1 {
        font-size: 36px;
    }

    .container h2 {
        font-size: 32px;
    }

    .container h3 {
        font-size: 28px;
    }

    /* Wider containers */
    .container {
        width: 100%;
        margin: 0;
    }

    /* Grid - 3+ columns on desktop */
    .grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .grid.grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    .grid.grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Flex layouts */
    .flex {
        gap: 20px;
    }

    /* Buttons - Slightly larger (scoped to legacy un-classed) */
    button:not([class]),
    .btn {
        padding: 12px 24px;
    }

    /* Tables - Better spacing (scoped to .container) */
    .container table {
        font-size: 15px;
    }

    .container th,
    .container td {
        padding: 16px;
    }

    /* Side-by-side layouts */
    .row-2 {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .row-3 {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }
}

/* ========================================
   LARGE DESKTOP STYLES (1400px and up)
   ======================================== */

@media (min-width: 1400px) {
    body {
        font-size: 16px;
    }

    .container h1 {
        font-size: 40px;
    }

    .container h2 {
        font-size: 36px;
    }

    .grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 24px;
    }

    /* More spacing on large screens */
    .flex {
        gap: 24px;
    }
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   ======================================== */

/* Will-change for frequently animated elements */
.nav-container,
.card:hover {
    will-change: transform, background-color;
    transform: translateZ(0);
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1e1e1e;
        color: #e0e0e0;
    }

    .card,
    .panel,
    .container input,
    .container select,
    .container textarea {
        background-color: #2d2d2d;
        color: #e0e0e0;
        border-color: #444;
    }

    .container th {
        background-color: #3d3d3d;
    }

    .container tbody tr {
        border-color: #444;
    }
}

/* Print styles */
@media print {
    body {
        background: white;
        color: black;
    }

    .mobile-menu-toggle,
    .no-print {
        display: none;
    }

    button:not([class]),
    input[type="submit"]:not([class]),
    .btn {
        display: none;
    }

    a:not([class]) {
        color: black;
        text-decoration: underline;
    }

    .card,
    .panel {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid black;
    }
}