:root {
  --bg: #EEF2F0;
  --surface: #FFFFFF;
  --border: #C7D3CE;
  --ink: #14201D;
  --ink-muted: #5C6D68;
  --accent: #0E7C6B;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101614;
    --surface: #182120;
    --border: #33443F;
    --ink: #EAF0EE;
    --ink-muted: #93A29D;
    --accent: #3FD9BC;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 560px;
  height: 80vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 18px;
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.status.connected {
  color: var(--accent);
}

.whoami {
  font-size: 13px;
  font-weight: 600;
}

.header-right button {
  padding: 6px 12px;
  font-size: 12px;
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--border);
}

.header-right button:hover {
  color: var(--ink);
  border-color: var(--ink-muted);
  opacity: 1;
}

.header-right button.danger-link {
  color: #C24545;
  border-color: #C24545;
}

.header-right button.danger-link:hover {
  background: #C24545;
  color: white;
}

.header-right button:disabled {
  opacity: 0.5;
  cursor: default;
}

#messages {
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#messages li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 14px;
}

#messages .time {
  color: var(--ink-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

#messages .author {
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.chat-error {
  min-height: 16px;
  margin: 0;
  padding: 0 20px;
  font-size: 12px;
  color: #C24545;
}

#form {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

#input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

#input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#input:disabled {
  opacity: 0.6;
}

button {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 14px;
  cursor: pointer;
}

button:hover {
  opacity: 0.9;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

.auth {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 28px 24px;
}

.auth h1 {
  font-size: 20px;
  margin: 0;
}

.auth-subtitle {
  margin: 4px 0 20px;
  color: var(--ink-muted);
  font-size: 14px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.auth-form label {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 12px;
}

.auth-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

.auth-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.auth-form button {
  margin-top: 18px;
}

.form-error {
  min-height: 18px;
  margin: 10px 0 0;
  font-size: 13px;
  color: #C24545;
}

.auth-switch {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--ink-muted);
  text-align: center;
}

.auth-switch a {
  color: var(--accent);
}

.admin {
  width: 100%;
  max-width: 860px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 40px auto;
  overflow: hidden;
}

.section-heading {
  margin: 0;
  padding: 16px 20px 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

.section-heading:first-of-type {
  padding-top: 20px;
}

.table-scroll {
  overflow-x: auto;
}

.link-button {
  font-size: 12px;
  color: var(--ink-muted);
  text-decoration: none;
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
}

.link-button:hover {
  color: var(--ink);
  border-color: var(--ink-muted);
}

.admin-note {
  margin: 0;
  padding: 12px 20px;
  min-height: 16px;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  word-break: break-word;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 12px 20px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}

th {
  font-size: 11px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.actions {
  display: flex;
  gap: 8px;
}

.actions button {
  padding: 6px 10px;
  font-size: 12px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
}

.actions button:hover {
  opacity: 1;
  border-color: var(--ink-muted);
}

.actions button.danger {
  color: #C24545;
  border-color: #C24545;
  background: transparent;
}

.actions button.danger:hover {
  background: #C24545;
  color: white;
}

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.conversation-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 20px;
  text-decoration: none;
  color: var(--ink);
  border-bottom: 1px solid var(--border);
}

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

.conversation-name {
  font-weight: 600;
  font-size: 15px;
}

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

.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 14px;
}
