:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --panel: #ffffff;
  --line: #dbe4f0;
  --text: #172033;
  --muted: #64748b;
  --brand: #2457d6;
  --brand-strong: #173f9c;
  --soft: #edf4ff;
  --ok: #067647;
  --danger: #b42318;
  --shadow: 0 18px 44px rgba(27, 42, 71, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(36, 87, 214, 0.10), transparent 32%),
    linear-gradient(315deg, rgba(38, 166, 154, 0.10), transparent 30%),
    var(--bg);
}

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

button {
  height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--text);
}

input,
select {
  height: 38px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  min-height: 88px;
  padding: 10px;
  line-height: 1.55;
}

.app-shell {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 18px;
  height: 100vh;
  max-height: 100vh;
  padding: 18px;
  overflow: hidden;
}

.assistant-pane,
.table-pane,
.table-card,
.topbar,
.inspector article,
.modal-body {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(219, 228, 240, 0.95);
  box-shadow: var(--shadow);
}

.assistant-pane {
  min-width: 0;
  min-height: 0;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #2457d6, #26a69a);
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 22px;
  margin-top: 4px;
}

#runtime-status,
.eyebrow,
.doc-meta,
.message-meta {
  color: var(--muted);
  font-size: 12px;
}

.table-row {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
}

.new-table-row {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
}

.model-row {
  display: grid;
}

.doc-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfdff;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.text-btn,
.icon-btn {
  height: 30px;
  padding: 0 8px;
  color: var(--brand);
  background: transparent;
}

.upload-zone {
  display: grid;
  place-items: center;
  min-height: 72px;
  border: 1px dashed #9eb3d2;
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  cursor: pointer;
  text-align: center;
}

.upload-zone input {
  display: none;
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 128px;
  overflow: auto;
  margin-top: 8px;
}

.doc-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.doc-item strong {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
  word-break: break-word;
}

.chat-log {
  min-height: 0;
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px;
  overscroll-behavior: contain;
}

.message {
  max-width: 92%;
  border-radius: 10px;
  padding: 10px 12px;
  line-height: 1.55;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  color: #fff;
  background: var(--brand);
}

.message.assistant {
  align-self: flex-start;
  background: var(--soft);
}

.composer {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.primary {
  color: #fff;
  background: var(--brand);
}

.primary:hover {
  background: var(--brand-strong);
}

.secondary {
  color: var(--brand);
  background: var(--soft);
}

.wide {
  width: 100%;
}

.table-pane {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.topbar {
  border-radius: 8px;
  min-height: 82px;
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-card {
  min-height: 0;
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

#table-grid {
  height: 100%;
  min-height: 0;
}

.sheet-toolbar {
  height: 44px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
  overflow-x: auto;
}

.tool-button {
  height: 30px;
  min-width: 30px;
  border-radius: 6px;
  padding: 0 9px;
  color: #22324d;
  background: transparent;
  border: 1px solid transparent;
}

.tool-button:hover,
.tool-button.active {
  background: #eaf2ff;
  border-color: #c7d8ff;
  color: var(--brand);
}

.toolbar-divider {
  width: 1px;
  height: 22px;
  background: var(--line);
  margin: 0 4px;
}

.toolbar-select,
.toolbar-size {
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
}

.toolbar-select {
  width: 150px;
}

.toolbar-size {
  width: 70px;
}

.formula-bar {
  height: 34px;
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.cell-name {
  height: 100%;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--line);
  color: #42526e;
  font-size: 13px;
}

.formula-bar input {
  height: 100%;
  border: 0;
  border-radius: 0;
  padding: 0 12px;
  color: #172033;
}

.tabulator {
  border: 0;
  border-radius: 0;
  font-size: 13px;
  background: #fff;
}

.tabulator .tabulator-header {
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.tabulator .tabulator-col {
  background: #f8fafc;
  border-right: 1px solid var(--line);
}

.tabulator .tabulator-col-title {
  font-weight: 600;
  color: #26364f;
}

.tabulator-row {
  border-bottom: 1px solid #edf2f7;
}

.tabulator-row .tabulator-cell {
  border-right: 1px solid #edf2f7;
}

.tabulator-row:hover {
  background: #f7fbff;
}

.inspector {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.inspector article {
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.38);
}

.modal-body {
  width: min(820px, 96vw);
  max-height: 86vh;
  overflow: auto;
  border-radius: 8px;
  padding: 16px;
}

.modal-body header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

pre {
  max-height: 52vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 440px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #172033;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.toast.error {
  background: var(--danger);
}

.toast.ok {
  background: var(--ok);
}

@media (max-width: 1060px) {
  .app-shell {
    height: auto;
    max-height: none;
    overflow: visible;
    grid-template-columns: 1fr;
  }

  .assistant-pane {
    min-height: 620px;
  }

  .table-pane {
    min-height: 720px;
  }
}
