:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --sidebar: #f3f4f6;
  --sidebar-hover: #e9ecef;
  --line: #d9dde3;
  --line-strong: #c4cad3;
  --muted: #6b7280;
  --text: #111827;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --user: #e9f7f3;
  --danger: #b42318;
  --success: #087443;
  --shadow: 0 18px 44px rgba(17, 24, 39, 0.11);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

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

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

button {
  color: inherit;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  padding: 12px;
}

.sidebar-top {
  display: grid;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 4px;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.brand h1,
.brand p,
.chat-header h2,
.chat-header p {
  margin: 0;
}

.brand h1 {
  font-size: 15px;
  line-height: 1.2;
}

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

.new-chat,
.history-item,
.header-action,
.drawer summary,
.upload-panel button,
.composer button,
.prompt-chips button {
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.new-chat {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  min-height: 42px;
  background: var(--surface);
  border-color: var(--line);
  padding: 0 12px;
  font-weight: 650;
}

.new-chat span:first-child {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 8px;
  background: #eef2f7;
  font-size: 18px;
  line-height: 1;
}

.new-chat:hover,
.history-item:hover,
.drawer summary:hover,
.header-action:hover {
  background: var(--sidebar-hover);
}

.chat-history {
  display: grid;
  gap: 4px;
  margin-top: 18px;
}

.history-item {
  width: 100%;
  min-height: 36px;
  overflow: hidden;
  background: transparent;
  padding: 0 10px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item.is-active {
  background: #e7eaee;
  font-weight: 650;
}

.sidebar-bottom {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.drawer {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.drawer summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  list-style: none;
  padding: 0 12px;
  font-weight: 650;
}

.drawer summary::-webkit-details-marker {
  display: none;
}

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

.upload-panel,
.settings {
  display: grid;
  gap: 9px;
  border-top: 1px solid var(--line);
  padding: 12px;
}

.upload-panel label,
.settings label {
  color: #4b5563;
  font-size: 12px;
  font-weight: 650;
}

.upload-panel input,
.upload-panel select,
.settings input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
  outline: none;
}

.upload-panel input:focus,
.upload-panel select:focus,
.settings input:focus,
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.toggle-stack {
  display: grid;
  gap: 6px;
  padding: 4px 0;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.file-picker {
  display: grid;
  gap: 3px;
  min-height: 52px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #fafafa;
  padding: 8px 10px;
  cursor: pointer;
}

.file-picker span:first-child {
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-picker span:last-child {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

#documentInput {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.upload-panel button,
.composer button {
  min-height: 40px;
  background: var(--accent);
  color: #fff;
  font-weight: 750;
}

.upload-panel button:hover,
.composer button:hover {
  background: var(--accent-strong);
}

.composer .secondary-action {
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--text);
}

.composer .secondary-action:hover {
  background: #eef2f7;
}

.upload-panel button:disabled,
.composer button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.upload-status {
  min-height: 32px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.upload-status[data-tone="success"] {
  color: var(--success);
}

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

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 100vh;
  background: var(--bg);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  border-bottom: 1px solid rgba(217, 221, 227, 0.72);
  background: rgba(247, 247, 248, 0.86);
  padding: 10px max(20px, calc((100vw - 1120px) / 2));
  backdrop-filter: blur(12px);
}

.chat-header p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.chat-header h2 {
  margin-top: 2px;
  font-size: 16px;
  line-height: 1.2;
}

.header-action {
  min-height: 36px;
  background: var(--surface);
  border-color: var(--line);
  padding: 0 12px;
  font-weight: 650;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding: 32px max(18px, calc((100vw - 1120px) / 2)) 26px;
}

.empty-state {
  display: grid;
  gap: 14px;
  width: min(760px, 100%);
  margin: auto;
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  font-size: 34px;
  line-height: 1.12;
  font-weight: 760;
}

.empty-state p {
  max-width: 620px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

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

.prompt-chips button {
  min-height: 54px;
  background: var(--surface);
  border-color: var(--line);
  padding: 10px 12px;
  color: #374151;
  text-align: left;
  line-height: 1.25;
}

.prompt-chips button:hover {
  border-color: var(--line-strong);
  box-shadow: 0 6px 18px rgba(17, 24, 39, 0.06);
}

.message {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: min(820px, 100%);
  align-self: center;
}

.avatar {
  display: none;
}

.bubble {
  min-width: 0;
  line-height: 1.62;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble.rendered-response {
  display: grid;
  gap: 11px;
  white-space: normal;
}

.rendered-response h3,
.rendered-response h4 {
  margin: 8px 0 0;
  color: #0f172a;
  line-height: 1.25;
}

.rendered-response h3 {
  font-size: 20px;
  font-weight: 780;
}

.rendered-response h4 {
  font-size: 16px;
  font-weight: 760;
}

.rendered-response p {
  margin: 0;
}

.rendered-response .response-label {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  border: 1px solid #c9d8d4;
  border-radius: 8px;
  background: #f3faf8;
  padding: 6px 9px;
  color: #164e47;
  font-size: 13px;
  line-height: 1.35;
}

.rendered-response ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 22px;
}

.rendered-response li {
  padding-left: 3px;
}

.rendered-response li::marker {
  color: var(--accent);
}

.rendered-response code {
  border: 1px solid #d8dee7;
  border-radius: 6px;
  background: #f8fafc;
  padding: 1px 5px;
  color: #0f172a;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.matrix-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.response-matrix {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.45;
}

.response-matrix th,
.response-matrix td {
  border-bottom: 1px solid #e5e7eb;
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

.response-matrix th {
  background: #eef6f4;
  color: #123b36;
  font-size: 12px;
  font-weight: 780;
  letter-spacing: 0;
  text-transform: uppercase;
}

.response-matrix tr:last-child td {
  border-bottom: 0;
}

.response-matrix tbody tr:nth-child(even) {
  background: #fafafa;
}

.evidence-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 0;
}

.evidence-panel summary {
  min-height: 40px;
  cursor: pointer;
  padding: 10px 12px;
  color: #263238;
  font-size: 13px;
  font-weight: 760;
}

.evidence-notices {
  display: grid;
  gap: 6px;
  border-top: 1px solid #e5e7eb;
  padding: 10px 12px;
}

.evidence-notices p {
  color: #4b5563;
  font-size: 13px;
}

.evidence-group {
  display: grid;
  gap: 8px;
  border-top: 1px solid #e5e7eb;
  padding: 12px;
}

.evidence-group h4 {
  margin: 0;
  color: #0f172a;
  font-size: 13px;
}

.evidence-grid {
  display: grid;
  gap: 8px;
}

.evidence-card {
  display: grid;
  gap: 8px;
  border: 1px solid #e1e7ef;
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.evidence-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.evidence-card-top strong {
  font-size: 13px;
  line-height: 1.35;
}

.evidence-badge {
  flex: 0 0 auto;
  border: 1px solid #d0d7e2;
  border-radius: 999px;
  background: #f3f4f6;
  padding: 2px 7px;
  color: #374151;
  font-size: 11px;
  font-weight: 750;
}

.evidence-badge[data-classification="official"],
.evidence-badge[data-classification^="official_"] {
  border-color: #b7dbc8;
  background: #ecfdf3;
  color: #087443;
}

.evidence-badge[data-classification="internal_methodology"] {
  border-color: #c9d8d4;
  background: #f3faf8;
  color: #164e47;
}

.evidence-card dl {
  display: grid;
  gap: 5px;
  margin: 0;
}

.evidence-card dl div {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 8px;
}

.evidence-card dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.evidence-card dd {
  min-width: 0;
  margin: 0;
  color: #1f2937;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.message.assistant .bubble {
  padding: 2px 0;
}

.message.assistant .bubble.is-thinking {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px 14px;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.06);
}

.thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #374151;
  font-size: 14px;
}

.thinking-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--accent);
  animation: pulse 1.25s ease-in-out infinite;
}

.thinking-time {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.progress-bar {
  height: 3px;
  overflow: hidden;
  border-radius: 8px;
  background: #e5e7eb;
  margin-top: 10px;
}

.progress-bar span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  animation: progress-slide 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.88);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes progress-slide {
  0% {
    transform: translateX(-110%);
  }
  100% {
    transform: translateX(250%);
  }
}

.message.user {
  justify-items: end;
}

.message.user .bubble {
  max-width: min(680px, 92%);
  border: 1px solid #d6ebe5;
  border-radius: 8px;
  background: var(--user);
  padding: 12px 14px;
}

.composer-wrap {
  border-top: 1px solid rgba(217, 221, 227, 0.72);
  background: rgba(247, 247, 248, 0.9);
  padding: 14px max(18px, calc((100vw - 1120px) / 2)) 12px;
  backdrop-filter: blur(12px);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px 74px;
  gap: 10px;
  width: min(820px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px;
  box-shadow: var(--shadow);
}

.composer textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 11px 8px;
  line-height: 1.45;
  outline: none;
}

.composer textarea:focus {
  box-shadow: none;
}

.composer button {
  align-self: end;
  min-height: 40px;
}

.composer-note {
  width: min(820px, 100%);
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
}

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

  .sidebar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-top {
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .new-chat {
    width: 126px;
  }

  .chat-history {
    display: none;
  }

  .sidebar-bottom {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    margin-top: 0;
  }

  .chat-panel {
    min-height: calc(100vh - 128px);
  }

  .chat-header {
    padding: 10px 14px;
  }

  .messages {
    padding: 24px 14px;
  }

  .prompt-chips {
    grid-template-columns: 1fr;
  }

  .composer-wrap {
    padding: 12px;
  }
}

@media (max-width: 560px) {
  .brand p,
  .chat-header p,
  .header-action,
  .composer-note {
    display: none;
  }

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

  .sidebar-top,
  .sidebar-bottom {
    grid-template-columns: 1fr;
  }

  .new-chat {
    width: 100%;
  }

  .chat-panel {
    min-height: calc(100vh - 246px);
  }

  .empty-state h2 {
    font-size: 28px;
  }

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