:root {
  --bg: #f4f5f7;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: #ffffff;
  --panel-soft: #f7f8fb;
  --border: #dfe3eb;
  --border-strong: #c9d3e4;
  --text: #243042;
  --text-muted: #6d798b;
  --text-soft: #94a0b3;
  --blue: #4484f3;
  --blue-strong: #2e6ce3;
  --blue-soft: #dfeafc;
  --green: #1fa972;
  --green-soft: #e8f8f0;
  --red: #d35f5f;
  --red-soft: #fdecec;
  --shadow: 0 24px 50px rgba(44, 62, 104, 0.08);
  --radius-xl: 28px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --content: 1480px;
  --font-ui: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-report: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  color: var(--text);
  background:
    linear-gradient(180deg, #f7f8fb 0%, #eef1f7 100%);
  -webkit-font-smoothing: antialiased;
}

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

.shell {
  min-height: 100vh;
  padding: 18px;
}

.workspace {
  max-width: var(--content);
  min-height: calc(100vh - 40px);
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid rgba(203, 211, 225, 0.9);
  border-radius: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(16px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}

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

.page-title {
  margin: 0;
  font-size: 26px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

.connection-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 16px;
  background: var(--green-soft);
  color: var(--green);
  font-weight: 700;
}

.connection-text {
  font-size: 14px;
}

.connection-meta {
  font-size: 14px;
}

.header-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #b7c0ce;
  flex-shrink: 0;
}

.header-dot.online {
  background: #23bf7e;
}

.header-dot.offline {
  background: #e06d6d;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--panel-strong);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}

.settings-trigger:hover {
  background: #f7faff;
  border-color: #b9c8e6;
}

.settings-trigger-icon {
  font-size: 17px;
  line-height: 1;
}

.model-picker select {
  width: min(380px, 30vw);
  border: 1px solid var(--border-strong);
  background: var(--panel-strong);
  color: #1f2532;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.02);
}

.icon-btn {
  border: 0;
  background: transparent;
  font-size: 18px;
  color: #a0a8b5;
  cursor: pointer;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
}

.icon-btn:hover {
  background: rgba(68, 132, 243, 0.08);
  color: var(--blue-strong);
}

.chat-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px 0;
  background:
    linear-gradient(180deg, rgba(248, 249, 252, 0.65), rgba(244, 246, 251, 0.9));
}

.empty {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  align-items: center;
  padding: 28px 20px;
}

.hero-card {
  max-width: 860px;
  padding: 22px 26px;
  border-radius: 24px;
  background: linear-gradient(180deg, #ffffff, #f5f8ff);
  border: 1px solid var(--border);
  box-shadow: 0 16px 34px rgba(64, 92, 145, 0.08);
  text-align: center;
}

.hero-title {
  font-size: 28px;
  line-height: 1.05;
  font-weight: 700;
  margin-bottom: 10px;
}

.hero-sub {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-muted);
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  max-width: 1100px;
}

.suggest {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
}

.suggest:hover {
  border-color: #b7c8eb;
  background: #f4f8ff;
}

.msg {
  max-width: none;
  width: 100%;
  display: flex;
  margin: 0;
}

.msg.user {
  justify-content: flex-end;
  padding: 0 18px 12px 260px;
}

.msg.assistant {
  justify-content: flex-start;
  padding: 0 260px 22px 18px;
}

.avatar {
  display: none;
}

.bubble {
  border-radius: 22px;
  max-width: 100%;
  overflow: hidden;
}

.msg.user .bubble {
  background: linear-gradient(180deg, #4f8df7, #3f7ef0);
  color: #fff;
  border-radius: 24px;
  padding: 18px 22px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
  box-shadow: 0 18px 30px rgba(63, 126, 240, 0.18);
}

.msg.assistant .bubble {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  padding: 20px 22px;
  box-shadow: 0 8px 24px rgba(94, 108, 137, 0.08);
}

.tool-hint {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-soft);
}

.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.thinking span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #b1bbcd;
  animation: pulse 1.2s infinite ease-in-out;
}

.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.report {
  color: #546173;
  font-size: 16px;
  line-height: 1.6;
}

.report p {
  margin: 0 0 18px;
}

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

.report strong {
  color: #4d5a6d;
  font-weight: 700;
}

.report h1,
.report h2,
.report h3 {
  margin: 0 0 18px;
  color: #20263a;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.report h1 { font-size: 34px; }
.report h2 { font-size: 28px; }
.report h3 { font-size: 22px; }

.report ul,
.report ol {
  margin: 0 0 22px 24px;
  padding: 0;
}

.report li {
  margin-bottom: 8px;
}

.report code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 2px 10px;
  border-radius: 12px;
  background: #eef2f7;
  color: #5b6471;
  font-size: 0.92em;
}

.report pre {
  background: #1f2430;
  color: #eef3ff;
  border-radius: 18px;
  padding: 18px 20px;
  overflow-x: auto;
  font-size: 16px;
  line-height: 1.45;
  margin: 0 0 20px;
}

.report-table-wrap {
  overflow-x: auto;
  margin: 20px 0 26px;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 18px;
  overflow: hidden;
  font-size: 14px;
}

.report-table th {
  background: #21243b;
  color: rgba(255, 255, 255, 0.88);
  text-align: left;
  font-weight: 600;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.report-table td {
  padding: 12px 14px;
  border: 1px solid #d8dfeb;
  color: #49586d;
  background: #ffffff;
}

.report-table tbody tr:nth-child(odd) td {
  background: #edf7ee;
}

.report-table tbody tr:nth-child(even) td {
  background: #fff6dc;
}

.report-table tbody tr:last-child td {
  background: #f0f0f2;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin: 18px 0 26px;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid #cfe0f1;
}

.metric-card {
  padding: 14px 18px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.metric-card:nth-child(1) { background: #dff5ee; }
.metric-card:nth-child(2) { background: #dbe9fb; }
.metric-card:nth-child(3) { background: #fff0d4; }

.metric-label {
  font-size: 14px;
  color: #6d7584;
  margin-bottom: 8px;
}

.metric-value {
  font-size: 24px;
  line-height: 1;
  color: #223049;
  letter-spacing: -0.03em;
}

.composer {
  padding: 12px 18px 16px;
  background: linear-gradient(180deg, rgba(244, 246, 251, 0), rgba(244, 246, 251, 0.9) 22%);
}

.composer-box {
  max-width: 1400px;
  margin: 0 auto;
  background: #ffffff;
  border: 3px solid #c8c8ff;
  border-radius: 24px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 16px 14px 18px;
  box-shadow: 0 10px 26px rgba(118, 132, 171, 0.1);
}

#input {
  flex: 1;
  border: 0;
  resize: none;
  outline: none;
  min-height: 42px;
  max-height: 180px;
  font-size: 16px;
  line-height: 1.45;
  color: #444a55;
  background: transparent;
}

#input::placeholder {
  color: #888d98;
}

.send-btn {
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #4d8cf6, #3678ed);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  box-shadow: 0 14px 30px rgba(54, 120, 237, 0.28);
}

.send-arrow {
  font-size: 22px;
  transform: translateX(2px);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(30, 36, 52, 0.36);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(920px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #ffffff;
  border-radius: 24px;
  border: 1px solid var(--border);
  box-shadow: 0 26px 54px rgba(31, 45, 74, 0.18);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 26px 28px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 6px;
}

.modal-sub {
  color: var(--text-muted);
  font-size: 16px;
}

.modal-close {
  border: 0;
  background: transparent;
  color: #97a1b1;
  font-size: 34px;
  cursor: pointer;
  line-height: 1;
}

.settings-form {
  padding: 26px 28px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-form fieldset {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-form legend {
  padding: 0 8px;
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-form label > span {
  color: #5b6676;
  font-size: 15px;
}

.settings-form input[type="password"],
.settings-form input[type="text"],
.settings-form textarea,
.settings-form select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: #fbfcfe;
  color: var(--text);
  padding: 14px 16px;
  outline: none;
}

.settings-form textarea {
  resize: vertical;
  min-height: 120px;
}

.settings-form small {
  color: var(--text-soft);
}

.settings-form input:focus,
.settings-form textarea:focus,
.settings-form select:focus {
  border-color: #8db0f6;
}

.row {
  display: flex;
  gap: 10px;
}

.row-model {
  align-items: flex-start;
}

.model-combobox {
  position: relative;
  flex: 1;
}

.model-combobox input[type="text"] {
  padding-right: 44px;
}

.model-combobox-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
}

.model-combobox-toggle:hover {
  background: #f1f5fc;
  color: var(--text);
}

.model-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 18px 34px rgba(31, 45, 74, 0.14);
  z-index: 20;
}

.model-option {
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid #eef2f8;
}

.model-option:last-child {
  border-bottom: 0;
}

.model-option:hover,
.model-option.active {
  background: #f4f8ff;
}

.model-option-name {
  color: var(--text);
  font-size: 14px;
  margin-bottom: 4px;
}

.model-option-id {
  color: var(--text-muted);
  font-size: 12px;
}

.model-empty {
  padding: 14px;
  color: var(--text-muted);
  font-size: 14px;
}

.settings-form input[type="range"] {
  width: 100%;
}

.check {
  flex-direction: row;
  align-items: center;
}

.check input {
  width: auto;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.ghost-btn,
.primary-btn {
  border-radius: 14px;
  padding: 12px 18px;
  cursor: pointer;
  border: 1px solid var(--border-strong);
}

.ghost-btn {
  background: #f7f9fd;
  color: var(--text);
}

.primary-btn {
  border-color: transparent;
  background: linear-gradient(180deg, #4d8cf6, #3678ed);
  color: #fff;
  box-shadow: 0 12px 24px rgba(54, 120, 237, 0.22);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  border-radius: 16px;
  padding: 14px 18px;
  background: rgba(34, 44, 62, 0.94);
  color: #fff;
  z-index: 200;
  box-shadow: 0 18px 30px rgba(31, 45, 74, 0.18);
}

.toast[hidden] {
  display: none;
}

.toast.success {
  background: rgba(31, 154, 109, 0.94);
}

.toast.error {
  background: rgba(196, 74, 74, 0.94);
}

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

@media (max-width: 1400px) {
  .msg.user {
    padding-left: 120px;
  }

  .msg.assistant {
    padding-right: 120px;
  }

  .page-title { font-size: 24px; }
  .msg.user .bubble { font-size: 17px; }
}

@media (max-width: 980px) {
  .shell {
    padding: 0;
  }

  .workspace {
    min-height: 100vh;
    border-radius: 0;
  }

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

  .topbar-main,
  .topbar-actions {
    width: 100%;
  }

  .topbar-main {
    flex-wrap: wrap;
  }

  .topbar-actions {
    justify-content: space-between;
  }

  .model-picker {
    flex: 1;
  }

  .settings-trigger {
    flex-shrink: 0;
  }

  .model-picker select {
    width: 100%;
  }

  .msg.user,
  .msg.assistant {
    padding-left: 0;
    padding-right: 0;
  }

  .msg.user .bubble {
    font-size: 20px;
  }

  .report {
    font-size: 18px;
  }

  .report h1 { font-size: 34px; }
  .report h2 { font-size: 28px; }
  .report h3 { font-size: 24px; }

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

  #input {
    font-size: 18px;
  }

  .composer-box {
    padding: 14px 16px;
  }

  .send-btn {
    width: 56px;
    height: 56px;
  }
}
