:root {
  --bg: #0f1419;
  --bg-elevated: #161b22;
  --bg-panel: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #238636;
  --accent-hover: #2ea043;
  --accent-soft: rgba(35, 134, 54, 0.15);
  --danger: #f85149;
  --danger-soft: rgba(248, 81, 73, 0.12);
  --link: #58a6ff;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow: hidden;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* Auth */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background:
    radial-gradient(circle at top right, rgba(35, 134, 54, 0.12), transparent 40%),
    var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.brand.compact { margin-bottom: 0; }

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #1f6feb);
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
}

.brand p, .brand .muted {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
}

.auth-form label {
  display: block;
  margin: 1rem 0 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-form input {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  font-size: 1rem;
}

.auth-form button { margin-top: 1.25rem; width: 100%; }

.alert {
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.alert-error {
  background: var(--danger-soft);
  border: 1px solid rgba(248, 81, 73, 0.35);
  color: #ffb4af;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.95rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--bg-panel);
  text-decoration: none;
}

.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.78rem; }
.btn-block { width: 100%; }

/* Topbar */
.topbar {
  border-bottom: 1px solid var(--border);
  background: rgba(22, 27, 34, 0.95);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.pill {
  font-size: 0.78rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--muted);
}

.pill-accent {
  background: var(--accent-soft);
  border-color: rgba(35, 134, 54, 0.35);
  color: #7ee787;
}

.copyright {
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.7;
  white-space: nowrap;
  padding-left: 0.75rem;
}

/* Layout */
.layout {
  max-width: 1600px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1rem;
  padding: 1rem 1.25rem 1rem;
  height: calc(100vh - 64px);
  min-height: 0;
}

.sidebar {
  overflow: auto;
  min-height: 0;
}

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

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.panel h2 {
  margin: 0 0 0.85rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.filter-form label {
  display: block;
  margin: 0.65rem 0 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.filter-form input,
.filter-form select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
}

.filter-form .checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.85rem;
  color: var(--text);
}

.filter-form .checkbox input { width: auto; }

.filter-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.1rem;
}

.filter-actions .btn { flex: 1; }

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

.room-item {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}

.room-item:hover, .room-item.active {
  background: var(--bg-panel);
  text-decoration: none;
}

.room-name { font-size: 0.9rem; }
.room-meta { font-size: 0.75rem; color: var(--muted); }

/* Nav + stats */
.nav-panel { padding-bottom: 0.75rem; }

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-link {
  display: block;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
  font-size: 0.9rem;
}

.nav-link:hover {
  background: var(--bg-panel);
  text-decoration: none;
}

.nav-link.active {
  background: var(--accent-soft);
  color: #7ee787;
  border: 1px solid rgba(35, 134, 54, 0.35);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin: 0;
}

.stats-grid > div {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
}

.stats-grid dt {
  margin: 0;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stats-grid dd {
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.stats-wide { grid-column: 1 / -1; }

.path-code {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  word-break: break-all;
}

/* Table — only tbody area scrolls; header stays fixed inside .table-wrap */
.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.data-table,
.messages-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 960px;
}

.data-table th,
.data-table td,
.messages-table th,
.messages-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  text-align: left;
}

.data-table thead th,
.messages-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  z-index: 2;
  box-shadow: 0 1px 0 var(--border);
}

.data-table tbody tr:hover,
.messages-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.col-time { width: 170px; white-space: nowrap; font-size: 0.82rem; color: var(--muted); }
.col-user { width: 110px; }
.col-room { width: 180px; }

.user-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #7ee787;
  font-size: 0.78rem;
  font-weight: 600;
}

.message-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.system-event {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.event-type {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #d2a8ff;
}

.params {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
}

.tiny-link {
  display: inline-block;
  margin-top: 0.2rem;
  font-size: 0.72rem;
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.file-item {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
}

.file-name { font-weight: 600; font-size: 0.85rem; display: block; }
.file-meta { font-size: 0.72rem; color: var(--muted); display: block; margin-top: 0.15rem; }
.file-actions { display: flex; gap: 0.35rem; margin-top: 0.45rem; flex-wrap: wrap; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem !important;
}

@media (max-width: 960px) {
  body { overflow: auto; }
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 64px);
  }
  .sidebar { order: 2; max-height: none; }
  .table-wrap { max-height: 70vh; }
}
