/* shadcn/ui design tokens — zinc base, 0.5rem radius, HSL channel triplets. */
:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --success: 142 71% 45%;
  --radius: 0.5rem;
}

.dark {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 10% 3.9%;
  --card-foreground: 0 0% 98%;
  --popover: 240 10% 3.9%;
  --popover-foreground: 0 0% 98%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 3.7% 15.9%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 0 0% 98%;
  --border: 240 3.7% 15.9%;
  --input: 240 3.7% 15.9%;
  --ring: 240 4.9% 83.9%;
  --success: 142 71% 45%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  border-color: hsl(var(--border));
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Inter, Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

/* ── App shell ─────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-right: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  padding: 16px 12px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-sub {
  color: hsl(var(--muted-foreground));
  font-size: 12px;
}

.section-label {
  padding: 12px 8px 6px;
  color: hsl(var(--muted-foreground));
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.room-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: hsl(var(--foreground));
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.room-btn:hover {
  background: hsl(var(--accent));
}

.room-btn[aria-current='true'] {
  background: hsl(var(--secondary));
  font-weight: 500;
}

.room-hash {
  color: hsl(var(--muted-foreground));
  font-weight: 400;
}

.room-blurb {
  margin-left: auto;
  color: hsl(var(--muted-foreground));
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 96px;
}

.presence-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.presence-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: calc(var(--radius) - 2px);
  color: hsl(var(--muted-foreground));
  font-size: 13px;
}

.presence-row .avatar {
  width: 22px;
  height: 22px;
  font-size: 10px;
}

.presence-you {
  margin-left: auto;
  font-size: 11px;
  color: hsl(var(--muted-foreground));
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid hsl(var(--border));
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-footer .avatar {
  width: 28px;
  height: 28px;
  font-size: 11px;
}

.footer-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Main column ───────────────────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: hsl(var(--background));
}

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 60px;
  padding: 0 20px;
  border-bottom: 1px solid hsl(var(--border));
  flex-shrink: 0;
}

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

.header-sub {
  color: hsl(var(--muted-foreground));
  font-size: 12px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-btn {
  display: none;
}

/* ── Primitives ────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px;
  border: 1px solid hsl(var(--border));
  border-radius: 9999px;
  background: hsl(var(--background));
  color: hsl(var(--muted-foreground));
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background: hsl(var(--muted-foreground));
  flex-shrink: 0;
}

.badge[data-state='live'] {
  color: hsl(var(--foreground));
}

.badge[data-state='live'] .dot {
  background: hsl(var(--success));
  box-shadow: 0 0 0 3px hsl(var(--success) / 0.16);
}

.badge[data-state='connecting'] .dot {
  background: hsl(38 92% 50%);
  animation: pulse 1.4s ease-in-out infinite;
}

.badge[data-state='offline'] .dot {
  background: hsl(var(--destructive));
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 2px);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.btn-primary:hover:not(:disabled) {
  background: hsl(var(--primary) / 0.9);
}

.btn-ghost {
  background: transparent;
  color: hsl(var(--foreground));
}

.btn-ghost:hover {
  background: hsl(var(--accent));
}

.btn-icon {
  width: 36px;
  padding: 0;
}

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

.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9999px;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
  user-select: none;
}

.input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--background));
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
  color: hsl(var(--muted-foreground));
}

.input:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.14);
}

/* ── Messages ──────────────────────────────────────────────────────────── */
.scroller {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 8px;
  scrollbar-width: thin;
  scrollbar-color: hsl(var(--border)) transparent;
}

.scroller::-webkit-scrollbar {
  width: 10px;
}

.scroller::-webkit-scrollbar-thumb {
  background: hsl(var(--border));
  border: 3px solid hsl(var(--background));
  border-radius: 9999px;
}

.msg {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  padding: 3px 0;
  animation: rise 0.18s ease-out;
}

.msg.grouped {
  padding-top: 0;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .msg {
    animation: none;
  }
  .badge[data-state='connecting'] .dot {
    animation: none;
  }
}

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 1px;
}

.msg-author {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
}

.msg-time {
  color: hsl(var(--muted-foreground));
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.msg-text {
  font-size: 14px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.msg-mine .msg-author {
  color: hsl(var(--foreground));
}

.day-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 10px;
  color: hsl(var(--muted-foreground));
  font-size: 11px;
  font-weight: 500;
}

.day-divider::before,
.day-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: hsl(var(--border));
}

.empty {
  display: grid;
  place-items: center;
  gap: 6px;
  height: 100%;
  text-align: center;
  color: hsl(var(--muted-foreground));
}

.empty-title {
  color: hsl(var(--foreground));
  font-weight: 500;
}

/* ── Composer ──────────────────────────────────────────────────────────── */
.composer-wrap {
  padding: 4px 20px 20px;
  flex-shrink: 0;
}

.typing {
  height: 18px;
  padding: 0 2px 2px;
  color: hsl(var(--muted-foreground));
  font-size: 12px;
  font-style: italic;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px;
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  background: hsl(var(--card));
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer:focus-within {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.14);
}

.composer textarea {
  flex: 1;
  max-height: 148px;
  padding: 7px 6px;
  border: 0;
  background: transparent;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
}

.composer textarea:focus {
  outline: none;
}

.composer textarea::placeholder {
  color: hsl(var(--muted-foreground));
}

.hint {
  padding: 6px 2px 0;
  color: hsl(var(--muted-foreground));
  font-size: 11px;
}

kbd {
  padding: 1px 5px;
  border: 1px solid hsl(var(--border));
  border-radius: 4px;
  background: hsl(var(--muted));
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
}

/* ── Dialog ────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: hsl(240 10% 3.9% / 0.8);
  animation: fade 0.15s ease-out;
}

.overlay[hidden] {
  display: none;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.dialog {
  width: 100%;
  max-width: 400px;
  padding: 24px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  box-shadow: 0 10px 15px -3px hsl(0 0% 0% / 0.1), 0 4px 6px -4px hsl(0 0% 0% / 0.1);
  animation: zoom 0.15s ease-out;
}

@keyframes zoom {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
}

.dialog h2 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.dialog p {
  margin: 0 0 18px;
  color: hsl(var(--muted-foreground));
  font-size: 14px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
}

.dialog .btn {
  width: 100%;
  margin-top: 16px;
}

.error-text {
  margin: 8px 0 0;
  color: hsl(var(--destructive));
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 60;
  max-width: 340px;
  padding: 12px 14px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  box-shadow: 0 10px 15px -3px hsl(0 0% 0% / 0.1);
  font-size: 13px;
  animation: rise 0.2s ease-out;
}

.toast[hidden] {
  display: none;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: 264px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: none;
    box-shadow: 0 10px 15px -3px hsl(0 0% 0% / 0.2);
  }

  .menu-btn {
    display: inline-flex;
  }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: hsl(240 10% 3.9% / 0.6);
  }

  .scrim[hidden] {
    display: none;
  }

  .header,
  .scroller {
    padding-left: 14px;
    padding-right: 14px;
  }

  .composer-wrap {
    padding: 4px 14px 14px;
  }

  .room-blurb {
    display: none;
  }
}
