/* ══════════════════════════════════════════════════════════
   Discord Theme — index.css
   Requires: src/common.css loaded first
   ══════════════════════════════════════════════════════════ */

:root {
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --bg-primary: #36393f;
    --bg-secondary: #2f3136;
    --bg-input: #202225;
    --bg-hover: #3c3f45;
    --text-primary: #dcddde;
    --text-heading: #fff;
    --text-muted: #b9bbbe;
    --text-dim: #72767d;
    --text-notice: #f7aaaa;
    --accent: #5865f2;
    --accent-hover: #4752c4;
    --border: #202225;
    --border-subtle: #40444b;
    --input-border: none;
    --focus-ring: 0 0 0 2px #5865f2;
    --login-box-border: none;
    --login-box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    --login-tab-border: 2px solid #202225;
    --btn-radius: 3px;
    --btn-weight: 500;
    --modal-backdrop: rgba(0, 0, 0, 0.75);
    --modal-radius: 8px;
    --modal-input-radius: 4px;
    --scrollbar-thumb: #1e2124;
    --scrollbar-hover: #2a2d31;
    --skeleton-gradient: linear-gradient(90deg, #2f3136 25%, #36393f 50%, #2f3136 75%);
    --lightbox-bg: rgba(0, 0, 0, 0.85);
    --lightbox-close-bg: rgba(0,0,0,0.6);
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
    width: 250px;
    min-width: 180px;
    background-color: #2f3136;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.guilds {
    padding: 8px;
    height: 40%;
    overflow-y: auto;
    flex-shrink: 0;
}

.resizer-y {
    height: 4px;
    background-color: #202225;
    cursor: ns-resize;
    flex-shrink: 0;
    transition: background-color 0.15s;
}

.resizer-y:hover,
.resizer-y.dragging { background-color: #5865f2; }

.channels {
    padding: 8px;
    flex-grow: 1;
    overflow-y: auto;
}

.guild-item,
.channel-item {
    padding: 7px 8px;
    cursor: pointer;
    border-radius: 4px;
    margin-bottom: 1px;
    color: #8e9297;
    font-size: 0.9rem;
    transition: background-color 0.15s, color 0.15s;
    user-select: none;
    position: relative;
}

.guild-item:hover,
.channel-item:hover { background-color: #393c43; color: #dcddde; }

.guild-item.active,
.channel-item.active { background-color: #40444b; color: #fff; font-weight: 500; }

/* ── Unread Indicator ──────────────────────────────── */
.guild-item.unread,
.channel-item.unread { color: #fff; font-weight: 600; }

.guild-item.unread::before,
.channel-item.unread::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 8px;
    background: #fff;
    border-radius: 0 4px 4px 0;
}

/* ── Messages ───────────────────────────────────────── */
.messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
}

.message {
    padding: 1px 8px;
    margin: 0 -8px;
    border-radius: 3px;
    transition: background-color 0.08s;
}

.message.is-new { animation: fadeIn 0.15s ease-out; }

.message:hover { background-color: #32353b; }
.message + .message { margin-top: 4px; }
.message.chained { margin-top: 0; }

.msg-body { min-width: 0; }

.compact-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
    min-width: 0;
}

.message .author {
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}

.message .author:hover { text-decoration: underline; }

/* ── Author Tooltip ────────────────────────────────── */
.author-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #18191c;
    color: #b9bbbe;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 400;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.author-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #18191c;
}

.message .author:hover .author-tooltip { display: block; }

.message .timestamp {
    font-size: 0.68rem;
    color: #72767d;
    flex-shrink: 0;
}

.message .content {
    line-height: 1.3rem;
    white-space: pre-wrap;
    word-break: break-word;
    flex: 1;
    min-width: 0;
}

/* ── Message Input ─────────────────────────────────── */
#message-input {
    flex-grow: 1;
    padding: 11px 14px;
    border-radius: 0 5px 5px 0;
    border: none;
    background-color: #40444b;
    color: #dcddde;
    outline: none;
    font-size: 0.95rem;
    font-family: inherit;
    transition: background-color 0.1s;
}

#message-input:focus { background-color: #454a52; box-shadow: 0 0 0 1px #5865f244; }

#send-button { border-radius: 0 3px 3px 0; margin-left: 6px; }

/* ── Context Menu ───────────────────────────────────── */
.context-menu {
    position: fixed;
    background: #18191c;
    border: 1px solid #2c2d31;
    border-radius: 4px;
    padding: 4px;
    min-width: 150px;
    z-index: 2000;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.context-item {
    color: #ed4245;
    padding: 8px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.875rem;
}

.context-item:hover { background: #ed4245; color: #fff; }

.context-item.neutral { color: #dcddde; }
.context-item.neutral:hover { background: #5865f2; color: #fff; }

/* ── Reply banner ───────────────────────────────────── */
#reply-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: #2f3136;
    border-top: 1px solid #202225;
    font-size: 0.8rem;
}

.reply-banner-label { color: #b9bbbe; white-space: nowrap; }
.reply-banner-label strong { color: #fff; }

.reply-banner-preview {
    flex: 1;
    color: #72767d;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-cancel {
    background: none;
    border: none;
    color: #72767d;
    cursor: pointer;
    font-size: 1rem;
    padding: 0 2px;
    line-height: 1;
}
.reply-cancel:hover { color: #dcddde; }

/* ── Reply quote in message ─────────────────────────── */
.reply-ref {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 3px;
    padding-left: 8px;
    border-left: 2px solid #4f545c;
    font-size: 0.8rem;
    opacity: 0.75;
    cursor: default;
    overflow: hidden;
}

.reply-ref-author { color: #fff; font-weight: 600; white-space: nowrap; }
.reply-ref-content { color: #b9bbbe; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── File Upload ────────────────────────────────────── */
.file-upload-btn {
    background-color: #40444b;
    color: #8e9297;
    border-radius: 5px 0 0 5px;
    padding: 0 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    transition: background-color 0.1s, color 0.1s;
    border-right: 1px solid #36393f;
    flex-shrink: 0;
}

.file-upload-btn:hover { background-color: #4a4f57; color: #dcddde; }
.file-upload-btn.active { color: #5865f2; }

/* ── Attachments ────────────────────────────────────── */
.attachment-preview {
    max-width: 420px;
    max-height: 300px;
    border-radius: 4px;
    margin-top: 6px;
    display: block;
    min-height: 48px;
    background: #2f3136;
    background: #202225;
}

.attachment-audio {
    display: block;
    margin-top: 6px;
    max-width: 420px;
    width: 100%;
}

.attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 8px 12px;
    background: #2f3136;
    border: 1px solid #26282c;
    border-radius: 4px;
    color: #00aff4;
    text-decoration: none;
    font-size: 0.875rem;
    transition: background-color 0.1s;
}

.attachment-link:hover { background: #393c43; text-decoration: underline; }

.download-link {
    display: inline-block;
    margin-top: 4px;
    color: #00aff4;
    font-size: 0.75rem;
    text-decoration: none;
    opacity: 0.8;
}

.download-link:hover { opacity: 1; text-decoration: underline; }

/* ── Twemoji ────────────────────────────────────────── */
img.twemoji {
    height: 1.375em;
    width: 1.375em;
    vertical-align: -0.3em;
    display: inline;
}

/* ── Add DM Modal ──────────────────────────────────── */
#add-dm-modal .modal {
    width: 340px;
}

/* ── Custom emoji ──────────────────────────────────── */
img.custom-emoji {
    width: 22px;
    height: 22px;
    vertical-align: -5px;
    display: inline;
}

/* ── Mentions ──────────────────────────────────────── */
.mention {
    background: rgba(88,101,242,0.15);
    color: #dee0fc;
    border-radius: 3px;
    padding: 0 3px;
    font-weight: 500;
}
.mention.mention-self-pill {
    background: rgba(250,168,26,0.2);
    color: #faa81a;
}
.message.mention-self {
    background: rgba(250,168,26,0.06);
}

/* ── Embed media ───────────────────────────────────── */
.embed-media { margin-top: 4px; }
.embed-media img, .embed-media video {
    max-width: 400px;
    max-height: 300px;
    border-radius: 4px;
    display: block;
}

/* ── Stickers ──────────────────────────────────────── */
.sticker-img {
    width: 160px;
    height: 160px;
    object-fit: contain;
    display: block;
    margin-top: 4px;
}

/* ── @mention dropdown ─────────────────────────────── */
#mention-dropdown {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 0;
    background: #2f3136;
    border: 1px solid #202225;
    border-radius: 6px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    width: 260px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    margin-bottom: 4px;
}
.mention-item {
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.88rem;
    color: #dcddde;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mention-item:hover { background: #393c43; }
#mention-dropdown.open { display: block; }

/* ── Gateway Status Indicator ────────────────────────── */
.gateway-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background-color 0.4s;
    position: relative;
    cursor: default;
}

.gateway-status.connected { background-color: #43b581; }
.gateway-status.reconnecting { background-color: #faa61a; animation: pulse 1.5s infinite; }
.gateway-status.disconnected { background-color: #747f8d; }

.gateway-status-tooltip {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #18191c;
    color: #b9bbbe;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 400;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.gateway-status:hover .gateway-status-tooltip { display: block; }

/* ── Typing Indicator ──────────────────────────────── */
#typing-indicator {
    height: 24px;
    padding: 0 16px;
    font-size: 0.78rem;
    color: #b9bbbe;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    overflow: hidden;
}

.typing-dots::after {
    content: '';
    animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

/* ── E2E Encryption ──────────────────────────────────── */
.e2e-btn {
    background: none;
    color: #8e9297;
    padding: 0 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    font-size: 18px;
    border: none;
    border-radius: 0;
    transition: color 0.15s;
    flex-shrink: 0;
}

.e2e-btn:hover { color: #dcddde; background: none; }
.e2e-btn.active { color: #43b581; }

.e2e-popover {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    background: #18191c;
    border: 1px solid #2c2d31;
    border-radius: 8px;
    padding: 12px;
    width: 260px;
    z-index: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.e2e-popover.active { display: flex; flex-direction: column; gap: 8px; }

.e2e-popover label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #b9bbbe;
}

.e2e-popover input {
    width: 100%;
    padding: 8px 10px;
    border-radius: 4px;
    border: none;
    background: #202225;
    color: #dcddde;
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
}

.e2e-popover input:focus { box-shadow: 0 0 0 2px #5865f2; }

.e2e-popover-btns {
    display: flex;
    gap: 6px;
}

.e2e-popover-btns button {
    flex: 1;
    padding: 6px;
    font-size: 0.8rem;
}

.e2e-popover-btns .btn-clear {
    background: #ed4245;
}

.e2e-popover-btns .btn-clear:hover { background: #c03537; }

.message.encrypted .content {
    border-left: 2px solid #43b58166;
    padding-left: 8px;
}

.msg-lock {
    font-size: 0.7rem;
    color: #43b581;
    margin-left: 6px;
    opacity: 0.7;
}

/* ── Blocked list ─────────────────────────────────────── */
.blocked-list-ui {
    background: #202225;
    padding: 8px;
    border-radius: 4px;
    font-size: 13px;
    max-height: 90px;
    overflow-y: auto;
}

.blocked-none { color: #72767d; font-size: 12px; }

.blocked-item-ui {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
}

.unblock-btn {
    background: #ed4245;
    padding: 2px 8px;
    font-size: 11px;
    border-radius: 3px;
    cursor: pointer;
    color: #fff;
    border: none;
    font-family: inherit;
}

.unblock-btn:hover { background: #c03537; }

/* ── Skeleton (Discord-specific) ──────────────────────── */
.skeleton-message {
    display: flex;
    gap: 12px;
    padding: 8px 16px;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
}

.skeleton-lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.skeleton-line.short { width: 40%; }
.skeleton-line.medium { width: 70%; }
.skeleton-line.long { width: 90%; }

/* ── Channel categories ───────────────────────────────────── */
.category-header {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 4px 2px;
    color: #72767d;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.07em;
    cursor: pointer;
    user-select: none;
    border-radius: 3px;
}

.category-header:hover { color: #dcddde; }
.category-header.unread { color: #fff; }

.category-arrow {
    font-size: 9px;
    width: 10px;
    flex-shrink: 0;
}

.category-children { padding-left: 8px; }

/* ── Guild unread badge ───────────────────────────────────── */
.guild-badge {
    position: absolute;
    top: 2px;
    right: 4px;
    background: #ed4245;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    pointer-events: none;
}

/* ── Markdown ─────────────────────────────────────────────── */
.md-code {
    background: #202225;
    color: #e06c75;
    padding: 1px 5px;
    border-radius: 3px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.88em;
}

.md-codeblock {
    background: #202225;
    border: 1px solid #40444b;
    border-radius: 4px;
    padding: 8px 12px;
    margin: 4px 0;
    overflow-x: auto;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.88em;
    white-space: pre;
    color: #abb2bf;
}

.md-codeblock code { background: none; padding: 0; color: inherit; }

.md-blockquote {
    border-left: 4px solid #4f545c;
    padding-left: 8px;
    margin: 2px 0;
    color: #b9bbbe;
    display: block;
}

.md-link {
    color: #00aff4;
    text-decoration: none;
    word-break: break-all;
}
.md-link:hover { text-decoration: underline; }

/* ── Edited marker ────────────────────────────────────────── */
.msg-edited {
    font-size: 0.7rem;
    color: #72767d;
    font-style: italic;
}

/* ── Emoji picker ─────────────────────────────────────────── */
.emoji-picker {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    width: 320px;
    max-height: 360px;
    background: #18191c;
    border: 1px solid #2c2d31;
    border-radius: 8px;
    z-index: 500;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.emoji-search {
    padding: 8px 10px;
    background: #202225;
    border: none;
    border-bottom: 1px solid #2c2d31;
    color: #dcddde;
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    flex-shrink: 0;
}

.emoji-search:focus { box-shadow: inset 0 0 0 1px #5865f2; }

/* ── GIF / Sticker pickers ────────────────────────────── */
.media-picker {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    right: 0;
    height: 300px;
    background: #18191c;
    border: 1px solid #2c2d31;
    border-radius: 8px;
    z-index: 500;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.media-picker-search {
    padding: 8px 10px;
    background: #202225;
    border: none;
    border-bottom: 1px solid #2c2d31;
    color: #dcddde;
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    flex-shrink: 0;
}
.media-picker-search:focus { box-shadow: inset 0 0 0 1px #5865f2; }

.gif-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
    padding: 6px;
    overflow-y: auto;
    flex: 1;
}

.gif-grid img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    background: #2c2d31;
}
.gif-grid img:hover { transform: scale(0.97); transition: transform 0.1s; }

.sticker-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    padding: 8px;
    overflow-y: auto;
    flex: 1;
}

.sticker-grid img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    border-radius: 6px;
    cursor: pointer;
    background: #2c2d31;
    padding: 4px;
}
.sticker-grid img:hover { background: #36393f; }
.sticker-grid .sticker-name {
    font-size: 0.65rem;
    color: #8e9297;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.emoji-tabs {
    display: flex;
    padding: 4px;
    gap: 2px;
    background: #18191c;
    flex-shrink: 0;
    overflow-x: auto;
    border-bottom: 1px solid #2c2d31;
}

.emoji-tab {
    padding: 4px 8px;
    background: none;
    color: #72767d;
    border-radius: 4px;
    font-size: 0.78rem;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.emoji-tab:hover { background: #2f3136; color: #dcddde; }
.emoji-tab.active { background: #40444b; color: #fff; }

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 6px;
    overflow-y: auto;
    flex: 1;
}

.emoji-item {
    font-size: 1.4rem;
    text-align: center;
    padding: 4px;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1.4;
    transition: background-color 0.1s;
}

.emoji-item:hover { background: #40444b; }

/* ── Drag-over overlay ───────────────────────────────────── */
.main.drag-over::after {
    content: 'Drop file to upload';
    position: absolute;
    inset: 0;
    background: rgba(88,101,242,0.12);
    border: 2px dashed #5865f2;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #dee0fc;
    font-weight: 600;
    pointer-events: none;
    z-index: 50;
}

.main { position: relative; }

/* ── Formatting toolbar ──────────────────────────────────── */
#fmt-toolbar button {
    padding: 3px 8px;
    font-size: 0.82rem;
    background: #40444b;
    color: #b9bbbe;
    border-radius: 3px;
    border: none;
    cursor: pointer;
    line-height: 1.4;
}

#fmt-toolbar button:hover { background: #4a4f57; color: #fff; }
