/* base.css — layout & component structure. Colors/fonts come from themes.css tokens. */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font-body); background: var(--bg-chat); color: var(--text-normal); font-size: 15px; line-height: 1.4; }
body.resizing { user-select: none; cursor: col-resize; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { font: inherit; }
.hidden { display: none !important; }

/* ── App grid: rail | channels | divider | chat | divider | members ── */
#app {
  display: grid;
  grid-template-columns: var(--col-rail, 72px) var(--col-channels, 240px) 4px minmax(320px, 1fr) 4px var(--col-members, 240px);
  grid-template-rows: 100%;
  height: 100vh; overflow: hidden;
}
/* #modal-root lives inside #app but must not occupy a grid cell —
   its children (.modal-overlay/.modal) are position:fixed */
#modal-root { display: contents; }
.divider { cursor: col-resize; background: transparent; transition: background 0.1s; touch-action: none; }
.divider:hover { background: var(--accent); }

/* ── Rail ── */
#rail { background: var(--bg-rail); overflow-y: auto; overflow-x: hidden; padding: 12px 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
#rail-nodes { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.rail-icon { width: 48px; height: 48px; border-radius: 50%; background: var(--bg-sidebar); color: var(--text-normal); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 18px; transition: border-radius 0.15s, background 0.15s; position: relative; flex-shrink: 0; }
.rail-icon:hover, .rail-icon.active { border-radius: var(--radius-lg); background: var(--accent); color: var(--on-accent); }
.rail-icon.active::before { content: ''; position: absolute; left: -12px; width: 4px; height: 40px; background: var(--text-heading); border-radius: 0 4px 4px 0; }
.rail-separator { width: 32px; height: 2px; background: var(--border); border-radius: 1px; flex-shrink: 0; }

/* ── Channel sidebar ── */
#sidebar { background: var(--bg-sidebar); display: flex; flex-direction: column; overflow: hidden; min-width: 0; position: relative; }
#sidebar-header { height: 48px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); cursor: pointer; flex-shrink: 0; }
#sidebar-header:hover { background: var(--bg-hover); }
#node-name { font-weight: 600; color: var(--text-heading); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dropdown { position: absolute; top: 52px; left: 8px; right: 8px; background: var(--bg-rail); border-radius: var(--radius-sm); padding: 6px; z-index: 30; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24); }
.menu-item { padding: 8px 10px; border-radius: var(--radius-sm); font-size: 14px; color: var(--text-muted); cursor: pointer; }
.menu-item:hover { background: var(--accent); color: var(--on-accent); }
#channel-section { flex: 1; overflow-y: auto; padding: 12px 8px; }
.section-label { display: flex; justify-content: space-between; align-items: center; padding: 0 8px 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-muted); }
.section-label button:hover { color: var(--text-heading); }
.channel { display: flex; align-items: center; gap: 6px; width: 100%; padding: 6px 8px; border-radius: var(--radius-sm); color: var(--text-muted); font-size: 15px; text-align: left; }
.channel:hover { background: var(--bg-hover); color: var(--text-normal); }
.channel.active { background: var(--bg-active); color: var(--text-heading); }
.hash { color: var(--text-muted); }
.channel.unread { color: var(--text-heading); font-weight: 600; }
.channel-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

/* ── User panel ── */
#user-panel { height: 52px; background: var(--bg-rail); display: flex; align-items: center; gap: 8px; padding: 0 8px; flex-shrink: 0; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; flex-shrink: 0; position: relative; }
#user-panel .user-meta { flex: 1; min-width: 0; }
#user-panel .user-nick { font-size: 14px; font-weight: 600; color: var(--text-heading); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#user-panel .user-disc { font-size: 11px; color: var(--text-muted); }
.icon-btn { padding: 6px; border-radius: var(--radius-sm); color: var(--text-muted); }
.icon-btn:hover { background: var(--bg-hover); color: var(--text-normal); }

/* ── Chat column ── */
#main { display: flex; flex-direction: column; overflow: hidden; background: var(--bg-chat); min-width: 0; }
#channel-header { height: 48px; padding: 0 16px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
#channel-header .hash { font-size: 20px; }
#channel-name { font-weight: 600; color: var(--text-heading); }
#header-actions { margin-left: auto; display: flex; gap: 4px; }
#messages { flex: 1; overflow-y: auto; padding: 16px 0 8px; }
.welcome { padding: 8px 16px 16px; color: var(--text-muted); font-size: 14px; }
.date-divider { display: flex; align-items: center; gap: 8px; margin: 16px 16px 8px; color: var(--text-muted); font-size: 12px; font-weight: 600; }
.date-divider::before, .date-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Messages ── */
.message { position: relative; display: flex; gap: 16px; padding: 2px 16px; }
.message:hover { background: var(--bg-hover); }
.message.group-start { margin-top: 16px; }
.message.pending { opacity: 0.5; }
.message.pending.failed { opacity: 0.8; }
.message.pending.failed .msg-content { color: var(--danger); }
.msg-gutter { width: 40px; flex-shrink: 0; display: flex; justify-content: center; }
.msg-avatar { width: 40px; height: 40px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 16px; cursor: pointer; flex-shrink: 0; }
.msg-hover-time { display: none; font-size: 10px; color: var(--text-muted); align-self: center; }
.message:hover .msg-hover-time { display: block; }
.msg-body { flex: 1; min-width: 0; }
.msg-nick { font-weight: 600; color: var(--text-heading); cursor: pointer; margin-right: 8px; }
.msg-nick:hover { text-decoration: underline; }
.msg-time { font-size: 11px; color: var(--text-muted); }
.msg-content { color: var(--text-normal); word-break: break-word; white-space: pre-wrap; }
.md-p { margin: 0; }
.md-p:not(:last-child) { margin-bottom: 4px; }
.md-bold { font-weight: 600; }
.md-italic { font-style: italic; }
.md-underline { text-decoration: underline; }
.md-strike { text-decoration: line-through; }
.md-sup { vertical-align: super; font-size: 0.75em; }
.md-sub { vertical-align: sub; font-size: 0.75em; }
.md-code-inline { background: var(--bg-hover); border-radius: var(--radius-sm); padding: 1px 4px; font-family: var(--font-mono); font-size: 0.9em; }
.md-code-block { background: var(--bg-hover); border-radius: var(--radius-sm); padding: 8px; margin: 4px 0; overflow-x: auto; }
.md-code-block code { font-family: var(--font-mono); white-space: pre; }
.md-blockquote { border-left: 2px solid var(--border); padding-left: 8px; margin: 4px 0; color: var(--text-muted); }
.md-hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.md-table { border-collapse: collapse; margin: 4px 0; }
.md-table td, .md-table th { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.md-link { color: var(--accent); text-decoration: underline; }
.msg-edited { font-size: 10px; color: var(--text-muted); margin-left: 4px; }
.reply-block { display: block; width: 100%; text-align: left; margin-bottom: 6px; padding: 4px 8px; background: var(--bg-hover); border-left: 2px solid var(--accent); color: var(--text-muted); font-size: 12px; border-radius: var(--radius-sm); }
.reply-highlight { outline: 2px solid var(--accent); outline-offset: 2px; }
.msg-toolbar { display: none; position: absolute; top: -14px; right: 16px; background: var(--bg-modal); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; gap: 2px; z-index: 5; }
.message:hover .msg-toolbar { display: flex; }
.msg-toolbar button { padding: 4px 6px; border-radius: var(--radius-sm); font-size: 14px; }
.msg-toolbar button:hover { background: var(--bg-hover); }
.edit-input { width: 100%; background: var(--bg-input); border: none; border-radius: var(--radius-sm); color: var(--text-normal); padding: 8px; outline: none; resize: vertical; font-family: inherit; font-size: inherit; min-height: 2.4em; }
.edit-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.confirm-pop { position: absolute; right: 16px; top: 20px; z-index: 20; background: var(--bg-modal); border-radius: var(--radius-sm); padding: 10px; display: flex; gap: 8px; align-items: center; font-size: 13px; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24); }
.btn-danger { background: var(--danger); color: #fff; padding: 4px 10px; border-radius: var(--radius-sm); }

/* ── User hover card ── */
.user-card { position: fixed; width: 240px; background: var(--bg-modal); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; z-index: 50; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24); }
.user-card-banner { height: 60px; }
.user-card-body { padding: 12px; position: relative; }
.user-card .avatar { width: 56px; height: 56px; font-size: 22px; position: absolute; top: -28px; left: 12px; border: 4px solid var(--bg-modal); }
.user-card-name { margin-top: 24px; font-weight: 700; color: var(--text-heading); }
.user-card-disc { color: var(--text-muted); font-size: 13px; }
.user-card-uuid { margin-top: 8px; padding: 6px; background: var(--bg-input); border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: 10px; word-break: break-all; color: var(--text-muted); }

/* ── Typing + input ── */
#typing-indicator { min-height: 20px; padding: 0 16px 2px; font-size: 12px; color: var(--text-muted); font-style: italic; flex-shrink: 0; }
#message-form { flex-shrink: 0; position: relative; }
#reply-composer-slot { margin: 0 16px 8px; }
.reply-composer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-left: 2px solid var(--accent); background: var(--bg-hover); border-radius: var(--radius-sm); }
.reply-composer-text { min-width: 0; font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-composer-cancel { color: var(--text-normal); }
.reply-picker { display: grid; gap: 6px; padding: 8px 0; }
.reply-picker-item { text-align: left; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--bg-hover); color: var(--text-normal); }
.reply-picker-item:hover { background: var(--bg-active); }
.message-context-menu { position: fixed; z-index: 120; display: grid; gap: 4px; min-width: 140px; padding: 6px; background: var(--bg-modal); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24); }
.message-context-menu button { text-align: left; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text-normal); }
.message-context-menu button:hover { background: var(--bg-hover); }
#input-bar { margin: 0 16px 20px; background: var(--bg-input); border-radius: var(--radius-md); display: flex; align-items: flex-end; padding: 0 12px; position: relative; }
#gif-btn { font-weight: 700; font-size: 12px; color: var(--text-muted); border: 2px solid var(--text-muted); border-radius: 4px; padding: 1px 4px; margin-right: 10px; display: none; }
#gif-btn.enabled { display: block; }
#gif-btn:hover { color: var(--text-normal); border-color: var(--text-normal); }
#message-input { flex: 1; background: none; border: none; color: var(--text-normal); padding: 12px 0; outline: none; min-width: 0; resize: none; font-family: inherit; font-size: inherit; max-height: 40vh; overflow-y: auto; }
#message-input::placeholder { color: var(--text-muted); }
#reconnect-banner { position: absolute; top: -28px; left: 0; right: 0; background: var(--warning); color: #000; font-size: 12px; text-align: center; padding: 4px; border-radius: var(--radius-sm); z-index: 10; }

/* ── Members column ── */
#members { background: var(--bg-sidebar); overflow-y: auto; padding: 16px 8px; min-width: 0; }
.member { display: flex; align-items: center; gap: 10px; padding: 5px 8px; border-radius: var(--radius-sm); }
.member:hover { background: var(--bg-hover); }
.member .avatar { width: 28px; height: 28px; font-size: 12px; }
.presence-dot { position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--bg-sidebar); }
.presence-dot.active { background: var(--success); }
.presence-dot.idle { background: var(--warning); }
.presence-dot.offline { background: var(--text-muted); }
.member-nick { font-size: 14px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Modals ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); z-index: 90; }
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: var(--bg-modal); border-radius: var(--radius-md); width: 440px; max-width: 92vw; max-height: 85vh; overflow-y: auto; padding: 20px; }
.modal-box h2 { color: var(--text-heading); font-size: 20px; margin-bottom: 16px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 6px; }
.form-group input[type='text'], .form-group select { width: 100%; background: var(--bg-input); border: none; border-radius: var(--radius-sm); color: var(--text-normal); padding: 10px; outline: none; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; }
.btn { padding: 10px 16px; border-radius: var(--radius-sm); font-size: 14px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-link { color: var(--text-normal); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.settings-devices { padding-top: 10px; border-top: 1px solid var(--border); }
.devices-list { display: grid; gap: 8px; margin-bottom: 10px; }
.device-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--bg-input); border-radius: var(--radius-sm); padding: 10px; }
.device-row-text { min-width: 0; color: var(--text-normal); font-size: 13px; line-height: 1.4; }
.devices-hint { color: var(--text-muted); font-size: 12px; min-height: 18px; margin-bottom: 8px; }
.devices-link-slot { margin-bottom: 10px; }
.identity-actions { display: flex; gap: 8px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab { padding: 6px 12px; border-radius: var(--radius-sm); color: var(--text-muted); }
.tab.active { background: var(--bg-active); color: var(--text-heading); }

/* ── Toasts ── */
#toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--bg-modal); color: var(--text-normal); border-left: 4px solid var(--accent); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 14px; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24); }
.toast.error { border-left-color: var(--danger); }

/* ── Landing ── */
#landing { height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; }
#landing h1 { color: var(--text-heading); font-size: 40px; letter-spacing: 2px; }
#landing p { color: var(--text-muted); }
#landing .error { color: var(--danger); font-size: 13px; }
#join-form { display: flex; gap: 8px; }
#node-input { width: 320px; background: var(--bg-input); border: none; border-radius: var(--radius-sm); color: var(--text-normal); padding: 12px; outline: none; }
#join-btn { background: var(--accent); color: var(--on-accent); padding: 12px 20px; border-radius: var(--radius-sm); font-weight: 600; }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ── Mobile: single column + overlay drawers ── */
@media (max-width: 767px) {
  #app { grid-template-columns: 1fr; }
  #rail, #sidebar, #members, .divider { display: none; }
  #app.drawer-left-open #rail { display: flex; position: fixed; left: 0; top: 0; bottom: 0; width: 72px; z-index: 60; }
  #app.drawer-left-open #sidebar { display: flex; position: fixed; left: 72px; top: 0; bottom: 0; width: 240px; z-index: 60; }
  #app.drawer-right-open #members { display: block; position: fixed; right: 0; top: 0; bottom: 0; width: 240px; z-index: 60; }
  #drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 55; }
}

/* ── Reactions ── */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-badge { display: inline-flex; align-items: center; gap: 5px; background: var(--bg-input); border: 1px solid transparent; border-radius: var(--radius-md); padding: 2px 8px; font-size: 13px; }
.reaction-badge:hover { border-color: var(--text-muted); }
.reaction-badge.mine { background: color-mix(in srgb, var(--accent) 25%, transparent); border-color: var(--accent); }
.reaction-count { color: var(--text-muted); font-size: 12px; }
.emoji-picker { position: fixed; z-index: 80; display: flex; gap: 4px; background: var(--bg-modal); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 6px; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24); }
.emoji-picker button { font-size: 18px; padding: 4px; border-radius: var(--radius-sm); }
.emoji-picker button:hover { background: var(--bg-hover); }

/* ── GIFs ── */
.gif-message { max-width: 320px; max-height: 240px; border-radius: var(--radius-md); display: block; margin-top: 2px; }
.gif-picker { position: absolute; bottom: 100%; left: 16px; right: 16px; margin-bottom: 8px; background: var(--bg-modal); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px; z-index: 40; }
.gif-picker input { width: 100%; background: var(--bg-input); border: none; border-radius: var(--radius-sm); color: var(--text-normal); padding: 8px 10px; outline: none; margin-bottom: 8px; }
.gif-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; max-height: 260px; overflow-y: auto; }
.gif-result { padding: 0; border-radius: var(--radius-sm); overflow: hidden; }
.gif-result img { width: 100%; display: block; }
.gif-result:hover { outline: 2px solid var(--accent); }

/* ── Link previews ── */
.link-preview { margin-top: 6px; padding: 10px 12px; background: var(--bg-sidebar); border-left: 4px solid var(--accent); border-radius: var(--radius-sm); max-width: 440px; display: flex; flex-direction: column; gap: 4px; }
.preview-site { font-size: 11px; color: var(--text-muted); }
.preview-title { color: var(--text-link); font-weight: 600; text-decoration: none; }
.preview-title:hover { text-decoration: underline; }
.preview-desc { font-size: 13px; color: var(--text-normal); }
.preview-image { max-width: 100%; max-height: 200px; border-radius: var(--radius-sm); object-fit: cover; }
.link-preview iframe { border: none; max-width: 100%; border-radius: var(--radius-sm); }

/* ── Cold-load skeleton ── */
.skeleton-list { padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 14px; }
.skeleton-row { display: flex; gap: 14px; align-items: flex-start; }
.skeleton-avatar,
.skeleton-line {
  background: linear-gradient(90deg, var(--bg-hover) 0%, color-mix(in srgb, var(--bg-hover) 65%, var(--text-muted)) 50%, var(--bg-hover) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s linear infinite;
}
.skeleton-avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; }
.skeleton-body { flex: 1; display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.skeleton-line { height: 12px; border-radius: 999px; }
.skeleton-line-wide { width: 72%; }
.skeleton-line-mid { width: 56%; }
.skeleton-line-narrow { width: 43%; }
.skeleton-line-short { width: 28%; height: 10px; }
@keyframes skeleton-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}
