/* ==========================================================================
   SmartChat — design system stylesheet
   Hand-written. No build step, no framework, no external fonts.
   Sections: tokens/themes · reset · typography · utilities · layout shell
             sidebar · topbar · cards · stats · forms · buttons · tables
             lists · badges · alerts · toast · modal · progress/spinner
             dropzone · chat · markdown · code/snippet · tabs/pills · chart
             auth · responsive
   ========================================================================== */

/* ===== tokens / themes ===== */

:root {
  color-scheme: light;

  /* surfaces */
  --bg: #f7f8fa;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #e9eaee;

  /* lines */
  --border: #e4e6eb;
  --border-strong: #cfd3da;

  /* ink */
  --text: #14161a;
  --text-muted: #5c6370;
  --text-faint: #8b919c;

  /* accent */
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-fg: #ffffff;
  --accent-soft: rgba(79, 70, 229, 0.1);

  /* status */
  --success: #15803d;
  --success-soft: rgba(21, 128, 61, 0.1);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --info: #0369a1;
  --info-soft: rgba(3, 105, 161, 0.1);

  /* geometry */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --sidebar-w: 260px;

  /* elevation */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 8px 24px -12px rgba(16, 24, 40, 0.18);
  --shadow-lg: 0 24px 48px -16px rgba(16, 24, 40, 0.28), 0 2px 6px rgba(16, 24, 40, 0.06);

  /* type */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", "Courier New", monospace;
}

/* Dark theme tokens, shared by media query and explicit attribute. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #0b0c0f;
    --bg-elevated: #14161a;
    --surface: #14161a;
    --surface-2: #1b1e24;
    --surface-3: #23272f;

    --border: #262a32;
    --border-strong: #363b45;

    --text: #f2f4f7;
    --text-muted: #a2a9b6;
    --text-faint: #6f7785;

    --accent: #6366f1;
    --accent-hover: #7c7ff5;
    --accent-fg: #ffffff;
    --accent-soft: rgba(99, 102, 241, 0.18);

    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, 0.14);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, 0.14);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.16);
    --info: #60a5fa;
    --info-soft: rgba(96, 165, 250, 0.16);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.55), 0 12px 28px -16px rgba(0, 0, 0, 0.8);
    --shadow-lg: 0 28px 60px -20px rgba(0, 0, 0, 0.85), 0 2px 8px rgba(0, 0, 0, 0.5);
  }
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0b0c0f;
  --bg-elevated: #14161a;
  --surface: #14161a;
  --surface-2: #1b1e24;
  --surface-3: #23272f;

  --border: #262a32;
  --border-strong: #363b45;

  --text: #f2f4f7;
  --text-muted: #a2a9b6;
  --text-faint: #6f7785;

  --accent: #6366f1;
  --accent-hover: #7c7ff5;
  --accent-fg: #ffffff;
  --accent-soft: rgba(99, 102, 241, 0.18);

  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.16);
  --info: #60a5fa;
  --info-soft: rgba(96, 165, 250, 0.16);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.55), 0 12px 28px -16px rgba(0, 0, 0, 0.8);
  --shadow-lg: 0 28px 60px -20px rgba(0, 0, 0, 0.85), 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* Explicit light theme wins over the dark media query. */
[data-theme="light"] {
  color-scheme: light;

  --bg: #f7f8fa;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #e9eaee;

  --border: #e4e6eb;
  --border-strong: #cfd3da;

  --text: #14161a;
  --text-muted: #5c6370;
  --text-faint: #8b919c;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-fg: #ffffff;
  --accent-soft: rgba(79, 70, 229, 0.1);

  --success: #15803d;
  --success-soft: rgba(21, 128, 61, 0.1);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --info: #0369a1;
  --info-soft: rgba(3, 105, 161, 0.1);

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 8px 24px -12px rgba(16, 24, 40, 0.18);
  --shadow-lg: 0 24px 48px -16px rgba(16, 24, 40, 0.28), 0 2px 6px rgba(16, 24, 40, 0.06);
}

/* `[data-theme="auto"]` intentionally inherits :root + the media query. */

/* ===== reset ===== */

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
figure,
blockquote,
dl,
dd {
  margin: 0;
}

ul,
ol {
  margin: 0;
  padding: 0;
}

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

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0;
}

[hidden] {
  display: none !important;
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

/* ===== base typography ===== */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.011em;
  color: var(--text);
}

h1 {
  font-size: 1.5rem;
}

h2 {
  font-size: 1.25rem;
}

h3 {
  font-size: 1.0625rem;
}

h4 {
  font-size: 0.9375rem;
}

small {
  font-size: 0.8125rem;
}

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
}

strong,
b {
  font-weight: 600;
}

/* Global motion + focus policy */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@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;
  }
}

/* ===== utilities ===== */

.flex {
  display: flex;
}

.inline-flex {
  display: inline-flex;
}

.items-center {
  align-items: center;
}

.items-start {
  align-items: flex-start;
}

.justify-between {
  justify-content: space-between;
}

.justify-end {
  justify-content: flex-end;
}

.flex-col {
  flex-direction: column;
}

.flex-wrap {
  flex-wrap: wrap;
}

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

.gap-1 {
  gap: 4px;
}

.gap-2 {
  gap: 8px;
}

.gap-3 {
  gap: 12px;
}

.gap-4 {
  gap: 16px;
}

.gap-6 {
  gap: 24px;
}

.mt-1 {
  margin-top: 4px;
}

.mt-2 {
  margin-top: 8px;
}

.mt-4 {
  margin-top: 16px;
}

.mt-6 {
  margin-top: 24px;
}

.mb-2 {
  margin-bottom: 8px;
}

.mb-4 {
  margin-bottom: 16px;
}

.mb-6 {
  margin-bottom: 24px;
}

.p-0 {
  padding: 0 !important;
}

.p-4 {
  padding: 16px;
}

.w-full {
  width: 100%;
}

.h-full {
  height: 100%;
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.text-sm {
  font-size: 0.8125rem;
}

.text-xs {
  font-size: 0.75rem;
}

.text-lg {
  font-size: 1rem;
}

.font-medium {
  font-weight: 500;
}

.font-semibold {
  font-weight: 600;
}

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

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

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

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

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

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

.hidden {
  display: none !important;
}

.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;
}

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

.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  margin: 0 -16px -16px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.scroll-y {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.scroll-y::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.scroll-y::-webkit-scrollbar-track {
  background: transparent;
}

.scroll-y::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}

.scroll-y::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
  background-clip: content-box;
}

.max-w-sm {
  max-width: 480px;
}

.max-w-md {
  max-width: 640px;
}

.max-w-lg {
  max-width: 800px;
}

.max-w-xl {
  max-width: 1040px;
}

.mx-auto {
  margin-left: auto;
  margin-right: auto;
}

.relative {
  position: relative;
}

.nowrap {
  white-space: nowrap;
}

/* ===== layout shell ===== */

.app-shell {
  min-height: 100vh;
  display: block;
  background: var(--bg);
}

.main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-left: var(--sidebar-w);
  transition: margin-left 0.22s ease;
}

.content {
  flex: 1 1 auto;
  width: 100%;
  max-width: 1200px;
  padding: 24px 28px 56px;
  margin: 0 auto;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.page-subtitle {
  margin-top: 4px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  max-width: 68ch;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.breadcrumbs a {
  color: var(--text-muted);
  text-decoration: none;
}

.breadcrumbs a:hover {
  color: var(--text);
  text-decoration: none;
}

.breadcrumbs > *:not(:last-child)::after {
  content: "/";
  margin-left: 6px;
  color: var(--text-faint);
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-toggle:active {
  background: var(--surface-3);
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(9, 11, 15, 0.5);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* ===== sidebar ===== */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 12px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  transition: transform 0.22s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 14px;
  font-weight: 600;
  font-size: 0.9375rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}

.sidebar-brand:hover {
  text-decoration: none;
}

.sidebar-logo {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.875rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.sidebar-nav {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px;
  margin: 0 -2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 8px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 0 2px;
}

.nav-section:first-child {
  padding-top: 2px;
}

.nav-section-title {
  padding: 4px 8px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  user-select: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  border: 0;
  width: 100%;
  text-align: left;
  transition: background 0.13s ease, color 0.13s ease;
}

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

.nav-item:active {
  background: var(--surface-3);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

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

.nav-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  color: var(--text-faint);
  transition: color 0.13s ease;
}

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

.sidebar-footer {
  flex: 0 0 auto;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-faint);
}

/* ===== topbar ===== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

/* ===== cards ===== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  min-width: 0;
}

.card-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text);
}

.card-description {
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

.card-body {
  padding: 16px;
}

.card-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  font-size: 0.8125rem;
}

.card-flush {
  padding: 0;
}

.card-flush > .card-header,
.card-flush > .card-body,
.card-flush > .card-footer {
  padding-left: 16px;
  padding-right: 16px;
}

.card-flush > .table-wrap,
.card-flush > .list,
.card-flush > .chat-log {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

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

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

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

/* ===== stats ===== */

.stat {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.stat:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--text-muted);
  text-transform: none;
}

.stat-value {
  margin-top: 2px;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.stat-delta.up {
  color: var(--success);
}

.stat-delta.down {
  color: var(--danger);
}

.stat-delta.up::before {
  content: "▲";
  font-size: 0.5625rem;
  line-height: 1;
}

.stat-delta.down::before {
  content: "▼";
  font-size: 0.5625rem;
  line-height: 1;
}

.stat-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ===== forms ===== */

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.005em;
}

.input,
.textarea,
.select {
  width: 100%;
  padding: 7px 10px;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
  appearance: none;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--text-faint);
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input:focus-visible,
.textarea:focus-visible,
.select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.input:disabled,
.textarea:disabled,
.select:disabled {
  background: var(--surface-2);
  color: var(--text-faint);
  cursor: not-allowed;
  opacity: 0.75;
}

.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

.textarea {
  min-height: 88px;
  resize: vertical;
  line-height: 1.6;
  font-family: inherit;
}

.select {
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) calc(50% + 1px), calc(100% - 10px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.select[multiple] {
  padding-right: 10px;
  background-image: none;
  min-height: 120px;
}

.field-hint {
  font-size: 0.6875rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.field-error {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--danger);
  line-height: 1.4;
}

.form-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.form-row > .field {
  flex: 1 1 200px;
}

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid > .field-full {
  grid-column: 1 / -1;
}

.input-group {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-width: 0;
}

.input-group > * {
  border-radius: 0;
  margin-left: -1px;
}

.input-group > *:first-child {
  border-top-left-radius: var(--radius-sm);
  border-bottom-left-radius: var(--radius-sm);
  margin-left: 0;
}

.input-group > *:last-child {
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
}

.input-group .input {
  flex: 1 1 auto;
  min-width: 0;
}

.input-group .input:focus {
  z-index: 2;
  position: relative;
}

.input-group .btn {
  flex: 0 0 auto;
  box-shadow: none;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.checkbox input[type="checkbox"],
.checkbox input[type="radio"] {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  accent-color: var(--accent);
  cursor: pointer;
  border-radius: 4px;
}

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

.checkbox:active {
  opacity: 0.85;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
  font-size: 0.8125rem;
  color: var(--text);
  position: relative;
}

.switch-input {
  position: absolute;
  opacity: 0;
  width: 36px;
  height: 20px;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}

.switch-track {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  transition: background 0.16s ease, border-color 0.16s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, background 0.16s ease;
}

.switch:hover .switch-track {
  border-color: var(--text-faint);
}

.switch-input:checked + .switch-track {
  background: var(--accent);
  border-color: var(--accent);
}

.switch-input:checked + .switch-track::after {
  transform: translateX(16px);
  background: var(--accent-fg);
}

.switch-input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch-input:disabled + .switch-track {
  opacity: 0.5;
  cursor: not-allowed;
}

.range {
  width: 100%;
  height: 20px;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
}

.range::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-elevated);
  box-shadow: var(--shadow-sm);
}

.range::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
}

.range::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-elevated);
}

.range:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.char-count {
  font-size: 0.6875rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.char-count.over {
  color: var(--danger);
}

/* ===== buttons ===== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease,
    box-shadow 0.14s ease, transform 0.06s ease;
}

.btn:hover {
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn svg {
  flex: 0 0 auto;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-primary:active {
  background: var(--accent-hover);
  filter: brightness(0.96);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

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

.btn-secondary:active {
  background: var(--surface-3);
}

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

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

.btn-ghost:active {
  background: var(--surface-3);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:active {
  filter: brightness(0.95);
}

.btn-sm {
  padding: 4px 9px;
  font-size: 0.75rem;
  gap: 4px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 10px 18px;
  font-size: 0.875rem;
  border-radius: var(--radius);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-icon {
  padding: 0;
  width: 32px;
  height: 32px;
  gap: 0;
  flex: 0 0 auto;
}

.btn-icon.btn-sm {
  width: 26px;
  height: 26px;
}

.btn-icon.btn-lg {
  width: 40px;
  height: 40px;
}

.btn[disabled],
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn[disabled]:hover,
.btn:disabled:hover {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text-muted);
}

.btn-primary[disabled]:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.btn-group {
  display: inline-flex;
  align-items: stretch;
  border-radius: var(--radius-sm);
}

.btn-group > .btn {
  border-radius: 0;
  margin-left: -1px;
  box-shadow: none;
}

.btn-group > .btn:first-child {
  border-top-left-radius: var(--radius-sm);
  border-bottom-left-radius: var(--radius-sm);
  margin-left: 0;
}

.btn-group > .btn:last-child {
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
}

.btn-group > .btn:hover,
.btn-group > .btn.active {
  z-index: 2;
  position: relative;
}

/* ===== tables ===== */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.table-wrap::-webkit-scrollbar {
  height: 10px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.table {
  width: 100%;
  font-size: 0.8125rem;
  border-collapse: collapse;
}

.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 14px;
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  transition: background 0.13s ease;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

/* Row states target cells through :where() so they outrank the base `.table td`
   rule without raising specificity beyond a single class. */
.table :where(tr:hover) td {
  background: var(--surface-2);
}

.table :where(tr:active) td {
  background: var(--surface-3);
}

.table td.numeric,
.table th.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ===== lists ===== */

.list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  min-width: 0;
  cursor: default;
  transition: background 0.13s ease, box-shadow 0.13s ease;
}

.list-item:last-child {
  border-bottom: 0;
}

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

.list-item:active {
  background: var(--surface-3);
}

.list-item.selected {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.list-item-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-item-title {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.list-item-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0.85;
  transition: opacity 0.13s ease;
}

.list-item:hover .list-item-actions {
  opacity: 1;
}

/* ===== badges ===== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.6;
  letter-spacing: 0.01em;
  white-space: nowrap;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
}

.badge-success {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
  color: var(--success);
}

.badge-warn {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 35%, transparent);
  color: var(--warn);
}

.badge-danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
}

.badge-muted {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-faint);
}

.badge-accent {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent);
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--text-faint);
}

.dot-success {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.dot-warn {
  background: var(--warn);
  box-shadow: 0 0 0 3px var(--warn-soft);
}

.dot-danger {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

/* ===== alerts ===== */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.alert-info {
  background: var(--info-soft);
  border-color: color-mix(in srgb, var(--info) 30%, transparent);
  border-left-color: var(--info);
  color: var(--text);
}

.alert-warn {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 30%, transparent);
  border-left-color: var(--warn);
  color: var(--text);
}

.alert-danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
  border-left-color: var(--danger);
  color: var(--text);
}

.alert-success {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
  border-left-color: var(--success);
  color: var(--text);
}

/* ===== empty states ===== */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 48px 24px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 2px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-faint);
}

.empty-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.empty-text {
  font-size: 0.8125rem;
  color: var(--text-muted);
  max-width: 46ch;
}

/* ===== toast ===== */

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 40px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.22s ease both;
}

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

.toast-success {
  border-left-color: var(--success);
}

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

.toast-info {
  border-left-color: var(--info);
}

.toast-close {
  flex: 0 0 auto;
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-sm);
  color: var(--text-faint);
  font-size: 0.875rem;
  line-height: 1;
  transition: background 0.13s ease, color 0.13s ease;
}

.toast-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.toast-close:active {
  background: var(--surface-3);
}

/* ===== modal ===== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(9, 11, 15, 0.55);
  backdrop-filter: blur(3px);
  animation: fade-in 0.16s ease both;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.2s ease both;
  overflow: hidden;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-body {
  flex: 1 1 auto;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.modal-body::-webkit-scrollbar {
  width: 10px;
}

.modal-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.modal-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.modal-close {
  flex: 0 0 auto;
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  color: var(--text-faint);
  font-size: 1rem;
  line-height: 1;
  transition: background 0.13s ease, color 0.13s ease;
}

.modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.modal-close:active {
  background: var(--surface-3);
}

/* ===== progress / spinner / skeleton ===== */

.progress {
  position: relative;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.3s ease;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.skeleton {
  display: block;
  width: 100%;
  height: 12px;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--surface-3) 50%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* ===== dropzone ===== */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 28px 20px;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.dropzone:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.dropzone:active {
  background: var(--surface-2);
}

.dropzone.dragover {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ===== chat / playground ===== */

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 16px;
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  scroll-behavior: smooth;
}

.chat-log::-webkit-scrollbar {
  width: 10px;
}

.chat-log::-webkit-scrollbar-track {
  background: transparent;
}

.chat-log::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}

.chat-log::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
  background-clip: content-box;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 78%;
  min-width: 0;
}

.msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-bubble {
  position: relative;
  padding: 9px 13px;
  font-size: 0.8125rem;
  line-height: 1.6;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  overflow-wrap: anywhere;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.msg-user .msg-bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.msg-bubble:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

.msg-user .msg-bubble:hover {
  border-color: var(--accent-hover);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.6875rem;
  color: var(--text-faint);
  padding: 0 2px;
  font-variant-numeric: tabular-nums;
}

.msg-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.msg:hover .msg-actions,
.msg:focus-within .msg-actions {
  opacity: 1;
}

.msg-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.13s ease, color 0.13s ease, border-color 0.13s ease;
}

.source-chip:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-strong);
  text-decoration: none;
}

.source-chip:active {
  transform: translateY(1px);
}

.source-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.source-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}

.source-panel-title {
  padding: 8px 12px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.source-panel-body {
  padding: 12px;
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--text-muted);
  max-height: 260px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.source-panel-body::-webkit-scrollbar {
  width: 8px;
}

.source-panel-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}

.composer-input {
  flex: 1 1 auto;
  min-height: 40px;
  max-height: 200px;
  resize: none;
  padding: 9px 12px;
  font-size: 0.8125rem;
  font-family: inherit;
  line-height: 1.55;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.composer-input::placeholder {
  color: var(--text-faint);
}

.composer-input:hover {
  border-color: var(--text-faint);
}

.composer-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.feedback-btn {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  color: var(--text-faint);
  background: transparent;
  transition: background 0.13s ease, color 0.13s ease, border-color 0.13s ease;
}

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

.feedback-btn:active {
  background: var(--surface-3);
}

.feedback-btn.active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--accent);
}

/* ===== markdown ===== */

.markdown {
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--text);
  overflow-wrap: anywhere;
}

.markdown > *:first-child {
  margin-top: 0;
}

.markdown > *:last-child {
  margin-bottom: 0;
}

.markdown h1 {
  font-size: 1.375rem;
  margin: 22px 0 10px;
}

.markdown h2 {
  font-size: 1.125rem;
  margin: 20px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}

.markdown h3 {
  font-size: 1rem;
  margin: 18px 0 6px;
}

.markdown h4 {
  font-size: 0.875rem;
  margin: 16px 0 6px;
  color: var(--text-muted);
}

.markdown p {
  margin: 0 0 12px;
}

.markdown ul,
.markdown ol {
  margin: 0 0 12px;
  padding-left: 22px;
}

.markdown ul {
  list-style: disc;
}

.markdown ol {
  list-style: decimal;
}

.markdown li {
  margin: 0 0 4px;
}

.markdown li > ul,
.markdown li > ol {
  margin: 4px 0 0;
}

.markdown blockquote {
  margin: 0 0 12px;
  padding: 4px 14px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.markdown blockquote > *:last-child {
  margin-bottom: 0;
}

.markdown hr {
  margin: 18px 0;
}

.markdown table {
  width: 100%;
  margin: 0 0 14px;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.markdown th {
  padding: 7px 11px;
  text-align: left;
  font-weight: 600;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.markdown td {
  padding: 7px 11px;
  border-bottom: 1px solid var(--border);
}

.markdown tbody tr:last-child td {
  border-bottom: 0;
}

.markdown a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown a:hover {
  color: var(--accent-hover);
}

.markdown strong {
  font-weight: 600;
}

.markdown em {
  font-style: italic;
}

.markdown img {
  max-width: 100%;
  height: auto;
  margin: 4px 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.markdown :not(pre) > code {
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 0.8125em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
}

/* ===== code / snippet ===== */

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

pre.code {
  display: block;
  padding: 13px 15px;
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.65;
  tab-size: 2;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

pre.code::-webkit-scrollbar {
  height: 10px;
}

pre.code::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.snippet {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.snippet-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px 7px 13px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.snippet-copy {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background 0.13s ease, color 0.13s ease, border-color 0.13s ease;
}

.snippet-copy:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-strong);
}

.snippet-copy:active {
  transform: translateY(1px);
}

.snippet > pre.code {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.6;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  box-shadow: var(--shadow-sm);
}

.kbd:active {
  border-bottom-width: 1px;
  transform: translateY(1px);
  color: var(--text);
}

/* ===== tabs / pills ===== */

.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.tab:hover {
  color: var(--text);
  background: var(--surface-2);
  text-decoration: none;
}

.tab:active {
  background: var(--surface-3);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.pill-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.pill:hover {
  color: var(--text);
  background: var(--surface-3);
  text-decoration: none;
}

.pill:active {
  transform: translateY(1px);
}

.pill.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ===== chart ===== */

.chart {
  position: relative;
  width: 100%;
  min-height: 180px;
  display: flex;
  align-items: flex-end;
  padding: 12px 0 0;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  height: 180px;
  border-bottom: 1px solid var(--border);
  padding: 0 4px;
}

.bar {
  position: relative;
  flex: 1 1 0;
  min-width: 4px;
  height: 100%;
  display: flex;
  align-items: flex-end;
  background: var(--surface-2);
  border-radius: 4px 4px 0 0;
  overflow: hidden;
  transition: background 0.15s ease;
}

.bar:hover {
  background: var(--surface-3);
}

.bar-fill {
  width: 100%;
  min-height: 2px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  transition: height 0.3s ease, background 0.15s ease;
}

.bar:hover .bar-fill {
  background: var(--accent-hover);
}

.chart-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.chart-legend > * {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend .dot {
  width: 8px;
  height: 8px;
}

.sparkline {
  display: block;
  width: 100%;
  height: 40px;
  color: var(--accent);
  overflow: visible;
}

/* ===== auth ===== */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 26px 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 18px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
}

.auth-brand .sidebar-logo {
  width: 34px;
  height: 34px;
}

.auth-title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: center;
  color: var(--text);
}

.auth-subtitle {
  margin-top: 5px;
  margin-bottom: 20px;
  font-size: 0.8125rem;
  text-align: center;
  color: var(--text-muted);
}

.auth-footer {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  text-align: center;
  color: var(--text-muted);
}

.auth-split {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  background: var(--bg);
}

.auth-aside {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 48px 44px;
  color: var(--text);
  background: linear-gradient(
    160deg,
    var(--accent-soft),
    var(--surface-2) 55%,
    var(--surface)
  );
  border-right: 1px solid var(--border);
}

.auth-aside h1,
.auth-aside h2 {
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.auth-aside p {
  font-size: 0.875rem;
  color: var(--text-muted);
  max-width: 44ch;
}

.auth-split > .auth-card {
  align-self: center;
  justify-self: center;
  margin: 40px 24px;
  box-shadow: var(--shadow);
}

/* ===== responsive ===== */

@media (max-width: 1099.98px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .backdrop.show,
  .sidebar.open ~ .backdrop {
    opacity: 1;
    visibility: visible;
  }

  .content {
    padding: 20px 20px 48px;
  }

  .topbar {
    padding: 8px 20px;
  }
}

@media (max-width: 719.98px) {
  body {
    font-size: 14px;
  }

  /* .grid is already auto-fit; collapse the fixed column helpers. */
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: minmax(0, 1fr);
  }

  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .hide-sm {
    display: none !important;
  }

  .table th,
  .table td {
    padding: 8px 10px;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .page-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .content {
    padding: 16px 14px 40px;
  }

  .topbar {
    padding: 8px 14px;
  }

  .msg {
    max-width: 92%;
  }

  .chat-log {
    padding: 14px 12px;
  }

  .toast-stack {
    left: 14px;
    right: 14px;
    bottom: 14px;
    max-width: none;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .modal {
    max-height: calc(100vh - 24px);
  }

  .auth-split {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-aside {
    padding: 28px 20px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .auth-card {
    padding: 20px 16px;
  }

  .sticky-actions {
    margin: 0 -14px -16px;
    padding: 10px 14px;
  }
}

@media (min-width: 1100px) {
  .sidebar {
    transform: none;
  }

  .backdrop {
    display: none;
  }
}
