/**
 * AlertOwl — Responsive Enhancements
 * Version: 0.8.0
 * 
 * Loaded AFTER all page-specific CSS files.
 * Adds: mobile bottom nav for dashboard, hamburger menu for landing,
 *        grid fixes, touch targets, and tablet breakpoints.
 */

/* ===========================================
   DASHBOARD — Mobile Bottom Navigation
   Replaces the hidden sidebar on screens ≤768px
   =========================================== */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--card, #141417);
    border-top: 1px solid var(--border, #27272a);
    padding: 6px 0 env(safe-area-inset-bottom, 0);
}

.mobile-bottom-nav-inner {
    display: flex;
    justify-content: space-around;
    align-items: center;
    max-width: 500px;
    margin: 0 auto;
}

.mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px 6px;
    background: none;
    border: none;
    color: var(--text-muted, #71717a);
    font-size: 10px;
    font-family: var(--font, 'DM Sans', sans-serif);
    cursor: pointer;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
    min-width: 56px;
}

.mobile-nav-btn .mobile-nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}
.mobile-nav-btn .mobile-nav-icon svg { display: block; }

.mobile-nav-btn .mobile-nav-label {
    font-size: 10px;
    line-height: 1.2;
    margin-top: 2px;
}

.mobile-nav-btn.active {
    color: var(--accent, #14b8a6);
}

.mobile-nav-btn:active {
    transform: scale(0.92);
}

/* ===========================================
   DASHBOARD — Mobile Header
   Shows brand + user info when sidebar is hidden
   =========================================== */
.mobile-top-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--card, #141417);
    border-bottom: 1px solid var(--border, #27272a);
    position: sticky;
    top: 0;
    z-index: 150;
}

.mobile-top-bar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: inherit;
}

.mobile-top-bar-brand .sidebar-brand-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    font-size: 16px;
}

.mobile-top-bar-brand .sidebar-brand-name {
    font-size: 15px;
}

.mobile-top-bar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mobile-top-bar .btn-logout {
    font-size: 11px;
    padding: 5px 12px;
    background: transparent;
    border: 1px solid var(--border, #27272a);
    border-radius: 6px;
    color: var(--text-muted, #71717a);
    cursor: pointer;
    font-family: var(--font, 'DM Sans', sans-serif);
}

/* ===========================================
   LANDING — Mobile Hamburger Menu
   =========================================== */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary, #fafafa);
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
}

.landing-nav-links.mobile-open {
    display: flex !important;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    flex-direction: column;
    background: rgba(12, 17, 40, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 32px 24px;
    gap: 0;
    z-index: 99;
    animation: mobileMenuIn 0.25s ease;
}

@keyframes mobileMenuIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.landing-nav-links.mobile-open .nav-link {
    display: block !important;
    padding: 16px 0;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

/* ===========================================
   GLOBAL — Touch target minimums
   =========================================== */
@media (max-width: 768px) {
    button, a.btn, .nav-btn, .tab-btn, [role="button"] {
        min-height: 44px;
    }
}

/* ===========================================
   DASHBOARD — Tablet (769–1024px)
   =========================================== */
@media (max-width: 1024px) and (min-width: 769px) {
    .sidebar {
        width: 180px;
    }

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

    .main-content {
        padding: 24px 20px;
    }
}

/* ===========================================
   DASHBOARD — Mobile (≤768px)
   =========================================== */
@media (max-width: 768px) {
    /* Show mobile nav elements */
    .mobile-bottom-nav {
        display: block;
    }

    .mobile-top-bar {
        display: flex;
    }

    /* Hide sidebar (already done in dashboard.css, reinforced here) */
    .sidebar {
        display: none !important;
    }

    /* Adjust app layout */
    .app-layout {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .main-content {
        padding: 16px 16px 80px; /* 80px bottom for nav bar */
        overflow: auto;
        height: auto;
    }

    /* Page titles */
    .page-title {
        font-size: 18px;
    }

    .page-desc {
        font-size: 13px;
    }

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

    .stat-card {
        padding: 14px 12px;
    }

    .stat-card-value {
        font-size: 22px;
    }

    /* ── Stage 05a — Narrative mobile ── */
    .ov-narrative {
        padding: 12px 14px;
        gap: 10px;
        font-size: 14px;
        margin: 16px 0 0;
    }

    .ov-narrative-action {
        padding: 5px 10px;
        font-size: 11px;
    }

    /* Overview grid */
    .overview-grid {
        grid-template-columns: 1fr;
    }

    /* Connections grid */
    .connections-grid {
        grid-template-columns: 1fr;
    }

    /* Messages grid — mobile: stacked card layout using grid-template-areas.
       Override the old dashboard.css 5-column mobile rule — we use areas. */
    .messages-grid {
        grid-template-columns: auto 1fr auto !important;
        grid-template-areas:
            "priority subject alert"
            "source sender time" !important;
        gap: 4px 10px;
        font-size: 12px;
        padding: 12px 14px;
        align-items: center;
    }

    .messages-grid .hide-mobile {
        display: none;
    }

    /* Position each cell by role. Child indices match JSX <span> order:
       1=Time 2=Source 3=Sender 4=Subject 5=Priority 6=Category(hidden)
       7=Mood(hidden) 8=Alert block (div). */
    .table-row.messages-grid > *:nth-child(1) { grid-area: time; text-align: right; font-size: 10px; color: var(--text-muted); }
    .table-row.messages-grid > *:nth-child(2) { grid-area: source; justify-self: start; }
    .table-row.messages-grid > *:nth-child(3) { grid-area: sender; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
    .table-row.messages-grid > *:nth-child(4) { grid-area: subject; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; padding-right: 0 !important; }
    .table-row.messages-grid > *:nth-child(5) { grid-area: priority; justify-self: start; }
    .table-row.messages-grid > *:nth-child(8) { grid-area: alert; justify-self: end; }

    /* Hide the table header on mobile — rows are self-labeling via position */
    .table-container .table-header.messages-grid {
        display: none;
    }

    /* Rules grid — simplify */
    .rules-grid {
        grid-template-columns: 32px 52px 1fr 60px;
        gap: 6px;
        font-size: 12px;
    }

    .rules-grid .hide-mobile {
        display: none;
    }

    /* Rule form */
    .rule-form-grid {
        grid-template-columns: 1fr;
    }

    /* Settings sections */
    .settings-row {
        flex-direction: column;
        gap: 8px;
    }

    /* Feedback grid */
    .feedback-grid {
        grid-template-columns: 1fr;
    }

    /* Trial/beta banner */
    .trial-banner {
        flex-direction: column;
        gap: 8px;
        text-align: center;
        font-size: 13px;
        padding: 10px 16px;
    }

    /* Cards */
    .card {
        padding: 16px;
    }

    /* ── Stage 05b — Connections mobile ── */

    .conn-row-hdr {
        padding: 12px 14px;
        gap: 12px;
        flex-wrap: wrap;
    }
    .conn-row-icon {
        width: 32px;
        height: 32px;
    }
    .conn-row-label {
        font-size: 13px;
    }
    .conn-row-meta {
        font-size: 11px;
    }
    .conn-row-caret {
        width: 28px;
        height: 28px;
    }

    /* Expanded panel — reduce padding + collapse stats to 2 columns if needed */
    .conn-panel {
        padding: 14px 14px 12px;
    }
    .conn-panel-stats {
        gap: 10px;
    }
    .conn-panel-stat-val {
        font-size: 18px;
    }
    .conn-panel-rule {
        gap: 10px;
        padding: 8px 10px;
    }
    .conn-panel-error {
        gap: 10px;
        padding: 10px 12px;
    }
    .conn-panel-error-btn {
        font-size: 11px;
        padding: 5px 10px;
    }

    /* Legacy — preserved in case any cached markup uses it */
    .conn-row-action {
        font-size: 11px;
        padding: 8px 12px;
    }

    /* ── Stage 06 — Overview mobile ── */

    /* 7-day chart: shrink bar width, compress gaps */
    .ov-chart {
        height: 120px;
        gap: 4px;
    }
    .ov-chart-bar {
        width: 85%;
        max-width: 32px;
    }
    .ov-chart-label {
        font-size: 10px;
        letter-spacing: 0;
    }
    .ov-chart-count {
        font-size: 9px;
    }

    /* Critical list: slightly tighter spacing, priority badge shrinks */
    .ov-critical-row {
        gap: 8px;
        padding: 12px 0;
    }
    .ov-critical-subject {
        font-size: 12px;
    }
    .ov-critical-meta {
        font-size: 10px;
    }

    /* ── Stage 06 — Settings mobile ── */

    /* Collapse inline 1fr 1fr form grids to single column.
       React renders style={gridTemplateColumns:'1fr 1fr'} as the inline
       attribute grid-template-columns: 1fr 1fr. */
    .settings-stack [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Section eyebrow labels — slightly smaller on mobile */
    .settings-section-label {
        font-size: 10px;
        margin-top: 12px;
    }
    .settings-section-label:first-child {
        margin-top: 0;
    }

    /* Plan modules grid — stack to 2-column on mobile */
    .settings-stack [style*="minmax(200px"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ===========================================
   DASHBOARD — Small phones (≤480px)
   =========================================== */
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card-value {
        font-size: 20px;
    }

    .main-content {
        padding: 12px 12px 80px;
    }

    /* Full-width buttons */
    .btn-secondary,
    .btn-primary {
        font-size: 13px;
        padding: 10px 14px;
    }
}

/* ===========================================
   LANDING — Tablet (769–1024px)
   =========================================== */
@media (max-width: 1024px) and (min-width: 769px) {
    .hero-grid {
        gap: 40px;
    }

    .hero-title {
        font-size: 2.4rem;
    }

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

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

    .footer-grid {
        grid-template-columns: 1fr 1fr;
        gap: 32px;
    }

    .phone-frame {
        width: 270px;
    }
}

/* ===========================================
   LANDING — Mobile (≤768px)
   =========================================== */
@media (max-width: 768px) {
    /* Hamburger menu */
    .mobile-menu-toggle {
        display: block;
    }

    .landing-nav-links {
        display: none;
    }

    .landing-nav-links .nav-link.nav-link-signin {
        display: block !important;
    }

    /* Hero */
    .hero-section {
        padding-top: 100px;
        padding-bottom: 60px;
    }

    .hero-grid {
        flex-direction: column;
        gap: 40px;
    }

    .hero-content {
        text-align: center;
    }

    .hero-subtitle {
        margin-left: auto;
        margin-right: auto;
    }

    .hero-actions {
        justify-content: center;
    }

    .hero-checklist {
        justify-content: center;
    }

    .hero-trust {
        justify-content: center;
    }

    .hero-demo {
        margin-top: 0;
    }

    .hero-title {
        font-size: 2rem;
    }

    .phone-frame {
        width: 280px;
    }

    /* Sections */
    .features-grid {
        grid-template-columns: 1fr;
    }

    .how-steps, .how-steps-v2 {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .bundles-grid {
        grid-template-columns: 1fr;
    }

    .footer-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 24px;
    }

    .footer-brand {
        grid-column: 1 / -1; /* full width on top */
        margin-bottom: 8px;
    }

    .landing-nav-links .nav-link:not(.nav-link-signin) {
        display: none;
    }

    /* How trust bar */
    .how-trust-bar {
        flex-wrap: wrap;
        gap: 8px;
        font-size: 0.82rem;
    }

    /* Quote */
    .quote-text {
        font-size: 1.1rem;
    }

    .quote-marks-wrapper {
        padding: 0 20px;
    }

    /* Beta signup */
    .beta-signup-card {
        padding: 28px 20px;
    }

    /* FAQ */
    .faq-q span {
        font-size: 0.92rem;
    }

    /* Section spacing */
    .features-section,
    .how-section,
    .faq-section-landing,
    .cta-section-landing {
        padding: 60px 0;
    }

    .stats-section {
        padding: 32px 0;
    }

    .quote-section {
        padding: 48px 0 40px;
    }

    /* Section headings */
    .section-heading {
        font-size: 1.6rem;
    }
}

/* ===========================================
   LANDING — Small phones (≤480px)
   =========================================== */
@media (max-width: 480px) {
    .hero-actions {
        flex-direction: column;
    }

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

    .hero-checklist {
        flex-direction: column;
        gap: 8px;
    }

    .landing-section {
        padding: 0 16px;
    }

    .hero-title {
        font-size: 1.75rem;
    }

    .stat-number {
        font-size: 2rem;
    }

    .footer-bottom {
        flex-direction: column;
        text-align: center;
    }

    .footer-grid {
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }

    .footer-brand {
        grid-column: 1 / -1;
    }
}

/* ===========================================
   AUTH PAGES — Fine-tuning
   =========================================== */
@media (max-width: 520px) {
    .auth-container {
        padding: 12px;
        align-items: flex-start;
        padding-top: 40px;
    }

    .auth-card {
        padding: 28px 20px;
        border-radius: 12px;
    }

    .auth-card.wide {
        max-width: 100%;
    }

    .auth-title {
        font-size: 22px;
    }

    .auth-subtitle {
        font-size: 14px;
    }

    .form-input {
        padding: 12px 14px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    .plan-cards {
        flex-direction: column;
    }

    .phone-input-group {
        flex-direction: column;
        gap: 8px;
    }

    .country-select {
        width: 100%;
    }

    .password-requirements {
        grid-template-columns: 1fr;
    }
}

/* iOS zoom prevention on inputs */
@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ===========================================
   ADMIN — Mobile (≤768px)
   =========================================== */
@media (max-width: 768px) {
    .admin-content {
        padding: 16px;
    }

    .admin-topbar {
        padding: 12px 16px;
        flex-direction: column;
        gap: 8px;
    }

    .admin-tab-nav {
        padding: 0 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .admin-tab-nav::-webkit-scrollbar {
        display: none;
    }

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

    .admin-table {
        font-size: 12px;
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    .admin-stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ===========================================
   LEGAL PAGE — Mobile
   =========================================== */
@media (max-width: 600px) {
    .tab-nav-inner {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 4px;
    }

    .tab-nav-inner::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        white-space: nowrap;
        font-size: 13px;
        padding: 8px 14px;
    }

    .content {
        padding: 24px 16px 64px;
    }

    .content table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 13px;
    }

    .highlight-box {
        padding: 16px;
        font-size: 14px;
    }
}

/* ===========================================
   HELP PAGE — Mobile
   =========================================== */
@media (max-width: 600px) {
    .help-hero h1 {
        font-size: 1.4rem;
    }

    .help-info-grid {
        grid-template-columns: 1fr;
    }

    .help-step {
        flex-direction: column;
        gap: 12px;
    }

    .help-header .header-links {
        gap: 12px;
    }

    .section-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
    }

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

    .section-nav a {
        white-space: nowrap;
        padding: 6px 12px;
        font-size: 13px;
    }
}

/* ===========================================
   MESSAGE DETAIL — Already has good responsive,
   just reinforce safe-area for bottom nav
   =========================================== */
@media (max-width: 768px) {
    .message-detail-panel {
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
}

/* ===========================================
   UTILITY — safe area for iPhone notch/bar
   =========================================== */
@supports (padding: env(safe-area-inset-bottom)) {
    .mobile-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
    }
}
