/* ============================================================================
   VinceAI — ChatGPT-style interface
   Own code, own branding. Layout, spacing, radii and typography follow the
   familiar chat-app pattern: 260px rail, centred 768px column, pill composer.
   ============================================================================ */

:root {
  --rail: 260px;
  --column: 768px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 26px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --t-fast: 120ms var(--ease);
  --t-med: 220ms var(--ease);
}

html[data-theme="dark"] {
  --bg: #212121;
  --rail-bg: #171717;
  --rail-hover: #2b2b2b;
  --rail-active: #2f2f2f;
  --text: #ececec;
  --text-2: #cdcdcd;
  --muted: #b4b4b4;
  --faint: #8f8f8f;
  --border: rgba(255, 255, 255, 0.14);
  --border-soft: rgba(255, 255, 255, 0.08);
  --composer: #303030;
  --composer-border: transparent;
  --bubble: #303030;
  --code-head: #2f2f2f;
  --code-body: #0d0d0d;
  --brand: #46d68d;
  --brand-soft: rgba(70, 214, 141, 0.16);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  --overlay: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #ffffff;
  --rail-bg: #f9f9f9;
  --rail-hover: #ececec;
  --rail-active: #e8e8e8;
  --text: #0d0d0d;
  --text-2: #2f2f2f;
  --muted: #5d5d5d;
  --faint: #8f8f8f;
  --border: rgba(0, 0, 0, 0.12);
  --border-soft: rgba(0, 0, 0, 0.07);
  --composer: #f4f4f4;
  --composer-border: rgba(0, 0, 0, 0.06);
  --bubble: #f4f4f4;
  --code-head: #f1f1f1;
  --code-body: #fafafa;
  --brand: #0f9d63;
  --brand-soft: rgba(15, 157, 99, 0.12);
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.12);
  --overlay: rgba(0, 0, 0, 0.35);
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
a:hover { opacity: 0.85; }

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; border-radius: 6px; }
::selection { background: var(--brand-soft); }

* { scrollbar-width: thin; scrollbar-color: rgba(128, 128, 128, 0.35) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: rgba(128, 128, 128, 0.3); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(128, 128, 128, 0.55); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================== App shell ============================== */
.app {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  height: 100dvh;
}

/* ============================== Sidebar ============================== */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--rail-bg);
  padding: 0 8px 8px;
  z-index: 40;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  height: 56px;
  padding: 0 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  max-width: 100%;
  transition: background var(--t-fast);
}
.brand:hover { background: var(--rail-hover); }
.brand-logo { width: 24px; height: 24px; display: grid; place-items: center; }
.brand-logo svg { width: 24px; height: 24px; stroke: none; }
.brand-logo img { width: 24px; height: 24px; display: block; }
.brand-mark-dark { display: none; }
[data-theme="dark"] .brand-mark-light { display: none; }
[data-theme="dark"] .brand-mark-dark { display: block; }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.brand-name b { color: #26a9f2; font-weight: inherit; }
.brand-caret { width: 16px; height: 16px; color: var(--faint); margin-left: -2px; }

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 2px 6px;
}

.rail-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  color: var(--text-2);
  transition: background var(--t-fast), color var(--t-fast);
  flex: none;
}
.rail-btn:hover { background: var(--rail-hover); color: var(--text); }
.rail-btn svg { width: 18px; height: 18px; }

.rail-search { flex: 1; min-width: 0; }
.rail-search[hidden] { display: none; }
.rail-search input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  font-size: 13.5px;
  outline: none;
}
.rail-search input::placeholder { color: var(--faint); }

.sidebar-section { display: flex; flex-direction: column; min-height: 0; }
.sidebar-section.grow { flex: 1; }

.section-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--faint);
  padding: 10px 10px 6px;
  letter-spacing: 0.01em;
}

.side-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: 4px;
}

.side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  font-size: 14px;
  color: var(--text-2);
  text-align: left;
  width: 100%;
  transition: background var(--t-fast), color var(--t-fast);
}
.side-item svg { width: 18px; height: 18px; color: var(--faint); transition: color var(--t-fast); flex: none; }
.side-item span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-item:hover { background: var(--rail-hover); color: var(--text); }
.side-item:hover svg { color: var(--text-2); }
.side-item.is-active { background: var(--rail-active); color: var(--text); }
.side-item.is-active svg { color: var(--brand); }

.history-item { position: relative; }
.history-item .more {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--faint);
  opacity: 0;
  transition: opacity var(--t-fast), background var(--t-fast);
}
.history-item:hover .more { opacity: 1; }
.history-item .more:hover { background: var(--rail-active); color: var(--text); }
.history-item .more svg { width: 15px; height: 15px; }
.history-item .more.open { opacity: 1; }
.history-item .t { padding-right: 18px; }

.side-empty {
  padding: 8px 10px;
  font-size: 13px;
  color: var(--faint);
  line-height: 1.5;
}

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 2px 0;
  border-top: 1px solid var(--border-soft);
}

.account-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  transition: background var(--t-fast);
  text-align: left;
}
.account-btn:hover { background: var(--rail-hover); }
.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 12px;
  font-weight: 600;
  flex: none;
}
.account-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.account-name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-plan { font-size: 11.5px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-chev { width: 14px; height: 14px; color: var(--faint); margin-left: auto; }

/* ============================== Main ============================== */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}

/* Overlay for the mobile drawer — never a grid item on desktop. */
.scrim { display: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 52px;
  padding: 0 10px;
  flex: none;
  position: relative;
  z-index: 10;
}

.model-picker {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: var(--r-sm);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  max-width: 60%;
  transition: background var(--t-fast);
}
.model-picker:hover { background: var(--rail-hover); }
.model-picker svg { width: 16px; height: 16px; color: var(--faint); }
.model-picker #model-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  color: var(--text-2);
  transition: background var(--t-fast), color var(--t-fast), opacity var(--t-fast);
}
.icon-btn:hover { background: var(--rail-hover); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.sm svg { width: 17px; height: 17px; }
.icon-btn svg { width: 19px; height: 19px; }

html[data-theme="dark"] .ico-sun { display: none; }
html[data-theme="light"] .ico-moon { display: none; }

.main-body { flex: 1; min-height: 0; display: flex; position: relative; }
.view { display: none; flex: 1; min-height: 0; flex-direction: column; min-width: 0; }
.view.is-active { display: flex; }

/* ============================== Chat scroll ============================== */
.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  scroll-behavior: smooth;
}
.scroll.is-empty { justify-content: center; }

.hero {
  width: 100%;
  max-width: var(--column);
  margin: 0 auto;
  padding: 8px 0 0;
  text-align: center;
  display: none;
  flex-direction: column;
  align-items: center;
}
.hero.is-visible { display: flex; animation: fade var(--t-med) both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.hero-title {
  font-size: 28px;
  line-height: 1.25;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 0 0 22px;
  color: var(--text);
}
.hero-slot { width: 100%; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 22px;
  max-width: 620px;
}
.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13.5px;
  color: var(--text-2);
  background: transparent;
  transition: background var(--t-fast), border-color var(--t-fast);
  text-align: left;
}
.chip:hover { background: var(--rail-hover); }
.chip.is-on {
  background: var(--rail-hover);
  border-color: transparent;
  color: var(--text);
}

.thread {
  width: 100%;
  max-width: var(--column);
  margin: 0 auto;
  padding: 16px 0 28px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* ============================== Messages ============================== */
.msg { display: flex; animation: msgIn 260ms var(--ease) both; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg-user { justify-content: flex-end; }
.msg-user .bubble {
  background: var(--bubble);
  border-radius: 20px;
  padding: 10px 18px;
  max-width: 75%;
  font-size: 16px;
  line-height: 26px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-user .files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-top: 8px; }
.msg-user .images { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-bottom: 8px; }
.msg-user .images img {
  max-width: 220px;
  max-height: 220px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  object-fit: cover;
}

.msg-assistant { width: 100%; flex-direction: column; }
.prose {
  font-size: 16px;
  line-height: 28px;
  color: var(--text);
  overflow-wrap: anywhere;
}
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }
.prose p { margin: 0 0 16px; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  margin: 26px 0 12px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.prose h1 { font-size: 24px; }
.prose h2 { font-size: 20px; }
.prose h3 { font-size: 18px; }
.prose h4 { font-size: 16px; }
.prose ul, .prose ol { margin: 0 0 16px; padding-left: 26px; }
.prose li { margin: 5px 0; }
.prose li::marker { color: var(--muted); }
.prose strong { font-weight: 600; }
.prose a { color: var(--text); text-decoration: underline; }
.prose blockquote {
  margin: 0 0 16px;
  padding-left: 16px;
  border-left: 2px solid var(--border);
  color: var(--text-2);
}
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }
.prose img { max-width: 100%; border-radius: var(--r-md); margin: 8px 0; }

.prose code {
  font-family: var(--mono);
  font-size: 13.5px;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--composer);
}
.prose pre {
  margin: 0 0 18px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-soft);
  overflow: hidden;
  background: var(--code-body);
}
.prose pre .code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px 6px 14px;
  background: var(--code-head);
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--font);
  font-size: 12px;
  color: var(--muted);
}
.prose pre .copy-code {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 5px;
  transition: background var(--t-fast), color var(--t-fast);
}
.prose pre .copy-code:hover { background: rgba(128, 128, 128, 0.18); color: var(--text); }
.prose pre code {
  display: block;
  padding: 14px 16px;
  overflow-x: auto;
  background: none;
  border-radius: 0;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre;
  tab-size: 2;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 18px;
  font-size: 14.5px;
  display: block;
  overflow-x: auto;
}
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.prose th { background: var(--composer); font-weight: 600; }

.msg-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity var(--t-fast);
}
.msg:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.action-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  color: var(--faint);
  transition: background var(--t-fast), color var(--t-fast);
}
.action-btn:hover { background: var(--rail-hover); color: var(--text); }
.action-btn svg { width: 16px; height: 16px; }
.action-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 8px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--faint);
  transition: background var(--t-fast), color var(--t-fast);
}
.action-label:hover { background: var(--rail-hover); color: var(--text); }
.action-label svg { width: 15px; height: 15px; }

.msg-note {
  font-size: 13px;
  color: var(--faint);
  margin-top: 8px;
}

/* thinking + streaming */
.dots { display: inline-flex; align-items: center; gap: 4px; height: 28px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: pulse 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 100% { opacity: 0.3; transform: scale(0.9); } 45% { opacity: 1; transform: scale(1); } }

.caret {
  display: inline-block;
  width: 8px;
  height: 17px;
  vertical-align: -3px;
  margin-left: 2px;
  border-radius: 2px;
  background: var(--text);
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* notices */
.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  max-width: var(--column);
  margin: 0 auto 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-2);
  background: transparent;
}
.notice[hidden] { display: none; }
.notice svg { width: 16px; height: 16px; margin-top: 2px; color: var(--muted); }
.notice.warn { border-color: rgba(214, 120, 60, 0.45); }
.notice b, .notice strong { color: var(--text); }

/* ============================== Composer ============================== */
.composer-wrap {
  width: 100%;
  max-width: var(--column);
  margin: 0 auto;
  padding: 0;
}

.composer {
  position: relative;
  background: var(--composer);
  border: 1px solid var(--composer-border);
  border-radius: var(--r-xl);
  padding: 10px 10px 8px 12px;
  transition: box-shadow var(--t-med), background var(--t-fast);
}
.composer:focus-within { box-shadow: 0 0 0 1px var(--border); }

.composer textarea {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  font-size: 16px;
  line-height: 24px;
  padding: 6px 8px 4px;
  min-height: 28px;
  max-height: 200px;
  overflow-y: auto;
  color: var(--text);
}
.composer textarea::placeholder { color: var(--faint); }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 4px 8px; }
.attachments[hidden] { display: none; }
.attach {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 220px;
  padding: 6px 8px 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
  font-size: 12.5px;
  color: var(--text-2);
}
.attach img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.attach .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach button { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 4px; color: var(--faint); }
.attach button:hover { background: var(--rail-hover); color: var(--text); }
.attach svg { width: 13px; height: 13px; }

.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.composer-left, .composer-right { display: flex; align-items: center; gap: 2px; }

.tool-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-2);
  transition: background var(--t-fast), color var(--t-fast);
}
.tool-btn:hover { background: rgba(128, 128, 128, 0.18); }
.tool-btn.is-on { background: var(--brand-soft); color: var(--brand); }
.tool-btn svg { width: 19px; height: 19px; }

.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-2);
  border: 1px solid var(--border);
  transition: background var(--t-fast), border-color var(--t-fast);
  max-width: 190px;
}
.mode-btn:hover { background: rgba(128, 128, 128, 0.16); }
.mode-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.send-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  transition: opacity var(--t-fast), transform var(--t-fast), background var(--t-fast);
}
.send-btn:hover { opacity: 0.86; }
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.3; cursor: default; }
.send-btn svg { width: 18px; height: 18px; stroke-width: 2.2; }

.fineprint {
  text-align: center;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--faint);
  margin: 10px 0 0;
  padding: 0 12px;
}

.dock { flex: none; padding: 0 16px 14px; background: var(--bg); }

/* ============================== Panes (tools) ============================== */
.pane {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px 40px;
}
.pane-inner { width: 100%; max-width: 820px; margin: 0 auto; }

.pane-head { margin-bottom: 22px; }
.pane-head h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.pane-head h1 .ico { color: var(--brand); }
.pane-head p { margin: 0; color: var(--muted); font-size: 14.5px; max-width: 62ch; }

.card {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  background: transparent;
}
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-size: 15.5px; margin: 0; font-weight: 600; }
.card-head p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field small { font-size: 12px; color: var(--faint); }

.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--r-md);
  padding: 10px 12px;
  font-size: 14.5px;
  color: var(--text);
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.textarea { resize: vertical; min-height: 88px; font-family: inherit; line-height: 1.55; }
.select { cursor: pointer; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }
.row.end { justify-content: flex-end; }
.row.end > * { flex: 0 0 auto; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--t-fast), opacity var(--t-fast), border-color var(--t-fast);
}
.btn:hover { background: var(--rail-hover); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--text); color: var(--bg); border-color: transparent; }
.btn.primary:hover { opacity: 0.88; background: var(--text); }
.btn.ghost { border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--rail-hover); color: var(--text); }
.btn.danger { color: #e05a5a; border-color: rgba(224, 90, 90, 0.4); }
.btn.danger:hover { background: rgba(224, 90, 90, 0.12); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: 0.45; pointer-events: none; }

.segmented { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; border: 1px solid var(--border); }
.segmented button {
  height: 30px;
  padding: 0 13px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
  transition: background var(--t-fast), color var(--t-fast);
}
.segmented button:hover { color: var(--text); }
.segmented button.is-on { background: var(--rail-active); color: var(--text); }

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-soft);
}
.setting:last-child { border-bottom: 0; }
.setting-text strong { display: block; font-size: 14px; font-weight: 500; }
.setting-text span { font-size: 13px; color: var(--muted); }
.setting-ctl { flex: none; display: flex; align-items: center; gap: 8px; }

.switch {
  position: relative;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: rgba(128, 128, 128, 0.35);
  transition: background var(--t-med);
  flex: none;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform var(--t-med);
}
.switch.is-on { background: var(--brand); }
.switch.is-on::after { transform: translateX(16px); }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.badge.ok { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); }
.badge.off { color: #e0a15a; border-color: rgba(224, 161, 90, 0.45); }

.usage { height: 6px; border-radius: 999px; background: var(--rail-active); overflow: hidden; margin-top: 8px; }
.usage i { display: block; height: 100%; border-radius: 999px; background: var(--brand); transition: width var(--t-med); }

.empty-mini { padding: 18px 4px; font-size: 13.5px; color: var(--faint); text-align: center; }

/* live status */
.live-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px; }
.stat .k { font-size: 12px; color: var(--faint); margin-bottom: 4px; }
.stat .v { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.stat .v.small { font-size: 14px; font-weight: 500; }

.server-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.server-icon { width: 52px; height: 52px; border-radius: var(--r-sm); border: 1px solid var(--border); image-rendering: pixelated; background: var(--rail-active); }
.server-title { flex: 1; min-width: 0; }
.server-title strong { display: block; font-size: 16px; font-weight: 600; }
.server-title span { font-size: 13px; color: var(--muted); }
.status-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.status-dot i { width: 8px; height: 8px; border-radius: 50%; background: #8f8f8f; }
.status-dot.online i { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18); }
.status-dot.offline i { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.16); }

.player-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.player {
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--rail-active);
  color: var(--text-2);
}
.motd { font-family: var(--mono); font-size: 13px; color: var(--text-2); white-space: pre-wrap; word-break: break-word; }

/* news */
.news-list { display: flex; flex-direction: column; gap: 10px; }
.news-item {
  display: flex;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: background var(--t-fast), border-color var(--t-fast);
  text-decoration: none;
  color: inherit;
}
.news-item:hover { background: var(--rail-hover); text-decoration: none; opacity: 1; }
.news-item img { width: 96px; height: 62px; border-radius: var(--r-sm); object-fit: cover; flex: none; background: var(--rail-active); }
.news-body { min-width: 0; flex: 1; }
.news-body strong { display: block; font-size: 14.5px; font-weight: 600; margin-bottom: 3px; }
.news-body p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.news-meta { font-size: 12px; color: var(--faint); margin-top: 6px; display: flex; gap: 8px; }

.skeleton { border: 1px solid var(--border-soft); border-radius: var(--r-md); padding: 14px; }
.skeleton .bar { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--rail-active) 25%, var(--rail-hover) 50%, var(--rail-active) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; margin-bottom: 8px; }
.skeleton .bar:nth-child(2) { width: 60%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* mod creator */
.mod-files { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.mod-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: 12.5px;
  cursor: pointer;
}
.mod-file:hover { background: var(--rail-hover); }
.mod-file .path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mod-file .size { color: var(--faint); }
pre.big {
  margin: 12px 0 0;
  padding: 14px 16px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  background: var(--code-body);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  max-height: 320px;
  overflow: auto;
  white-space: pre;
}
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); }
.check input { accent-color: var(--brand); width: 16px; height: 16px; }

/* image studio (modal) */
.img-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 14px; }
.img-card { position: relative; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--border); aspect-ratio: 1; background: var(--rail-active); }
.img-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-card .pick {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity var(--t-fast);
}
.img-card:hover .pick { opacity: 1; }

/* ============================== Toasts / modals ============================== */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 300;
  pointer-events: none;
  width: min(92vw, 440px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: toastIn 200ms var(--ease) both;
  max-width: 100%;
}
.toast svg { width: 16px; height: 16px; }
.toast.err { background: #b4302f; color: #fff; }
.toast.leaving { animation: toastOut 140ms var(--ease) both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }

.modal-root { position: fixed; inset: 0; z-index: 200; display: none; }
.modal-root.is-open { display: block; }
.modal-scrim { position: absolute; inset: 0; background: var(--overlay); animation: fade 140ms var(--ease) both; }
.modal {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 520px);
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 22px;
  animation: modalIn 200ms var(--ease) both;
}
@keyframes modalIn { from { opacity: 0; transform: translate(-50%, -48%) scale(0.98); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.modal.wide { width: min(94vw, 560px); }
.modal h3 { margin: 0 0 6px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.modal p.sub { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal .close-x { position: absolute; top: 12px; right: 12px; }

/* ChatGPT-style settings dialog */
.modal.settings {
  width: min(96vw, 820px);
  height: min(88dvh, 620px);
  padding: 0;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  overflow: hidden;
}
.settings-nav { border-right: 1px solid var(--border-soft); padding: 18px 10px; display: flex; flex-direction: column; gap: 2px; }
.settings-nav h3 { font-size: 15px; margin: 0 10px 12px; font-weight: 600; }
.settings-nav button {
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  font-size: 14px;
  color: var(--text-2);
  transition: background var(--t-fast);
}
.settings-nav button:hover { background: var(--rail-hover); }
.settings-nav button.is-on { background: var(--rail-active); color: var(--text); }
.settings-body { padding: 22px 22px 26px; overflow-y: auto; }
.settings-body h4 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.settings-body .hint { margin: 0 0 18px; font-size: 13px; color: var(--muted); }

.modal-list { display: flex; flex-direction: column; gap: 2px; margin: 0 -6px; }
.modal-list button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--r-sm);
  text-align: left;
  width: 100%;
  transition: background var(--t-fast);
}
.modal-list button:hover { background: var(--rail-hover); }
.modal-list .m { flex: 1; min-width: 0; }
.modal-list strong { display: block; font-size: 14px; font-weight: 500; }
.modal-list span { font-size: 12.5px; color: var(--muted); }
.modal-list .check-ico { width: 16px; height: 16px; opacity: 0; color: var(--brand); }
.modal-list button.is-on .check-ico { opacity: 1; }

/* ============================== Responsive ============================== */
.only-mobile { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .only-mobile { display: grid; }
  .only-desktop { display: none !important; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 300px);
    transform: translateX(-102%);
    transition: transform var(--t-med);
    box-shadow: none;
  }
  body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: var(--overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-med);
  }
  body.sidebar-open .scrim { opacity: 1; pointer-events: auto; }
  .modal.settings { grid-template-columns: 1fr; height: min(92dvh, 700px); }
  .settings-nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border-soft); padding: 10px; }
  .settings-nav h3 { display: none; }
  .settings-nav button { white-space: nowrap; }
}

@media (max-width: 640px) {
  .topbar { height: 48px; padding: 0 6px; }
  .model-picker { font-size: 16px; }
  .scroll { padding: 0 12px; }
  .thread { gap: 22px; padding-bottom: 20px; }
  .hero-title { font-size: 24px; margin-bottom: 18px; }
  .chips { gap: 6px; margin-top: 18px; }
  .chip { font-size: 13px; padding: 6px 12px; }
  .dock { padding: 0 10px 10px; }
  .composer { border-radius: 24px; padding: 8px 8px 6px 10px; }
  .composer textarea { font-size: 16px; }
  .msg-user .bubble { max-width: 88%; }
  .prose { font-size: 15.5px; line-height: 26px; }
  .prose pre code { font-size: 12.5px; }
  .modal { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; top: 0; left: 0; transform: none; animation: none; }
  .modal.settings { width: 100vw; height: 100dvh; }
  .img-grid { grid-template-columns: repeat(2, 1fr); }
  .news-item img { width: 72px; height: 52px; }
  .pane { padding: 8px 12px 32px; }
  .pane-head h1 { font-size: 20px; }
  .row > * { min-width: 100%; }
}

@supports (padding: env(safe-area-inset-bottom)) {
  .dock { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .sidebar { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .topbar { height: calc(52px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
}

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