:root {
  --bg-0: #f3efe6;
  --bg-1: #e4d7c1;
  --panel: #fffdf8;
  --panel-2: #fff7ea;
  --text: #221f19;
  --muted: #6f675b;
  --accent: #1f7a6b;
  --accent-2: #d26a3f;
  --line: #d8cdbb;
  --danger: #ac3f3f;
  --shadow: 0 16px 42px rgba(36, 31, 24, 0.14);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 10% 4%, #fffdf7 0%, var(--bg-0) 42%, var(--bg-1) 100%);
}

body {
  padding: 18px;
  display: flex;
  flex-direction: column;
}

#root {
  flex: 1;
  overflow: hidden;
  display: flex;
}

.page-shell {
  max-width: 1260px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.top-toolbar {
  position: relative;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(135deg, #fffdf7 0%, #f8efe0 100%);
  overflow: visible;
  z-index: 20;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar-title {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5b5346;
  font-weight: 700;
  padding: 0 8px;
}

.toolbar-button {
  min-height: 42px;
}

.settings-panel {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.settings-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.settings-footer {
  display: flex;
  align-items: center;
  gap: 10px;
}

.login-wait-panel {
  padding: 16px;
}

.login-wait-panel h3 {
  margin: 0 0 6px;
}

.toolbar-popover {
  position: absolute;
  top: calc(100% + 10px);
  left: 16px;
  width: min(920px, calc(100vw - 64px));
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 251, 243, 0.98);
  box-shadow: 0 20px 48px rgba(36, 31, 24, 0.2);
  padding: 14px;
}

.toolbar-popover-grid {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 14px;
}

.toolbar-pane {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf8;
  min-height: 260px;
  display: grid;
  grid-template-rows: auto 1fr;
}

.toolbar-pane-head {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.toolbar-pane-head h3 {
  margin: 0;
  font-size: 0.95rem;
}

.toolbar-pane-body {
  padding: 12px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.index-item {
  width: 100%;
  text-align: left;
  border: 1px solid #d8cdbb;
  background: #fff8ef;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.index-item.active {
  border-color: #9ec8be;
  background: #eef8f5;
}

.index-item-name {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.83rem;
  color: #195a4e;
}

.index-item-meta {
  color: var(--muted);
  font-size: 0.77rem;
}

.metadata-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.metadata-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid #d6ccbb;
  border-radius: 999px;
  padding: 6px 10px;
  background: #fff;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.left-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  min-height: 0;
  background: linear-gradient(180deg, #fffdf9 0%, #fff8ee 100%);
}

.brand h1 {
  margin: 0;
  line-height: 1;
  letter-spacing: -0.02em;
  font-size: 1.65rem;
}

.brand p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.badge {
  display: inline-block;
  margin-top: 10px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid #cdd9d3;
  background: #f0f7f5;
  color: #295d54;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.left-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  padding: 12px;
}

.section-title {
  margin: 0 0 8px;
  font-size: 0.76rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.token-list,
.tools-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.token-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}

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

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  color: var(--text);
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(31, 122, 107, 0.2);
  border-color: var(--accent);
}

button {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.18s ease;
  font-weight: 600;
}

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

button:disabled {
  cursor: not-allowed;
  transform: none;
  opacity: 0.62;
}

.btn-primary {
  background: linear-gradient(135deg, #207766, #1a5f52);
  color: #fff;
}

.btn-secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

.btn-danger {
  background: #fff;
  color: var(--danger);
  border-color: rgba(172, 63, 63, 0.3);
}

.main-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  background: #fffcf6;
}

.chat-head h2 {
  margin: 0;
  font-size: 1.03rem;
}

.chat-stream {
  padding: 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.bubble {
  max-width: 86%;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  animation: rise 180ms ease;
}

.bubble.user {
  align-self: flex-end;
  background: #f2faf8;
  border-color: #bedcd4;
}

.bubble.assistant {
  align-self: flex-start;
  background: #fff4e7;
  border-color: #ecc9af;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 14px;
  display: grid;
  gap: 10px;
  flex-shrink: 0;
  background: #fffdf9;
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.status {
  margin-top: 8px;
  font-size: 0.83rem;
  color: var(--muted);
}

.status.success {
  color: #1b6f5f;
}

.status.pending {
  color: #9a6d37;
}

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

.tools-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.tools-item {
  border: 1px solid #d8cdbd;
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
}

.tools-item-name {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.79rem;
  color: #195a4e;
}

.tools-item-desc {
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--muted);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .page-shell {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .toolbar-popover {
    left: 12px;
    right: 12px;
    width: auto;
  }

  .toolbar-popover-grid {
    grid-template-columns: 1fr;
  }

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

  .settings-footer {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .main-panel {
    min-height: 62vh;
  }

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

  .tools-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .top-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-left,
  .toolbar-right {
    width: 100%;
  }

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

.status-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.info-icon {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 999px;
  border: 1px solid #c7bead;
  background: #fff;
  color: #3f3a32;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0;
  line-height: 1;
}

.claims-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 23, 19, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 90;
}

.claims-modal {
  width: min(720px, 100%);
  max-height: 78vh;
  overflow: hidden;
  background: #fffdf8;
  border: 1px solid #d5cab8;
  border-radius: 14px;
  box-shadow: 0 20px 45px rgba(34, 28, 20, 0.3);
  padding: 14px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 8px;
}

.claims-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.claims-head h3 {
  margin: 0;
  font-size: 1rem;
}

.claims-json {
  margin: 0;
  background: #fbf6ed;
  border: 1px solid #e0d5c4;
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
  font-size: 0.82rem;
  line-height: 1.45;
  color: #3a352e;
}

.upload-modal {
  width: min(820px, 100%);
  max-height: 82vh;
  overflow: hidden;
  background: #fffdf8;
  border: 1px solid #d5cab8;
  border-radius: 14px;
  box-shadow: 0 20px 45px rgba(34, 28, 20, 0.3);
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
}

.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 0;
}

.upload-card {
  border: 1px solid #dfd5c4;
  border-radius: 12px;
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  background: #fffaf1;
}

.upload-card h4 {
  margin: 0;
  font-size: 0.95rem;
}

.upload-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.upload-file-list {
  border: 1px solid #ddcfbb;
  border-radius: 10px;
  background: #fff;
  min-height: 96px;
  max-height: 220px;
  overflow: auto;
  padding: 8px;
  display: grid;
  align-content: start;
  gap: 6px;
}

.upload-file-item {
  border: 1px solid #d8ccb8;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.82rem;
  background: #fffdf9;
  word-break: break-word;
}

.hidden-input {
  display: none;
}
