:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #17191f;
  --panel-2: #20232b;
  --line: #2d313a;
  --text: #f4f2ee;
  --muted: #a7adb8;
  --accent: #4fb7a5;
  --accent-2: #e4b04a;
  --danger: #ef6b73;
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #071210;
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
  padding: 0 14px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d0f13;
  color: var(--text);
  padding: 11px 12px;
}

textarea {
  resize: vertical;
}

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

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 22px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.eyebrow {
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.login-panel h1,
.empty-state h1,
.chat-header h1 {
  margin: 0;
}

.muted,
.chat-header p {
  color: var(--muted);
}

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

.stack {
  display: grid;
  gap: 14px;
}

.stack label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: #0c0d10;
}

.brand {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.brand span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #071210;
  font-weight: 900;
}

.new-chat,
.logout button {
  width: 100%;
}

.conversation-list {
  display: grid;
  align-content: start;
  gap: 6px;
  overflow: auto;
}

.conversation-list a {
  overflow: hidden;
  padding: 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-list a:hover {
  background: var(--panel);
}

.empty-state {
  display: grid;
  place-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
}

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

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 78px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 17, 20, 0.94);
}

.chat-header p {
  margin: 4px 0 0;
}

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

.model-row select {
  width: auto;
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d0f13;
  color: var(--text);
  padding: 8px 10px;
}

.attachment-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.attachment-summary span {
  max-width: 160px;
  overflow: hidden;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  overflow: auto;
  padding: 26px clamp(16px, 5vw, 72px);
}

.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 14px;
  max-width: 980px;
  margin: 0 auto 22px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.message.assistant .avatar {
  background: #10201d;
  color: var(--accent);
}

.bubble {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.message.assistant .bubble {
  background: var(--panel-2);
}

.message.pending .bubble {
  border-color: rgba(79, 183, 165, 0.55);
}

.message.pending pre::after {
  content: "";
  display: inline-block;
  width: 1.1em;
  animation: dots 1.2s steps(4, end) infinite;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  line-height: 1.5;
}

.feedback {
  display: grid;
  grid-template-columns: 40px 40px minmax(0, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.feedback button {
  min-height: 34px;
  padding: 0;
  background: #303640;
  color: var(--text);
}

.feedback input {
  min-height: 34px;
  padding: 7px 10px;
}

.tool-trace {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
}

.tool-trace summary {
  cursor: pointer;
  font-weight: 700;
}

.tool-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #12151a;
}

.tool-row strong {
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-row em {
  color: var(--danger);
  font-style: normal;
}

.analysis-panel,
.tool-card,
.result-table-wrap {
  margin-top: 12px;
}

.analysis-panel {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: var(--muted);
}

.analysis-panel summary,
.tool-trace summary {
  cursor: pointer;
}

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

.analysis-grid div,
.tool-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12151a;
  padding: 10px;
}

.analysis-grid span,
.table-meta {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.analysis-grid strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
}

.pattern-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.pattern-list span {
  max-width: 100%;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: #0d0f13;
  color: var(--muted);
  font-size: 12px;
}

.tool-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
}

.tool-card p {
  margin: 8px 0;
  color: var(--muted);
}

.tool-card code {
  display: block;
  overflow-wrap: anywhere;
  color: var(--accent-2);
}

.tool-error {
  border-color: rgba(239, 107, 115, 0.65);
}

.result-table-wrap {
  overflow: auto;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.result-table th,
.result-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.result-table th {
  color: var(--accent);
  font-weight: 800;
}

.status-line {
  min-height: 24px;
  padding: 0 clamp(16px, 5vw, 72px);
  color: var(--muted);
  font-size: 14px;
}

.status-line[data-tone="ok"] {
  color: var(--accent);
}

.status-line[data-tone="warn"] {
  color: var(--accent-2);
}

.status-line[data-tone="error"] {
  color: var(--danger);
}

.composer {
  display: grid;
  gap: 10px;
  padding: 16px clamp(16px, 5vw, 72px) 22px;
  border-top: 1px solid var(--line);
  background: #0c0d10;
}

.composer-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
  100% { content: ""; }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .conversation-list,
  .logout {
    display: none;
  }

  .chat-shell {
    height: calc(100vh - 122px);
  }
}
