:root {
  --bg: #f4f7fb;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --text: #0f172a;
  --muted: #566173;
  --line: rgba(15, 23, 42, 0.1);
  --line-strong: rgba(15, 23, 42, 0.16);
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --success: #0f9f6e;
  --success-soft: rgba(15, 159, 110, 0.14);
  --warning: #a16207;
  --warning-soft: rgba(161, 98, 7, 0.14);
  --danger: #cf3345;
  --danger-soft: rgba(207, 51, 69, 0.12);
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.07);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --content-width: 1460px;
  --font-stack: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  --bg: #07111d;
  --surface: rgba(10, 18, 33, 0.88);
  --surface-strong: rgba(10, 18, 33, 0.98);
  --text: #edf3fb;
  --muted: #9cabbd;
  --line: rgba(148, 163, 184, 0.14);
  --line-strong: rgba(148, 163, 184, 0.22);
  --accent: #7bb4ff;
  --accent-soft: rgba(123, 180, 255, 0.14);
  --success: #32d5a1;
  --success-soft: rgba(50, 213, 161, 0.16);
  --warning: #ffcd73;
  --warning-soft: rgba(255, 205, 115, 0.15);
  --danger: #ff8b98;
  --danger-soft: rgba(255, 139, 152, 0.16);
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.26);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-stack);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.09), transparent 26%),
    radial-gradient(circle at top right, rgba(15, 159, 110, 0.07), transparent 22%),
    var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
  background: rgba(148, 163, 184, 0.12);
  padding: 0.14rem 0.36rem;
  border-radius: 0.5rem;
}

.app-shell {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 320px;
  gap: 20px;
}

.mobile-topbar {
  display: none;
}

.left-rail,
.right-rail {
  min-width: 0;
}

.sticky-block {
  position: sticky;
  top: 24px;
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  padding: 22px;
}

.brand-panel {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  font-weight: 800;
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(37, 99, 235, 0.16), rgba(15, 159, 110, 0.14));
  border: 1px solid var(--line);
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.brand-subtitle,
.muted {
  color: var(--muted);
}

.small-text {
  font-size: 0.92rem;
}

.nav-panel,
.drawer-body {
  display: grid;
  gap: 10px;
}

.nav-link {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 14px 16px;
  border-radius: 16px;
  text-align: left;
  transition: 180ms ease;
}

.nav-link:hover,
.nav-link.active {
  background: var(--accent-soft);
  border-color: rgba(37, 99, 235, 0.18);
}

.section-kicker,
.eyebrow {
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border-radius: 999px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.08);
  font-weight: 600;
}

.connection-pill.connected {
  background: var(--success-soft);
  color: var(--success);
  border-color: rgba(15, 159, 110, 0.18);
}

.connection-pill.waiting {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: rgba(161, 98, 7, 0.18);
}

.connection-pill.small-pill {
  padding: 8px 12px;
  font-size: 0.92rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: currentColor;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.stat-card {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.05);
  text-align: center;
}

.stat-number {
  font-size: 1.32rem;
  font-weight: 700;
}

.stat-label {
  color: var(--muted);
  font-size: 0.88rem;
}

.center-column {
  display: grid;
  gap: 20px;
}

.hero-panel h1,
.onboarding-panel h2,
.chat-panel h2,
.skills-panel h2 {
  margin: 8px 0 12px;
  line-height: 1.1;
}

.hero-panel h1 {
  font-size: clamp(1.8rem, 2.3vw, 2.7rem);
}

.hero-panel p,
.onboarding-panel p {
  color: var(--muted);
  max-width: 70ch;
  margin: 0;
}

.hero-topline,
.skills-header,
.chat-header,
.chat-controls {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stack-form {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-weight: 600;
}

input[type="password"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--surface-strong);
  color: var(--text);
  border-radius: 16px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input[type="password"]:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

textarea {
  min-height: 112px;
  resize: vertical;
}

.button {
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 12px 16px;
  color: var(--text);
  background: rgba(148, 163, 184, 0.1);
  transition: 180ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.96), rgba(59, 130, 246, 0.92));
  color: #fff;
}

.button.secondary {
  background: transparent;
  border-color: var(--line-strong);
}

.button.ghost {
  background: var(--accent-soft);
  color: var(--accent);
}

.button.large {
  padding: 14px 20px;
  font-weight: 700;
}

.inline-status {
  min-height: 1.4rem;
  font-size: 0.94rem;
}

.chat-window {
  margin-top: 16px;
  display: grid;
  gap: 14px;
  max-height: 480px;
  overflow: auto;
  padding-right: 4px;
}

.bubble {
  border-radius: 20px;
  border: 1px solid var(--line);
  padding: 16px;
  background: rgba(148, 163, 184, 0.06);
}

.bubble.user {
  background: var(--accent-soft);
  border-color: rgba(37, 99, 235, 0.18);
}

.bubble.assistant {
  background: rgba(15, 159, 110, 0.06);
  border-color: rgba(15, 159, 110, 0.14);
}

.bubble.thinking {
  color: var(--muted);
  font-style: italic;
}

.bubble-role {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--muted);
}

.bubble-text {
  white-space: pre-wrap;
}

.suggestion-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 18px 0 12px;
}

.chip {
  border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 12px;
}

.chip:hover {
  background: var(--accent-soft);
  border-color: rgba(37, 99, 235, 0.18);
}

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

.skill-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  background: rgba(148, 163, 184, 0.06);
  display: grid;
  gap: 12px;
}

.skill-card-top,
.skill-meta,
.skill-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.skill-tag {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.skill-db-flag {
  font-size: 0.82rem;
  color: var(--muted);
}

.skill-card.installed {
  border-color: rgba(15, 159, 110, 0.22);
  background: var(--success-soft);
}

.skill-card.installed .skill-install-button {
  background: transparent;
  color: var(--success);
  border-color: rgba(15, 159, 110, 0.24);
}

.skill-install-button {
  justify-self: start;
}

.plain-list {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.plain-list li + li {
  margin-top: 10px;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.34);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: min(360px, 90vw);
  height: 100vh;
  background: var(--surface-strong);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(-102%);
  transition: transform 220ms ease;
  display: grid;
  grid-template-rows: auto 1fr;
  z-index: 20;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.drawer-body {
  overflow: auto;
  padding: 16px 18px 24px;
}

.drawer-divider {
  height: 1px;
  background: var(--line);
  margin: 8px 0 6px;
}

.drawer-skills {
  display: grid;
  gap: 10px;
}

.drawer-skill {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.06);
}

.hidden {
  display: none !important;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 300px;
  }

  .left-rail {
    display: none;
  }

  .mobile-topbar {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 5;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    grid-column: 1 / -1;
    padding: 10px 0;
    background: linear-gradient(var(--bg), rgba(0, 0, 0, 0));
  }

  .mobile-brand {
    font-weight: 700;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    padding-inline: 14px;
  }

  .right-rail {
    order: 3;
  }

  .sticky-block {
    position: static;
  }

  .hero-topline,
  .skills-header,
  .chat-header,
  .chat-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .skills-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 560px) {
  .panel {
    padding: 18px;
    border-radius: 22px;
  }

  .hero-panel h1 {
    font-size: 1.7rem;
  }

  .chat-window {
    max-height: 420px;
  }
}


input[type="text"],
input[type="number"] {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--surface-strong);
  color: var(--text);
  border-radius: 16px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input[type="text"]:focus,
input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.app-shell-public {
  min-height: 100vh;
}

.page-actions {
  margin-top: 18px;
}

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

.module-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  background: rgba(148, 163, 184, 0.06);
  display: grid;
  gap: 12px;
}

.module-meta code {
  word-break: break-word;
}

.notice-panel {
  padding: 16px 18px;
}

.success-panel {
  background: var(--success-soft);
  color: var(--success);
  border-color: rgba(15, 159, 110, 0.22);
}

.form-grid {
  display: grid;
  gap: 16px;
}

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

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.item-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(148, 163, 184, 0.05);
}

.item-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.item-main code {
  word-break: break-word;
}

.item-meta {
  display: grid;
  gap: 6px;
  text-align: right;
}

.item-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.inline-form {
  margin: 0;
}

.danger-outline {
  border-color: rgba(207, 51, 69, 0.28);
  color: var(--danger);
}

.code-preview {
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dynamic-block-panel .dynamic-block-html {
  color: var(--text);
  margin-top: 10px;
}

.dynamic-block-panel .dynamic-block-html p:first-child {
  margin-top: 0;
}

.dynamic-block-panel .dynamic-block-html p:last-child {
  margin-bottom: 0;
}

.dynamic-block-panel .dynamic-block-html a {
  color: var(--accent);
}

.stat-grid-four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.placeholder-hero {
  min-height: 0;
}

@media (max-width: 860px) {
  .module-grid,
  .form-grid.two-up {
    grid-template-columns: 1fr;
  }

  .item-row {
    grid-template-columns: 1fr;
  }

  .item-meta,
  .item-actions {
    text-align: left;
    justify-content: flex-start;
  }

  .stat-grid-four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .stat-grid-four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
