:root {
  --bg: #0a0a0f;
  --panel: #13131c;
  --panel-2: #1a1a26;
  --line: #272736;
  --text: #e9e9f2;
  --muted: #8b8b9e;
  --accent: #7a5cff;
  --accent-2: #40e0d0;
  --danger: #ff5c7a;
  --radius: 16px;
  font-synthesis-weight: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 12% -10%, rgba(122, 92, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(64, 224, 208, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

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

h1 {
  font-size: 20px;
  margin: 0;
}

/* ===== 登录 ===== */
.auth-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01)), var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.auth-brand {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.auth-brand p {
  margin: 4px 0 0;
  font-size: 13px;
}

.logo-dot {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px rgba(122, 92, 255, 0.4);
}

.tabs {
  display: flex;
  gap: 6px;
  background: var(--panel-2);
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 18px;
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
}

.tab.active {
  background: rgba(122, 92, 255, 0.18);
  color: var(--text);
}

.auth-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

input,
textarea,
select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(122, 92, 255, 0.65);
}

textarea {
  resize: vertical;
}

button {
  font: inherit;
  cursor: pointer;
}

.primary {
  border: 0;
  border-radius: 11px;
  padding: 11px 18px;
  color: #fff;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent), #5b7cff);
  box-shadow: 0 10px 24px rgba(122, 92, 255, 0.28);
}

.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.primary.wide {
  width: 100%;
}

.ghost {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
}

.ghost:hover {
  border-color: rgba(122, 92, 255, 0.5);
}

/* ===== 主界面 ===== */
.app-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 10, 15, 0.7);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
}

.brand .logo-dot {
  width: 26px;
  height: 26px;
  border-radius: 9px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-right .select {
  width: auto;
  min-width: 150px;
}

.upstream-picker {
  display: flex;
  align-items: center;
  gap: 12px;
}

.picker {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.picker .select {
  width: auto;
  min-width: 126px;
  padding: 6px 10px;
  font-size: 13px;
}

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  color: #ffd9a0;
  background: rgba(255, 176, 32, 0.14);
  border: 1px solid rgba(255, 176, 32, 0.35);
  white-space: nowrap;
}

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.85fr);
  gap: 16px;
  padding: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 13px;
}

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

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 92%;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.assistant {
  align-self: flex-start;
}

.bubble {
  padding: 11px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.msg.user .bubble {
  background: linear-gradient(135deg, rgba(122, 92, 255, 0.24), rgba(91, 124, 255, 0.16));
  border-color: rgba(122, 92, 255, 0.4);
}

.bubble-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bubble-images img {
  width: 110px;
  height: 110px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.msg-tools {
  display: flex;
  gap: 6px;
  opacity: 0.75;
}

.tiny-btn {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

.tiny-btn:hover {
  color: var(--text);
  border-color: rgba(122, 92, 255, 0.5);
}

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

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.right-col {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
}

.right-col .panel:first-child {
  padding-bottom: 14px;
}

.right-col .panel:first-child > *:not(.panel-head) {
  margin: 0 14px;
}

.right-col .panel:first-child > *:not(.panel-head) + *:not(.panel-head) {
  margin-top: 10px;
}

.gen-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.batch-box {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}

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

.field {
  font-size: 12px;
}

.field .select {
  padding: 8px 10px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 8px 4px 4px;
  font-size: 12px;
}

.chip img {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  object-fit: cover;
}

.chip button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}

.chip button:hover {
  color: var(--danger);
}

.assets {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  align-content: start;
}

.asset {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.asset img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.asset.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(64, 224, 208, 0.35);
}

.asset-meta {
  padding: 7px 9px;
  font-size: 11px;
  color: var(--muted);
  display: grid;
  gap: 2px;
}

.asset-meta strong {
  color: var(--text);
  font-weight: 500;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-actions {
  position: absolute;
  inset: auto 6px 6px auto;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

.asset:hover .asset-actions {
  opacity: 1;
}

.asset-actions button {
  border: 0;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 11px;
  background: rgba(10, 10, 15, 0.82);
  color: var(--text);
  border: 1px solid var(--line);
}

.tag {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(10, 10, 15, 0.78);
  border: 1px solid var(--line);
  color: var(--muted);
}

.empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  padding: 24px 8px;
  text-align: center;
}

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}

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

/* ===== 管理页（接口设置 + 账号管理）===== */
.admin-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.admin-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 16px;
  align-content: start;
  /* 关键：每行按内容高度，别被均分成等高的行（否则表单会被裁掉、按钮点不到） */
  grid-auto-rows: max-content;
}

/* 管理页的面板要随内容长高，整页滚动；不能套用工作台那套「固定高度 + 内部滚动」 */
.admin-main > .panel {
  min-height: auto;
  overflow: visible;
}

.admin-main .admin-body {
  flex: 0 0 auto;
}

.admin-body {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.storage-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  overflow: hidden;
}

.storage-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.storage-bar.warn > i {
  background: linear-gradient(90deg, #ffb020, #ff5c7a);
}

.reg-settings {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
}

.inline-check input {
  width: auto;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.inline-field input {
  width: 220px;
  padding: 7px 10px;
}

.align-end {
  align-items: flex-end;
}

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

.user-row {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.user-row.is-disabled {
  opacity: 0.55;
}

code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 12px;
}

.upstream-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 18px;
}

.upstream-row {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.upstream-row.is-default {
  border-color: rgba(64, 224, 208, 0.45);
}

.row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.row-meta {
  font-size: 12px;
  color: var(--muted);
  display: grid;
  gap: 2px;
  word-break: break-all;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.pill.ok {
  color: #6ee7b7;
  border-color: rgba(110, 231, 183, 0.4);
}

.pill.warn {
  color: #ffd9a0;
  border-color: rgba(255, 176, 32, 0.4);
}

.pill.mj {
  color: #c4b5fd;
  border-color: rgba(196, 181, 253, 0.4);
}

.model-fetch {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.model-list {
  max-height: 260px;
  overflow-y: auto;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}

.model-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 8px;
}

.model-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.model-name {
  word-break: break-all;
  color: var(--text);
}

.model-row .tiny-btn.suggested {
  border-color: rgba(122, 92, 255, 0.55);
  color: var(--text);
}

.model-row .tiny-btn.active {
  background: rgba(122, 92, 255, 0.22);
  border-color: rgba(122, 92, 255, 0.7);
  color: #fff;
}

.advanced {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--panel-2);
}

.advanced summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  user-select: none;
}

.advanced[open] summary {
  margin-bottom: 10px;
  color: var(--text);
}

.advanced .form-row + .form-row {
  margin-top: 10px;
}

.upstream-form {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  display: grid;
  gap: 12px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.test-result {
  font-size: 12px;
  margin: 0;
  min-height: 16px;
}

.test-result.ok {
  color: #6ee7b7;
}

.test-result.bad {
  color: var(--danger);
}

@media (max-width: 620px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(320px, 1fr) auto;
    overflow-y: auto;
  }
}
