:root {
  --background: #0f1014;
  --sidebar: #14151a;
  --panel: #17181d;
  --panel-raised: #202128;
  --border: #30313a;
  --text: #f4f4f5;
  --muted: #9ca3af;
  --accent: #179ecb;
  --accent-hover: #21b6dd;
  --danger: #ef4444;
  --radius-small: 6px;
  --radius-medium: 10px;
  --radius-large: 16px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.app-shell.auth-locked {
  display: none;
}

.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--background);
}

.auth-screen.hidden {
  display: none;
}

.login-panel {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  text-align: center;
}

.login-panel .brand-logo {
  justify-self: center;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 700;
}

.login-panel input {
  min-height: 44px;
  border-radius: var(--radius-small);
  background: var(--panel-raised);
  color: var(--text);
  padding: 0 12px;
  outline: 0;
}

.login-error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 112px;
  z-index: 60;
  max-width: min(360px, calc(100vw - 36px));
  border-radius: var(--radius-medium);
  background: var(--panel-raised);
  color: var(--text);
  padding: 12px 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.36);
  font-size: 14px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-medium);
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0;
}

.brand-subtitle,
.status-text,
.project-label,
.conversation-preview,
.conversation-subtitle,
.project-description {
  color: var(--muted);
  font-size: 12px;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.sidebar-section.grow {
  flex: 1;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.stack-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
}

.project-item,
.conversation-item {
  width: 100%;
  border: none;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 9px 10px;
  cursor: pointer;
}

.project-item:hover,
.conversation-item:hover {
  background: var(--panel);
}

.project-item.active,
.conversation-item.active {
  background: var(--panel-raised);
  border-color: var(--border);
}

.project-title,
.conversation-title-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.project-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}

.vector-status {
  color: var(--muted);
  font-size: 11px;
}

.vector-status.ready,
.vector-status.active {
  color: #7dd3fc;
}

.vector-status.provisioning {
  color: #facc15;
}

.vector-status.error {
  color: var(--danger);
}

.project-actions {
  display: inline-flex;
  gap: 6px;
  font-size: 11px;
}

.project-action {
  color: var(--muted);
  cursor: pointer;
}

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

.badge {
  flex: 0 0 auto;
  border: none;
  border-radius: var(--radius-small);
  color: var(--muted);
  padding: 1px 5px;
  font-size: 11px;
}

.main-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  background: var(--background);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 16, 20, 0.96);
}

.conversation-heading {
  flex: 1;
  min-width: 0;
}

.title-input,
.subtitle-input {
  display: block;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
}

.title-input {
  font-size: 18px;
  font-weight: 700;
}

.subtitle-input {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.select-control,
.secondary-button,
.send-button,
.icon-button {
  border: none;
  border-radius: var(--radius-small);
  background: var(--panel-raised);
  color: var(--text);
}

.select-control {
  min-height: 36px;
  padding: 0 10px;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}

.icon-button:hover,
.secondary-button:hover,
.send-button:hover {
  border-color: var(--accent);
}

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

.secondary-button {
  min-height: 34px;
  cursor: pointer;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 20px clamp(14px, 4vw, 42px);
  scroll-behavior: smooth;
}

.messages.messages-empty {
  display: grid;
  place-items: center;
  padding-bottom: 12vh;
}

.empty-state {
  width: min(760px, 100%);
  text-align: center;
}

.empty-title {
  margin: 0;
  color: var(--text);
  font-size: clamp(30px, 5vw, 52px);
  font-weight: 400;
  line-height: 1.12;
  letter-spacing: 0;
}

.message {
  max-width: 880px;
  margin: 0 auto 18px;
  line-height: 1.55;
}

.message.user {
  display: flex;
  justify-content: flex-end;
}

.message.user .bubble {
  max-width: min(760px, 86%);
  border-radius: var(--radius-large);
  background: var(--panel-raised);
  padding: 12px 14px;
  white-space: pre-wrap;
}

.message.assistant .bubble {
  color: var(--text);
}

.message h1,
.message h2,
.message h3 {
  margin: 22px 0 10px;
  letter-spacing: 0;
  line-height: 1.2;
}

.message h1 {
  font-size: 26px;
  font-weight: 700;
}

.message h2 {
  font-size: 21px;
  font-weight: 650;
}

.message h3 {
  font-size: 17px;
  font-weight: 650;
}

.message p,
.message ul,
.message ol,
.message blockquote,
.message table {
  margin: 0 0 12px;
}

.message ul,
.message ol {
  padding-left: 24px;
}

.message li {
  margin: 5px 0;
}

.message blockquote {
  color: var(--muted);
  padding-left: 14px;
}

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

.message code {
  border-radius: var(--radius-small);
  background: var(--panel-raised);
  padding: 2px 5px;
}

.code-block {
  border: none;
  border-radius: var(--radius-medium);
  background: #0a0b0f;
  margin: 12px 0;
  overflow: hidden;
}

.code-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 34px;
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.copy-code {
  border: 0;
  border-radius: var(--radius-small);
  background: var(--panel-raised);
  color: var(--text);
  padding: 4px 8px;
  cursor: pointer;
}

.message pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
}

.message table {
  width: 100%;
  border-collapse: collapse;
}

.message th,
.message td {
  border: none;
  padding: 6px 8px;
}

.scroll-latest {
  position: absolute;
  right: clamp(22px, 5vw, 58px);
  bottom: 96px;
  z-index: 6;
  display: none;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: #000;
  color: #fff;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.scroll-latest.show {
  display: grid;
}

.composer {
  display: flex;
  gap: 10px;
  padding: 12px max(14px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  background: rgba(15, 16, 20, 0.96);
}

#message-input {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  border: none;
  border-radius: var(--radius-medium);
  background: var(--panel);
  color: var(--text);
  padding: 12px;
  outline: 0;
}

.send-button {
  min-width: 78px;
  background: var(--accent);
  border-color: var(--accent);
  cursor: pointer;
}

.send-button:hover {
  background: var(--accent-hover);
}

.mobile-only {
  display: none;
}

.hidden {
  display: none !important;
}

.hugo-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  background: var(--panel);
  padding: 3px;
}

.tab-button {
  min-height: 30px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  cursor: pointer;
}

.tab-button.active {
  background: var(--panel-raised);
  color: var(--text);
}

.knowledge-active {
  grid-template-rows: auto minmax(0, 1fr);
}

.knowledge-view {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 310px) minmax(0, 1fr);
  overflow: hidden;
}

.knowledge-explorer {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--sidebar);
  overflow: hidden;
}

.knowledge-root-row,
.knowledge-actions,
.knowledge-editor-actions,
.knowledge-empty-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.knowledge-root-row .select-control {
  width: 100%;
}

.knowledge-actions .secondary-button,
.knowledge-empty-actions .secondary-button,
.knowledge-editor-actions .secondary-button {
  padding: 0 12px;
}

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

.knowledge-tree {
  min-height: 0;
  overflow: auto;
  padding-bottom: 40px;
}

.knowledge-tree-status {
  color: var(--muted);
  padding: 12px 4px;
  font-size: 13px;
}

.knowledge-node,
.knowledge-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 4px 4px calc(4px + (var(--depth) * 16px));
  border-radius: var(--radius-small);
  color: var(--text);
  cursor: pointer;
}

.knowledge-node:hover,
.knowledge-node.active {
  background: var(--panel-raised);
}

.knowledge-node-toggle {
  width: 20px;
  height: 24px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.knowledge-node-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.knowledge-node-actions {
  display: inline-flex;
  gap: 4px;
}

.knowledge-node-actions button {
  min-height: 24px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 0 8px;
  font-size: 12px;
  cursor: pointer;
}

.knowledge-inline {
  align-items: flex-start;
  flex-direction: column;
  cursor: default;
}

.knowledge-inline-input {
  width: min(220px, 100%);
  min-height: 30px;
  border-radius: var(--radius-small);
  background: var(--panel-raised);
  color: var(--text);
  outline: 0;
  padding: 0 10px;
}

.knowledge-inline-error {
  color: var(--danger);
  font-size: 12px;
}

.knowledge-editor-shell {
  min-width: 0;
  min-height: 0;
  display: grid;
  background: var(--background);
}

.knowledge-empty {
  align-self: center;
  justify-self: center;
  width: min(620px, calc(100% - 32px));
  text-align: center;
}

.knowledge-empty h2 {
  margin: 0 0 10px;
  font-size: clamp(32px, 5vw, 52px);
  font-weight: 400;
  letter-spacing: 0;
}

.knowledge-empty p {
  margin: 0 0 22px;
  color: var(--muted);
}

.knowledge-empty-actions {
  justify-content: center;
}

.knowledge-editor {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 18px clamp(14px, 3vw, 34px);
}

.knowledge-breadcrumbs {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.knowledge-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.knowledge-editor-header h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0;
}

#knowledge-textarea {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  border-radius: var(--radius-medium);
  background: var(--panel);
  color: var(--text);
  outline: 0;
  padding: 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.45);
  }

  .brand {
    padding-left: 60px;
  }

  .main-panel {
    height: 100dvh;
  }

  .mobile-only {
    display: inline-grid;
  }

  #drawer-toggle {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    z-index: 40;
  }

  #mobile-project-select {
    max-width: 132px;
  }

  .project-label,
  #archive-conversation {
    display: none;
  }

  .topbar {
    gap: 8px;
    padding: 10px;
  }

  .hugo-tabs {
    margin-left: 46px;
  }

  .title-input {
    font-size: 15px;
  }

  .subtitle-input {
    display: none;
  }

  .messages {
    padding: 16px 12px;
  }

  .message.user .bubble {
    max-width: 92%;
  }

  .knowledge-view {
    display: block;
    height: calc(100dvh - 58px);
  }

  .knowledge-menu {
    position: fixed;
    top: max(64px, calc(env(safe-area-inset-top) + 58px));
    left: max(10px, env(safe-area-inset-left));
    z-index: 45;
    background: #000;
    color: #fff;
  }

  .knowledge-explorer {
    position: fixed;
    z-index: 35;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0);
  }

  .knowledge-explorer.open {
    transform: translateX(0);
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.45);
  }

  .knowledge-editor-shell {
    height: 100%;
  }

  .knowledge-editor {
    padding: 58px 12px 12px;
  }

  .knowledge-editor-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .knowledge-editor-actions {
    width: 100%;
    overflow-x: auto;
  }

  .knowledge-empty {
    padding-top: 18vh;
  }
}

/* Borderless Hugo restyle requested after the MVP pass. */
*,
*::before,
*::after {
  border: none !important;
}

.fa-icon {
  display: block;
  width: 14px;
  height: 14px;
}

.icon-button {
  background: transparent;
  color: var(--text);
  border-radius: 999px;
}

.icon-button:hover {
  background: var(--panel-raised);
}

.danger {
  color: #fff;
}

.danger:hover {
  color: #fff;
}

.project-item.active,
.conversation-item.active,
.project-item:hover,
.conversation-item:hover {
  background: var(--panel-raised);
}

.badge,
.select-control,
.secondary-button,
.copy-code {
  background: var(--panel-raised);
}

.topbar {
  background: rgba(15, 16, 20, 0.98);
}

button,
.sidebar,
.topbar,
.composer,
.composer-inner,
.project-item,
.conversation-item,
.message,
.bubble,
.icon-button,
.secondary-button,
.send-button,
.select-control,
#message-input {
  border: none !important;
}

.composer {
  justify-content: center;
  padding: 14px max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: rgba(15, 16, 20, 0.98);
}

.composer-inner {
  position: relative;
  display: flex;
  align-items: flex-end;
  width: min(920px, 100%);
  min-height: 52px;
  border-radius: 28px;
  background: var(--panel-raised);
  padding: 8px 54px 8px 18px;
}

#message-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 36px;
  max-height: 160px;
  background: transparent;
  border-radius: 0;
  padding: 8px 4px;
}

.send-button {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: inline-grid;
  place-items: center;
  width: 36px;
  min-width: 36px;
  height: 36px;
  border-radius: 999px;
  background: #000;
  color: #fff;
  cursor: pointer;
  padding: 0;
}

.send-button:hover {
  background: #111;
}

.send-button .fa-icon {
  width: 14px;
  height: 14px;
}

.code-block,
.message th,
.message td {
  background-clip: padding-box;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.56);
  padding: 18px;
}

.modal-backdrop.hidden,
.hidden {
  display: none !important;
}

.modal-panel {
  width: min(440px, 100%);
  border-radius: var(--radius-medium);
  background: var(--panel);
  color: var(--text);
  padding: 18px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.45);
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.modal-fields {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.modal-fields label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.modal-fields input,
.modal-fields textarea {
  width: 100%;
  border-radius: var(--radius-small);
  background: var(--panel-raised);
  color: var(--text);
  outline: 0;
  padding: 10px 12px;
}

.modal-fields textarea {
  resize: vertical;
  min-height: 84px;
}

.modal-warning {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.modal-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 118px;
  padding: 0 14px;
}

.danger-submit {
  background: #7f1d1d;
  color: #fff;
}
