:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #5d6b75;
  --line: #d9e0e5;
  --surface: #ffffff;
  --surface-soft: #f4f7f8;
  --accent: #0d6f7b;
  --accent-strong: #084f58;
  --warning: #8a5a00;
  --shadow: 0 18px 42px rgba(23, 32, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(13, 111, 123, 0.12), transparent 32%),
    linear-gradient(315deg, rgba(196, 86, 48, 0.1), transparent 28%),
    #edf2f4;
  font-family: Arial, Helvetica, sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  width: min(1400px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.chat-panel,
.library-panel {
  min-height: calc(100vh - 36px);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chat-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}

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

.header-status {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

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

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
}

.status {
  flex: 0 0 auto;
  max-width: 220px;
  padding: 7px 10px;
  border: 1px solid rgba(13, 111, 123, 0.28);
  border-radius: 999px;
  color: var(--accent-strong);
  background: rgba(13, 111, 123, 0.08);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.user-status {
  max-width: 240px;
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  color: #24323a;
  background: #ffffff;
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-status,
.rag-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #4b5962;
  background: #ffffff;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.ai-dot,
.rag-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #9aa6ad;
  box-shadow: 0 0 0 3px rgba(154, 166, 173, 0.16);
}

.ai-status.online,
.rag-status.online {
  border-color: rgba(13, 111, 123, 0.3);
  color: var(--accent-strong);
  background: rgba(13, 111, 123, 0.08);
}

.ai-status.online .ai-dot,
.rag-status.online .rag-dot {
  background: #168a5b;
  box-shadow: 0 0 0 3px rgba(22, 138, 91, 0.16);
}

.ai-status.offline,
.rag-status.offline {
  border-color: rgba(138, 90, 0, 0.24);
  color: var(--warning);
  background: rgba(138, 90, 0, 0.08);
}

.ai-status.offline .ai-dot,
.rag-status.offline .rag-dot {
  background: #b06a00;
  box-shadow: 0 0 0 3px rgba(176, 106, 0, 0.16);
}

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(260px, 340px) minmax(180px, 260px);
  gap: 10px;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.auth-panel.confirmed {
  background: rgba(13, 111, 123, 0.06);
}

.auth-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 8px;
}

.auth-form button {
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 800;
}

.auth-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.examples button,
.composer button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.examples button {
  padding: 8px 10px;
  color: #24323a;
  background: #ffffff;
  border: 1px solid var(--line);
}

.examples button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  overflow: auto;
}

.message {
  display: flex;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(760px, 88%);
  padding: 13px 15px;
  border-radius: 8px;
  line-height: 1.48;
  white-space: pre-wrap;
}

.message-meta {
  margin-bottom: 6px;
  color: rgba(23, 32, 38, 0.68);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.user .message-meta {
  color: rgba(255, 255, 255, 0.78);
}

.assistant .bubble {
  background: #eef6f7;
  border: 1px solid rgba(13, 111, 123, 0.18);
}

.user .bubble {
  color: #ffffff;
  background: var(--accent-strong);
}

.related-files {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(13, 111, 123, 0.18);
}

.related-files-title {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.related-file {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 10px;
  align-items: center;
  padding: 9px;
  border: 1px solid rgba(13, 111, 123, 0.18);
  border-radius: 8px;
  background: #ffffff;
}

.related-file-info {
  min-width: 0;
}

.related-file-name {
  overflow: hidden;
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.related-file-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.related-file-download {
  display: grid;
  place-items: center;
  min-height: 32px;
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.related-file-download:hover {
  background: var(--accent-strong);
}

.process-trace {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(13, 111, 123, 0.18);
  white-space: normal;
}

.process-trace summary {
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.process-trace-list {
  display: grid;
  gap: 7px;
  margin-top: 9px;
}

.process-trace-row {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 7px 8px;
  border: 1px solid rgba(13, 111, 123, 0.16);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.72);
}

.process-trace-label {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.process-trace-value {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #37464f;
  font-size: 12px;
  line-height: 1.35;
}

.feedback-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(13, 111, 123, 0.18);
}

.feedback-label,
.feedback-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.feedback-button {
  min-height: 28px;
  padding: 5px 10px;
  border: 1px solid rgba(13, 111, 123, 0.28);
  border-radius: 6px;
  color: var(--accent-strong);
  background: #ffffff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.feedback-button:hover {
  border-color: var(--accent);
  background: #eef6f7;
}

.feedback-button:disabled {
  cursor: default;
  opacity: 0.58;
}

.feedback-row[data-rating="good"] .feedback-button:first-of-type,
.feedback-row[data-rating="bad"] .feedback-button:last-of-type {
  color: #ffffff;
  background: var(--accent);
}

.correction-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px;
  gap: 8px;
  margin-top: 8px;
}

.correction-form[hidden] {
  display: none;
}

.correction-input {
  min-height: 54px;
  resize: vertical;
  border: 1px solid rgba(13, 111, 123, 0.28);
  border-radius: 6px;
  padding: 8px 9px;
  background: #ffffff;
}

.correction-save {
  min-height: 36px;
  align-self: start;
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.correction-save:hover {
  background: var(--accent-strong);
}

.correction-save:disabled {
  cursor: default;
  opacity: 0.62;
}

.match-list {
  display: grid;
  gap: 8px;
  width: min(760px, 88%);
}

.match-card,
.product-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.match-card {
  padding: 12px;
}

.match-title {
  font-weight: 800;
}

.match-score {
  margin-top: 3px;
  color: var(--warning);
  font-size: 13px;
  font-weight: 700;
}

.match-reasons {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 172px;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.composer-main {
  display: grid;
  gap: 8px;
}

.composer-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #ffffff;
}

textarea:disabled,
input:disabled,
button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

textarea {
  min-height: 72px;
  max-height: 180px;
  resize: vertical;
  padding: 11px 12px;
}

input {
  max-width: 150px;
  padding: 8px 10px;
}

textarea:focus,
input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(13, 111, 123, 0.16);
}

.send-button,
.attach-button {
  display: grid;
  place-items: center;
  min-height: 40px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.attach-button {
  border: 1px solid var(--line);
  color: var(--accent-strong);
  background: #ffffff;
}

.attach-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.attach-button:hover {
  border-color: var(--accent);
  background: #eef6f7;
}

.send-button {
  color: #ffffff;
  background: var(--accent);
}

.send-button:hover {
  background: var(--accent-strong);
}

.send-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.attachment-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
}

.mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #43515a;
  background: #ffffff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.mode-row label:has(input:checked) {
  border-color: rgba(13, 111, 123, 0.42);
  color: var(--accent-strong);
  background: rgba(13, 111, 123, 0.08);
}

.mode-row input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

.attachment-chip {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid rgba(13, 111, 123, 0.22);
  border-radius: 6px;
  overflow: hidden;
  color: var(--accent-strong);
  background: rgba(13, 111, 123, 0.08);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #4b5962;
  background: #ffffff;
  cursor: pointer;
  font-weight: 800;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.library-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.library-scroll {
  display: grid;
  grid-template-rows: auto auto;
  min-height: 0;
  overflow: auto;
}

.products,
.tds-files {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 14px;
}

.tds-files {
  max-height: 720px;
  overflow: auto;
}

.product-card {
  padding: 12px;
}

.product-code {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.product-name {
  margin-top: 3px;
  font-weight: 800;
}

.product-desc {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 9px;
}

.tag {
  padding: 4px 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: #43515a;
  font-size: 11px;
  font-weight: 700;
}

.tds-files-section {
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.rag-update-section {
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.openai-section {
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 0;
}

.file-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.openai-form {
  display: grid;
  gap: 8px;
  padding: 12px 14px 14px;
}

.openai-form input {
  width: 100%;
  max-width: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.openai-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.openai-form button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 800;
}

.openai-form button:hover {
  background: var(--accent-strong);
}

.openai-form .secondary-button {
  border: 1px solid rgba(13, 111, 123, 0.28);
  color: var(--accent-strong);
  background: #ffffff;
}

.openai-form .secondary-button:hover {
  background: #eef6f7;
}

.rag-update-button {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.rag-update-button:hover {
  background: var(--accent-strong);
}

.rag-update-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.rag-progress {
  display: grid;
  gap: 8px;
  padding: 12px 14px 14px;
}

.rag-progress-meta,
.rag-update-stats {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.rag-progress-meta span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rag-progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.rag-progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.2s ease;
}

.rag-progress-bar.running {
  background: linear-gradient(90deg, var(--accent), #c45630);
}

.rag-log {
  display: grid;
  gap: 4px;
  max-height: 150px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.rag-log-line {
  overflow: hidden;
  color: #43515a;
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tds-file-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.tds-file-info {
  min-width: 0;
}

.tds-file-name {
  overflow: hidden;
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tds-file-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.download-button {
  display: grid;
  place-items: center;
  min-height: 32px;
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.download-button:hover {
  background: var(--accent-strong);
}

.empty-state {
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #ffffff;
  font-size: 13px;
}

@media (max-width: 920px) {
  .shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .chat-panel,
  .library-panel {
    min-height: auto;
  }

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

  .library-panel {
    max-height: 520px;
  }
}

@media (max-width: 640px) {
  .topbar,
  .panel-header,
  .auth-panel,
  .composer {
    grid-template-columns: 1fr;
  }

  .auth-form {
    grid-template-columns: 1fr;
  }

  .topbar,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .status,
  .header-status,
  input {
    max-width: none;
  }

  .header-status {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .composer {
    display: flex;
    flex-direction: column;
  }

  .composer button {
    min-height: 44px;
  }

  .bubble,
  .match-list {
    max-width: 100%;
    width: 100%;
  }

  .correction-form {
    grid-template-columns: 1fr;
  }
}
