:root {
  --background: #edf0f2;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #657078;
  --line: #d9dfe3;
  --line-strong: #bbc5cb;
  --accent: #0f766e;
  --accent-dark: #0b5e58;
  --accent-soft: #dff4f1;
  --danger: #b42318;
  --focus: #2563eb;
  --radius: 6px;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  color: var(--ink);
  background: var(--background);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--background);
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }

button { cursor: pointer; }

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

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.login-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(140deg, #e8f1f0 0, #f5f6f7 45%, #e9edf0 100%);
}

.login-panel {
  width: min(420px, 100%);
  padding: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 18px 54px rgba(24, 37, 45, 0.12);
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
}

.brand-mark.small { width: 30px; height: 30px; font-size: 16px; }

.eyebrow {
  margin: 28px 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

h1 { margin: 0 0 28px; font-size: 28px; letter-spacing: 0; }

label { display: block; margin-bottom: 8px; color: #3e4a51; font-size: 13px; font-weight: 700; }

.secret-input { position: relative; }

.secret-input input {
  width: 100%;
  height: 44px;
  padding: 0 44px 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--ink);
  background: #fff;
}

.secret-input .icon-button { position: absolute; top: 4px; right: 4px; }

.primary-button, .secondary-button, .danger-button, .icon-button {
  min-height: 38px;
  border-radius: var(--radius);
  font-weight: 700;
}

.primary-button {
  width: 100%;
  margin-top: 16px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-button:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
.primary-button.compact { width: auto; min-width: 76px; margin: 0; padding: 0 16px; }

.secondary-button {
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
}

.secondary-button:hover { background: #f3f5f6; }

.danger-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #f0b5af;
  background: #fff;
  color: var(--danger);
  font-size: 12px;
}

.icon-button {
  display: inline-grid;
  width: 36px;
  min-height: 36px;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
}

.icon-button:hover { background: #eef1f2; color: var(--ink); }

.form-error { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 13px; }

.workspace { height: 100%; overflow: hidden; }

.topbar {
  height: 58px;
  display: grid;
  grid-template-columns: minmax(160px, 260px) minmax(220px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.brand-inline { display: flex; align-items: center; gap: 10px; white-space: nowrap; }

.document-controls { min-width: 0; display: flex; align-items: center; gap: 10px; }

.title-input {
  width: min(360px, 70%);
  height: 34px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--ink);
  font-weight: 700;
}

.title-input:hover, .title-input:focus { border-color: var(--line-strong); }

.save-state { color: var(--muted); font-size: 12px; white-space: nowrap; }

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

.model-control { display: flex; align-items: center; gap: 8px; margin: 0; }

.model-control select {
  width: 180px;
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

.icon-button.top { border-left: 1px solid var(--line); border-radius: 0; }

.work-area {
  --panel-width: 390px;
  height: calc(100% - 58px);
  display: grid;
  grid-template-columns: var(--panel-width) 6px minmax(0, 1fr);
}

.side-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

.panel-resizer {
  position: relative;
  z-index: 3;
  width: 6px;
  cursor: col-resize;
  background: #e5e9eb;
  touch-action: none;
}

.panel-resizer::after {
  content: "";
  position: absolute;
  inset: 0 2px;
  background: var(--line-strong);
}

.panel-resizer:hover,
.panel-resizer:focus-visible,
.panel-resizer.dragging { background: var(--accent-soft); outline: 0; }

.panel-resizer:hover::after,
.panel-resizer:focus-visible::after,
.panel-resizer.dragging::after { background: var(--accent); }

.panel-tabs {
  flex: 0 0 45px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--line);
}

.panel-tab {
  border: 0;
  border-bottom: 2px solid transparent;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.panel-tab.active { border-bottom-color: var(--accent); color: var(--accent); }

.panel-content { min-height: 0; flex: 1; }

.chat-panel { display: flex; flex-direction: column; }

.messages { flex: 1; overflow-y: auto; padding: 18px; }

.chat-empty {
  height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
}

.empty-symbol {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-size: 24px;
}

.message { margin-bottom: 16px; }
.message-role { margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 800; }
.message-body { padding: 10px 12px; border-radius: var(--radius); line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user .message-body { background: var(--accent-soft); }
.message.assistant .message-body { border: 1px solid var(--line); background: #fff; }
.message.error .message-body { border: 1px solid #f0b5af; background: #fff2f0; color: var(--danger); }

.message.artifact .message-body { padding: 0; border: 0; background: transparent; }
.artifact-button {
  width: 100%;
  min-height: 52px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  text-align: left;
}
.artifact-button:hover { border-color: var(--accent); background: #f4faf9; }
.artifact-type {
  min-width: 46px;
  padding: 4px 6px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 800;
  text-align: center;
}
.artifact-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.artifact-open { color: var(--muted); font-size: 12px; }

.prompt-form { flex: 0 0 auto; padding: 12px; border-top: 1px solid var(--line); background: #f7f8f8; }

.prompt-form textarea {
  width: 100%;
  min-height: 148px;
  max-height: 320px;
  resize: vertical;
  padding: 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--ink);
  background: #fff;
  line-height: 1.5;
}

.prompt-footer { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; margin-top: 8px; }
.prompt-options { min-width: 0; display: flex; align-items: end; gap: 8px; }
.prompt-footer span { color: var(--muted); font-size: 11px; }
.prompt-footer .model-control { min-width: 0; flex: 1; display: grid; gap: 3px; margin: 0; }
.prompt-footer .model-control select { width: 100%; height: 38px; }
.prompt-footer #prompt-count { flex: 0 0 auto; padding-bottom: 4px; white-space: nowrap; }

.files-panel { overflow-y: auto; padding: 12px; }
.section-heading { display: flex; min-height: 40px; align-items: center; justify-content: space-between; }
.diagram-list, .version-list { border-top: 1px solid var(--line); }
.diagram-row, .version-row {
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 11px 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-align: left;
}
.diagram-row:hover, .diagram-row.active, .version-row:hover { background: #f0f7f6; }
.diagram-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { color: var(--muted); font-size: 11px; }
.versions-section { margin-top: 24px; }
.empty-list { padding: 24px 8px; color: var(--muted); text-align: center; }

.editor-shell { min-width: 0; overflow: hidden; display: flex; flex-direction: column; background: #f4f5f6; }
.editor-toolbar {
  flex: 0 0 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 8px 0 12px;
  border-bottom: 1px solid #2f3539;
  background: #171a1c;
  color: #f7f8f8;
}
.editor-filename { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.editor-actions { display: flex; align-items: center; gap: 2px; }
.editor-action {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #e5e7e8;
  font-size: 18px;
  font-weight: 700;
}
.editor-action:hover,
.editor-action.active { background: #303538; color: #fff; }
.editor-stage { position: relative; min-height: 0; flex: 1; overflow: hidden; }
.editor-stage iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.editor-loading { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; color: var(--muted); background: #f4f5f6; }
.xml-source {
  width: 100%;
  height: 100%;
  resize: none;
  padding: 18px;
  border: 0;
  outline: 0;
  background: #111516;
  color: #d8e5e2;
  font: 13px/1.55 Consolas, "Courier New", monospace;
  white-space: pre;
  tab-size: 2;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100% - 36px));
  padding: 11px 14px;
  border-radius: var(--radius);
  background: #1d2930;
  color: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  font-size: 13px;
}

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

@media (max-width: 900px) {
  .topbar { grid-template-columns: auto minmax(150px, 1fr) auto; gap: 8px; }
  .brand-inline strong { display: none; }
  .work-area { --panel-width: 42%; }
}

@media (max-width: 680px) {
  .topbar { height: 104px; grid-template-columns: auto 1fr; grid-template-rows: 48px 44px; }
  .document-controls { grid-column: 1 / -1; grid-row: 2; }
  .title-input { width: 70%; }
  .topbar-actions { justify-self: end; }
  .secondary-button { padding: 0 8px; }
  .work-area { --panel-width: 46%; height: calc(100% - 104px); }
  .prompt-form textarea { min-height: 118px; }
}
