/* ── Mobile-Only Styles ──────────────────────────────────
   These rules ONLY apply on mobile phone screens (max-width: 768px).
   Desktop layout is completely unaffected.
   ─────────────────────────────────────────────────────── */

@media (max-width: 768px) {

    /* ── Global layout ─────────────────────────────────── */

    #layout {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    #terminal-panel {
        width: 100% !important;
        height: auto;
        max-height: 100vh;
        overflow-y: auto;
        border-right: none;
        border-bottom: 1px solid #222;
        transition: max-height 0.3s ease;
        flex-shrink: 0;
    }

    /* When terminal is collapsed (user tapped toggle to see content) */
    #terminal-panel.mobile-collapsed {
        max-height: 0;
        overflow: hidden;
        border-bottom: none;
        padding: 0;
    }

    #right-panel {
        width: 100% !important;
        flex: 1;
        min-height: 0;
        height: auto !important;
        overflow-y: auto;
    }

    #terminal {
        padding: 20px 12px 20px;
        min-height: auto !important;
    }

    /* ── Mobile toggle bar ─────────────────────────────── */

    #mobile-toggle-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px 14px;
        background: #0a0a0a;
        border-bottom: 1px solid #222;
        flex-shrink: 0;
        z-index: 50;
    }

    #mobile-toggle-bar .mobile-page-title {
        color: #777;
        font-size: 14px;
        font-family: 'VT323', monospace;
        letter-spacing: 1px;
    }

    #mobile-toggle-btn {
        background: #111;
        border: 1px solid #333;
        color: #ccc;
        font-family: 'VT323', monospace;
        font-size: 14px;
        padding: 4px 12px;
        cursor: pointer;
    }

    #mobile-toggle-btn:active {
        background: #222;
    }

    /* ── Font and touch adjustments ────────────────────── */

    html, body {
        font-size: 16px;
        -webkit-text-size-adjust: 100%;
        -webkit-tap-highlight-color: transparent;
    }

    /* Larger tap targets for buttons */
    button, .mail-btn, .settings-btn, .net-nav-btn, .net-action-btn,
    .quote-action-btn, #fs-new-folder-btn, #fs-upload-btn,
    #chat-send-btn, #chat-upload-btn {
        min-height: 40px;
        min-width: 40px;
    }

    /* ── Home page ─────────────────────────────────────── */

    body[data-page="home"] #right-panel {
        display: flex;
    }

    #hero-content {
        max-width: 95%;
        gap: 16px;
        padding: 20px 0;
    }

    #main-hero-img {
        max-height: 40vh;
    }

    #hero-quote-text {
        font-size: 16px;
    }

    /* Settings panel mobile */
    #user-settings-panel {
        padding: 24px 16px;
        gap: 24px;
    }

    .settings-section {
        max-width: 100%;
    }

    .settings-header {
        font-size: 22px;
    }

    /* ── Postings / Chat ───────────────────────────────── */

    body[data-page="postings"] #right-panel {
        display: block;
    }

    #chat-container {
        height: 100% !important;
    }

    #chat-placeholder {
        height: 100%;
    }

    .chat-msg {
        max-width: 90%;
    }

    .chat-bubble {
        font-size: 16px;
        padding: 8px 12px;
    }

    .chat-bubble img {
        max-width: 200px;
        max-height: 150px;
    }

    #chat-input-area {
        padding: 8px 10px;
        gap: 6px;
    }

    #chat-text-input {
        font-size: 16px;
        padding: 8px 10px;
    }

    /* Edit button always visible on mobile (no hover) */
    .chat-msg .chat-edit-btn,
    .chat-msg .chat-delete-btn,
    .chat-msg .chat-reply-btn {
        opacity: 0.6;
    }

    /* ── Networking ─────────────────────────────────────── */

    body[data-page="networking"] #right-panel {
        display: flex;
    }

    .net-article-list {
        padding: 12px;
    }

    .net-article-card {
        padding: 12px;
    }

    .net-article-full {
        padding: 12px 16px 30px;
    }

    .net-full-title {
        font-size: 22px;
    }

    .net-article-nav {
        flex-wrap: wrap;
        gap: 8px;
    }

    .net-editor {
        padding: 12px 16px 30px;
    }

    .net-editor-textarea {
        font-size: 16px;
    }

    /* Make delete button visible on mobile (no hover) */
    .net-article-delete {
        opacity: 0.7;
    }

    /* ── File System ────────────────────────────────────── */

    body[data-page="filesystem"] #right-panel {
        display: flex;
    }

    #fs-header {
        padding: 12px 14px;
        flex-wrap: wrap;
        gap: 8px;
    }

    #fs-breadcrumb {
        font-size: 16px;
    }

    .fs-item {
        padding: 10px 14px;
        font-size: 16px;
    }

    .fs-item .fs-item-delete {
        opacity: 0.7;
    }

    #fs-actions {
        padding: 12px 14px;
    }

    #fs-action-buttons {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* Grid view: smaller thumbnails on mobile */
    #fs-items.fs-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
        padding: 12px;
    }

    .fs-grid-item .fs-item-delete {
        opacity: 0.7;
    }

    /* ── Webmail ────────────────────────────────────────── */

    body[data-page="webmail"] #right-panel {
        display: block;
    }

    body[data-page="webmail"] #terminal-panel {
        width: 100% !important;
    }

    #mail-console {
        height: 100%;
    }

    /* Stack sidebar and content vertically */
    #mail-content {
        flex-direction: column;
    }

    #mail-sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        border-right: none;
        border-bottom: 1px solid #222;
        padding: 6px 8px;
        gap: 2px;
        overflow-y: visible;
    }

    .mail-folder {
        padding: 6px 10px;
        font-size: 14px;
    }

    .mail-folder.active {
        border-left: none;
        border-bottom: 2px solid #fff;
    }

    #mail-sidebar-actions {
        flex-direction: row;
        margin-top: 0;
        border-top: none;
        padding: 4px 0;
        gap: 4px;
    }

    .mail-sidebar-btn {
        width: auto;
    }

    #mail-sidebar-bottom {
        margin-top: 0;
        margin-left: auto;
        border-top: none;
        padding: 4px 0;
    }

    #mail-list {
        flex: 1;
        min-height: 0;
    }

    /* Top bar: stack on small screens */
    #mail-topbar {
        flex-wrap: wrap;
        gap: 6px;
        padding: 6px 10px;
    }

    #mail-topbar-right {
        flex-wrap: wrap;
        gap: 4px;
    }

    /* Search bar */
    #mail-search-bar {
        padding: 6px 10px;
        gap: 6px;
    }

    /* Email list items */
    .mail-item {
        padding: 8px 10px;
        gap: 8px;
    }

    .mail-item-sender {
        max-width: 150px;
    }

    .mail-item .mail-item-delete {
        opacity: 0.7;
    }

    /* Email view actions: wrap buttons */
    #mail-view-header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 10px;
    }

    #mail-view-actions {
        flex-wrap: wrap;
        gap: 4px;
    }

    #mail-view-meta {
        padding: 10px 12px;
    }

    #mail-view-subject {
        font-size: 18px;
    }

    #mail-view-body {
        padding: 12px;
        font-size: 16px;
    }

    /* Compose modal: full screen on mobile */
    #mail-compose-box {
        width: 100%;
        max-width: none;
        max-height: 100vh;
        height: 100vh;
        border: none;
    }

    #mail-compose-body {
        margin: 0 10px;
        font-size: 16px;
    }

    .mail-compose-fields {
        padding: 8px 10px 0;
    }

    .mail-compose-row {
        flex-direction: column;
        gap: 4px;
    }

    .mail-compose-row label {
        width: auto;
        text-align: left;
    }

    .mail-compose-footer {
        padding: 8px 10px;
        flex-wrap: wrap;
    }

    /* Settings modal: full screen on mobile */
    #mail-settings-box {
        width: 100%;
        max-width: none;
        max-height: 100vh;
    }

    /* Bulk action bar */
    #mail-bulk-bar {
        flex-wrap: wrap;
        padding: 6px 10px;
        gap: 6px;
    }

    /* ── Admin ──────────────────────────────────────────── */

    .request-review-panel {
        padding: 24px 16px;
    }

    .request-field {
        flex-direction: column;
        gap: 4px;
    }

    .quote-panel {
        padding: 24px 16px;
    }

    /* ── Modals ─────────────────────────────────────────── */

    #delete-modal-content {
        padding: 24px 20px;
        margin: 0 16px;
    }

    #image-modal-img {
        max-width: 95vw;
        max-height: 85vh;
    }

    #image-modal-close,
    #preview-modal-close {
        top: 10px;
        right: 14px;
        font-size: 28px;
    }

    #preview-body {
        max-width: 95vw;
    }

    #preview-body pre {
        max-width: 90vw;
        font-size: 14px;
        padding: 12px;
    }

    /* ── Scrollbar: thinner on mobile ──────────────────── */

    ::-webkit-scrollbar {
        width: 4px;
    }

}

/* Hide the toggle bar on desktop */
@media (min-width: 769px) {
    #mobile-toggle-bar {
        display: none !important;
    }
}
