:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #172033;
  --muted: #64748b;
  --line: #dbe3ef;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --teal: #0f766e;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --warning-bg: #fff7ed;
  --warning-line: #fed7aa;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

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

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

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

button:hover,
.file-button:hover {
  border-color: #a9b8cc;
  background: #f8fafc;
}

button:active,
.file-button:active {
  transform: translateY(1px);
}

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

.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.primary:hover {
  border-color: var(--primary-dark);
  background: var(--primary-dark);
}

.danger {
  border-color: #fecaca;
  color: var(--danger);
}

.danger:hover {
  border-color: var(--danger);
  background: #fef2f2;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input,
select {
  height: 40px;
  padding: 0 11px;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13);
}

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

.sidebar,
.work-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  overflow: auto;
  max-height: calc(100vh - 36px);
  padding: 18px;
}

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

.brand h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
}

.brand p,
.panel-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.side-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.side-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.section-title,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title h2,
.panel-header h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #edf2ff;
  color: #1e40af;
  font-size: 12px;
  white-space: nowrap;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.field span {
  color: #334155;
  font-size: 13px;
  font-weight: 650;
}

.button-row,
.button-grid {
  display: grid;
  gap: 10px;
}

.button-row {
  grid-template-columns: 1fr 1fr;
}

.full-button {
  width: 100%;
  margin-top: 10px;
}

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

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.notice {
  padding: 14px;
  margin: 14px 0 0;
  border: 1px solid var(--warning-line);
  border-radius: var(--radius);
  background: var(--warning-bg);
}

.notice ul {
  margin: 0;
  padding-left: 20px;
  color: #7c2d12;
  font-size: 13px;
  line-height: 1.65;
}

.workspace {
  display: grid;
  grid-template-rows: minmax(420px, 1fr) minmax(360px, 0.92fr);
  gap: 18px;
  min-width: 0;
  min-height: calc(100vh - 36px);
}

.work-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  padding: 16px;
}

.panel-header {
  flex: 0 0 auto;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.panel-actions button {
  padding: 0 12px;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 14px 4px;
}

.empty-state {
  display: grid;
  min-height: 160px;
  place-items: center;
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--muted);
  text-align: center;
}

.message {
  display: grid;
  gap: 7px;
  max-width: 860px;
  margin: 0 0 14px;
}

.message.user {
  margin-left: auto;
}

.message.assistant {
  margin-right: auto;
}

.message-meta {
  color: var(--muted);
  font-size: 12px;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 12px 14px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.message.assistant .bubble {
  border-color: #ccfbf1;
  background: #f0fdfa;
}

.markdown h1,
.markdown h2,
.markdown h3 {
  margin: 12px 0 8px;
  font-size: 17px;
  line-height: 1.35;
}

.markdown p {
  margin: 0 0 10px;
}

.markdown p:last-child,
.markdown ul:last-child,
.markdown ol:last-child,
.markdown pre:last-child {
  margin-bottom: 0;
}

.markdown ul,
.markdown ol {
  margin: 0 0 10px;
  padding-left: 22px;
}

.markdown blockquote {
  margin: 0 0 10px;
  padding-left: 12px;
  border-left: 3px solid #94a3b8;
  color: #475569;
}

.markdown code {
  border-radius: 5px;
  background: rgba(15, 23, 42, 0.08);
  padding: 2px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.93em;
}

.markdown pre {
  overflow: auto;
  margin: 0 0 10px;
  border-radius: var(--radius);
  background: #101827;
  color: #e2e8f0;
  padding: 12px;
}

.markdown pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.markdown a {
  color: var(--primary);
  text-decoration: none;
}

.markdown a:hover {
  text-decoration: underline;
}

.composer,
.image-form {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.composer textarea,
.image-form textarea {
  min-height: 76px;
}

.composer button,
.image-form button {
  align-self: stretch;
}

.image-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  overflow: auto;
  min-height: 0;
  padding: 14px 4px 0;
}

.image-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 10px;
}

.image-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  background: #e2e8f0;
  object-fit: contain;
}

.image-card-meta {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

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

.image-card-actions a,
.image-card-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.image-card-actions a:hover,
.image-card-actions button:hover {
  background: #f8fafc;
  border-color: #a9b8cc;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  display: none;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  background: #eff6ff;
  color: #1e3a8a;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  line-height: 1.5;
}

.toast.show {
  display: block;
}

.toast.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.toast.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.loading-line {
  color: var(--muted);
  font-size: 13px;
}

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

  .sidebar {
    max-height: none;
  }

  .workspace {
    grid-template-rows: auto auto;
    min-height: 0;
  }

  .chat-panel {
    min-height: 560px;
  }

  .image-panel {
    min-height: 520px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    gap: 12px;
    padding: 10px;
  }

  .sidebar,
  .work-panel {
    padding: 14px;
  }

  .button-row,
  .composer,
  .image-form,
  .image-card-actions {
    grid-template-columns: 1fr;
  }

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

  .panel-actions {
    width: 100%;
    justify-content: stretch;
  }

  .panel-actions button {
    width: 100%;
  }

  .message {
    max-width: 100%;
  }

  .image-results {
    grid-template-columns: 1fr;
  }
}
