/*
 * LVChat — Discord-style web chat (PHP + SQLite)
 *
 * Copyright (C) LVChat contributors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * SPDX-License-Identifier: AGPL-3.0-only
 */

/* LVChat Messenger — old-school IM styling. Light + dark themes via CSS vars. */

:root {
  --online: #3a9a3a;
  --away: #c98a00;
  --offline: #999;
  --danger: #d33;
}

/* ── Light theme (classic AIM-ish) ─────────────────────────── */
.theme-light {
  --bg: #e8e8e8;
  --panel: #ffffff;
  --panel-2: #f4f4f6;
  --border: #cfcfcf;
  --head-bg: #3b6ea5;
  --head-fg: #ffffff;
  --text: #222222;
  --muted: #666666;
  --accent: #3b6ea5;
  --accent-fg: #ffffff;
  --hover: #e2e2e6;
  --stream: #ffffff;
  --mine-bubble: #dce9f7;
  --their-bubble: #f1f1f1;
  --input-bg: #ffffff;
}

/* ── Dark theme ────────────────────────────────────────────── */
.theme-dark {
  --bg: #14141c;
  --panel: #1d1d29;
  --panel-2: #242434;
  --border: #31313f;
  --head-bg: #232331;
  --head-fg: #e8e8ef;
  --text: #ddddE6;
  --muted: #8a8a99;
  --accent: #5b84c4;
  --accent-fg: #ffffff;
  --hover: #2c2c3d;
  --stream: #1a1a26;
  --mine-bubble: #2b3a56;
  --their-bubble: #262635;
  --input-bg: #242434;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  overflow-x: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

button { cursor: pointer; font: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.view { height: 100%; width: 100%; }
.view[hidden] { display: none !important; }

.view-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ── Cards (login / mfa) ───────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.login-card { width: 380px; max-width: 100%; padding: 26px; }

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand .logo, .logo {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-fg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; letter-spacing: -0.5px;
  flex: none;
}
.brand h1 { margin: 0; font-size: 18px; }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.sub { color: var(--muted); font-size: 12px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.check { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin: 10px 0; cursor: pointer; }

.error { color: var(--danger); font-size: 13px; margin: 8px 0; }
.error[hidden] { display: none; }

button.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-weight: 600;
}
button.primary:disabled { opacity: 0.6; cursor: default; }
button.wide { width: 100%; padding: 10px; }
button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
}
button.ghost.small { padding: 3px 8px; font-size: 12px; }
button.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 15px;
  width: 30px; height: 30px;
  border-radius: 6px;
}
button.icon-btn:hover { background: var(--hover); color: var(--text); }

.code-input { text-align: center; font-size: 18px; letter-spacing: 0.4em; font-family: ui-monospace, monospace; }

.links { display: flex; justify-content: space-between; margin-top: 16px; font-size: 13px; }
#login-target { margin-top: 18px; text-align: center; }

/* ── Main layout ───────────────────────────────────────────── */
#view-main { display: flex; flex-direction: column; }
#app-row { display: flex; flex: 1; min-height: 0; min-width: 0; overflow: hidden; }

/* Offline banner: a slim strip above the sidebar/chat when disconnected. */
#offline-banner {
  flex: none;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  color: #fff;
  background: #a33;
}
#offline-banner[hidden] { display: none; }

#sidebar {
  width: var(--sidebar-width, 320px);
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  container-type: inline-size;
}

/* Drag handle to resize the list (Advanced view). */
#sidebar-resizer {
  width: 5px;
  flex: none;
  cursor: col-resize;
  background: transparent;
  margin-left: -1px;
}
#sidebar-resizer:hover { background: var(--accent); }
body.resizing #sidebar-resizer { background: var(--accent); }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing iframe, body.resizing img { pointer-events: none; }
#chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--stream);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--head-bg);
  color: var(--head-fg);
}

/* Compact view: the window is sized to the list width and the sidebar fills
 * the whole window horizontally — Compact is just the left pane of the
 * Advanced view. Any frame sliver blends with the panel colour. */
body.compact #chat { display: none; }
body.compact #sidebar-resizer { display: none; }
body.compact #sidebar { width: 100%; border-right: none; }
body.compact #view-main { background: var(--panel); }

/* Dedicated conversation windows: sidebar hidden, chat fills the window. */
body.chat-window #sidebar { display: none; }
body.chat-window #sidebar-resizer { display: none; }

/* When the list is too narrow to fit the header icons beside the username,
 * collapse the icons into the hamburger menu. */
.head-menu-anchor { position: relative; }
#menu-btn { display: none; }
@container (max-width: 400px) {
  #menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  #view-mode-btn, #theme-toggle, #profile-manager, #logout-btn { display: none; }
}
.head-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 1100;
  min-width: 200px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 5px;
}
/* Phones (< 768px) are Compact-only — never show the layout toggle. */
@media (max-width: 767px) {
  #view-mode-btn { display: none !important; }
}
.head-menu[hidden] { display: none; }
.me { display: flex; align-items: center; gap: 8px; min-width: 0; position: relative; }
.me-info { min-width: 0; }
.me-status {
  display: block;
  font-size: 11px;
  opacity: 0.9;
  background: transparent;
  border: none;
  color: inherit;
  padding: 0;
  text-align: left;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  cursor: pointer;
}
.me-status:hover { text-decoration-style: solid; }
.me-status.dnd { color: #f87171; }
.me-status.away { color: var(--away); }
.me-status.offline { color: var(--offline); }
.status-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 1200;
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 5px;
}
.status-menu[hidden] { display: none; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  overflow: visible;
  flex: none;
  position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-status {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--head-bg);
  background: var(--offline);
}
#me-avatar { cursor: pointer; }
.avatar-status.online { background: var(--online); }
.avatar-status.away { background: var(--away); }
.avatar-status.dnd { background: var(--danger); }
.avatar-status.offline { background: var(--offline); }
.me-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-status { font-size: 11px; opacity: 0.85; }
.head-actions { display: flex; gap: 2px; }
.head-actions .icon-btn { color: var(--head-fg); }
.head-actions .icon-btn:hover { background: rgba(255, 255, 255, 0.15); color: var(--head-fg); }

.search-row { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.search-row input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}
.search-row input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.nav { display: flex; border-bottom: 1px solid var(--border); }
.nav-tab {
  flex: 1;
  padding: 8px 4px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}
.nav-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.badge {
  display: inline-block;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  padding: 0 4px;
  margin-left: 5px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}

.panel { flex: 1; overflow-y: auto; padding: 6px 0; }
.panel-title { padding: 8px 12px 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.buddy-actions { padding: 6px 10px 2px; }

/* Group nodes */
.group { margin-bottom: 2px; }
.group-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.group-head:hover { background: var(--hover); }
.group-head .caret { display: inline-block; transition: transform 0.12s; font-size: 9px; }
.group.collapsed .caret { transform: rotate(-90deg); }
.group.collapsed .group-members { display: none; }
.group-head .count { color: var(--muted); font-weight: 400; }
.group-head .g-actions { margin-left: auto; }
.group-head .g-actions .icon-btn { width: 20px; height: 20px; font-size: 11px; display: none; }
.group-head:hover .g-actions .icon-btn { display: inline-flex; align-items: center; justify-content: center; }

/* Buddy rows */
.contact {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  cursor: pointer;
  border-radius: 4px;
}
.contact:hover { background: var(--hover); }
.contact.selected { background: var(--hover); }
.contact .avatar { width: 28px; height: 28px; font-size: 12px; }
.contact .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.contact .dot.online { background: var(--online); }
.contact .dot.away { background: var(--away); }
.contact .dot.dnd { background: var(--danger); }
.contact .dot.offline { background: var(--offline); }
.contact .contact-name-col { flex: 1; min-width: 0; }
.contact .contact-name { flex: none; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact .contact-status {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.contact .unread {
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 9px;
  min-width: 17px; height: 17px;
  line-height: 17px;
  padding: 0 4px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
}
.contact.off { opacity: 0.55; }

.empty { padding: 12px; color: var(--muted); font-size: 12px; }

/* Request rows */
.req { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.req .req-meta { display: flex; align-items: center; gap: 8px; }
.req .req-name { font-weight: 600; }
.req .req-sub { color: var(--muted); font-size: 12px; margin: 2px 0 0 36px; }
.req .req-actions { margin-top: 6px; display: flex; gap: 6px; }

/* Chat head */
#chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.chat-head-info { flex: 1; min-width: 0; }
.chat-head-actions { flex: none; display: flex; align-items: center; gap: 6px; }
.chat-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { color: var(--muted); font-size: 12px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#chat-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#chat-main { flex: 1; display: flex; min-height: 0; min-width: 0; overflow: hidden; }
#stream { flex: 1; min-width: 0; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }

/* Channel URL pane: embedded web page above the chat (rooms only). */
#channel-url-pane {
  flex: 1 1 45%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
#channel-url-pane[hidden] { display: none; }
#channel-url-pane.url-pane-collapsed { flex: 0 0 auto; }
#channel-url-pane.url-pane-collapsed #url-frame { display: none; }
.url-pane-head { display: flex; align-items: center; gap: 8px; padding: 4px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
#url-pane-host { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#url-frame { flex: 1; min-height: 0; width: 100%; border: 0; }

/* Channel settings modal (bans / registered ops / topic / URL). */
.chan-settings-modal {
  width: 560px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
}
.chan-settings-modal .modal-title { margin-bottom: 4px; }
.chan-settings-modal .modal-title #cs-name { color: var(--accent); }
.cs-tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cs-tabs button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.cs-tabs button.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.cs-tabs button:disabled { opacity: 0.5; cursor: default; }
.cs-body { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 0; }
.cs-msg { color: var(--online); font-size: 12.5px; margin-top: 8px; }
.cs-msg[hidden] { display: none; }
.cs-section { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.cs-section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-bottom: 8px; }
.cs-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.cs-row > input, .cs-row > select { flex: 1; min-width: 0; }
.cs-row input[type="url"], .cs-row input:not([type]), .cs-row input[type="text"] {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
}
.cs-row select { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--input-bg); color: var(--text); }
.cs-list { max-height: 220px; overflow-y: auto; margin-top: 8px; border: 1px solid var(--border); border-radius: 6px; }
.cs-list-row { display: flex; align-items: center; gap: 8px; padding: 6px 9px; border-bottom: 1px solid var(--border); font-size: 13px; }
.cs-list-row:last-child { border-bottom: none; }
.cs-list-row .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.cs-list-row .spacer { flex: 1; }
.cs-list-empty { padding: 12px; color: var(--muted); font-size: 12.5px; text-align: center; }
textarea.cs-topic { width: 100%; min-height: 72px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--input-bg); color: var(--text); font: inherit; resize: vertical; }
#members {
  flex: none;
  width: 220px;
  border-left: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  padding: 10px 0;
}
#members[hidden] { display: none; }
.members-title { padding: 0 12px 6px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }

/* Messages */
.msg { display: flex; gap: 10px; padding: 4px 8px; border-radius: 6px; }
.msg:hover { background: var(--hover); }
.msg .avatar { width: 30px; height: 30px; font-size: 13px; }
.msg-body { min-width: 0; flex: 1; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; }
.msg-author { font-weight: 700; font-size: 13px; }
.msg-time { color: var(--muted); font-size: 11px; }
.msg-pending {
  color: var(--away);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.msg.pending .msg-content { opacity: 0.6; }
.msg.pending .avatar { opacity: 0.6; }
.msg-content { margin-top: 1px; white-space: pre-wrap; word-wrap: break-word; font-size: 13.5px; line-height: 1.4; }
.msg-content img.media {
  max-width: min(320px, 100%);
  max-height: 240px;
  border-radius: 8px;
  margin: 4px 0;
  display: block;
  background: var(--panel-2);
}
.msg-content .caption { color: var(--muted); font-size: 12px; margin-top: 2px; }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .msg-body { text-align: right; }
.msg.mine .msg-meta { justify-content: flex-end; }
.msg.mine .msg-content { color: var(--text); }
.msg.mine .bubble {
  background: var(--mine-bubble);
  border-radius: 10px;
  padding: 6px 10px;
  display: inline-block;
  text-align: left;
  max-width: 100%;
}
.msg.system { text-align: center; }
.msg.system .msg-content { color: var(--muted); font-style: italic; font-size: 12px; }
.msg.system { justify-content: center; }
.msg.action .msg-content { font-style: italic; color: var(--accent); }
.msg img.emoji-inline { height: 1.2em; vertical-align: -0.2em; }

.date-sep {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  margin: 10px 0 6px;
}

/* Composer */
#composer { padding: 8px 12px 12px; background: var(--panel); border-top: 1px solid var(--border); }
#composer[hidden] { display: none; }
.composer-wrap { position: relative; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  padding: 9px 12px;
  max-height: 140px;
  min-height: 38px;
}
.composer-row textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

.picker-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
}

/* @mention autocomplete */
.mention-ac {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 6px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 4px;
  z-index: 900;
}
.mention-ac[hidden] { display: none; }
.mention-ac .ma-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.mention-ac .ma-item.selected { background: var(--hover); }
.mention-ac .ma-item .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.mention-ac .ma-item .dot.online { background: var(--online); }
.mention-ac .ma-item .dot.offline { background: var(--offline); }
.mention-ac .ma-item .ma-name { font-weight: 600; }
.mention-ac .ma-empty { padding: 8px 10px; color: var(--muted); font-size: 12px; }

/* @mention highlight in messages */
.msg-content .mention {
  color: var(--accent);
  font-weight: 600;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-radius: 4px;
  padding: 0 2px;
}
#emoji-panel { display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; max-height: 180px; }
#emoji-panel[hidden] { display: none; }
#emoji-panel button { font-size: 19px; background: transparent; border: none; border-radius: 6px; padding: 2px; }
#emoji-panel button:hover { background: var(--hover); }

.gif-search-row input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  margin-bottom: 8px;
}
#gif-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
#gif-grid .gif-item img { width: 100%; height: 90px; object-fit: cover; border-radius: 6px; cursor: pointer; }
#gif-grid .gif-item img:hover { outline: 2px solid var(--accent); }
#gif-grid .gif-note { grid-column: 1 / -1; color: var(--muted); font-size: 12px; padding: 6px; }

/* Scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* Context menu */
.ctx-menu {
  position: fixed;
  z-index: 1000;
  min-width: 170px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 5px;
}.ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 5px;
  font-size: 13px;
}
.ctx-item:hover { background: var(--hover); }
.ctx-item.checked { color: var(--accent); font-weight: 600; }
.ctx-item.danger { color: var(--danger); }
.ctx-label {
  padding: 5px 10px 3px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.ctx-sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* Modal dialogs (replaces window.prompt/confirm/alert) */
#modal { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; }
#modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.modal {
  position: relative;
  width: 360px;
  max-width: calc(100vw - 40px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.modal-title { font-weight: 700; font-size: 15px; margin-bottom: 10px; }
.modal-message { color: var(--text); font-size: 13.5px; margin-bottom: 10px; white-space: pre-wrap; }
#modal-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  margin-bottom: 12px;
}
#modal-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Settings modal */
#settings-modal { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; }
#settings-modal[hidden] { display: none; }
.settings-modal { width: 400px; max-width: calc(100vw - 40px); max-height: calc(100vh - 60px); overflow-y: auto; }
.settings-section { margin: 4px 0 14px; }
.settings-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 8px;
}
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0; }
.settings-row .check { margin: 0; }
.settings-row select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  min-width: 130px;
}
.settings-hint { color: var(--muted); font-size: 11.5px; margin: 6px 0 8px; }
.settings-status {
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  padding: 8px 10px;
  margin-bottom: 12px;
}
.settings-status[hidden] { display: none; }
