:root {
  --bg: #f3f1ed;
  --surface: #ffffff;
  --surface-2: #f7f5f1;
  --ink: #1f2421;
  --muted: #6f746f;
  --line: #dedbd4;
  --accent: #0f7b6f;
  --accent-strong: #0b5d54;
  --accent-soft: #e1f1ee;
  --warm: #c4622d;
  --danger: #b3403a;
  --danger-soft: #f8e5e3;
  --shadow: 0 1px 2px rgba(31, 36, 33, 0.05), 0 8px 24px rgba(31, 36, 33, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15, 123, 111, 0.08), rgba(196, 98, 45, 0.08)),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

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

.brand h1,
.brand h2 {
  margin: 0;
  line-height: 1.1;
}

.brand h1 {
  font-size: 22px;
}

.brand h2 {
  font-size: 16px;
}

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

.login form {
  margin-top: 30px;
  display: grid;
  gap: 16px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 123, 111, 0.12);
}

.primary-button,
.ghost-button,
.text-button,
.icon-button,
.danger-button {
  border: 0;
  border-radius: 6px;
  padding: 9px 12px;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.ghost-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.text-button {
  background: transparent;
  color: var(--muted);
  padding: 0;
}

.text-button:hover {
  color: var(--accent);
}

.icon-button {
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  padding: 2px 8px;
}

.danger-button {
  background: var(--danger-soft);
  color: var(--danger);
}

.error {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--danger-soft);
  color: var(--danger);
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 16px;
  background: #202522;
  color: #f8f5ef;
}

.sidebar .brand p {
  color: #b9b8b2;
}

.sidebar nav {
  display: grid;
  gap: 4px;
}

.sidebar nav button {
  border: 0;
  border-radius: 6px;
  padding: 10px 12px;
  text-align: left;
  background: transparent;
  color: #e6e1d8;
}

.sidebar nav button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sidebar nav button.active {
  background: var(--accent);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #c7c3ba;
  font-size: 13px;
}

.sidebar-footer .text-button {
  color: #c7c3ba;
}

.content {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar h2 {
  margin: 0;
  font-size: 26px;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
}

.view {
  display: grid;
  gap: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
}

.stat-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 18px;
}

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

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

/* 生成能力状态：未配置令牌时用醒目颜色提示管理员 */
.stat-card.warn {
  border-color: var(--danger, #d9534f);
}

.stat-card.warn strong {
  color: var(--danger, #d9534f);
  font-size: 18px;
}

.stat-card.ok strong {
  color: var(--success, #35a06b);
  font-size: 18px;
}

.panel {
  padding: 0;
  overflow: hidden;
}

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

.panel-head h3 {
  margin: 0;
  font-size: 16px;
}

/* 面板标题右侧的操作按钮组 */
.head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 面板正文与标题共用 18px 边距，避免说明/表格贴边、上下间距忽大忽小 */
.panel > .hint {
  margin: 14px 18px 12px;
}

.panel > .empty {
  margin: 0;
}

th:first-child,
td:first-child {
  padding-left: 18px;
}

th:last-child,
td:last-child {
  padding-right: 18px;
}

/* 表单里的整行说明（例如安装包信息） */
.form-note {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-2);
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: #fbfaf7;
}

.status {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.status.active,
.status.paid,
.status.sent {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status.pending,
.status.expired {
  background: #f4eadf;
  color: var(--warm);
}

.status.disabled,
.status.failed,
.status.canceled,
.status.refunded {
  background: var(--danger-soft);
  color: var(--danger);
}

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.form-grid .actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.check input {
  width: auto;
}

.email-layout {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
}

.email-config {
  border-right: 1px solid var(--line);
}

.template-item {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.template-item:last-child {
  border-bottom: 0;
}

.template-item strong {
  display: block;
}

.template-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.empty {
  padding: 36px 18px;
  text-align: center;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(31, 36, 33, 0.42);
}

.modal-panel {
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(31, 36, 33, 0.24);
}

/* 图片详情：左图右信息（提示词 + 参考图） */
.detail-panel {
  width: min(1180px, 100%);
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(31, 36, 33, 0.24);
}

.detail-panel .panel-head {
  border-bottom: 1px solid var(--line);
  padding: 16px 20px;
}

.detail-body {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 1fr);
  gap: 20px;
  padding: 20px;
  overflow: auto;
}

.detail-image {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  overflow: hidden;
  background: #f5f6f5;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.detail-image img {
  display: block;
  max-width: 100%;
  max-height: 76vh;
  height: auto;
  object-fit: contain;
}

.detail-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.detail-block h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.detail-prompt {
  margin: 0 0 8px;
  padding: 10px 12px;
  max-height: 220px;
  overflow: auto;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f5f6f5;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.detail-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  font-size: 13px;
}

.detail-meta dt {
  color: var(--muted);
}

.detail-meta dd {
  margin: 0;
  word-break: break-all;
}

.detail-refs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 10px;
}

.detail-ref {
  position: relative;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 92px;
  overflow: hidden;
  cursor: zoom-in;
  background: #f5f6f5;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.detail-ref img {
  display: block;
  width: 100%;
  max-height: 150px;
  height: 100%;
  object-fit: cover;
}

.ref-badge {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 2;
  padding: 1px 8px;
  font-size: 11px;
  color: #fff;
  background: rgba(37, 99, 235, 0.9);
  border-radius: 999px;
}

@media (max-width: 900px) {
  .detail-body {
    grid-template-columns: minmax(0, 1fr);
  }
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
}

.toast.error {
  background: var(--danger);
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 12px 14px;
  }

  .sidebar nav {
    display: flex;
    gap: 4px;
  }

  .sidebar-footer {
    margin-left: auto;
  }

  .content {
    padding: 18px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .email-layout {
    grid-template-columns: 1fr;
  }

  .email-config {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

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

  .form-grid .actions {
    grid-column: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* 图片管理：所有用户生成的图片都保存在服务器上 */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  padding: 4px;
}

/* ---------- 作品大厅巡查：已共享标记 + 只看已共享开关 ---------- */

.share-badge {
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 2;
  padding: 1px 8px;
  font-size: 11px;
  color: #fff;
  background: rgba(15, 123, 111, 0.92);
  border-radius: 999px;
}

.image-share {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--accent-strong);
  word-break: break-word;
}

.check-inline {
  align-items: center;
  display: inline-flex;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

/* 全局 .filter-row input 会把复选框撑成整行输入框，这里必须显式复位 */
.check-inline input[type="checkbox"] {
  flex: 0 0 auto;
  min-width: 0;
  width: 16px;
  height: 16px;
  margin: 0;
}

.filter-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.filter-row input {
  flex: 1 1 240px;
  min-width: 160px;
}

.hint {
  color: var(--muted, #6b7280);
  font-size: 13px;
  line-height: 1.7;
  margin: 0 0 12px;
}

.muted-line {
  color: var(--muted, #6b7280);
  font-size: 12px;
  margin-top: 2px;
}

.image-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.image-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

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

.thumb-placeholder {
  color: var(--muted);
  font-size: 12px;
}

.image-meta {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.image-meta strong {
  font-size: 13px;
}

.image-prompt {
  margin: 0;
  font-size: 12px;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.image-sub {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.image-meta .row-actions {
  margin-top: 6px;
}
