:root {
  --bg: #f3efe8;
  --panel: rgba(255, 255, 255, 0.9);
  --border: rgba(27, 31, 36, 0.12);
  --text: #1b1f24;
  --muted: #66707c;
  --accent: #0f766e;
  --accent-2: #b45309;
  --assistant: #ffffff;
  --user: #daf5f0;
  --shadow: 0 24px 64px rgba(25, 28, 31, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Space Grotesk", "Noto Sans SC", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 14% 8%, #f9dcc0 0%, transparent 30%),
    radial-gradient(circle at 88% 84%, #cce7ff 0%, transparent 32%), var(--bg);
  display: grid;
  place-items: center;
  padding: 20px;
}

.bg-shape {
  position: fixed;
  z-index: 0;
  pointer-events: none;
  opacity: 0.38;
  filter: blur(40px);
}

.shape-a {
  width: 340px;
  height: 340px;
  top: -100px;
  right: -90px;
  background: #f59e0b;
}

.shape-b {
  width: 300px;
  height: 300px;
  left: -90px;
  bottom: -90px;
  background: #14b8a6;
}

.app-frame {
  position: relative;
  z-index: 1;
  width: min(1280px, 100%);
  height: min(92vh, 920px);
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 14px;
}

.sidebar,
.shell {
  display: grid;
  background: var(--panel);
  border: 1px solid var(--border);
  overflow: hidden;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.sidebar {
  grid-template-rows: auto 1fr;
  border-radius: 24px;
}

.shell {
  grid-template-rows: auto 1fr auto;
  border-radius: 28px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

#new-conversation {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(15, 118, 110, 0.2);
  border-radius: 12px;
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

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

.conversation-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  width: 100%;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
}

.conversation-title,
.conversation-menu-button {
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.conversation-title {
  min-width: 0;
  min-height: 38px;
  padding: 10px 8px 10px 12px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-menu-button {
  width: 30px;
  height: 30px;
  margin-right: 4px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.conversation-row.active {
  border-color: rgba(15, 118, 110, 0.18);
  background: rgba(15, 118, 110, 0.08);
}

.conversation-row.active .conversation-title {
  color: var(--accent);
  font-weight: 700;
}

.conversation-row:hover,
.conversation-row.menu-open {
  background: rgba(255, 255, 255, 0.72);
}

.conversation-menu-button:hover,
.conversation-row.menu-open .conversation-menu-button {
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent);
}

.conversation-menu {
  position: absolute;
  z-index: 6;
  top: 34px;
  right: 6px;
  min-width: 94px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 32px rgba(25, 28, 31, 0.14);
}

.conversation-menu button {
  display: block;
  width: 100%;
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.conversation-menu button:hover {
  background: rgba(15, 118, 110, 0.08);
}

.conversation-menu button.danger {
  color: #b91c1c;
}

.conversation-menu button.danger:hover {
  background: rgba(185, 28, 28, 0.08);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(120deg, rgba(15, 118, 110, 0.08), rgba(180, 83, 9, 0.08));
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

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

.brand h1 {
  margin: 0;
  font-size: 26px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
}

.dataset-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
}

.template-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.template-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(180, 83, 9, 0.18);
  background: rgba(255, 247, 237, 0.92);
  color: #9a3412;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

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

.dataset-label {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.dataset-status {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.chat {
  display: grid;
  align-content: start;
  gap: 14px;
  overflow: auto;
  padding: 22px;
}

.msg {
  display: grid;
  gap: 6px;
  max-width: 78%;
  animation: fadeUp 0.2s ease;
}

.msg.user {
  justify-self: end;
}

.msg.assistant {
  justify-self: start;
}

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

.bubble {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--assistant);
  word-break: break-word;
  line-height: 1.6;
}

.msg.user .bubble {
  background: var(--user);
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  margin-bottom: 10px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.mode-badge.clarify {
  border-color: rgba(180, 83, 9, 0.22);
  background: rgba(251, 146, 60, 0.12);
  color: #9a3412;
}

.mode-badge.error {
  border-color: rgba(185, 28, 28, 0.2);
  background: rgba(254, 226, 226, 0.8);
  color: #991b1b;
}

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

.msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.artifact-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(15, 118, 110, 0.2);
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

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

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.quick-actions button {
  min-height: 32px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid rgba(15, 118, 110, 0.2);
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

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

.composer {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  padding: 16px 18px 18px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.84);
}

.capability-menu {
  position: absolute;
  left: 18px;
  right: 260px;
  bottom: 84px;
  z-index: 20;
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.capability-menu[hidden] {
  display: none;
}

.capability-option {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.capability-option span {
  font-weight: 700;
}

.capability-option small {
  color: var(--muted);
  font-size: 12px;
}

.capability-option:hover {
  background: rgba(15, 118, 110, 0.08);
}

#input {
  width: 100%;
  min-height: 56px;
  max-height: 180px;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: white;
  resize: none;
  font: inherit;
  outline: none;
}

.composer-actions {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.file-trigger,
#upload-btn,
#send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 0 18px;
  border: none;
  border-radius: 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.file-trigger {
  color: var(--text);
  background: #fff7ed;
  border: 1px solid rgba(180, 83, 9, 0.24);
}

#upload-btn {
  color: white;
  background: linear-gradient(140deg, var(--accent-2), #9a3412);
}

#send {
  color: white;
  background: linear-gradient(140deg, var(--accent), #0a5d57);
}

.file-trigger:hover,
#upload-btn:hover,
#send:hover {
  transform: translateY(-1px);
}

.file-trigger:active,
#upload-btn:active,
#send:active {
  transform: translateY(0);
}

#input:focus {
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.08);
}

#upload-btn:disabled,
#send:disabled,
.file-trigger.disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

@media (max-width: 900px) {
  .app-frame {
    grid-template-columns: 1fr;
    height: 95vh;
  }

  .sidebar {
    max-height: 156px;
  }

  .conversation-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(160px, 220px);
    overflow-x: auto;
    overflow-y: hidden;
  }

  .topbar,
  .composer {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar-tools {
    flex-direction: column;
    align-items: stretch;
  }

  .dataset-bar {
    max-width: 100%;
  }

  .composer-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .capability-menu {
    right: 18px;
    bottom: 150px;
  }
}

@media (max-width: 640px) {
  body {
    padding: 10px;
  }

  .app-frame {
    gap: 10px;
  }

  .shell {
    border-radius: 20px;
  }

  .msg {
    max-width: 92%;
  }

  .composer-actions {
    width: 100%;
  }

  .file-trigger,
  #upload-btn,
  #send {
    flex: 1 1 auto;
  }
}
