:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --bg-panel: #101318;
  --bg-elevated: #151a21;
  --bg-hover: #1a2029;
  --border: #252b36;
  --border-strong: #323a47;
  --text: #e8eaed;
  --text-muted: #9aa3af;
  --text-dim: #6b7280;
  --accent: #38bdf8;
  --accent-dim: #0e7490;
  --accent-soft: rgba(56, 189, 248, 0.1);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.12);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --bubble: #141920;
  --bubble-bot: #0f1a24;
  --radius: 8px;
  --font: "Inter", "Pretendard", "Apple SD Gothic Neo", system-ui, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

/* ── Splash / Login ── */

.splash {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, #0d1117 0%, #0b0d10 100%);
}

.splash-shell {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-panel);
}

.splash-hero {
  padding: 40px 36px;
  border-right: 1px solid var(--border);
  background:
    linear-gradient(135deg, rgba(56, 189, 248, 0.06) 0%, transparent 55%),
    var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.splash-badge {
  display: inline-flex;
  align-self: flex-start;
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--accent);
}

.splash-logo {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 36px;
  margin-top: 8px;
}

.logo-bar {
  width: 6px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.85;
}

.logo-bar:nth-child(1) { height: 40%; opacity: 0.45; }
.logo-bar:nth-child(2) { height: 72%; }
.logo-bar:nth-child(3) { height: 100%; }

.splash-title {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.splash-tagline {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.splash-features {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.splash-features li {
  position: relative;
  padding-left: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.splash-features li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  width: 6px;
  height: 6px;
  border-radius: 1px;
  background: var(--accent-dim);
}

.splash-footer {
  margin: auto 0 0;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-dim);
}

.splash-card {
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.splash-card-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.splash-card-head p {
  margin: 6px 0 24px;
  font-size: 13px;
  color: var(--text-dim);
}

.splash-form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-transform: none;
}

.field input:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.splash-btn {
  margin-top: 4px;
  padding: 11px 16px;
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #155e75 0%, #0e4f63 100%);
  color: #ecfeff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.splash-btn:hover {
  filter: brightness(1.06);
}

.splash-error {
  margin: 0;
  font-size: 12px;
  color: var(--danger);
}

/* ── App shell ── */

/* App shell — flex column only (do not use grid on .app) */
.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.35);
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar-sub {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 24px;
  flex: 1;
  min-width: 0;
}

.topbar-pill {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--success);
  padding: 4px 8px;
  border: 1px solid rgba(52, 211, 153, 0.25);
  border-radius: 4px;
  background: var(--success-soft);
  white-space: nowrap;
}

.topbar-meta {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  margin-left: auto;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}

.logout-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 6px;
}

.content-toolbar {
  display: flex;
  gap: 10px;
  padding: 12px 20px 0;
  align-items: center;
  border-bottom: 1px solid transparent;
}

.search-input,
.select {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.select-compact {
  min-width: 88px;
  padding: 6px 8px;
  font-size: 11px;
}

.select {
  width: auto;
  min-width: 128px;
  flex-shrink: 0;
}

.search-input {
  margin: 0 12px 8px;
}

.content-toolbar .search-input {
  margin: 0;
  flex: 1;
}

.search-input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.message-room {
  font-family: var(--mono);
  color: var(--text-dim);
  font-size: 10px;
}

.status-card {
  margin: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  flex-shrink: 0;
}

.card-head,
.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.label,
.section-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.section-title {
  padding: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--mono);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.pill::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 1px;
  background: currentColor;
}

.pill.connected {
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid rgba(52, 211, 153, 0.2);
}

.pill.disconnected,
.pill.unknown {
  color: var(--warning);
  background: var(--warning-soft);
  border: 1px solid rgba(251, 191, 36, 0.2);
}

.pill.error {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-panel);
}

.stat-value {
  font-size: 17px;
  font-weight: 600;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-meta {
  margin: 10px 0 0;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text-dim);
  line-height: 1.5;
}

.sidebar-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.room-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 12px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.room-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 10px;
  border-radius: 6px;
  cursor: pointer;
  display: grid;
  gap: 4px;
  border: 1px solid transparent;
}

.room-item:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}

.room-item.active {
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.25);
}

.room-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.room-id {
  font-size: 12px;
  font-weight: 500;
  font-family: var(--mono);
}

.room-count {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text-dim);
}

.room-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-time {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text-dim);
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.main-header,
.content-toolbar {
  flex-shrink: 0;
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}

.main-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.room-meta {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.tab.active {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.panel {
  display: none;
  flex: 1;
  min-height: 0;
}

.panel.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  -webkit-overflow-scrolling: touch;
}

.feed-head,
.feed-row {
  display: grid;
  grid-template-columns: 148px 88px 120px 1fr;
  gap: 12px;
  align-items: start;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.feed-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-panel);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.feed-row {
  background: var(--bg);
}

.feed-row:hover {
  background: var(--bg-hover);
}

.feed-row.bot {
  background: rgba(56, 189, 248, 0.04);
}

.feed-time,
.feed-channel,
.feed-author,
.feed-body {
  min-width: 0;
}

.feed-time,
.feed-channel {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

.feed-author {
  font-weight: 500;
  color: var(--text-muted);
}

.author-link {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 500;
  color: var(--accent);
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(56, 189, 248, 0.35);
  text-underline-offset: 2px;
}

.author-link:hover,
.author-link.active {
  color: #7dd3fc;
  text-decoration-color: currentColor;
}

.author-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.author-filter-label {
  font-size: 12px;
  color: var(--accent);
  font-family: var(--mono);
}

.author-filter-clear {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.author-filter-clear:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.feed-row.bot .feed-author {
  color: var(--accent);
}

.feed-body {
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.message {
  max-width: 78%;
  display: grid;
  gap: 4px;
}

.message-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text-dim);
}

.message-author {
  color: var(--text-muted);
  font-weight: 500;
  font-family: var(--font);
  font-size: 11px;
}

.message-bubble {
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--bubble);
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.bot .message-bubble {
  background: var(--bubble-bot);
  border-color: rgba(56, 189, 248, 0.2);
}

.message.bot .message-author {
  color: var(--accent);
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}

.outbox-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 20px 24px;
  display: grid;
  gap: 8px;
  align-content: start;
  -webkit-overflow-scrolling: touch;
}

.outbox-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--bg-panel);
}

.outbox-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text-dim);
}

.outbox-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.outbox-status {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.outbox-status.sent {
  color: var(--success);
  background: var(--success-soft);
}

.outbox-status.pending {
  color: var(--warning);
  background: var(--warning-soft);
}

.outbox-status.error {
  color: var(--danger);
  background: var(--danger-soft);
}

@media (max-width: 1100px) {
  .feed-head,
  .feed-row {
    grid-template-columns: 120px 72px 1fr;
  }

  .feed-head span:nth-child(3),
  .feed-row .feed-author {
    display: none;
  }
}

@media (max-width: 768px) {
  .splash-shell {
    grid-template-columns: 1fr;
  }

  .splash-hero {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 28px 24px;
  }

  .splash-card {
    padding: 28px 24px;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: 36vh;
  }

  .room-list {
    max-height: 120px;
  }

  .topbar {
    flex-wrap: nowrap;
    height: 52px;
    padding: 0 16px;
  }

  .topbar-status {
    margin-left: auto;
    width: auto;
    order: unset;
    flex: 1;
    justify-content: flex-end;
  }

  .logout-btn {
    margin-left: 12px;
  }
}

/* ── Settings ── */

.settings {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px 28px;
  -webkit-overflow-scrolling: touch;
}

.settings-hint {
  margin: 0 0 16px;
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.settings-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  padding: 16px;
}

.settings-title {
  margin: 0 0 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.settings-card .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.settings-card .field span {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.settings-card input[type='text'],
.settings-card input[type='password'],
.settings-card input[type='number'],
.settings-card select,
.settings-card textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.settings-card textarea {
  resize: vertical;
  min-height: 88px;
  font-family: inherit;
  line-height: 1.45;
}

.field-check {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
}

.field-check input {
  width: auto;
}

.field-hint {
  margin: -4px 0 12px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
}

.settings-rules {
  margin-bottom: 16px;
}

.settings-rules-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.rules-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.rules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.rules-table th,
.rules-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.rules-table th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  background: var(--bg);
}

.rules-table input,
.rules-table select {
  width: 100%;
  min-width: 72px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

.rules-table input[type='checkbox'] {
  width: auto;
  min-width: 0;
}

.settings-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.settings-status {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.btn-primary,
.btn-secondary {
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-dim);
}

.btn-primary:hover {
  background: rgba(56, 189, 248, 0.18);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.btn-icon {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}

.btn-icon:hover {
  color: var(--danger);
}

@media (max-width: 900px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}
