:root {
  --bg: #171717;
  --bg-soft: #1f1f1f;
  --panel: #1d1d1d;
  --panel-rail: #1b1b1b;
  --line: rgba(255, 255, 255, 0.08);
  --line-soft: rgba(255, 255, 255, 0.05);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.46);
  --muted-strong: rgba(255, 255, 255, 0.62);
  --accent: #6ee7b7;
  --accent-strong: #34d399;
  --user-bg: #212121;
  --danger: #fca5a5;
  --edge-safe: 128px;
  --rail-safe: 56px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, "SF Pro Display", "Segoe UI", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #141414 0%, var(--bg) 100%);
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

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

.workspace-shell {
  position: relative;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 280px;
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
}

.edge-rail {
  position: fixed;
  top: 0;
  width: 48px;
  height: 100vh;
  z-index: 40;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  pointer-events: none;
}

.edge-rail-left {
  left: 0;
}

.edge-rail-right {
  right: 0;
}

.sidebar,
.tools-panel {
  height: 100vh;
  padding: 18px 16px;
  background: var(--panel);
  overflow: hidden;
  transition: width 0.22s ease, padding 0.22s ease, background 0.22s ease;
}

.sidebar {
  width: 280px;
  border-right: 1px solid var(--line);
}

.tools-panel {
  width: 280px;
  border-left: 1px solid var(--line);
}

body.history-collapsed .workspace-shell {
  grid-template-columns: 60px minmax(0, 1fr) 280px;
}

body.tools-collapsed .workspace-shell {
  grid-template-columns: 280px minmax(0, 1fr) 60px;
}

body.history-collapsed.tools-collapsed .workspace-shell {
  grid-template-columns: 60px minmax(0, 1fr) 60px;
}

body.history-collapsed .sidebar,
body.tools-collapsed .tools-panel {
  width: 60px;
  padding: 18px 10px;
  background: var(--panel-rail);
}

body.history-collapsed .sidebar > *:not(.sidebar-top),
body.tools-collapsed .tools-panel > *:not(.tools-header) {
  opacity: 0;
  pointer-events: none;
}

body.history-collapsed .sidebar h2,
body.tools-collapsed .tools-panel h3,
body.history-collapsed .sidebar .ghost-button,
body.tools-collapsed .tools-panel .tool-section {
  display: none;
}

.sidebar,
.tools-panel,
.app-shell {
  min-width: 0;
}

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

.tools-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.sidebar-top,
.tools-header {
  min-height: 76px;
  padding-top: 8px;
}

.sidebar-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-left: var(--rail-safe);
  padding-right: 8px;
}

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

.sidebar-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sidebar h2,
.tools-header h3 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.tools-header {
  padding-left: 8px;
  padding-right: var(--rail-safe);
}

.tools-subtitle {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.primary-button,
.ghost-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  width: 100%;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #131313;
  font-weight: 700;
}

.ghost-button {
  width: auto;
  min-height: 36px;
  background: transparent;
  color: var(--muted-strong);
  border-color: var(--line);
}

.primary-button:hover,
.ghost-button:hover,
.edge-toggle:hover,
.chat-form button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.history-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}

.history-item,
.history-empty,
.tool-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 15px 16px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
}

.history-item.is-active {
  border-color: rgba(110, 231, 183, 0.36);
  background: rgba(110, 231, 183, 0.08);
}

.tool-section {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.025);
}

.tool-section-featured {
  gap: 10px;
}

.tool-section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.tool-section strong {
  display: block;
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

.tool-section-copy {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.history-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.history-time,
.history-empty,
.tool-card-head,
.tool-card-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
}

.tool-card-head {
  gap: 0;
}

.tool-card-body {
  gap: 4px;
}

.tool-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.tool-card strong {
  display: block;
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.tool-card-featured {
  gap: 8px;
  padding-top: 14px;
  padding-bottom: 14px;
}

.tool-card-featured .tool-card-body {
  gap: 3px;
}

.tool-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  max-width: none;
  min-height: 24px;
  white-space: nowrap;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(110, 231, 183, 0.1);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1;
  text-transform: uppercase;
  align-self: start;
  margin: 0;
}

.upload-form {
  display: grid;
  gap: 10px;
}

.upload-dropzone {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px dashed rgba(110, 231, 183, 0.22);
  border-radius: 14px;
  background: rgba(110, 231, 183, 0.05);
  cursor: pointer;
}

.upload-dropzone span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.upload-dropzone small {
  color: var(--muted);
  line-height: 1.45;
}

.upload-form input[type="file"] {
  display: none;
}

.document-list {
  display: grid;
  gap: 8px;
}

.document-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
}

.document-item input {
  margin: 2px 0 0;
}

.document-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.document-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.document-meta,
.empty-documents {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.document-status-ready {
  border-color: rgba(110, 231, 183, 0.16);
}

.document-status-indexing,
.document-status-uploaded {
  border-color: rgba(255, 255, 255, 0.08);
}

.document-status-error {
  border-color: rgba(252, 165, 165, 0.22);
}

.choice-list {
  display: grid;
  gap: 8px;
}

.choice-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
}

.choice-item input {
  margin: 2px 0 0;
}

.choice-item span {
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
}

.edge-toggle {
  position: sticky;
  top: 14px;
  z-index: 41;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(23, 23, 23, 0.92);
  color: var(--muted-strong);
  cursor: pointer;
  pointer-events: auto;
}

.edge-toggle-icon {
  font-size: 16px;
  line-height: 1;
}

.app-shell {
  height: 100vh;
  padding: 14px 18px 18px;
  min-width: 0;
}

.chat-layout {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  gap: 10px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 28px;
  padding: 10px calc(40px + var(--edge-safe)) 14px 32px;
}

.header-side {
  flex: 0 0 180px;
  min-width: 180px;
  display: flex;
  justify-content: flex-end;
  padding-right: 10px;
}

.brand-copy h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.model-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted-strong);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(110, 231, 183, 0.45);
}

.header-meta {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  white-space: normal;
  max-width: 150px;
  text-align: right;
  overflow-wrap: anywhere;
  line-height: 1.35;
  padding-top: 4px;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}

.context-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 calc(48px + var(--edge-safe)) 4px 32px;
}

.context-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border: 1px solid rgba(110, 231, 183, 0.14);
  border-radius: 999px;
  background: rgba(110, 231, 183, 0.08);
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  line-height: 1.2;
}

.context-chip-soft {
  border-color: var(--line-soft);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted-strong);
}

.chat-box {
  min-height: 0;
  padding: 8px calc(48px + var(--edge-safe)) 96px 32px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.chat-box::-webkit-scrollbar,
.history-list::-webkit-scrollbar {
  width: 10px;
}

.chat-box::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}

.message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  margin-bottom: 18px;
  animation: message-in 0.28s ease;
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 34px;
}

.message.user .avatar {
  order: 2;
}

.message.user .message-content {
  order: 1;
  align-items: flex-end;
  padding-right: 22px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line-soft);
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  font-weight: 600;
}

.message.user .avatar {
  background: rgba(255, 255, 255, 0.09);
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.message-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.bubble {
  max-width: 100%;
  padding: 0;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--text);
}

.bubble p {
  margin: 0 0 0.78rem;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble strong {
  font-weight: 650;
  color: rgba(255, 255, 255, 0.98);
}

.bubble em {
  font-style: italic;
}

.bubble code {
  padding: 0.14rem 0.38rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.96);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.bubble pre {
  margin: 0.95rem 0;
  padding: 14px 16px;
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.22);
}

.bubble pre:last-child {
  margin-bottom: 0;
}

.bubble pre code {
  display: block;
  padding: 0;
  background: transparent;
  border-radius: 0;
  line-height: 1.65;
}

.code-label {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.message.bot .bubble {
  background: transparent;
}

.message.user .bubble {
  max-width: min(78%, 560px);
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--user-bg);
  border: 1px solid var(--line-soft);
  margin-right: 22px;
}

.message.is-streaming .bubble::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.1em;
  margin-left: 4px;
  vertical-align: text-bottom;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  animation: pulse-caret 0.9s steps(1) infinite;
}

.sources-list {
  display: grid;
  gap: 8px;
  width: min(100%, 760px);
}

.source-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 10px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.028);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.source-index {
  grid-row: 1 / span 2;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.source-name {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
}

.source-locator {
  color: var(--muted);
  font-size: 12px;
}

.source-snippet {
  grid-column: 2;
  color: var(--muted-strong);
  font-size: 12px;
  line-height: 1.55;
}

.chat-form {
  position: sticky;
  bottom: 0;
  padding: 4px calc(48px + var(--edge-safe)) 0 32px;
  background: linear-gradient(180deg, rgba(23, 23, 23, 0) 0%, rgba(23, 23, 23, 0.9) 24%, rgba(23, 23, 23, 1) 100%);
}

.composer {
  display: grid;
  gap: 10px;
  padding: 14px 14px 12px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(33, 33, 33, 0.72);
  backdrop-filter: blur(18px);
}

.chat-form textarea {
  width: 100%;
  min-height: 28px;
  max-height: 180px;
  resize: none;
  padding: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  line-height: 1.6;
}

.chat-form textarea::placeholder,
.auth-form input::placeholder {
  color: var(--muted);
}

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

.composer-actions p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.chat-form button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.38);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.chat-form button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.chat-form button.is-ready {
  background: var(--accent);
  color: #121212;
}

.chat-form button:disabled {
  cursor: default;
  opacity: 1;
}

.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: min(100%, 1040px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 32px;
  background: rgba(255, 255, 255, 0.03);
}

.auth-copy {
  margin-bottom: 20px;
}

.auth-copy h1 {
  margin: 0 0 10px;
  font-size: 36px;
  letter-spacing: -0.04em;
}

.auth-copy p {
  margin: 0;
  color: var(--muted-strong);
  line-height: 1.6;
}

.auth-error {
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid rgba(252, 165, 165, 0.18);
  border-radius: 16px;
  background: rgba(252, 165, 165, 0.08);
  color: var(--danger);
}

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

.auth-form {
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line-soft);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.02);
}

.auth-form h2 {
  margin: 0;
  font-size: 22px;
}

.auth-form label {
  display: grid;
  gap: 8px;
}

.auth-form label span {
  color: var(--muted-strong);
  font-size: 13px;
}

.auth-form input {
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: none;
}

.auth-form input:focus {
  border-color: rgba(110, 231, 183, 0.45);
}

.source-dialog {
  width: min(680px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #1b1b1b;
  color: var(--text);
}

.source-dialog::backdrop {
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(4px);
}

.source-dialog-panel {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.source-dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.source-dialog-head h3 {
  margin: 0;
  font-size: 22px;
}

.source-dialog-locator {
  color: var(--muted);
  font-size: 12px;
}

.source-dialog-body {
  padding: 14px 16px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.7;
  white-space: pre-wrap;
}

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

@keyframes pulse-caret {
  0%,
  49% {
    opacity: 1;
  }

  50%,
  100% {
    opacity: 0.24;
  }
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1100px) {
  :root {
    --edge-safe: 104px;
    --rail-safe: 0px;
  }

  .workspace-shell,
  body.history-collapsed .workspace-shell,
  body.tools-collapsed .workspace-shell,
  body.history-collapsed.tools-collapsed .workspace-shell {
    grid-template-columns: 60px minmax(0, 1fr) 60px;
  }

  .sidebar,
  .tools-panel {
    width: 60px;
    padding: 18px 10px;
    background: var(--panel-rail);
  }

  .sidebar-top,
  .tools-header {
    min-height: 84px;
    padding-top: 0;
    padding-left: 0;
    padding-right: 0;
  }

  .sidebar > *:not(.sidebar-top),
  .tools-panel > *:not(.tools-header) {
    opacity: 0;
    pointer-events: none;
  }

  .sidebar h2,
  .tools-panel h3,
  .sidebar .ghost-button,
  .tool-section {
    display: none;
  }

  .app-shell {
    padding: 14px 10px 18px;
  }

  .header-side {
    flex-basis: 132px;
    min-width: 132px;
  }

  .header-meta {
    max-width: 116px;
    font-size: 10px;
  }

  .app-header {
    padding-right: calc(24px + var(--edge-safe));
  }

  .context-bar,
  .chat-box {
    padding-right: calc(28px + var(--edge-safe));
  }

  .chat-form {
    padding-right: calc(28px + var(--edge-safe));
  }

  .edge-rail {
    width: 42px;
  }
}

@media (max-width: 640px) {
  :root {
    --edge-safe: 86px;
  }

  .app-header,
  .context-bar,
  .chat-box,
  .chat-form {
    padding-left: 18px;
    padding-right: calc(24px + var(--edge-safe));
  }

  .app-header {
    align-items: flex-start;
    gap: 12px;
  }

  .header-side {
    flex: 0 1 auto;
    min-width: 0;
    width: 100%;
    justify-content: flex-start;
    padding-right: 0;
  }

  .header-meta {
    max-width: 100%;
    font-size: 11px;
    white-space: normal;
    text-align: left;
    padding-top: 0;
  }

  .auth-shell {
    padding: 12px;
  }

  .auth-card {
    padding: 18px;
    border-radius: 20px;
  }

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

  .auth-copy h1,
  .brand-copy h1 {
    font-size: 24px;
  }

  .model-row {
    font-size: 12px;
  }

  .message.user .bubble {
    max-width: calc(84% - 10px);
    margin-right: 14px;
  }

  .message.user .message-content {
    padding-right: 14px;
  }

  .composer-actions {
    align-items: flex-end;
  }

  .composer-actions p {
    max-width: 180px;
    line-height: 1.45;
  }
}
