:root {
  --bg: #0d1117;
  --surface: #151b23;
  --surface-2: #1c2430;
  --border: #2a3444;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4f8cff;
  --accent-hover: #6ba0ff;
  --danger: #e5534b;
  --danger-bg: rgba(229, 83, 75, 0.12);
  --success: #3fb950;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.mono {
  font-family: var(--mono);
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.brand-name {
  font-weight: 700;
  font-family: var(--mono);
  font-size: 15px;
}

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

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

.identity-pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.identity-pill.active {
  color: var(--text);
  border-color: var(--accent);
}

.workspace {
  display: grid;
  grid-template-columns: 280px 1fr;
  flex: 1;
  min-height: 0;
}

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

.panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.panel:last-child {
  border-bottom: none;
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.handle-display {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

.token-box {
  margin-top: 6px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row-gap {
  display: flex;
  gap: 6px;
}

input[type="text"], textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 13px;
}

input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

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

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--muted);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: rgba(229, 83, 75, 0.35);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(229, 83, 75, 0.22);
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover {
  color: var(--text);
}

.room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 9px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 13px;
}

.room-item:hover {
  background: var(--surface-2);
}

.room-item.active {
  background: rgba(79, 140, 255, 0.16);
  color: #fff;
}

.room-item.deleted {
  color: var(--muted);
  text-decoration: line-through;
}

.main-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.toast {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 20;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.toast.error {
  border-color: var(--danger);
  color: #ffb4b0;
}

.view {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

.room-view {
  max-width: none;
  padding: 0;
  gap: 0;
  overflow: hidden;
}

.hero-card h1 {
  margin: 0 0 6px 0;
  font-size: 24px;
}

.hero-card p {
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.card-header h2 {
  margin: 0 0 4px 0;
  font-size: 16px;
}

.card-header p {
  margin: 0;
}

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

.grid-3 h3 {
  margin: 0 0 4px 0;
  font-size: 14px;
}

.grid-3 p {
  margin: 0;
}

.snippet-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.snippet-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.code-block {
  margin: 0;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  overflow-x: auto;
  color: #c9d1d9;
}

/* Room view */
.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.room-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-title-row h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: 17px;
}

.badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 999px;
}

.badge-live {
  background: rgba(63, 185, 80, 0.15);
  color: var(--success);
  border: 1px solid rgba(63, 185, 80, 0.35);
}

.badge-deleted {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(229, 83, 75, 0.35);
}

.manage-drawer {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.manage-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.manage-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
}

.chip button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}

.chip button:hover {
  color: var(--danger);
}

.inline-form {
  display: flex;
  gap: 6px;
  max-width: 300px;
}

.invite-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.inline-code {
  padding: 4px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}

.banner-danger {
  padding: 10px 20px;
  background: var(--danger-bg);
  border-bottom: 1px solid rgba(229, 83, 75, 0.35);
  color: #ffb4b0;
  font-size: 13px;
}

.message-feed {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
}

.msg-sender {
  font-family: var(--mono);
  font-weight: 600;
}

.msg-seq, .msg-time {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13.5px;
}

.composer {
  display: flex;
  gap: 10px;
  padding: 12px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  align-items: flex-end;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
}

.qr-box {
  display: flex;
  justify-content: center;
  padding: 12px;
  background: #ffffff;
  border-radius: var(--radius);
}

.qr-box img {
  width: 210px;
  height: 210px;
  display: block;
}

.link-code-display {
  text-align: center;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.big-code {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--accent);
}

@media (max-width: 820px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 42vh;
  }
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .brand-sub {
    display: none;
  }
}
