:root {
  --bg: #0c0e12;
  --panel: #12151c;
  --border: #2a3140;
  --text: #d7dde8;
  --muted: #7d8799;
  --accent: #6ee7b7;
  --accent-dim: #34d399;
  --user: #93c5fd;
  --admin: #fbbf24;
  --danger: #f87171;
  --input: #0a0c10;
  --mono: "Cascadia Code", "SF Mono", "Consolas", "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

a {
  color: var(--accent);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand .prompt {
  color: var(--accent);
}

.brand .name {
  color: var(--text);
}

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

.layout {
  flex: 1;
  display: grid;
  min-height: 0;
}

.layout.user {
  grid-template-rows: auto 1fr auto;
}

.layout.admin {
  grid-template-columns: minmax(220px, 300px) 1fr;
}

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

.sidebar h2 {
  margin: 0;
  padding: 12px 14px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
}

.conv-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  cursor: pointer;
  font: inherit;
}

.conv-item:hover,
.conv-item.active {
  background: #1a2030;
}

.conv-item .title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.conv-item .preview {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-block;
  min-width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(110, 231, 183, 0.6);
}

.main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.banner {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  background: #0f131a;
}

.terminal {
  flex: 1;
  overflow: auto;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(110, 231, 183, 0.03), transparent 120px),
    var(--bg);
}

.line {
  margin: 0 0 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.line .who {
  font-weight: 600;
}

.line.user .who {
  color: var(--user);
}

.line.admin .who {
  color: var(--admin);
}

.line.system .who {
  color: var(--muted);
}

.line .time {
  color: var(--muted);
  font-size: 11px;
  margin-left: 8px;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.composer input,
.composer textarea,
.name-row input,
.login-box input {
  flex: 1;
  background: var(--input);
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
  border-radius: 6px;
  outline: none;
}

.composer textarea {
  resize: none;
  min-height: 44px;
  max-height: 140px;
}

.composer input:focus,
.composer textarea:focus,
.name-row input:focus,
.login-box input:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.25);
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #1b2433;
  color: var(--text);
  padding: 10px 14px;
}

button.primary {
  background: #123528;
  border-color: #1f6b4f;
  color: var(--accent);
}

button.primary:hover {
  background: #164433;
}

button.danger {
  color: var(--danger);
  border-color: #5a2a2a;
  background: #2a1515;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.name-row {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: #0f131a;
}

.login-wrap {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* `hidden` must win over display:grid or login/denied cards stay visible after sign-in */
.login-wrap[hidden],
.layout[hidden],
#chatView[hidden],
#adminView[hidden],
#passcodeView[hidden],
#loginView[hidden],
#deniedView[hidden] {
  display: none !important;
}

.login-box {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-box h1 {
  margin: 0;
  font-size: 18px;
}

.login-box p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.clerk-signin-host {
  width: 100%;
  min-height: 120px;
}

.login-box code {
  color: var(--accent);
  font-size: 12px;
}

#userButton {
  min-width: 32px;
  min-height: 32px;
}

.error {
  color: var(--danger);
  font-size: 12px;
  min-height: 1.2em;
}

.empty {
  color: var(--muted);
  padding: 24px 14px;
}

.admin-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

@media (max-width: 720px) {
  .layout.admin {
    grid-template-columns: 1fr;
    grid-template-rows: 180px 1fr;
  }

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