/* === Repartee Web Base Styles === */

/* Nerd Font for terminal (powerline glyphs, icons) */
@font-face {
    font-family: 'FiraCode Nerd Font Mono';
    src: url('/fonts/FiraCodeNerdFontMono-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: block;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: 'FiraCode Nerd Font Mono', 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', monospace;
    font-size: 13px;
    line-height: var(--line-height, 1.35);
    overflow: hidden;
    overscroll-behavior: none;
}

/* === Layout === */

.app {
    display: flex;
    flex-direction: column;
    height: 100vh; /* fallback */
    height: 100dvh; /* dynamic viewport height — accounts for mobile browser chrome */
    overflow: hidden;
    position: fixed;
    inset: 0;
}

.desktop-only {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.topic-bar {
    background: var(--bg-alt);
    padding: 2px 8px;
    height: 20px;
    display: flex;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}

.main-area {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* === Buffer List (left panel) === */

.buffer-list {
    width: 170px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    padding: 1px 0;
}

.buffer-list .buffer-item {
    padding: 0 6px;
    line-height: 1.4;
    cursor: pointer;
}

.buffer-list .buffer-item:hover { background: rgba(255,255,255,0.03); }

.buffer-list .buffer-item.active {
    background: rgba(122, 162, 247, 0.1);
    border-left: 2px solid var(--accent);
}

.buffer-item .num { color: var(--fg-muted); }
.buffer-item .name { color: var(--fg-dim); }
.buffer-item.type-server { margin-top: 4px; border-top: 1px solid var(--border); padding-top: 2px; }
.buffer-item.type-server:first-child { margin-top: 0; border-top: none; padding-top: 0; }
.buffer-item.type-server .num { color: var(--accent); }
.buffer-item.type-server .name { color: var(--accent); font-weight: bold; }
.buffer-item.type-query .name { color: var(--cyan); }
.buffer-item.type-dcc .name { color: var(--yellow); }
.buffer-item.active .num { color: var(--yellow); }
.buffer-item.active .name { color: var(--bright); font-weight: bold; }
.buffer-item.activity-1 .name { color: var(--green); }
.buffer-item.activity-2 .name { color: var(--red); }
.buffer-item.activity-3 .name { color: var(--yellow); }
.buffer-item.activity-4 .name { color: var(--purple); }

/* === Chat View (center) === */

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2px 0;
    overscroll-behavior: contain;
}

.chat-messages-outer {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.scroll-bottom-btn {
    position: absolute;
    bottom: 8px;
    right: 12px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--fg-muted);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    opacity: 0.85;
    transition: opacity 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.scroll-bottom-btn:hover { opacity: 1; }
.scroll-bottom-btn.hidden { display: none; }

/* Chat line — flex row, all items on same baseline */
.chat-line {
    padding: 0 8px;
    display: flex;
    align-items: baseline;
    line-height: var(--line-height, 1.35);
    max-width: 100%;
    overflow: hidden;
}

.chat-line .ts {
    width: 70px;
    flex-shrink: 0;
    color: var(--fg-dim);
}
.chat-line .nick {
    flex-shrink: 0;
    text-align: right;
    white-space: nowrap;
}
.chat-line .nick .mode { color: var(--fg-muted); }
.chat-line .nick .name { color: var(--accent); font-weight: bold; }
.chat-line .nick .sep { color: var(--accent); margin-left: 2px; }
.chat-line .text {
    padding-left: 4px;
    flex: 1;
    min-width: 0;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

/* Own message nick = green */
.chat-line.own .nick .name { color: var(--green); }
.chat-line.own .text { color: var(--bright); }

/* Mention/highlight background */
.chat-line.mention { background: var(--mention-bg); }
.chat-line.mention .text { color: var(--purple); }
.chat-line.highlight { background: var(--highlight-bg); }
.chat-line.highlight .text { color: var(--red); }

/* Mention log: pre-formatted line (mentions buffer) — no timestamp/nick column */
.chat-line.mention-log { background: var(--mention-bg); }
.chat-line.mention-log .mention-log-text { color: var(--purple); }

/* Date/backlog separator: centered, dimmed, no timestamp */
.chat-line.date-separator {
    justify-content: center;
    color: var(--fg-dim);
    padding: 4px 8px;
    opacity: 0.7;
}
.chat-line.date-separator .separator-text {
    text-align: center;
    letter-spacing: 0.5px;
}

/* Events: no nick column — text follows timestamp inline */

.chat-line .join-arrow { color: var(--green); }
.chat-line .part-arrow { color: var(--yellow); }
.chat-line .quit-arrow { color: var(--red); }
.chat-line .nick-arrow { color: var(--purple); }
.chat-line .kick-arrow { color: var(--red); }
.chat-line .kicked-arrow { color: var(--red); }
.chat-line .topic-arrow { color: var(--cyan); }
.chat-line .mode-arrow { color: var(--fg-muted); }
.chat-line .connect-arrow { color: var(--green); }
.chat-line .disconnect-arrow { color: var(--red); }
.chat-line .chghost-arrow { color: var(--purple); }
.chat-line .account-arrow { color: var(--fg-muted); }

/* Event-key-specific text coloring */
.chat-line.join-event { color: var(--green); }
.chat-line.part-event { color: var(--yellow); }
.chat-line.kick-event { color: var(--yellow); }
.chat-line.kicked-event { color: var(--red); font-weight: bold; }
.chat-line.nick-event { color: var(--purple); }
.chat-line.topic-event { color: var(--cyan); }
.chat-line.mode-event { color: var(--fg-muted); }

/* Action: * nick action text */
.chat-line.action { color: var(--yellow); }

/* Notice: -nick- text */
.chat-line.notice { color: var(--cyan); }
.chat-line .notice-body { color: var(--fg-muted); }
.chat-line .notice-nick { color: var(--cyan); }

/* === Nick List (right panel) === */

.nick-list {
    width: 150px;
    background: var(--bg);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    padding: 1px 0;
}

.nick-list .mode-group {
    padding: 0 6px;
    color: var(--fg-muted);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 1px;
    line-height: 1.6;
    margin-top: 3px;
}

.nick-list .mode-group:first-child { margin-top: 0; }

.nick-list .nick-entry {
    padding: 0 6px;
    line-height: 1.4;
    cursor: pointer;
}

.nick-entry .prefix-op { color: var(--green); }
.nick-entry .prefix-voice { color: var(--cyan); }
.nick-entry .prefix-normal { color: var(--fg-muted); }
.nick-entry.away { opacity: 0.4; }

/* === Bottom: Status + Input === */

.bottom-bar {
    background: var(--bg-alt);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}

.status-line {
    padding: 1px 8px;
    height: 17px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    font-size: 12px;
}

.status-line .bracket { color: var(--fg-dim); }
.status-line .sep { color: var(--fg-dim); }
.status-line .nick { color: var(--accent); }
.status-line .muted { color: var(--fg-muted); }
.status-line .act-green { color: var(--green); }
.status-line .act-yellow { color: var(--yellow); }
.status-line .act-red { color: var(--red); }
.status-line .act-purple { color: var(--purple); }

.input-line {
    padding: 2px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-line .prompt { color: var(--accent); }

.input-line textarea {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--fg);
    padding: 4px 8px;
    border-radius: 3px;
    outline: none;
    font-family: inherit;
    font-size: 13px;
    line-height: var(--line-height, 1.35);
    resize: none;
    overflow: hidden;
    min-height: 0;
}

.input-line textarea:focus { border-color: var(--accent); }

.input-line .send-btn {
    background: var(--accent);
    color: var(--bg);
    border: none;
    padding: 4px;
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    min-height: 28px;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

/* === Login === */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    gap: 16px;
}

.login-box {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    min-width: 300px;
    text-align: center;
}

.login-box input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--fg);
    padding: 8px 12px;
    border-radius: 4px;
    outline: none;
    font-family: inherit;
    font-size: 14px;
    margin-bottom: 12px;
}

.login-box button {
    width: 100%;
    background: var(--accent);
    color: var(--bg);
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
}

.login-box .error { color: var(--red); font-size: 12px; margin-top: 8px; }

/* === Mentions Badge === */

.mention-badge {
    color: var(--purple);
    font-size: 10px;
    background: rgba(187, 154, 247, 0.2);
    padding: 0 5px;
    border-radius: 8px;
    cursor: pointer;
}

/* === Mobile === */

/* Desktop: hide mobile elements */
@media (min-width: 768px) {
    .mobile-only { display: none !important; }
}

/* Mobile: hide desktop, show mobile */
@media (max-width: 767px) {
    .desktop-only { display: none !important; }
    .mobile-only {
        display: flex;
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
        touch-action: pan-y; /* vertical scroll only — horizontal swipe handled by JS */
        overscroll-behavior: none;
    }

    .buffer-list, .nick-list {
        display: none; /* hidden by default, shown inside slide-out panels */
    }

    /* Chat area — vertical scroll only, no horizontal */
    .chat-area {
        overflow: hidden;
        min-width: 0;
    }
    .chat-messages {
        touch-action: pan-y;
    }

    /* Inline chat layout — no nick column */
    .chat-line {
        display: block;
        padding: 0 6px;
        overflow: hidden;
        overflow-wrap: anywhere;
    }
    .chat-line .ts {
        display: inline;
        width: auto;
        margin-right: 4px;
    }
    .chat-line .nick {
        display: inline;
        width: auto;
        text-align: left;
    }
    .chat-line .text {
        display: inline;
        padding-left: 0;
        overflow-wrap: anywhere;
    }

    /* Mobile top bar */
    .mobile-topbar {
        display: flex;
        background: var(--bg-alt);
        padding: 4px 8px;
        align-items: center;
        border-bottom: 1px solid var(--border);
        min-height: 28px;
        flex-shrink: 0;
        touch-action: pan-y;
    }
    .mobile-topbar .hamburger,
    .mobile-topbar .nicklist-btn {
        color: var(--fg-muted);
        cursor: pointer;
        font-size: 16px;
        padding: 2px 4px;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-topbar-center {
        flex: 1;
        text-align: center;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        padding: 0 8px;
    }
    .mobile-topbar .mobile-chan {
        color: var(--accent);
        font-weight: bold;
        font-size: 13px;
    }
    .mobile-topbar .mobile-topic {
        color: var(--fg-muted);
        font-size: 11px;
    }
    .mobile-topbar-right {
        display: flex;
        gap: 6px;
        align-items: center;
        flex-shrink: 0;
    }

    /* Slide-out overlay — always in DOM, toggled via .visible */
    .slide-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 10;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }
    .slide-overlay.visible {
        opacity: 1;
        pointer-events: auto;
    }

    .slide-panel-left {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        width: 220px;
        background: var(--bg-alt);
        border-right: 1px solid var(--border);
        z-index: 11;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        display: flex;
        flex-direction: column;
        touch-action: pan-y;
        will-change: transform;
    }
    .slide-panel-left.open { transform: translateX(0); }

    .slide-panel-right {
        position: fixed;
        right: 0; top: 0; bottom: 0;
        width: 180px;
        background: var(--bg-alt);
        border-left: 1px solid var(--border);
        z-index: 11;
        overflow-y: auto;
        transform: translateX(100%);
        transition: transform 0.2s ease;
        display: flex;
        flex-direction: column;
        touch-action: pan-y;
        will-change: transform;
    }
    .slide-panel-right.open { transform: translateX(0); }

    .slide-panel-header {
        padding: 8px 10px;
        border-bottom: 1px solid var(--border);
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-shrink: 0;
    }

    /* Override desktop buffer-list/nick-list styles inside panels */
    .slide-panel-left .buffer-list,
    .slide-panel-right .nick-list {
        display: block;
        width: auto;
        border: none;
    }

    /* Compact status bar on mobile */
    .status-line { font-size: 11px; }

    /* Touch-friendly input — 16px prevents iOS Safari auto-zoom on focus */
    .input-line textarea {
        font-size: 16px;
        padding: 6px 8px;
    }
}

/* === Theme switcher === */

.theme-picker {
    display: flex;
    gap: 4px;
    padding: 2px 8px;
    justify-content: center;
    background: var(--bg-alt);
}

.theme-swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    cursor: pointer;
    border: 1px solid transparent;
}

.theme-swatch.active { border-color: var(--accent); }
.theme-swatch:hover { border-color: var(--fg-muted); }

/* === Shell terminal view (beamterm WebGL2 canvas) === */

.shell-terminal {
    flex: 1 1 0;
    display: block;
    width: 100%;
    min-height: 0;
    background: #000;
    outline: none;
}

.shell-terminal:focus {
    box-shadow: inset 0 0 0 1px var(--accent);
}
