:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --line: #dfe3eb;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #ff7a00;
  --accent-dark: #d86100;
  --green: #0f9f6e;
}

* {
  box-sizing: border-box;
}

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

.app-shell {
  width: min(960px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

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

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.status-dot {
  flex: 0 0 auto;
  color: var(--green);
  font-size: 14px;
  border: 1px solid rgba(15, 159, 110, 0.24);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(15, 159, 110, 0.08);
}

.quick-actions {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}

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

.quick-actions button {
  flex: 0 0 auto;
  padding: 9px 14px;
  color: var(--accent-dark);
  background: #fff3e8;
  border: 1px solid #ffd2a8;
}

.chat-panel {
  padding: 20px;
  overflow-y: auto;
}

.message {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

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

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #eef2ff;
  color: #3153b7;
  font-weight: 700;
  font-size: 13px;
}

.message.user .avatar {
  order: 2;
  background: #fff3e8;
  color: var(--accent-dark);
}

.bubble {
  max-width: min(680px, calc(100vw - 96px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.message.user .bubble {
  background: #fff7ed;
  border-color: #fed7aa;
}

.bubble p {
  margin-top: 4px;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  margin-top: 10px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.result-table {
  width: auto;
  min-width: 0;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.35;
}

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

.result-table th:last-child,
.result-table td:last-child {
  border-right: 0;
}

.result-table th {
  color: #374151;
  background: #f1f5f9;
  font-weight: 700;
  white-space: nowrap;
}

.result-table tr:last-child td {
  border-bottom: 0;
}

.result-table td:first-child {
  font-weight: 700;
  min-width: 220px;
  max-width: 430px;
}

.result-table th:nth-child(2),
.result-table th:nth-child(3),
.result-table th:nth-child(4),
.result-table th:nth-child(5),
.result-table td:nth-child(2),
.result-table td:nth-child(3),
.result-table td:nth-child(4),
.result-table td:nth-child(5) {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  width: 72px;
}

.field-table th:nth-child(2),
.field-table td:nth-child(2) {
  text-align: left;
  white-space: normal;
  width: auto;
  min-width: 360px;
  font-variant-numeric: normal;
}

.table-wrap:has(.field-table) {
  width: 100%;
}

.field-table {
  width: 100%;
  table-layout: fixed;
}

.field-table th:first-child,
.field-table td:first-child {
  width: 150px;
  min-width: 150px;
  max-width: 150px;
}

.field-table th:first-child:nth-last-child(2) + th,
.field-table td:first-child:nth-last-child(2) + td {
  text-align: left;
  white-space: normal;
  width: auto;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-variant-numeric: normal;
}

.choice-table th,
.choice-table td {
  text-align: left;
}

.choice-table th:first-child,
.choice-table td:first-child {
  width: 48px;
  min-width: 48px;
  text-align: right;
}

.file-link {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid #ffd2a8;
  border-radius: 6px;
  color: var(--accent-dark);
  background: #fff7ed;
  font-weight: 700;
  text-decoration: none;
  word-break: break-all;
}

.file-link:hover {
  background: #fff3e8;
}

.composer {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 10px;
  padding: 14px 20px 20px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

#attachButton {
  grid-column: 1;
}

#clearAttachmentsButton {
  grid-column: 2;
}

#messageInput {
  grid-column: 3;
}

.composer button[type="submit"] {
  grid-column: 4;
  width: auto;
  justify-self: end;
}

.attachment-input {
  display: none;
}

.attach-button {
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  color: var(--accent-dark);
  background: #fff3e8;
  border: 1px solid #ffd2a8;
  font-size: 22px;
  line-height: 1;
}

.clear-attachments-button {
  min-width: 82px;
  height: 44px;
  padding: 0 12px;
  color: #475569;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  font-size: 14px;
}

.clear-attachments-button:hover {
  background: #eef2f7;
}

.composer input {
  min-width: 0;
  height: 44px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0 12px;
  font: inherit;
  outline: none;
}

.composer input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 122, 0, 0.12);
}

.composer input:disabled {
  background: #f8fafc;
}

.composer button {
  min-width: 76px;
  padding: 0 18px;
  color: #fff;
  background: var(--accent);
}

.composer .clear-attachments-button {
  color: #475569;
  background: #f8fafc;
}

@media (max-width: 640px) {
  .app-shell {
    border: 0;
  }

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

  .composer {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
  }

  .composer button {
    height: 42px;
  }

  .composer button[type="submit"] {
    min-width: 62px;
    padding: 0 12px;
  }

  .clear-attachments-button {
    min-width: 70px;
    padding: 0 8px;
  }
}
