/* ==================== SOTERIA COVENANT — MOBILE PWA STYLES ==================== */
/* Optimizes the membership dashboard for smartphone screens.                     */
/* Loaded after base styles; all rules scoped to max-width media queries.         */

/* ==================== GLOBAL MOBILE (max-width: 768px) ==================== */
@media (max-width: 768px) {

    /* --- Standalone PWA: adjust for status bar --- */
    @media (display-mode: standalone) {
        body {
            padding-top: env(safe-area-inset-top);
            padding-bottom: env(safe-area-inset-bottom);
        }
    }

    /* --- Container --- */
    .container-wide {
        padding: 0 12px;
    }

    main {
        padding: 16px 12px 100px;
    }

    /* --- Dashboard Header --- */
    .dashboard-header {
        flex-direction: column;
        gap: 8px;
        text-align: center;
        padding: 8px 0;
    }

    .dashboard-header .welcome-section h1 {
        font-size: 14px;
        letter-spacing: 2px;
    }

    .dashboard-header .welcome-text {
        font-size: 13px;
    }

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

    /* --- Wisdom Quote --- */
    .wisdom-quote {
        margin-top: 8px;
        padding: 8px 14px;
    }

    .quote-text {
        font-size: 12px;
    }

    /* --- Tab Navigation: horizontal scroll with touch momentum --- */
    .main-nav-tabs {
        margin: 12px -12px 16px;
        padding: 0 12px;
        gap: 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        border-bottom-width: 1px;
    }

    .main-nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .main-nav-tab {
        padding: 10px 14px;
        font-size: 10px;
        letter-spacing: 1px;
        flex-shrink: 0;
        border-bottom-width: 2px;
        /* Larger touch target */
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* --- Profile Overview Grid --- */
    .profile-overview {
        grid-template-columns: 1fr;
        gap: 16px;
        margin-bottom: 24px;
    }

    /* --- Member ID Display --- */
    .member-id-display {
        flex-direction: column;
        text-align: center;
        gap: 12px;
        padding: 16px;
    }

    .member-avatar {
        width: 64px;
        height: 64px;
    }

    .member-avatar span {
        font-size: 22px;
    }

    .member-alias {
        font-size: 15px;
    }

    .member-info {
        text-align: center;
    }

    /* --- Standing & Tier --- */
    .standing-display {
        justify-content: center;
        flex-wrap: wrap;
    }

    .standing-badge {
        padding: 6px 14px;
        font-size: 10px;
    }

    .tier-display {
        justify-content: center;
    }

    .tier-badge {
        width: 44px;
        height: 44px;
    }

    .tier-number {
        font-size: 20px;
    }

    .tier-name {
        font-size: 12px;
    }

    .profile-dual-tiers {
        justify-content: center;
        flex-wrap: wrap;
    }

    /* --- Stats Grid --- */
    .stats-row {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-box {
        padding: 14px;
    }

    .stat-box .stat-value {
        font-size: 16px;
    }

    /* --- Data Grid (cards) --- */
    .data-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .data-card {
        max-height: none;
    }

    /* --- Cards general --- */
    .card {
        padding: 16px;
        border-radius: 8px;
    }

    /* --- Profile Fields --- */
    .profile-field {
        flex-direction: column;
        gap: 4px;
        padding: 10px 0;
    }

    .profile-field-label {
        min-width: 0;
        font-size: 10px;
    }

    .profile-field-value {
        text-align: left;
        font-size: 13px;
    }

    .profile-field-wrapper {
        justify-content: flex-start;
    }

    .profile-edit-btn {
        opacity: 1;
        position: static;
    }

    .profile-inline-edit {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .profile-inline-edit input,
    .profile-inline-edit textarea {
        width: 100%;
    }

    /* --- Network Map --- */
    #network-map {
        height: 300px !important;
    }

    .map-layer-toggle {
        gap: 6px;
    }

    .map-layer-btn {
        padding: 5px 10px;
        font-size: 10px;
    }

    /* --- Trust Newsboard --- */
    .newsboard-stats-bar {
        padding: 6px 8px;
        font-size: 9px;
        gap: 6px;
    }

    .newsboard-row {
        padding: 6px 12px;
    }

    /* --- Inbox --- */
    .inbox-toolbar {
        padding: 8px 12px;
    }

    .inbox-toolbar h2 {
        font-size: 1rem;
    }

    .inbox-toolbar-right {
        width: 100%;
    }

    .inbox-msg {
        padding: 10px 12px;
        gap: 10px;
    }

    .inbox-msg-icon {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }

    .inbox-msg-subject {
        font-size: 12px;
    }

    .inbox-msg-actions {
        flex-direction: column;
    }

    .inbox-compose {
        padding: 14px;
    }

    .inbox-reply-form {
        flex-direction: column;
    }

    /* --- Chat Panel --- */
    .chat-panel.expanded {
        height: 60vh;
    }

    .chat-sidebar {
        width: 120px;
    }

    .chat-messages {
        padding: 6px 10px;
    }

    .chat-input {
        font-size: 14px;
        padding: 10px 14px;
    }

    .chat-channel-tab {
        padding: 8px 12px;
        font-size: 10px;
    }

    /* --- Services List --- */
    .service-card {
        padding: 10px 12px;
        gap: 10px;
    }

    .service-name {
        font-size: 11px;
    }

    .service-link {
        padding: 6px 10px;
        font-size: 9px;
    }

    /* --- Projects --- */
    .project-card {
        padding: 14px;
    }

    .project-card-header {
        flex-direction: column;
        gap: 8px;
    }

    .project-card-meta {
        flex-wrap: wrap;
        gap: 8px;
    }

    .backing-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 12px 14px;
    }

    /* --- Tribunal --- */
    .tribunal-case-header {
        flex-direction: column;
        gap: 8px;
    }

    .tribunal-case-meta {
        gap: 12px;
    }

    .tribunal-actions {
        flex-direction: column;
        gap: 8px;
    }

    .tribunal-actions .btn {
        width: 100%;
        text-align: center;
    }

    /* --- Admin Tables --- */
    .admin-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 11px;
    }

    .admin-table th,
    .admin-table td {
        padding: 8px 10px;
        white-space: nowrap;
    }

    /* --- Directory Table --- */
    #directory-body td {
        padding: 8px 6px;
        font-size: 11px;
    }

    .dir-action-btn {
        padding: 4px 8px;
        font-size: 9px;
    }

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

    .settings-account-card {
        flex-direction: column;
        text-align: center;
        gap: 12px;
        padding: 14px;
    }

    .settings-section {
        padding: 20px 0;
    }

    /* --- Buttons: larger touch targets --- */
    .btn {
        padding: 12px 20px;
        font-size: 11px;
        min-height: 44px;
    }

    .btn-sm {
        padding: 8px 14px;
        min-height: 36px;
    }

    /* --- Credit / SOT grid --- */
    .credit-summary-grid,
    .credit-grid {
        grid-template-columns: 1fr;
    }

    /* --- Status selector --- */
    .status-menu {
        min-width: 160px;
    }

    /* --- Maintenance dropdown --- */
    .maint-dropdown {
        right: auto;
        left: 0;
    }

    /* --- Dark mode toggle --- */
    .dark-mode-toggle {
        top: 8px;
        right: 8px;
        padding: 4px 10px;
        font-size: 0.62em;
    }

    /* --- Forms: prevent zoom on iOS --- */
    input, textarea, select {
        font-size: 16px !important;
    }

    /* Restore smaller font after focus */
    .main-nav-tab,
    .inbox-filter,
    .inbox-btn,
    .dir-action-btn,
    .chat-channel-tab {
        font-size: inherit !important;
    }
}

/* ==================== SMALL PHONES (max-width: 420px) ==================== */
@media (max-width: 420px) {

    .container-wide {
        padding: 0 8px;
    }

    main {
        padding: 12px 8px 100px;
    }

    .dashboard-header .welcome-section h1 {
        font-size: 12px;
        letter-spacing: 1.5px;
    }

    .main-nav-tab {
        padding: 8px 10px;
        font-size: 9px;
        letter-spacing: 0.5px;
    }

    .stats-row {
        grid-template-columns: 1fr;
    }

    .stat-box .stat-value {
        font-size: 18px;
    }

    .card {
        padding: 12px;
    }

    #network-map {
        height: 220px !important;
    }

    .inbox-msg {
        padding: 8px 10px;
    }

    .inbox-msg-icon {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .chat-panel {
        width: 100% !important;
        right: 0 !important;
        left: 0;
    }

    .chat-panel.expanded {
        height: 70vh;
    }

    .chat-sidebar {
        display: none;
    }

    .newsboard-stats-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .profile-overview {
        gap: 12px;
    }
}

/* ==================== LANDSCAPE PHONE ==================== */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-panel.expanded {
        height: 80vh;
    }

    #network-map {
        height: 250px !important;
    }

    .main-nav-tabs {
        margin-top: 8px;
        margin-bottom: 12px;
    }
}

/* ==================== TOUCH DEVICE ENHANCEMENTS ==================== */
@media (hover: none) and (pointer: coarse) {
    /* Always show edit buttons on touch devices */
    .profile-field .profile-edit-btn {
        opacity: 1;
    }

    /* Larger tap targets for action buttons */
    .inbox-msg-actions button {
        padding: 8px;
        font-size: 16px;
    }

    .dir-action-btn {
        padding: 6px 10px;
        min-height: 36px;
    }

    /* Remove hover effects that feel wrong on touch */
    .service-card:hover,
    .project-card:hover,
    .tribunal-case-card:hover,
    .backing-card:hover {
        border-color: var(--border);
    }

    /* Active state for touch feedback instead */
    .service-card:active,
    .project-card:active,
    .main-nav-tab:active {
        opacity: 0.85;
    }

    /* Chat send button larger */
    .chat-send-btn {
        width: 40px;
        height: 40px;
    }

    /* Scrollbar hiding for touch */
    .main-nav-tabs,
    .newsboard-row-entries,
    .chat-channel-bar {
        scrollbar-width: none;
    }

    .main-nav-tabs::-webkit-scrollbar,
    .newsboard-row-entries::-webkit-scrollbar,
    .chat-channel-bar::-webkit-scrollbar {
        display: none;
    }
}

/* ==================== PWA STANDALONE ADJUSTMENTS ==================== */
@media (display-mode: standalone) {
    /* Remove any browser-specific UI hints */
    .dark-mode-toggle {
        top: max(8px, env(safe-area-inset-top));
    }

    /* Bottom safe area for gesture-nav phones */
    .chat-panel {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .chat-input-area {
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
}

/* ==================== MOBILE BOTTOM NAV BAR ==================== */
/* Hidden on desktop; replaces horizontal tab strip on phones.     */

.mobile-bottom-nav,
.mobile-more-drawer {
    display: none;
}

@media (max-width: 768px) {

    /* Hide the desktop horizontal tab strip */
    .main-nav-tabs {
        display: none !important;
    }

    /* --- Bottom Navigation Bar --- */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 2000;
        background: rgba(10, 10, 10, 0.97);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid var(--border);
        padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
        justify-content: space-around;
        align-items: center;
    }

    html[data-dark-mode="false"] .mobile-bottom-nav {
        background: rgba(245, 242, 235, 0.97);
    }

    .mobile-nav-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        background: none;
        border: none;
        color: var(--text-muted);
        cursor: pointer;
        padding: 6px 8px;
        min-width: 56px;
        position: relative;
        transition: color 0.15s;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-nav-btn span {
        font-size: 9px;
        font-weight: 600;
        letter-spacing: 0.5px;
        text-transform: uppercase;
    }

    .mobile-nav-btn svg {
        stroke: currentColor;
        fill: none;
    }

    .mobile-nav-btn.active {
        color: var(--gold);
    }

    /* Unread notification dot */
    .mobile-nav-dot {
        position: absolute;
        top: 2px;
        right: 10px;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #dc2626;
        border: 2px solid rgba(10, 10, 10, 0.97);
    }

    /* Adjust chat panel to sit above bottom nav */
    .chat-panel {
        bottom: calc(56px + env(safe-area-inset-bottom)) !important;
    }

    /* --- More Drawer --- */
    .mobile-more-drawer {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 2500;
    }

    .mobile-more-drawer.open {
        display: block;
    }

    .mobile-more-backdrop {
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        animation: mobileDrawerFadeIn 0.2s ease;
    }

    .mobile-more-panel {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-bottom: none;
        border-radius: 16px 16px 0 0;
        padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
        max-height: 70vh;
        overflow-y: auto;
        animation: mobileDrawerSlideUp 0.25s ease;
    }

    html[data-dark-mode="false"] .mobile-more-panel {
        background: rgba(255, 255, 255, 0.98);
    }

    .mobile-more-handle {
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: var(--text-muted);
        margin: 0 auto 16px;
        opacity: 0.4;
    }

    .mobile-more-group {
        margin-bottom: 16px;
    }

    .mobile-more-group:last-child {
        margin-bottom: 0;
    }

    .mobile-more-group-label {
        font-size: 9px;
        font-weight: 700;
        letter-spacing: 2px;
        text-transform: uppercase;
        color: var(--text-muted);
        padding: 0 4px 6px;
        border-bottom: 1px solid var(--border);
        margin-bottom: 8px;
    }

    .mobile-more-items {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .mobile-more-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        padding: 12px 8px;
        background: rgba(0, 0, 0, 0.15);
        border: 1px solid var(--border);
        border-radius: 10px;
        color: var(--text-secondary);
        font-size: 11px;
        font-weight: 500;
        cursor: pointer;
        transition: border-color 0.15s, color 0.15s;
        -webkit-tap-highlight-color: transparent;
    }

    html[data-dark-mode="false"] .mobile-more-item {
        background: rgba(139, 115, 85, 0.05);
    }

    .mobile-more-item:active {
        border-color: var(--gold);
        color: var(--gold);
    }

    .mobile-more-icon {
        font-size: 18px;
        line-height: 1;
    }

    @keyframes mobileDrawerSlideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    @keyframes mobileDrawerFadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
}
