/* ── Mobile-Specific Overrides (Loaded via media="max-width: 768px") ── */

/* Hide desktop menubar */
#menubar {
    display: none !important;
}

/* ── Mobile Header ─────────────────────────────────────────────── */
#mobile-header {
    display: flex;
    height: 56px;
    background: rgba(20, 20, 20, 0.85); /* Premium transluscent effect */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
    padding: 0 5px;
    padding-top: env(safe-area-inset-top);
    flex-shrink: 0;
    z-index: 100;
}

.m-toggle {
    background: none;
    border: none;
    color: var(--text);
    font-size: 24px;
    cursor: pointer;
    padding: 10px 15px;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s ease;
}

.m-toggle:active {
    transform: scale(0.9);
    opacity: 0.7;
}

#m-title-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    flex: 1;
    justify-content: center;
    min-width: 0;
}

#m-title {
    font-weight: bold;
    font-size: 16px;
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#ws-dot-m {
    flex-shrink: 0;
}

/* ── Side Drawer Backdrop ──────────────────────────────────────── */
#mobile-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px); /* Blur the content behind the drawer */
    -webkit-backdrop-filter: blur(3px);
    z-index: 80;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#mobile-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ── Server Tree Drawer (Left) ─────────────────────────────────── */
#server-tree {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 85vw;
    max-width: 320px;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    border-right: none;
    background: rgba(34, 34, 34, 0.9); /* Transluscent drawer */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
}

#server-tree.visible {
    transform: translateX(0);
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.5);
}

#tree-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Mobile menu at bottom of server tree */
#mobile-tree-menu {
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom);
}

.mtm-item {
    padding: 14px 16px;
    font-size: 14px;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    -webkit-tap-highlight-color: transparent;
}

.mtm-item:last-child {
    border-bottom: none;
}

.mtm-item:active {
    background: var(--hover);
    color: var(--text);
}

/* ── User List Drawer (Right) ──────────────────────────────────── */
#userlist-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    width: 85vw;
    max-width: 300px;
    z-index: 90;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    border-left: none;
    background: rgba(34, 34, 34, 0.9);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding-top: env(safe-area-inset-top);
}

#userlist-panel.visible {
    transform: translateX(0);
    box-shadow: -2px 0 15px rgba(0, 0, 0, 0.5);
}

/* Increase hit areas in side panels */
.tree-net-hdr {
    padding: 14px 12px;
    font-size: 14px;
}

.tree-ch {
    padding: 14px 12px 14px 28px;
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}

.tree-ch:active {
    background: var(--active);
}

.uentry {
    padding: 12px 14px;
    font-size: 14px;
    -webkit-tap-highlight-color: transparent;
}

/* ── Main Layout ───────────────────────────────────────────────── */
#app {
    height: var(--vvh, 100dvh) !important;
}

#main-layout {
    grid-template-columns: 1fr !important;
    height: 100%;
}

/* ── Chat Layout ───────────────────────────────────────────────── */
#chat-area {
    width: 100% !important;
    height: 100%;
}

#topic-bar {
    padding: 8px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

#chat-buffer {
    -webkit-overflow-scrolling: touch;
}

/* ── Message Styles ────────────────────────────────────────────── */
.ml {
    flex-direction: column;
    align-items: flex-start;
    padding: 6px 12px;
    margin-bottom: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.ml-ts {
    display: inline;
    font-size: 10px;
    color: var(--dim);
    margin-right: 6px;
}

.ml-nick {
    display: inline;
    text-align: left;
    min-width: unset;
    font-size: 13px;
    margin-right: 4px;
    opacity: 0.9;
}

.ml-text {
    width: 100%;
    margin-top: 4px;
    font-size: 14.5px;
    line-height: 1.6;
    word-break: break-word;
    color: var(--text);
}

/* System events stay inline */
.mt-join,
.mt-part,
.mt-quit,
.mt-mode,
.mt-nick-change {
    flex-direction: row;
    align-items: baseline;
    padding: 3px 12px;
}

.mt-join .ml-text,
.mt-part .ml-text,
.mt-quit .ml-text,
.mt-mode .ml-text,
.mt-nick-change .ml-text {
    margin-top: 0;
    font-size: 12px;
}

/* ── Input Bar ─────────────────────────────────────────────────── */
#input-bar {
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    height: auto;
    background: var(--panel2);
    align-items: center;
    gap: 8px;
}

#own-nick {
    display: none;
}

.isep {
    display: none;
}

#input {
    flex: 1;
    width: 100%;
    padding: 10px 14px;
    font-size: 16px; /* Prevents iOS auto-zoom */
    border-radius: 20px;
    background: var(--bg);
    border: 1px solid var(--border);
    margin-right: 0;
}

#input:focus {
    border-color: var(--accent);
}

/* ── Mobile Send Button ────────────────────────────────────────── */
#m-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

#m-send-btn:active {
    opacity: 0.7;
}

#m-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    margin-left: 2px;
}

/* ── Modals (Full-Screen on Mobile) ────────────────────────────── */
.modal-win {
    width: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border: none;
    border-radius: 0;
}

.settings-win,
.net-win {
    width: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
}

.modal-tb {
    padding: 15px;
    padding-top: calc(15px + env(safe-area-inset-top));
    font-size: 16px;
}

.modal-body {
    -webkit-overflow-scrolling: touch;
}

/* Tab bar in Preferences */
.modal-body-tabs {
    gap: 0;
    padding: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.m-tab {
    padding: 12px 14px;
    white-space: nowrap;
    font-size: 14px;
    flex-shrink: 0;
}

/* Settings layout (if used) */
.settings-layout {
    flex-direction: column;
}

.stabs {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    overflow-x: auto;
    padding: 0;
}

.stab {
    width: auto;
    padding: 12px 15px;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
}

.stab.active {
    background: transparent;
    border-bottom-color: var(--accent);
}

/* ── Forms ──────────────────────────────────────────────────────── */
.fgrid {
    grid-template-columns: 1fr;
    gap: 8px;
}

.fgrid label {
    margin-top: 8px;
    font-size: 13px;
}

.fgrid input[type=text],
.fgrid input[type=password],
.fgrid input[type=number] {
    padding: 12px;
    font-size: 16px; /* No iOS zoom */
    border-radius: 8px;
}

.fgrid select {
    padding: 12px;
    font-size: 16px;
    border-radius: 8px;
}

.mactions {
    padding: 15px;
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
    gap: 10px;
}

.btn-primary,
.btn-sec,
.btn-danger {
    padding: 14px 18px;
    font-size: 15px;
    border-radius: 8px;
}

/* ── Network List (Mobile) ─────────────────────────────────────── */
.nrow {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 10px;
}

.nrow-info {
    flex-basis: 100%;
}

.nst {
    font-size: 12px;
}

.btn-edit,
.btn-conn,
.btn-disc {
    padding: 10px 14px;
    font-size: 13px;
    border-radius: 6px;
    flex: 1;
    text-align: center;
}

/* ── Theme Editor (Mobile) ─────────────────────────────────────── */
.theme-grid {
    grid-template-columns: 1fr auto;
    gap: 10px 12px;
}

.theme-grid label {
    font-size: 13px;
}

.cpick {
    width: 44px;
    height: 32px;
}

.theme-presets {
    gap: 8px;
}

.btn-preset {
    padding: 10px 14px;
    font-size: 13px;
}

/* Mode radio options */
.mode-radios {
    gap: 10px;
}

.radio-opt {
    padding: 12px;
}

/* ── Log Browser (Mobile) ──────────────────────────────────────── */
.lb-win {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    transform: none !important;
    width: 100% !important;
    height: 100dvh !important;
    border: none !important;
    border-radius: 0 !important;
}

.lb-body {
    flex-direction: column;
}

.lb-sidebar {
    width: 100%;
    max-height: 50dvh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
}

.lb-field select,
.lb-field input {
    padding: 10px;
    font-size: 16px;
    border-radius: 6px;
}

.lb-messages {
    min-height: 0;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.lb-row {
    padding: 4px 6px;
}

/* ── Search Results ────────────────────────────────────────────── */
.sr-row {
    padding: 8px 10px;
}

.sr-hdr {
    padding: 10px;
    font-size: 13px;
}

/* ── Scrollbar (thinner on mobile) ─────────────────────────────── */
::-webkit-scrollbar {
    width: 3px;
    height: 3px;
}

/* ── Tap highlight removal ─────────────────────────────────────── */
* {
    -webkit-tap-highlight-color: transparent;
}

/* ── Login modal on mobile ─────────────────────────────────────── */
#login-modal .modal-win {
    width: 100% !important;
    height: auto !important;
    max-height: 100dvh !important;
    margin: 0 20px;
    border-radius: 12px;
}

/* ── Placeholder text (shorter on mobile) ──────────────────────── */
#input::placeholder {
    font-size: 14px;
}