/* ================================================================
   SHARED RESPONSIVE HARDENING — Tenant Manager
   Professional mobile-first responsive overrides.
   ================================================================ */
html,
body {
    overflow-x: hidden;
}

.nav-container,
.content-container,
.footer-content {
    width: min(100%, 1400px);
}

/* Tables scroll horizontally on small screens */
.page-content :is(
    .table-container,
    .table-responsive,
    .analytics-table,
    .data-table-wrapper
) {
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
}

.page-content :is(
    .data-table,
    .updates-table,
    .table,
    table
) {
    min-width: 860px;
}

/* ================================================================
   BREAKPOINT: 1200px — Tablet landscape / small desktop
   ================================================================ */
@media (max-width: 1200px) {
    .nav-container {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem 1rem !important;
    }

    /* Nav links drop to second row, scroll horizontally */
    .nav-menu {
        order: 3;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        display: flex;
        gap: 0.25rem;
        padding-bottom: 0.15rem;
        scrollbar-width: none;
    }

    .nav-menu::-webkit-scrollbar {
        display: none;
    }

    .nav-menu .nav-link {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .nav-actions {
        margin-left: auto;
    }

    .main-content {
        padding: 1rem 0.85rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.6rem;
    }

    .page-actions,
    .page-actions-group {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem;
    }
}

/* ================================================================
   BREAKPOINT: 900px — Tablet portrait
   ================================================================ */
@media (max-width: 900px) {
    .nav-header.light .nav-container {
        padding: 0.45rem 0.75rem !important;
    }

    .nav-link {
        padding: 0.32rem 0.6rem;
        font-size: 0.8rem;
    }

    .nav-link-icon {
        width: 24px;
        height: 24px;
    }

    .user-meta {
        display: none;
    }

    .user-caret {
        display: none;
    }

    .user-avatar {
        width: 28px !important;
        height: 28px !important;
        font-size: 0.7rem !important;
    }

    .main-content {
        padding: 0.85rem 0.65rem;
    }

    .page-title {
        font-size: 1.15rem;
    }

    .page-subtitle {
        font-size: 0.78rem;
    }

    .page-content :is(
        .cards-grid,
        .stats-grid,
        .form-grid,
        .tenant-form-grid
    ) {
        grid-template-columns: 1fr !important;
    }
}

/* ================================================================
   BREAKPOINT: 768px — Mobile landscape / small tablet
   Row 1: brand ··· avatar + theme + logout (all inline)
   Row 2: scrollable nav links
   ================================================================ */
@media (max-width: 768px) {
    .nav-container {
        display: grid;
        grid-template-columns: 1fr auto auto auto;
        grid-template-rows: auto auto;
        align-items: center;
        gap: 0 0.35rem;
        padding: 0.35rem 0.6rem !important;
    }

    /* Row 1, col 1 — Brand */
    .nav-brand {
        grid-row: 1;
        grid-column: 1;
        width: auto;
        gap: 0.4rem !important;
        min-width: 0;
    }

    .nav-logo {
        width: 28px !important;
        height: 28px !important;
        font-size: 0.65rem !important;
        border-radius: 6px !important;
    }

    .nav-title {
        font-size: 0.82rem !important;
        white-space: nowrap;
    }

    .nav-subtitle {
        display: none;
    }

    /* Row 1, col 2 — Avatar */
    .user-dropdown {
        grid-row: 1;
        grid-column: 2;
    }

    .user-toggle {
        padding: 0.15rem !important;
        gap: 0 !important;
        background: transparent !important;
        border: none !important;
    }

    .user-avatar {
        width: 26px !important;
        height: 26px !important;
        font-size: 0.6rem !important;
    }

    .user-meta {
        display: none;
    }

    .user-caret {
        display: none;
    }

    /* Row 1, col 3 — Theme toggle (icon only) */
    .nav-actions {
        grid-row: 1;
        grid-column: 3 / 5;
        margin-left: 0;
        gap: 0.25rem !important;
    }

    .btn-theme-toggle {
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        padding: 0 !important;
        justify-content: center;
        border-radius: 5px !important;
        font-size: 0.75rem;
    }

    .btn-theme-toggle span {
        display: none;
    }

    .btn-theme-toggle i {
        margin: 0 !important;
        font-size: 0.75rem;
    }

    .btn-logout-square {
        width: 28px !important;
        height: 28px !important;
        margin-right: 0 !important;
    }

    .btn-logout-square svg {
        width: 14px !important;
        height: 14px !important;
    }

    /* Row 2, full width — Nav links scroll horizontally */
    .nav-menu {
        grid-row: 2;
        grid-column: 1 / -1;
        width: 100%;
        gap: 0.15rem;
        border-top: 1px solid rgba(0,0,0,0.06);
        padding-top: 0.3rem;
        margin-top: 0.15rem;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .nav-menu::-webkit-scrollbar {
        display: none;
    }

    .nav-link {
        padding: 0.25rem 0.5rem;
        font-size: 0.78rem;
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .nav-link-icon {
        display: none;
    }

    .main-content {
        padding: 0.6rem 0.5rem;
    }

    .page-header {
        margin-bottom: 0.55rem;
        padding: 0.45rem 0.55rem;
    }

    .page-content :is(
        .data-table,
        .updates-table,
        .table,
        table
    ) {
        min-width: 700px;
    }

    /* Footer compact */
    .footer-content {
        padding: 0.65rem 0.55rem;
        gap: 0.4rem;
        flex-direction: column;
        text-align: center;
    }

    .footer-links {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

/* ================================================================
   BREAKPOINT: 480px — Mobile portrait (primary mobile)
   Ultra-compact, single-column, no wasted space
   ================================================================ */
@media (max-width: 480px) {
    .nav-container {
        padding: 0.3rem 0.45rem !important;
        gap: 0 0.25rem;
    }

    .nav-brand {
        gap: 0.3rem !important;
    }

    .nav-logo {
        width: 24px !important;
        height: 24px !important;
        font-size: 0.6rem !important;
        border-radius: 5px !important;
    }

    .nav-title {
        font-size: 0.78rem !important;
    }

    .nav-link {
        font-size: 0.72rem;
        padding: 0.2rem 0.38rem;
        gap: 0.2rem;
        border-radius: 4px;
    }

    /* Hide nav icons on small mobile to fit all links */
    .nav-link-icon {
        display: none;
    }

    .nav-menu {
        gap: 0.1rem;
    }

    .btn-theme-toggle {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
    }

    .btn-theme-toggle i {
        font-size: 0.65rem;
    }

    .btn-logout-square {
        width: 24px !important;
        height: 24px !important;
    }

    .btn-logout-square svg {
        width: 12px !important;
        height: 12px !important;
    }

    .user-avatar {
        width: 22px !important;
        height: 22px !important;
        font-size: 0.55rem !important;
    }

    .nav-menu {
        padding-top: 0.25rem;
        margin-top: 0.1rem;
    }

    .main-content {
        padding: 0.5rem 0.4rem;
    }

    .page-header {
        padding: 0.4rem 0.45rem;
        gap: 0.3rem;
    }

    .page-title {
        font-size: 1rem;
    }

    .page-subtitle {
        font-size: 0.72rem;
    }

    .page-content :is(
        .data-table,
        .updates-table,
        .table,
        table
    ) {
        min-width: 600px;
    }

    /* Buttons side-by-side on mobile */
    .page-actions,
    .page-actions-group {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    .page-actions-group .btn-primary,
    .page-actions-group .btn-secondary {
        flex: 1 1 auto;
        justify-content: center;
        font-size: 0.72rem !important;
        padding: 0.4rem 0.6rem !important;
    }

    /* Hide analytics shortcut on mobile — available in nav */
    .btn-analytics {
        display: none;
    }
}

/* ================================================================
   STAT CARDS — Compact horizontal layout on mobile
   ================================================================ */
@media (max-width: 900px) {
    .tenant-stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
    }
}

@media (max-width: 768px) {
    .tenant-stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.4rem !important;
        margin-bottom: 0.75rem !important;
    }

    /* Keep horizontal layout — small icon left, text right */
    .stat-card {
        flex-direction: row !important;
        align-items: center !important;
        text-align: left !important;
        padding: 0.4rem 0.5rem !important;
        gap: 0.4rem !important;
        border-radius: 6px !important;
    }

    .stat-icon {
        width: 22px !important;
        height: 22px !important;
        border-radius: 4px !important;
        flex-shrink: 0;
        font-size: 0.7rem !important;
    }

    .stat-icon::before {
        width: 12px !important;
        height: 12px !important;
    }

    .stat-number {
        font-size: 1rem !important;
        margin-bottom: 0 !important;
        line-height: 1.1 !important;
    }

    .stat-label {
        font-size: 0.6rem !important;
        line-height: 1.2 !important;
    }
}

/* ================================================================
   TENANT LIST — Compact cards on mobile
   ================================================================ */
@media (max-width: 768px) {
    .tenant-grid {
        grid-template-columns: 1fr !important;
        gap: 0.5rem !important;
    }
}

@media (max-width: 480px) {
    .tenant-grid {
        gap: 0.4rem !important;
    }

    .tenant-card {
        padding: 0.6rem !important;
        border-radius: 6px !important;
    }

    .tenant-stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.3rem !important;
    }

    .info-cards {
        grid-template-columns: 1fr !important;
    }

    .history-stats {
        flex-wrap: wrap;
        gap: 0.5rem !important;
    }

    .stat-item {
        flex: 1 1 80px;
        min-width: 0;
    }
}

/* ================================================================
   ANALYTICS PAGE RESPONSIVE
   ================================================================ */
@media (max-width: 1200px) {
    .metrics-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

@media (max-width: 900px) {
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
    }

    .charts-row {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 640px) {
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.35rem !important;
    }

    .metric-card {
        min-height: auto !important;
        padding: 0.4rem 0.5rem !important;
        border-radius: 5px !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 0.35rem !important;
        text-align: left !important;
    }

    .metric-content {
        align-items: flex-start !important;
    }

    .metric-icon {
        width: 22px !important;
        height: 22px !important;
        border-radius: 4px !important;
        flex-shrink: 0;
    }

    .metric-icon svg {
        width: 12px !important;
        height: 12px !important;
    }

    .metric-value {
        font-size: 0.95rem !important;
        line-height: 1.1 !important;
        margin-bottom: 0 !important;
    }

    .metric-label {
        font-size: 0.52rem !important;
        line-height: 1.2 !important;
        margin-bottom: 0.05rem !important;
    }

    .metric-trend {
        font-size: 0.5rem !important;
        padding: 0.05rem 0.2rem !important;
    }

    .chart-actions {
        flex-wrap: wrap;
    }

    .chart-btn {
        font-size: 0.72rem;
        padding: 0.3rem 0.55rem;
    }
}

@media (max-width: 480px) {
    .metric-card {
        padding: 0.4rem 0.45rem !important;
    }

    .chart-card {
        padding: 0.45rem !important;
        border-radius: 6px !important;
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.35rem;
    }

    .chart-title {
        font-size: 0.85rem !important;
    }
}

/* ================================================================
   FORM PAGES (Add Tenant, Add Admin, Updates) — Mobile
   ================================================================ */
@media (max-width: 768px) {
    .form-container {
        margin: 0;
    }

    .form-card {
        border-radius: 6px;
    }

    .form-header {
        padding: 0.6rem 0.75rem;
    }

    .form-icon {
        width: 28px;
        height: 28px;
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }

    .form-title {
        font-size: 0.95rem;
    }

    .form-description {
        font-size: 0.75rem;
    }

    .admin-form,
    .add-tenant-form,
    .update-form {
        padding: 0.6rem 0.65rem;
    }

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

    .form-section {
        margin-bottom: 0.75rem;
        padding-bottom: 0.6rem;
    }

    .section-title {
        font-size: 0.82rem;
        margin-bottom: 0.45rem;
    }

    .form-actions {
        flex-direction: column-reverse;
        gap: 0.4rem;
    }

    .form-actions .btn-primary,
    .form-actions .btn-secondary {
        width: 100%;
        justify-content: center;
    }

    .permission-grid {
        grid-template-columns: 1fr;
        gap: 0.35rem;
    }
}

@media (max-width: 480px) {
    .form-header {
        padding: 0.5rem 0.6rem;
    }

    .form-icon {
        width: 24px;
        height: 24px;
        font-size: 0.8rem;
    }

    .form-title {
        font-size: 0.9rem;
    }

    .admin-form,
    .add-tenant-form,
    .update-form {
        padding: 0.5rem;
    }

    .form-input,
    .form-select,
    .form-textarea {
        font-size: 0.8rem;
        padding: 0.4rem 0.55rem;
    }

    .form-label {
        font-size: 0.75rem;
    }

    /* Security notice compact */
    .security-notice {
        flex-direction: column;
        text-align: center;
        padding: 0.6rem;
        gap: 0.4rem;
    }
}

/* ================================================================
   MODALS — Full-screen on mobile
   ================================================================ */
@media (max-width: 640px) {
    .modal-overlay .modal,
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        min-height: 100vh;
    }

    .modal-header {
        padding: 0.6rem 0.75rem !important;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .modal-body {
        padding: 0.75rem !important;
    }

    .modal-footer {
        padding: 0.6rem 0.75rem !important;
        position: sticky;
        bottom: 0;
    }
}

/* ================================================================
   FILTER / SEARCH BARS — Stack on mobile
   ================================================================ */
@media (max-width: 640px) {
    .filter-bar,
    .search-filter-row {
        flex-direction: column;
        gap: 0.4rem;
    }

    .filter-pills {
        overflow-x: auto;
        white-space: nowrap;
        display: flex;
        gap: 0.2rem;
        scrollbar-width: none;
        padding-bottom: 0.1rem;
    }

    .filter-pills::-webkit-scrollbar {
        display: none;
    }

    .filter-buttons {
        gap: 0.2rem !important;
    }

    .filter-btn {
        padding: 0.2rem 0.45rem !important;
        font-size: 0.65rem !important;
        border-radius: 4px !important;
        gap: 0.15rem !important;
    }

    .filter-btn .count {
        font-size: 0.55rem !important;
        padding: 0.02rem 0.2rem !important;
    }

    .filter-btn .filter-icon svg {
        width: 10px !important;
        height: 10px !important;
    }

    .search-input-wrapper,
    .filter-input {
        width: 100%;
    }
}

/* ================================================================
   TENANT HOME / LOGIN SPLIT LAYOUT
   ================================================================ */
@media (max-width: 1024px) {
    .container {
        padding: 1rem !important;
        gap: 1rem !important;
    }

    .hero-section {
        padding: 1.15rem !important;
        max-width: 100% !important;
    }

    .hero-title {
        font-size: 1.85rem !important;
    }

    .features-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .login-section {
        width: 100% !important;
        max-width: 480px !important;
        margin: 0 auto !important;
        max-height: none !important;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0.6rem !important;
    }

    .hero-section {
        padding: 0.85rem !important;
    }

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

    .features-grid {
        grid-template-columns: 1fr !important;
        gap: 0.6rem !important;
    }

    .login-section {
        padding: 0.85rem !important;
        max-width: none !important;
        width: 100% !important;
    }
}

/* ================================================================
   OPERATOR MANUAL — Mobile overrides
   ================================================================ */
@media (max-width: 480px) {
    .manual-layout {
        gap: 0.5rem;
    }

    .manual-toc-panel,
    .manual-section,
    .manual-hero {
        border-radius: 8px;
        padding: 0.6rem;
    }

    .manual-hero-copy h1 {
        font-size: 1.05rem;
    }

    .manual-hero-copy p {
        font-size: 0.8rem;
    }

    .manual-section h3 {
        font-size: 0.88rem;
    }

    .manual-section p,
    .manual-section li,
    .manual-section td {
        font-size: 0.8rem;
    }
}
