* {
  box-sizing: border-box;
}

:root {
  --bg: #101010;
  --bg-alt: #181818;
  --bg-header: #222;
  --bg-input: #222;
  --bg-sidebar: #151515;
  --text: #eeeeee;
  --border: #333;
  --accent: #4da3ff;
  --error: #ff6666;
  --info: #66ccff;
  --local: #99ff99;
  --debug-raw: #aaaaaa;
  --debug-numeric: #66ccff;
  --debug-error: #ff6666;
}

:root[data-theme="light"] {
  --bg: #f5f5f5;
  --bg-alt: #ffffff;
  --bg-header: #e0e0e0;
  --bg-input: #eaeaea;
  --bg-sidebar: #f0f0f0;
  --text: #111111;
  --border: #cccccc;
  --accent: #0066cc;
  --error: #cc0000;
  --info: #006699;
  --local: #007733;
  --debug-raw: #666666;
  --debug-numeric: #004c99;
  --debug-error: #cc0000;
}

body {
  margin: 0;
  padding: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.25s ease, color 0.25s ease;
}

header {
  background: var(--bg-header);
  padding: 0.4rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
}

header label {
  font-size: 0.9rem;
}

header input[type="text"] {
  padding: 0.25rem 0.5rem;
  min-width: 150px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
}

header button {
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 0.85rem;
}

header button:hover {
  border-color: var(--accent);
}

#status {
  margin-left: auto;
  font-size: 0.8rem;
  opacity: 0.9;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

#main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#center {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border);
}

#tabs {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
  overflow-x: auto;
  white-space: nowrap;
}

#channel-tabs {
  display: inline-flex;
}

.tab {
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  border: none;
  background: transparent;
  font-size: 0.85rem;
  color: var(--text);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.tab.active {
  background: var(--bg);
  font-weight: 600;
  color: var(--accent);
}

.tab-unread::after {
  content: "•";
  margin-left: 4px;
  color: var(--accent);
}

#debug-tab {
  margin-left: auto;
  border-left: 1px solid var(--border);
  border-right: none;
}

#views {
  flex: 1;
  position: relative;
  min-height: 0;
}

.view {
  position: absolute;
  inset: 0;
  padding: 0.5rem 0.75rem;
  background: #000;
  overflow-y: auto;
  font-family: monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  display: none;
  transition: background 0.25s ease, color 0.25s ease;
}

.view.active {
  display: block;
}

:root[data-theme="light"] .view {
  background: #fdfdfd;
}

#sidebar {
  width: 180px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
}

#sidebar h2 {
  margin: 0;
  padding: 0.5rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

#userlist {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem;
  font-size: 0.8rem;
}

#userlist ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

#userlist li {
  padding: 0.12rem 0;
  border-bottom: 1px dotted var(--border);
}

#input-area {
  background: var(--bg-input);
  padding: 0.4rem 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border-top: 1px solid var(--border);
}

#message-input {
  flex: 1;
  padding: 0.35rem 0.5rem;
  font-family: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
}

#send-button {
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 0.85rem;
}

#send-button:hover {
  border-color: var(--accent);
}

.log-info {
  color: var(--info);
}
.log-error {
  color: var(--error);
}
.log-local {
  color: var(--local);
}

/* Debug formatting */
#debug-log .dbg-raw {
  color: var(--debug-raw);
}
#debug-log .dbg-numeric {
  color: var(--debug-numeric);
}
#debug-log .dbg-error {
  color: var(--debug-error);
  font-weight: 600;
}

/* Icon theming */
.icon-accent {
  color: var(--accent);
}
.icon-error {
  color: var(--error);
}
.icon-text {
  color: var(--text);
}

button i:hover {
  filter: brightness(1.35);
}

/* Screen-reader only text (for icon-only UI) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Settings dropdown styling */
#settings-menu {
  position: relative;
}

#settings-menu summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--border);
  padding: 0.25rem 0.4rem;
  background: var(--bg-alt);
  display: inline-flex;
  align-items: center;
}

#settings-menu[open] summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

#settings-menu summary::-webkit-details-marker {
  display: none;
}

.settings-panel {
  position: absolute;
  right: 0;
  margin-top: 0.1rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  min-width: 230px;
  z-index: 10;
}

.settings-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0;
}

.settings-item input[type="checkbox"] {
  margin: 0;
}

/* Nick / message formatting */
.nick {
  font-weight: 600;
}
.nick::before {
  content: "<";
  margin-right: 1px;
}
.nick::after {
  content: ">";
  margin-left: 1px;
}

.log-action {
  font-style: italic;
}

.mention {
  background-color: rgba(255, 255, 0, 0.18);
  padding: 0 2px;
  border-radius: 3px;
}

/* Links in logs */
.view a {
  color: var(--accent);
  text-decoration: underline;
}

/* Compact layout */
body.compact {
  font-size: 0.85rem;
}

body.compact header,
body.compact #input-area {
  padding: 0.25rem 0.4rem;
}

body.compact #message-input {
  font-size: 0.8rem;
}
