/* ==========================================================================
   ChitChat — foundations, tokens, layout
   ========================================================================== */

:root {
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --brand-a: #6c5ce7;
  --brand-b: #a78bfa;
  --brand-c: #ff6b8a;
  --brand-gradient: linear-gradient(135deg, #6c5ce7 0%, #9b7dff 48%, #ff6b8a 100%);
  --brand-gradient-soft: linear-gradient(135deg, rgba(108, 92, 231, .16), rgba(255, 107, 138, .14));
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-xl: 28px;
  --radius-pill: 999px;
  --topbar-h: 68px;
  --sidebar-w: 256px;
  --rail-w: 324px;
  --transition: 180ms cubic-bezier(.2, .7, .3, 1);
  --max-content: 680px;
}

html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0b0c13;
  --bg-elevated: #10111b;
  --surface: #151623;
  --surface-2: #1a1b2a;
  --surface-3: #222334;
  --surface-hover: #202132;
  --text: #f3f3fa;
  --text-soft: #d6d7e6;
  --muted: #9a9db6;
  --muted-2: #7b7e97;
  --border: #262838;
  --border-strong: #34364b;
  --primary: #8b7bff;
  --primary-strong: #7b6bf6;
  --primary-contrast: #ffffff;
  --primary-soft: rgba(139, 123, 255, .14);
  --accent: #ff7d9a;
  --accent-soft: rgba(255, 125, 154, .14);
  --like: #ff5c7c;
  --dislike: #7ea6ff;
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, .14);
  --warning: #fbbf24;
  --danger: #fb6b71;
  --danger-soft: rgba(251, 107, 113, .14);
  --overlay: rgba(5, 6, 12, .72);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-md: 0 14px 40px rgba(0, 0, 0, .38);
  --shadow-lg: 0 30px 80px rgba(0, 0, 0, .5);
  --glass: rgba(16, 17, 27, .82);
  --skeleton: linear-gradient(90deg, #1c1d2c 25%, #242537 37%, #1c1d2c 63%);
  --ring: rgba(139, 123, 255, .45);
}

html[data-theme='light'] {
  color-scheme: light;
  --bg: #f3f4fb;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f7fc;
  --surface-3: #eef0f8;
  --surface-hover: #f1f2fa;
  --text: #14152a;
  --text-soft: #33344d;
  --muted: #6d7089;
  --muted-2: #8b8ea5;
  --border: #e6e7f2;
  --border-strong: #d5d7e6;
  --primary: #6c5ce7;
  --primary-strong: #5a49d6;
  --primary-contrast: #ffffff;
  --primary-soft: rgba(108, 92, 231, .1);
  --accent: #f2557a;
  --accent-soft: rgba(242, 85, 122, .1);
  --like: #ee3f63;
  --dislike: #4f7fe6;
  --success: #0f9f7f;
  --success-soft: rgba(15, 159, 127, .1);
  --warning: #b7791f;
  --danger: #d83a44;
  --danger-soft: rgba(216, 58, 68, .09);
  --overlay: rgba(18, 19, 33, .46);
  --shadow-sm: 0 1px 2px rgba(20, 21, 42, .06);
  --shadow-md: 0 12px 32px rgba(20, 21, 42, .08);
  --shadow-lg: 0 30px 70px rgba(20, 21, 42, .16);
  --glass: rgba(255, 255, 255, .84);
  --skeleton: linear-gradient(90deg, #eef0f8 25%, #f7f7fc 37%, #eef0f8 63%);
  --ring: rgba(108, 92, 231, .35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 800;
  letter-spacing: -.025em;
  line-height: 1.25;
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

img,
video,
svg {
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

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

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

::selection {
  background: var(--primary);
  color: var(--primary-contrast);
}

/* Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

/* Utilities */
.icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.icon-sm {
  width: 18px;
  height: 18px;
}

.icon-xs {
  width: 15px;
  height: 15px;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: -60px;
  left: 16px;
  z-index: 999;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  transition: top var(--transition);
}

.skip-link:focus {
  top: 12px;
}

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

.small {
  font-size: 12.5px;
}

.text-soft {
  color: var(--text-soft);
}

.hidden,
[hidden] {
  display: none !important;
}

.sr-only:focus {
  position: static;
}

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

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

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.grow {
  flex: 1;
  min-width: 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
  border: 0;
}

.mention {
  color: var(--primary);
  font-weight: 600;
}

.hashtag {
  color: var(--accent);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Boot + config screens
   -------------------------------------------------------------------------- */
.boot-screen,
.config-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 28px;
  background:
    radial-gradient(900px 500px at 20% -10%, rgba(108, 92, 231, .18), transparent 60%),
    radial-gradient(700px 480px at 100% 20%, rgba(255, 107, 138, .12), transparent 60%),
    var(--bg);
}

.boot-word {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.04em;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--brand-gradient);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 22px rgba(108, 92, 231, .35);
  flex-shrink: 0;
}

.brand-mark svg {
  width: 78%;
  height: 78%;
}

.brand-mark-xl {
  width: 76px;
  height: 76px;
  border-radius: 24px;
  animation: float 3s ease-in-out infinite;
}

.brand-mark-xl svg {
  width: 74%;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.config-card {
  width: min(620px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}

.config-card h1 {
  font-size: 26px;
  margin: 20px 0 8px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 21px;
  letter-spacing: -.03em;
}

.setup-steps {
  margin: 20px 0;
  padding-left: 20px;
  color: var(--text-soft);
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 14px;
}

.setup-steps a,
.config-card a {
  color: var(--primary);
}

.setup-steps code,
.config-card code {
  background: var(--surface-3);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: .88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.config-code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.config-code pre {
  margin: 8px 0 0;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.7;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-soft);
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 24px;
  text-align: center;
}

/* --------------------------------------------------------------------------
   Shell layout
   -------------------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  padding: 22px 16px 18px;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: 22px;
  z-index: 30;
}

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

.brand-word {
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -.045em;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: var(--text-soft);
  font-weight: 600;
  font-size: 15px;
  position: relative;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.nav-item.active .nav-icon {
  color: var(--primary);
}

.nav-icon {
  display: inline-flex;
  color: var(--muted);
  transition: color var(--transition);
}

.nav-item:hover .nav-icon {
  color: var(--text);
}

.nav-spark {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand-gradient);
  margin-left: auto;
}

.nav-badge,
.badge-count {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.nav-badge {
  margin-left: auto;
}

.sidebar-create {
  margin-top: 2px;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-me {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background var(--transition);
}

.sidebar-me:hover {
  background: var(--surface-hover);
}

.sidebar-me .me-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-me .me-name {
  font-weight: 700;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-me .me-handle {
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 25;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}

.brand-mobile {
  display: none;
}

.search-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(440px, 46vw);
  padding: 10px 12px 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--muted);
  text-align: left;
  transition: border-color var(--transition), background var(--transition);
}

.search-pill:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.search-placeholder {
  flex: 1;
  font-size: 13.5px;
}

.search-pill kbd {
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
}

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

.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-soft);
  background: transparent;
  transition: background var(--transition), color var(--transition);
  position: relative;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-btn.has-badge .badge-count {
  position: absolute;
  top: 2px;
  right: 0;
  border: 2px solid var(--bg-elevated);
}

.topbar-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  margin-left: 6px;
  padding: 0;
  transition: transform var(--transition);
}

.topbar-avatar:hover {
  transform: scale(1.05);
}

.topbar-avatar .avatar {
  width: 38px !important;
  height: 38px !important;
}

#topbar-search-mobile,
.topbar-settings-btn {
  display: none;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rail-w);
  gap: 26px;
  padding: 0 24px;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  align-items: start;
}

.main-scroll {
  min-width: 0;
  padding: 24px 0 56px;
}

.view {
  width: 100%;
  max-width: var(--max-content);
  margin: 0 auto;
  animation: view-in 260ms ease;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.right-rail {
  position: sticky;
  top: calc(var(--topbar-h) + 24px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 24px;
  max-height: calc(100dvh - var(--topbar-h) - 32px);
  overflow-y: auto;
  scrollbar-width: none;
}

.right-rail::-webkit-scrollbar {
  display: none;
}

.bottom-nav {
  display: none;
}

/* Page headers */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-head h1 {
  font-size: 28px;
}

.page-head p {
  color: var(--muted);
  font-size: 13.5px;
  margin-top: 4px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 26px 0 12px;
}

.section-head h2 {
  font-size: 17px;
  font-weight: 800;
}

.section-head a {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--primary);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
