* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --bg-side: #f9f9f9;
  --border: #e5e5e5;
  --text: #0d0d0d;
  --text-soft: #5d5d5d;
  --text-muted: #8e8ea0;
  --accent: #10a37f;
  --danger: #ef4444;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --bg-soft: #2f2f2f;
    --bg-side: #171717;
    --border: #3a3a3a;
    --text: #ececec;
    --text-soft: #b4b4b4;
    --text-muted: #8e8ea0;
    --shadow: 0 2px 8px rgba(0,0,0,0.4);
  }
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input, select, textarea { font: inherit; color: inherit; }

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 260px;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
}

.logo-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: linear-gradient(135deg, #10a37f, #0ea5e9);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.new-chat-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  transition: background 0.15s;
}

.new-chat-btn:hover { background: var(--bg-soft); color: var(--text); }

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 0;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 8px 4px;
}

.history-list { display: flex; flex-direction: column; gap: 2px; }

.history-item {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  transition: background 0.15s;
}

.history-item:hover { background: var(--bg-soft); color: var(--text); }
.history-item.active { background: var(--bg-soft); color: var(--text); }

.history-item-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-count {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

.history-item-del {
  visibility: hidden;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.history-item:hover .history-item-del { visibility: visible; }
.history-item-del:hover { background: rgba(239,68,68,0.12); color: var(--danger); }

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--border);
}

.footer-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  transition: background 0.15s;
}

.footer-btn:hover { background: var(--bg-soft); }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  flex-shrink: 0;
}
.menu-btn:hover { background: var(--bg-soft); color: var(--text); }

.sidebar-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 49;
  opacity: 0;
  transition: opacity 0.2s;
}
.sidebar-mask.show {
  display: block;
  opacity: 1;
}

.provider-select, .model-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.provider-select label, .model-input label {
  font-size: 12px;
  color: var(--text-muted);
}

.topbar select, .topbar input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.topbar select:focus, .topbar input:focus { border-color: var(--accent); }
.model-input input { width: 240px; }

.result-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 8px;
  display: flex;
  flex-direction: column;
}

.welcome {
  margin: auto;
  text-align: center;
  max-width: 520px;
  padding: 40px 20px;
}

.welcome-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, #10a37f, #0ea5e9);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 16px;
}

.welcome h1 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 8px;
}

.welcome p {
  color: var(--text-soft);
  margin-bottom: 24px;
}

.welcome-tips {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.tip {
  background: var(--bg-soft);
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--text-soft);
  font-size: 13px;
}

.tip code {
  background: var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.messages {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg { display: flex; flex-direction: column; gap: 8px; }

.msg-prompt-row {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  max-width: 85%;
}

.msg-attachment-img {
  max-width: min(240px, 55vw);
  max-height: min(240px, 45vh);
  border-radius: 14px;
  display: block;
  cursor: zoom-in;
  border: 1px solid var(--border);
  background: var(--bg-soft);
}

.msg-prompt {
  align-self: flex-end;
  max-width: 85%;
  background: var(--bg-soft);
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-result {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.image-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  max-width: 100%;
}

.image-card {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: transparent;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
}

.image-card img {
  display: block;
  max-width: min(100%, 280px, 60vw);
  max-height: min(280px, 50vh);
  width: auto;
  height: auto;
  cursor: zoom-in;
  border-radius: 14px;
}

.image-dim {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: rgba(255, 255, 255, 0.92);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  backdrop-filter: blur(4px);
  line-height: 1.5;
}

.image-card .image-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

.image-card:hover .image-actions { opacity: 1; }

.image-actions button {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.image-actions button:hover { background: rgba(0,0,0,0.75); }

.loading-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(280px, 60vw);
  height: min(280px, 60vw, 50vh);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  color: var(--text-soft);
  position: relative;
  overflow: hidden;
  padding: 20px;
}

.loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 80%;
  max-width: 220px;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-text {
  font-size: 13px;
  color: var(--text-soft);
}

.loading-progress {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.loading-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #0ea5e9);
  border-radius: 2px;
  transition: width 0.25s ease-out;
}

.loading-time {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.error-card {
  border: 1px solid rgba(239,68,68,0.4);
  background: rgba(239,68,68,0.06);
  color: var(--danger);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.composer {
  border-top: 1px solid var(--border);
  padding: 12px 20px 16px;
  background: var(--bg);
  flex-shrink: 0;
}

.composer-options {
  max-width: 820px;
  margin: 0 auto 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.composer-options select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-soft);
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
}

.composer-options select:hover { border-color: var(--text-muted); }
.composer-options select:focus { border-color: var(--accent); }

.composer-input {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 8px 8px 8px 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.composer-input:focus-within {
  border-color: var(--text-muted);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.04);
}

.composer-input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.composer-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 4px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

.composer-attachments.hidden { display: none; }

.attachment {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
}

.attachment img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attachment-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
}
.attachment-remove:hover { background: rgba(0,0,0,0.85); }

.attach-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.attach-btn:hover { background: var(--border); color: var(--text); }

.composer-input textarea {
  flex: 1;
  resize: none;
  outline: none;
  border: none;
  background: transparent;
  max-height: 200px;
  padding: 8px 0;
  line-height: 1.5;
  color: var(--text);
}

.composer-input textarea::placeholder { color: var(--text-muted); }

.send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}

.send-btn:hover { opacity: 0.85; }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.send-btn.loading svg { animation: spin 1s linear infinite; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.composer-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden { display: none; }

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  width: 480px;
  max-width: calc(100vw - 32px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
  overflow: hidden;
  animation: modal-in 0.18s ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h2 { font-size: 16px; font-weight: 600; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
}

.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
}

.form-group input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus { border-color: var(--accent); }
.form-group input:disabled { background: var(--bg-soft); color: var(--text-muted); cursor: not-allowed; }

.form-hint { font-size: 11px; color: var(--text-muted); }

.modal-footer {
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}

.btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary {
  background: var(--text);
  color: var(--bg);
}
.btn-primary:hover { opacity: 0.85; }

.btn-ghost {
  background: transparent;
  color: var(--text-soft);
}
.btn-ghost:hover { color: var(--danger); background: rgba(239,68,68,0.08); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--text);
  color: var(--bg);
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: toast-in 0.2s ease-out;
}

.toast.hidden { display: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
}

.lightbox.hidden { display: none; }

.lightbox-mask {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.9);
}

.lightbox-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}
.lightbox-stage.grabbing { cursor: grabbing; }

.lightbox-stage img {
  max-width: 92vw;
  max-height: 92vh;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  transform-origin: center center;
  will-change: transform;
}

.lightbox-toolbar {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 1;
}

.lightbox-toolbar button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  transition: background 0.15s;
}
.lightbox-toolbar button:hover { background: rgba(255,255,255,0.25); }

.lightbox-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.55);
  font-size: 12px;
  z-index: 1;
  white-space: nowrap;
  pointer-events: none;
}

@media (max-width: 768px) {
  .menu-btn { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s ease-out;
    box-shadow: 4px 0 20px rgba(0,0,0,0.12);
  }
  .sidebar.open { transform: translateX(0); }

  .topbar {
    padding: 8px 12px;
    gap: 8px;
  }
  .topbar select, .topbar input {
    padding: 6px 8px;
    font-size: 13px;
  }
  .provider-select label, .model-input label { display: none; }
  .model-input input { width: 130px; }
  .provider-select select { max-width: 130px; }

  .result-area { padding: 16px 12px 4px; }
  .composer { padding: 10px 12px 14px; }
  .composer-options { gap: 6px; }
  .composer-options select { font-size: 11px; padding: 5px 8px; }

  .messages { padding: 0 4px; }

  .lightbox-toolbar { top: 12px; right: 12px; gap: 6px; }
  .lightbox-toolbar button { width: 36px; height: 36px; }
  .lightbox-hint { font-size: 11px; bottom: 14px; }
}

@media (max-width: 480px) {
  .welcome { padding: 24px 12px; }
  .welcome h1 { font-size: 22px; }
  .welcome-icon { width: 48px; height: 48px; font-size: 22px; }
}
