/**
 * Mobile Responsive CSS
 * Comprehensive mobile viewport fixes for WBRND website
 * Breakpoints: Mobile (< 768px), Tablet (768px-1024px), Desktop (> 1024px)
 */

/* ========== MOBILE FIRST - BASE STYLES ========== */

:root {
    --safe-area-left: max(0px, env(safe-area-inset-left));
    --safe-area-right: max(0px, env(safe-area-inset-right));
    --safe-area-top: max(0px, env(safe-area-inset-top));
    --safe-area-bottom: max(0px, env(safe-area-inset-bottom));
}

html {
    font-size: 100%;
}

body {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

img, video, picture {
    display: block;
    max-width: 100%;
    height: auto;
}

button, input[type="button"], input[type="submit"] {
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
    min-width: 44px;
}

input, select, textarea {
    -webkit-appearance: none;
    appearance: none;
    font-size: 1rem;
}
select {
    border-radius: 4px;
}

/* ========== HEADER & NAVIGATION - MOBILE ========== */

.site-header {
    padding: calc(var(--safe-area-top) + 0.75rem) var(--safe-area-left, 1rem) 0.75rem var(--safe-area-right, 1rem);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-container {
    padding: 0.75rem;
    gap: 0.5rem;
}

.logo-link {
    flex-shrink: 0;
    min-width: 44px;
    display: flex;
    align-items: center;
}

.logo-link img {
    max-height: 40px;
    width: auto;
}

.nav-toggle {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem;
    font-size: 1.25rem;
    border: 1px solid rgba(0, 0, 0, 0.12);
}

.main-nav {
    width: 100%;
    flex-direction: column;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    gap: 0;
}

.main-nav.open {
    max-height: 500px;
    overflow-y: auto;
}

.main-nav a,
.main-nav button {
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: left;
    border-radius: 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    min-height: 44px;
    display: flex;
    align-items: center;
}

.main-nav a:last-child,
.main-nav button:last-child {
    border-bottom: none;
}

/* ========== TYPOGRAPHY - MOBILE ========== */

h1 {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    line-height: 1.2;
    margin: 1rem 0 0.5rem 0;
}

h2 {
    font-size: clamp(1.25rem, 4vw, 2rem);
    line-height: 1.3;
    margin: 0.75rem 0 0.5rem 0;
}

h3 {
    font-size: clamp(1.1rem, 3vw, 1.5rem);
    line-height: 1.3;
    margin: 0.75rem 0 0.5rem 0;
}

h4, h5, h6 {
    font-size: clamp(1rem, 2vw, 1.25rem);
    line-height: 1.4;
}

p {
    font-size: 1rem;
    line-height: 1.6;
    margin: 0.75rem 0;
}

small, .small {
    font-size: 0.875rem;
}

/* ========== FORMS - MOBILE ========== */

form {
    width: 100%;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 1rem;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #ff7b00;
    outline-offset: 2px;
}

textarea {
    min-height: 100px;
    resize: vertical;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

/* ========== BUTTONS - MOBILE ========== */

button,
.btn,
input[type="button"],
input[type="submit"],
.auth-btn {
    min-height: 44px;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    border-radius: 4px;
    cursor: pointer;
    width: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

button:active,
.btn:active,
input[type="button"]:active,
input[type="submit"]:active {
    transform: scale(0.98);
}

.btn-block,
.full-width-btn {
    width: 100%;
    display: flex;
}

/* ========== TABLES - MOBILE ========== */

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1rem 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

table th {
    background: #f0f0f0;
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
}

table td {
    padding: 0.75rem;
    border-bottom: 1px solid #e0e0e0;
}

/* Stacked table layout for mobile */
@supports (display: grid) {
    .table-stacked {
        display: block;
        border: 0;
    }

    .table-stacked thead {
        display: none;
    }

    .table-stacked tr {
        display: grid;
        grid-template-columns: 150px 1fr;
        gap: 1rem;
        margin-bottom: 1.5rem;
        border: 1px solid #e0e0e0;
        border-radius: 4px;
        overflow: hidden;
    }

    .table-stacked td {
        padding: 0.75rem;
        border: none;
        display: flex;
        align-items: center;
    }

    .table-stacked td[data-label]::before {
        content: attr(data-label);
        font-weight: 600;
        color: #666;
        flex: 0 0 150px;
    }
}

/* ========== GRIDS - MOBILE ========== */

.grid-4,
.grid-3,
.grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.property-grid,
.product-grid,
.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-top: 1rem;
}

.two-column,
.three-column {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

/* ========== CARDS - MOBILE ========== */

.card,
.property-card,
.feature-card {
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 4px;
}

.card img {
    margin: -1rem -1rem 1rem -1rem;
    width: calc(100% + 2rem);
    border-radius: 4px 4px 0 0;
}

/* ========== MODALS & OVERLAYS - MOBILE ========== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 1rem var(--safe-area-left, 1rem) 1rem var(--safe-area-right, 1rem);
    padding-top: max(1rem, var(--safe-area-top, 1rem));
    padding-bottom: max(1rem, var(--safe-area-bottom, 1rem));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    width: 100%;
    max-width: 100%;
    margin: auto;
    border-radius: 8px;
}

/* ========== FIXED POSITIONING - MOBILE ========== */

.fixed-bottom,
.whatsapp-btn {
    bottom: max(1rem, var(--safe-area-bottom, 1rem));
    right: max(1rem, var(--safe-area-right, 1rem));
    left: auto;
}

.fixed-top {
    top: max(1rem, var(--safe-area-top, 1rem));
    left: max(1rem, var(--safe-area-left, 1rem));
    right: auto;
}

/* ========== UTILITIES - MOBILE ========== */

.container {
    width: 100%;
    max-width: 100%;
    padding: 0 1rem;
    margin: 0 auto;
}

.section {
    padding: 1.5rem 1rem;
}

.page-shell {
    padding: 0 1rem 2rem;
}

.hero {
    padding: 2rem 1rem;
    margin-bottom: 1rem;
}

.auth-container {
    padding: 1rem;
}

/* ========== MEDIA - MOBILE ========== */

/* Dashboard / Panel overrides for dark theme + responsive grids */
.panel {
    background: var(--surface);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: none;
}

.overview-card,
.card,
.feature-card {
    background: transparent;
}

.stats-grid { display: grid; gap: 1rem; }
.stats-grid.grid-cols-4 { grid-template-columns: 1fr; }
.stats-grid.grid-cols-3 { grid-template-columns: 1fr; }

.chart-container { width: 100%; }

table th { background: transparent; color: var(--text-muted); }
table td { border-bottom: 1px solid rgba(255,255,255,0.04); }

.profile-avatar { width: 48px; height: 48px; border-radius: 999px; overflow: hidden; }
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

@media (min-width: 768px) {
    .stats-grid.grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
    .stats-grid.grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
    .two-column { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
    .stats-grid.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
    .stats-grid.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
    .two-column { grid-template-columns: repeat(2, 1fr); }
}

.media-container {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    overflow: hidden;
    border-radius: 4px;
}

.media-container iframe,
.media-container video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ========== SPACING UTILITIES - MOBILE ========== */

.m-auto {
    margin: auto;
}

.mx-auto {
    margin-left: auto;
    margin-right: auto;
}

.p-responsive {
    padding: clamp(0.5rem, 2vw, 2rem);
}

.pt-responsive {
    padding-top: clamp(0.5rem, 2vw, 2rem);
}

/* ========== TOUCH TARGETS ========== */

a,
button,
[role="button"] {
    position: relative;
}

a:not([class]),
button,
input[type="button"],
input[type="submit"] {
    min-height: 44px;
    min-width: 44px;
}

/* ========== SCROLLING ========== */

html {
    scroll-behavior: smooth;
    scrollbar-width: thin;
}

body {
    overflow-x: hidden;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f0f0f0;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

/* ========== TABLET - 768px+ ========== */

@media (min-width: 768px) {
    html {
        font-size: 17px;
    }

    .main-nav {
        flex-direction: row;
        max-height: none;
        overflow: visible;
        width: auto;
        gap: 1rem;
    }

    .main-nav a,
    .main-nav button {
        width: auto;
        border-bottom: none;
    }

    .nav-toggle {
        display: none;
    }

    h1 {
        font-size: clamp(1.75rem, 4vw, 2.5rem);
    }

    .form-grid {
        grid-template-columns: 1fr 1fr;
    }

    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }

    .grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    .property-grid,
    .product-grid,
    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .two-column {
        grid-template-columns: 1fr 1fr;
    }

    .three-column {
        grid-template-columns: repeat(3, 1fr);
    }

    .container {
        max-width: 750px;
        padding: 0 1rem;
    }

    .section {
        padding: 2rem 1.5rem;
    }

    button,
    .btn {
        padding: 0.75rem 1.5rem;
    }

    table {
        font-size: 1rem;
    }

    @supports (display: grid) {
        .table-stacked tr {
            grid-template-columns: 200px 1fr;
        }
    }
}

/* ========== DESKTOP - 1024px+ ========== */

@media (min-width: 1024px) {
    html {
        font-size: 18px;
    }

    .grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }

    .grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    .property-grid,
    .product-grid,
    .card-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 2rem;
    }

    .three-column {
        grid-template-columns: repeat(3, 1fr);
    }

    .container {
        max-width: 1200px;
        padding: 0 2rem;
    }

    .section {
        padding: 3rem 2rem;
    }

    .form-grid {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 1.5rem;
    }

    .modal-content {
        max-width: 600px;
    }

    @supports (display: grid) {
        .table-stacked {
            display: table;
        }

        .table-stacked thead {
            display: table-header-group;
        }

        .table-stacked tr {
            display: table-row;
            grid-template-columns: initial;
            gap: initial;
            margin-bottom: initial;
            border: none;
            border-bottom: 1px solid #e0e0e0;
        }

        .table-stacked td {
            display: table-cell;
            border: none;
            border-bottom: 1px solid #e0e0e0;
        }

        .table-stacked td[data-label]::before {
            display: none;
        }
    }
}

/* ========== PRINT - ALL ========== */

@media print {
    .nav-toggle,
    .main-nav,
    .fixed-bottom,
    .whatsapp-btn {
        display: none !important;
    }

    body {
        background: white;
        color: #000;
    }

    a {
        color: #000;
    }
}

/* ========== LANDSCAPE ORIENTATION - MOBILE ========== */

@media (max-width: 768px) and (orientation: landscape) {
    .hero {
        padding: 1rem;
    }

    h1 {
        font-size: clamp(1.25rem, 4vw, 2rem);
    }

    .section {
        padding: 1rem;
    }

    button,
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
}

/* ========== HIGH DPI / RETINA ========== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* ========== DARK MODE SUPPORT ========== */

@media (prefers-color-scheme: dark) {
    table th {
        background: #2a2a2a;
        color: #fff;
    }

    table td {
        border-color: #444;
    }

    .table-stacked tr {
        border-color: #444;
    }
}

/* ========== REDUCED MOTION ========== */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
