:root {
  color-scheme: light;
  --bg: #f5f5f1;
  --surface: #ffffff;
  --surface-soft: #faf9f6;
  --surface-strong: #111827;
  --text: #20242b;
  --muted: #6f7681;
  --line: #dedbd3;
  --line-strong: #cbc6ba;
  --accent: #1466b8;
  --accent-soft: #e8f2fd;
  --green: #16836b;
  --amber: #9b6b14;
  --danger: #bf3150;
  --shadow: 0 18px 54px rgba(27, 34, 43, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(245, 245, 241, 0.92)),
    radial-gradient(circle at top left, rgba(20, 102, 184, 0.1), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

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

.hidden {
  display: none !important;
}

.app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 22px;
  border-bottom: 1px solid rgba(222, 219, 211, 0.74);
  background: rgba(250, 249, 246, 0.86);
  backdrop-filter: blur(18px);
}

.brand,
.top-controls,
.admin-userbar,
.drawer-head,
.job-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-strong);
  color: #fff;
  font-size: 13px;
  font-weight: 850;
}

.brand-copy {
  min-width: 0;
}

.site-name {
  overflow: hidden;
  max-width: 360px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
  font-weight: 820;
}

.live-line {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.top-controls {
  justify-content: flex-end;
}

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

select,
input {
  height: 42px;
  padding: 0 12px;
}

textarea {
  padding: 11px 12px;
  resize: vertical;
}

select:focus,
input:focus,
textarea:focus {
  border-color: rgba(20, 102, 184, 0.62);
  box-shadow: 0 0 0 3px rgba(20, 102, 184, 0.12);
}

.top-controls select {
  width: min(220px, 26vw);
}

.icon-btn,
.tool-btn,
.ghost-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: #323944;
  font-weight: 780;
}

.icon-btn,
.tool-btn,
.send-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
}

.icon-btn:hover,
.tool-btn:hover,
.ghost-btn:hover {
  border-color: var(--line-strong);
  background: #f3f2ed;
}

.announcement {
  width: min(920px, calc(100% - 36px));
  margin: 12px auto 0;
  padding: 10px 13px;
  border: 1px solid rgba(20, 102, 184, 0.18);
  border-radius: 8px;
  background: var(--accent-soft);
  color: #254864;
  font-size: 13px;
  line-height: 1.55;
}

.chat-main {
  min-height: 0;
}

.messages {
  height: 100%;
  overflow: auto;
  padding: 22px 18px 28px;
}

.message-list-inner {
  width: min(920px, 100%);
  margin: 0 auto;
}

.empty-state {
  display: grid;
  min-height: 54vh;
  place-items: center;
  text-align: center;
}

.empty-card {
  width: min(720px, 100%);
}

.empty-card h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.18;
}

.empty-card p {
  margin: 10px 0 22px;
  color: var(--muted);
  font-size: 15px;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  text-align: left;
}

.prompt-chip {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: #303844;
  padding: 12px;
  text-align: left;
}

.prompt-chip:hover {
  border-color: rgba(20, 102, 184, 0.42);
  background: #fff;
  box-shadow: 0 10px 28px rgba(27, 34, 43, 0.08);
}

.message {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  margin: 18px 0;
}

.avatar {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: #dedbd3;
  color: #3a414b;
  font-size: 13px;
  font-weight: 820;
}

.assistant .avatar {
  background: var(--surface-strong);
  color: #fff;
}

.bubble {
  max-width: 100%;
  color: #26313f;
  line-height: 1.72;
  overflow-wrap: anywhere;
}

.user .bubble {
  justify-self: end;
  width: fit-content;
  max-width: min(760px, 100%);
  padding: 11px 14px;
  border: 1px solid rgba(222, 219, 211, 0.72);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 32px rgba(31, 41, 51, 0.08);
}

.bubble pre {
  overflow: auto;
  padding: 13px;
  border-radius: 8px;
  background: #17202b;
  color: #e5edf6;
}

.bubble code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.message-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.message-tools button {
  height: 29px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: #59616d;
  padding: 0 10px;
  font-size: 12px;
}

.queue-pill,
.image-progress {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 7px 10px;
  border: 1px solid rgba(155, 107, 20, 0.22);
  border-radius: 8px;
  background: rgba(155, 107, 20, 0.08);
  color: var(--amber);
  font-size: 13px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(20, 102, 184, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.reference-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.reference-strip img,
.image-grid img {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  object-fit: cover;
}

.reference-strip img {
  width: 84px;
  height: 84px;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.image-grid img {
  width: 100%;
  aspect-ratio: 1;
}

.composer-dock {
  position: sticky;
  bottom: 0;
  z-index: 4;
  padding: 12px 18px 18px;
  background: linear-gradient(180deg, rgba(245, 245, 241, 0), var(--bg) 30%);
}

.composer,
.image-preview,
.status-line {
  width: min(920px, 100%);
  margin-right: auto;
  margin-left: auto;
}

.image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 0 8px;
}

.preview-item {
  position: relative;
}

.preview-item img {
  width: 76px;
  height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
}

.preview-item button {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: var(--danger);
  color: white;
}

.composer {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px 42px;
  gap: 8px;
  align-items: end;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.composer textarea {
  max-height: 190px;
  min-height: 42px;
  border: 0;
  padding: 10px 4px;
  background: transparent;
  box-shadow: none;
  resize: none;
}

.composer textarea:focus {
  box-shadow: none;
}

.send-btn,
.primary-btn {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 820;
}

.send-btn.stop {
  background: var(--danger);
}

.primary-btn {
  width: 100%;
  height: 44px;
}

.ghost-btn {
  height: 36px;
  padding: 0 12px;
}

.status-line {
  min-height: 20px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  background: rgba(31, 41, 51, 0.36);
}

.drawer-panel {
  width: min(720px, 100%);
  height: 100%;
  overflow: auto;
  padding: 20px;
  background: var(--surface-soft);
  box-shadow: var(--shadow);
}

.drawer-head,
.job-head,
.admin-userbar {
  justify-content: space-between;
}

.drawer-head {
  margin-bottom: 16px;
}

.drawer h2,
.job-box h3 {
  margin: 0;
}

.drawer p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: #394452;
  font-size: 13px;
  font-weight: 680;
}

.admin-login,
.admin-form,
.job-box,
.admin-userbar {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-userbar {
  margin-bottom: 14px;
}

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

.form-error,
.form-status {
  min-height: 20px;
  margin: 10px 0 0;
  font-size: 13px;
}

.form-error {
  color: var(--danger);
}

.form-status {
  color: var(--green);
}

.job-box {
  margin-top: 14px;
}

.job-list {
  display: grid;
  gap: 8px;
}

.job-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 52px;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 13px;
}

.job-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

@media (max-width: 760px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 11px 12px;
  }

  .top-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 42px 42px;
    width: 100%;
  }

  .top-controls select {
    width: 100%;
    min-width: 0;
  }

  .site-name {
    max-width: calc(100vw - 90px);
  }

  .announcement,
  .messages,
  .composer-dock {
    width: 100%;
  }

  .messages {
    padding: 18px 12px 22px;
  }

  .empty-card h1 {
    font-size: 25px;
  }

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

  .message {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 9px;
  }

  .avatar {
    width: 30px;
    height: 30px;
    font-size: 12px;
  }

  .composer-dock {
    padding: 10px 12px 14px;
  }

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

  .icon-btn,
  .tool-btn,
  .send-btn {
    width: 38px;
    height: 38px;
  }

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