:root {
  --bg: #0e0e12;
  --surface: #16161d;
  --surface-2: #1e1e28;
  --surface-hi: #262633;
  --border: #2a2a38;
  --text: #e8e6e1;
  --text-dim: #8a8895;
  --text-mute: #5f5d6b;
  --accent: #e8572a;
  --accent-hov: #f06b41;
  --accent-soft: rgba(232, 87, 42, 0.15);
  --gold: #d4a853;
  --teal: #3ec9a7;
  --blue: #5b8def;
  --purple: #9b6dff;
  --pink: #e85d9b;
  --danger: #ef4a4a;
  --warn: #e8a53d;
  --ok: #3ec9a7;
  --info: #5b8def;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hov); }
h1, h2, h3, h4 { font-family: 'Playfair Display', serif; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 0.5em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1rem; }
small, .text-dim { color: var(--text-dim); }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.logo { font-family: 'Playfair Display', serif; font-weight: 800; font-size: 1.4rem; color: var(--text); letter-spacing: -0.02em; }
.logo span { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; }
.topbar-right .user { color: var(--text-dim); }

/* Layout with sidebar */
.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 60px); }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 1.25rem 0.75rem;
}
.sidebar .nav-group { font-size: 0.7rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--text-mute); padding: 0.85rem 0.75rem 0.4rem; }
.sidebar a.nav-link {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.75rem; border-radius: 8px;
  color: var(--text-dim); font-size: 0.93rem; margin-bottom: 2px;
}
.sidebar a.nav-link:hover { background: var(--surface-2); color: var(--text); }
.sidebar a.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.sidebar a.nav-link .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.6; }
.main { padding: 1.75rem 2rem; max-width: 1200px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; margin-bottom: 1.25rem; }
.card-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-title h2, .card-title h3 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) { .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; } .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 600px) { .grid-3, .grid-4 { grid-template-columns: 1fr; } .app-shell { grid-template-columns: 1fr; } .sidebar { display: none; } }

/* Stats */
.stat { background: var(--surface-2); border-radius: 10px; padding: 1rem 1.2rem; border: 1px solid var(--border); }
.stat .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-dim); }
.stat .value { font-family: 'Playfair Display', serif; font-size: 1.75rem; font-weight: 700; margin-top: 0.35rem; }
.stat .trend { font-size: 0.8rem; color: var(--text-dim); margin-top: 0.25rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  background: var(--accent); color: white; border: none; padding: 0.65rem 1.15rem;
  border-radius: 8px; font-family: inherit; font-weight: 500; font-size: 0.92rem;
  cursor: pointer; transition: background 0.15s;
}
.btn:hover { background: var(--accent-hov); color: white; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-hi); color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.82rem; }
.btn-block { width: 100%; justify-content: center; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; margin-bottom: 0.35rem; color: var(--text-dim); font-weight: 500; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 0.65rem 0.85rem; border-radius: 8px; font-family: inherit; font-size: 0.95rem;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-row { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
.help { font-size: 0.8rem; color: var(--text-mute); margin-top: 0.25rem; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table th { text-align: left; font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-dim); padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--border); }
table td { padding: 0.75rem 0.8rem; border-bottom: 1px solid var(--border); }
table tr:last-child td { border-bottom: 0; }
table tr:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* Badges */
.badge { display: inline-block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; padding: 0.3rem 0.65rem; border-radius: 99px; font-weight: 600; }
.badge-ok { background: rgba(62,201,167,0.14); color: var(--ok); }
.badge-warn { background: rgba(232,165,61,0.14); color: var(--warn); }
.badge-bad { background: rgba(239,74,74,0.14); color: var(--danger); }
.badge-info { background: rgba(91,141,239,0.14); color: var(--info); }
.badge-mute { background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); }

/* Alerts */
.alert { padding: 0.85rem 1.1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.93rem; }
.alert-success { background: rgba(62,201,167,0.1); border: 1px solid rgba(62,201,167,0.3); color: var(--ok); }
.alert-error   { background: rgba(239,74,74,0.1); border: 1px solid rgba(239,74,74,0.3); color: var(--danger); }

/* Auth page */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem; background: radial-gradient(circle at 20% 20%, rgba(232,87,42,0.06), transparent 40%), var(--bg); }
.auth-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2rem; }
.auth-card h1 { margin-bottom: 0.25rem; }
.auth-card .sub { color: var(--text-dim); margin-bottom: 1.5rem; font-size: 0.95rem; }
.auth-card .tabs { display: flex; gap: 0; margin-bottom: 1.25rem; border: 1px solid var(--border); border-radius: 8px; padding: 0.25rem; background: var(--surface-2); }
.auth-card .tabs a { flex: 1; text-align: center; padding: 0.5rem; border-radius: 6px; color: var(--text-dim); font-size: 0.9rem; }
.auth-card .tabs a.active { background: var(--accent); color: white; }

/* Landing */
.landing { min-height: 100vh; background: var(--bg); }
.landing-nav { padding: 1.5rem 2rem; display: flex; align-items: center; justify-content: space-between; }
.landing-nav a { color: var(--text-dim); font-size: 0.9rem; margin-left: 1.25rem; }
.landing-nav a.cta { background: var(--accent); color: white; padding: 0.55rem 1.1rem; border-radius: 8px; }
.hero { text-align: center; padding: 5rem 1.5rem 4rem; max-width: 780px; margin: 0 auto; }
.hero .eyebrow { display: inline-block; font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); padding: 0.4rem 0.9rem; border-radius: 99px; margin-bottom: 1rem; }
.hero h1 { font-size: clamp(2.5rem, 6vw, 4.5rem); line-height: 1.05; margin-bottom: 1.2rem; background: linear-gradient(135deg, var(--text) 30%, var(--gold)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.hero p { color: var(--text-dim); font-size: 1.1rem; max-width: 560px; margin: 0 auto 2rem; }
.hero .actions { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }
.features-preview { max-width: 1100px; margin: 0 auto; padding: 3rem 1.5rem 5rem; display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 720px) { .features-preview { grid-template-columns: 1fr; } }
.aud-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2rem; }
.aud-card h3 { margin: 0.5rem 0 0.75rem; }
.aud-card .lbl { font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent); }
.aud-card ul { list-style: none; padding: 0; margin: 0; }
.aud-card li { padding: 0.55rem 0; border-top: 1px solid var(--border); font-size: 0.93rem; color: var(--text-dim); display: flex; gap: 0.6rem; }
.aud-card li:first-child { border-top: 0; }
.aud-card li::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); margin-top: 0.55rem; flex-shrink: 0; }
.aud-card li strong { color: var(--text); font-weight: 600; }
.site-footer { border-top: 1px solid var(--border); padding: 2rem 1.5rem; text-align: center; color: var(--text-dim); font-size: 0.85rem; }
.app-footer { border-top: 1px solid var(--border); padding: 1.5rem 1rem; text-align: center; color: var(--text-mute); font-size: 0.8rem; background: var(--surface); }
.app-footer a { color: var(--text-dim); }
.app-footer a:hover { color: var(--accent); }
.app-footer > div { margin: 0.15rem 0; }

/* Utility */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; }
.text-right { text-align: right; } .text-center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--text-dim); }
.empty h3 { color: var(--text); }

/* Threads */
.thread-list .thread-row { display: block; padding: 1rem; border-bottom: 1px solid var(--border); color: var(--text); }
.thread-list .thread-row:hover { background: var(--surface-2); }
.thread-list .thread-row .preview { color: var(--text-dim); font-size: 0.88rem; margin-top: 0.25rem; }
.msg-list { display: flex; flex-direction: column; gap: 0.85rem; max-height: 500px; overflow-y: auto; padding: 1rem; background: var(--bg); border-radius: 10px; border: 1px solid var(--border); }
.msg-bubble { max-width: 75%; padding: 0.7rem 1rem; border-radius: 12px; font-size: 0.93rem; }
.msg-bubble.me { align-self: flex-end; background: var(--accent); color: white; }
.msg-bubble.them { align-self: flex-start; background: var(--surface-2); color: var(--text); }
.msg-meta { font-size: 0.72rem; color: var(--text-mute); margin-top: 0.2rem; }

/* Lock cards */
.lock-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.2rem; }
.lock-card .lock-meta { display: flex; gap: 1rem; font-size: 0.8rem; color: var(--text-dim); margin-top: 0.35rem; }

/* Code chip */
.code-chip { font-family: 'Courier New', monospace; background: var(--bg); border: 1px solid var(--border); padding: 0.3rem 0.55rem; border-radius: 6px; font-weight: 600; letter-spacing: 0.08em; }
