:root {
  --accent: #6366f1;
  --bg: #f9f9f9;
  --bg-side: #f3f3f4;
  --bg-input: #f3f4f6;
  --text: #1a1c1c;
  --text-soft: #474747;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --hover: #e8e8e8;
  --row-hover: rgba(243, 243, 244, 0.5);
  --left-w: 200px;
  --right-w: 220px;
}

body {
  background: var(--bg) !important;
  color: var(--text) !important;
  margin: 0;
}

/* Layout via CSS vars (collapse-friendly) */
#left-bar { width: var(--left-w); background: var(--bg-side); transition: transform 0.2s ease, width 0.2s ease; }
#right-bar { width: var(--right-w); background: var(--bg-side); transition: transform 0.2s ease, width 0.2s ease; }
#main { margin-left: var(--left-w); margin-right: var(--right-w); transition: margin 0.2s ease; }
#topbar {
  left: var(--left-w); right: var(--right-w);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  transition: left 0.2s ease, right 0.2s ease;
}
#inputbar {
  left: var(--left-w); right: var(--right-w);
  background: var(--bg);
  transition: left 0.2s ease, right 0.2s ease;
}

/* Collapsed states */
body.left-hidden { --left-w: 0px; }
body.left-hidden #left-bar { transform: translateX(-100%); pointer-events: none; }
body.left-hidden #left-show { display: block !important; }

body.right-hidden { --right-w: 0px; }
body.right-hidden #right-bar { transform: translateX(100%); pointer-events: none; }

/* Theme: dark */
body.theme-dark {
  --bg: #1a1c1c;
  --bg-side: #141515;
  --bg-input: #2a2c2c;
  --text: #e8e8e8;
  --text-soft: #c4c4c4;
  --text-muted: #8a8a8a;
  --border: #2e2e2e;
  --hover: #242424;
  --row-hover: rgba(255,255,255,0.04);
}
body.theme-dark .request-item { background: #242424; border-color: #2e2e2e; }
body.theme-dark ::-webkit-scrollbar-thumb { background: #2e2e2e; }

/* Theme: sepia */
body.theme-sepia {
  --bg: #f4ecd8;
  --bg-side: #ece2c5;
  --bg-input: #e8dcb8;
  --text: #5b4636;
  --text-soft: #6b5440;
  --text-muted: #8b7355;
  --border: #d6c89a;
  --hover: #e2d4a8;
  --row-hover: rgba(91,70,54,0.05);
}

.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
  user-select: none;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.hidden { display: none !important; }

/* Section labels */
.section-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  opacity: 0.65;
  padding: 0 8px;
  margin-bottom: 6px;
}

/* Sidebar items */
.channel-item, .dm-item {
  padding: 4px 8px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
  border-radius: 4px;
}
.channel-item:hover, .dm-item:hover { background: var(--hover); color: var(--text); }
.channel-item.active, .dm-item.active { background: var(--hover); color: var(--text); font-weight: 500; }
.channel-item .name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-item .delete {
  font-size: 14px !important;
  cursor: pointer;
  opacity: 0;
  color: #ef4444;
  transition: opacity 0.15s;
}
.channel-item:hover .delete { opacity: 0.7; }
.channel-item .delete:hover { opacity: 1; }

.dm-item .dm-avatar {
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.dm-item .name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dm-item .unread {
  background: #ef4444; color: #fff;
  font-size: 9px; border-radius: 999px;
  padding: 0 5px; min-width: 14px; text-align: center;
}
.dm-item .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #d1d5db; flex-shrink: 0;
}
.dm-item.online .dot { background: #22c55e; }

/* Friends list (default compact) */
.friend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}
.friend-item:hover { background: var(--hover); color: var(--text); }
.friend-item .avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
  position: relative;
}
.friend-item .avatar::after {
  content: '';
  position: absolute;
  bottom: -1px; right: -1px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #d1d5db;
  border: 2px solid var(--bg-side);
}
.friend-item.online .avatar::after { background: #22c55e; }
.friend-item .name {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.friend-item .friend-status {
  display: none;
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.7;
}

/* Friends list — Card style */
body.friendstyle-card .friend-item {
  background: var(--bg-input);
  padding: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
body.friendstyle-card .friend-item .friend-status {
  display: block;
  width: 100%;
  padding-left: 30px;
}

/* Online list */
.user-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-muted);
}
.user-item .u-name {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-item .u-channel { font-size: 9px; opacity: 0.7; }
.user-item.me .u-name { color: var(--text); font-weight: 500; }
.user-item .add-btn {
  cursor: pointer;
  font-size: 14px !important;
  opacity: 0;
  color: var(--accent);
  transition: opacity 0.15s;
}
.user-item:hover .add-btn { opacity: 1; }

/* Friend requests */
.request-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11px;
}
.request-item .name { color: var(--text); margin-bottom: 4px; font-weight: 500; }
.request-item .actions { display: flex; gap: 4px; }
.request-item button {
  flex: 1; font-size: 10px; padding: 3px 6px;
  border-radius: 4px; cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  border: none;
}
.request-item .accept { background: #22c55e; color: #fff; }
.request-item .accept:hover { opacity: 0.9; }
.request-item .reject {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
}
.request-item .reject:hover { background: var(--hover); }

.outgoing-item {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 8px; font-size: 11px;
  color: var(--text-muted); opacity: 0.7;
}
.outgoing-item .name {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.outgoing-item .cancel {
  cursor: pointer; font-size: 14px !important;
  color: #ef4444; opacity: 0.6;
}
.outgoing-item .cancel:hover { opacity: 1; }

/* Date / divider */
.divider {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 8px; opacity: 0.3;
}
.divider .line { flex: 1; height: 1px; background: var(--text); }
.divider .label {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.2em; font-weight: 500;
}

/* Message row */
.msg-row {
  display: flex; align-items: baseline; gap: 6px;
  padding: 1px 8px; margin: 0 -8px;
  border-radius: 2px; transition: background 0.15s;
  position: relative;
}
.msg-row:hover { background: var(--row-hover); }
.msg-row.new-sender { margin-top: 10px; }
.msg-row.new-sender:first-child { margin-top: 0; }
.msg-actions {
  position: absolute;
  right: 8px; top: -10px;
  display: none;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  z-index: 5;
}
.msg-row:hover .msg-actions { display: flex; }
.msg-actions button {
  background: transparent; border: none; cursor: pointer;
  padding: 2px 4px; border-radius: 3px;
  color: var(--text-muted);
  display: flex; align-items: center;
}
.msg-actions button:hover { background: var(--hover); color: var(--text); }
.msg-actions button.danger:hover { color: #ef4444; }
.msg-actions .material-symbols-outlined { font-size: 16px !important; }

.msg-row .edited {
  font-size: 9px;
  opacity: 0.5;
  color: var(--text-muted);
  margin-left: 4px;
}

.msg-edit-input {
  flex: 1;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  font-family: inherit;
}
.msg-edit-input:focus { outline: none; border-color: var(--accent); }
.msg-edit-hint {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.6;
  margin-left: 4px;
}
.msg-row .name {
  color: var(--text); font-weight: 500; font-size: 13px; flex-shrink: 0;
}
.msg-row .time {
  font-size: 9px; color: var(--text-muted); opacity: 0.5;
  text-transform: uppercase; flex-shrink: 0;
}
.msg-row .text {
  color: var(--text-soft); font-size: 13px; line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word; word-break: break-word; min-width: 0;
  margin: 0;
}

/* Density */
body.density-compact .msg-row { padding: 1px 8px; }
body.density-cozy    .msg-row { padding: 4px 8px; margin-bottom: 2px; }
body.density-roomy   .msg-row { padding: 8px 8px; margin-bottom: 6px; }

/* Empty state */
.empty-state {
  text-align: center; color: var(--text-muted);
  font-size: 13px; padding: 60px 20px; opacity: 0.7;
}

/* Reply preview above input */
#reply-preview {
  background: var(--bg-input);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}
#reply-preview .who { color: var(--accent); font-weight: 500; }
#reply-preview .snippet {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-soft);
}
#reply-preview .close-btn {
  cursor: pointer;
  font-size: 14px !important;
  opacity: 0.6;
}
#reply-preview .close-btn:hover { opacity: 1; }

/* Image attachment previews (above input) */
#image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  margin-bottom: 6px;
  background: var(--bg-input);
  border-radius: 12px;
}
#image-previews .img-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0,0,0,0.2);
}
#image-previews .img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#image-previews .img-thumb.uploading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  background-image: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
#image-previews .img-thumb .remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 12px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
#image-previews .img-thumb:hover .remove { opacity: 1; }
#image-previews .img-thumb.error { outline: 2px solid #e74c3c; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Drag-over highlight on the input form */
#message-form.drag-over > div:last-of-type {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

/* Images in messages */
.msg-row.has-images { display: block; }
.msg-row.has-images .name,
.msg-row.has-images .time { display: inline; margin-right: 4px; vertical-align: baseline; }
.msg-row.has-images .text { display: inline; margin-left: 4px; }
.msg-row.has-images .reply-quote { display: flex; margin-bottom: 2px; }
.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  max-width: 420px;
}
.msg-images img {
  max-width: 320px;
  max-height: 240px;
  border-radius: 6px;
  cursor: zoom-in;
  display: block;
  background: rgba(0,0,0,0.2);
}

/* Image lightbox */
#image-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
#image-lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  border-radius: 4px;
}

/* Reply quote inside message */
.reply-quote {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
  padding-left: 8px;
  border-left: 2px solid var(--border);
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
}
.reply-quote:hover { color: var(--text); border-left-color: var(--accent); }
.reply-quote .who { color: var(--accent); font-weight: 500; }
.reply-quote .snippet {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.8;
}

.msg-row.has-reply { flex-wrap: wrap; }
.msg-row.has-reply .reply-quote { width: 100%; }

/* Message hover highlights for navigation */
.msg-row.reply-target {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  box-shadow: inset 2px 0 0 var(--accent);
}

@keyframes flash {
  0% { background: color-mix(in srgb, var(--accent) 40%, transparent); }
  100% { background: transparent; }
}
.msg-row.flash { animation: flash 1.2s ease-out; }

/* === Settings panel === */
.settings-tab {
  background: transparent; border: none; cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--text); border-color: var(--accent); }

.settings-input {
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-family: inherit;
}
.settings-input:focus { outline: none; border-color: var(--accent); }

.theme-swatch {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 4px;
  font-size: 10px; cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
}
.theme-swatch:hover { transform: translateY(-1px); }
.theme-swatch.active { box-shadow: 0 0 0 2px var(--accent); }

.accent-swatch, .avatar-swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s;
}
.accent-swatch:hover, .avatar-swatch:hover { transform: scale(1.15); }
.accent-swatch.active, .avatar-swatch.active { border-color: var(--text); }

.density-btn, .friendstyle-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 4px; font-size: 10px;
  color: var(--text-muted); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.density-btn:hover, .friendstyle-btn:hover { background: var(--hover); color: var(--text); }
.density-btn.active, .friendstyle-btn.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

/* Hide online list when toggled off */
body.no-online #user-list-section { display: none; }
