:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-subtle: #fafafa;
  --surface-hover: #f1f5f4;
  --surface-active: #e7eeec;
  --border: #dde3e2;
  --border-strong: #c7d0cf;
  --border-focus: #1f7a6d;
  --text: #19211f;
  --text-secondary: #52605d;
  --text-tertiary: #87918f;
  --accent: #1f7a6d;
  --accent-hover: #17685d;
  --accent-bg: rgba(31, 122, 109, 0.10);
  --accent-text: #17685d;
  --warning: #a66321;
  --success: #217a55;
  --danger: #c94c43;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow: 0 18px 44px rgba(25, 33, 31, 0.12);
  --shadow-sm: 0 8px 22px rgba(25, 33, 31, 0.08);
  --font: "PingFang SC", "Microsoft YaHei UI", "Segoe UI", system-ui, sans-serif;
  --topbar-h: 52px;
  --input-bar-h: 74px;
  --param-w: 292px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}
body {
  background: linear-gradient(180deg, #fbfcfc 0%, var(--bg) 100%);
}
body.auth-locked {
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.58; }
img, video { display: block; max-width: 100%; }
[hidden] { display: none !important; }
[data-vip-tier] { display: none !important; }
fieldset { border: none; margin: 0; padding: 0; }
legend { font-weight: 600; font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0; }

/* ========== TOPBAR ========== */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(25, 33, 31, 0.03);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.brand-link {
  display: flex; align-items: center; gap: 10px;
  padding: 0; border: none; background: transparent;
  color: inherit; border-radius: 8px;
}
.brand-link:hover .brand { filter: brightness(1.08); }
.brand {
  width: auto; min-width: 42px; height: 32px;
  padding: 0 8px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: #17211f;
  color: #fff; font-weight: 700; font-size: 0.74rem; letter-spacing: 0;
  line-height: 1;
  white-space: nowrap;
}
.brand-name { font-weight: 700; font-size: 0.95rem; margin-right: 8px; letter-spacing: 0; }
.mode-switch {
  display: flex; gap: 2px;
  padding: 3px; border-radius: 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
}
.mode-btn {
  padding: 5px 18px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-secondary); font-size: 0.85rem;
  transition: background 0.15s, color 0.15s;
}
.mode-btn.active { background: var(--text); color: #fff; }
.mode-btn:hover:not(.active) { color: var(--text); }

.status-pill {
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 0.75rem; color: var(--text-secondary);
}
.status-pill.status-success {
  color: var(--success);
  background: rgba(45, 138, 110, 0.13);
  border-color: rgba(45, 138, 110, 0.38);
}
.status-pill.status-danger {
  color: var(--danger);
  background: rgba(192, 57, 43, 0.13);
  border-color: rgba(192, 57, 43, 0.4);
}
.status-button { transition: background 0.15s, border-color 0.15s, color 0.15s; }
.status-button:hover { background: var(--surface-hover); border-color: var(--text-tertiary); color: var(--text); }
.topbar-btn {
  padding: 5px 13px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text-secondary); font-size: 0.8rem;
  transition: background 0.15s, border-color 0.15s;
}
.topbar-btn:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }
.topbar-btn-accent { background: var(--text); color: #fff; border-color: transparent; }
.topbar-btn-accent:hover { background: var(--accent-hover); }
.topbar-btn.active {
  border-color: rgba(31, 122, 109, 0.32);
  background: var(--accent-bg);
  color: var(--accent-text);
}
body.admin-route .workspace,
body.admin-route .input-bar,
body.admin-route .mobile-param-toggle {
  display: none !important;
}
body.admin-route .mode-switch,
body.admin-route #refresh-btn,
body.admin-route #history-btn,
body.admin-route #queue-badge,
body.admin-route #redeem-btn {
  display: none !important;
}

/* ========== LOGIN ========== */
.login-screen {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  padding: 24px;
  background: rgba(246, 247, 248, 0.88);
  backdrop-filter: blur(14px);
}
.login-card {
  position: relative;
  width: min(420px, 100%);
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}
.login-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
}
.login-brand {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 24px;
}
.login-logo { min-width: 54px; height: 44px; font-size: 0.95rem; }
.login-brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0; }
.login-brand p { margin: 3px 0 0; color: var(--text-secondary); font-size: 0.86rem; }
.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  margin: -8px 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}
.auth-tab {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-weight: 700;
}
.auth-tab:hover {
  color: var(--text);
  background: var(--surface-hover);
}
.auth-tab.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}
.login-error {
  margin: 4px 0 12px;
  color: var(--danger);
  font-size: 0.82rem;
}
.password-field {
  display: flex; align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  overflow: hidden;
}
.password-field:focus-within { border-color: var(--border-focus); }
.password-field input {
  flex: 1;
  min-width: 0;
  border: none !important;
  background: transparent !important;
}
.password-field input:focus { outline: none; }
.password-toggle {
  position: relative;
  width: 42px; height: 100%;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none; border-left: 1px solid var(--border);
  background: transparent;
  color: var(--text-tertiary);
  font-size: 0;
}
.password-toggle:hover { color: var(--text); background: rgba(97, 127, 255, 0.08); }
.password-toggle-icon {
  position: relative;
  width: 18px;
  height: 12px;
  display: inline-block;
}
.password-toggle-icon::before {
  content: "";
  position: absolute;
  inset: 1px 0;
  border: 1.6px solid currentColor;
  border-radius: 50% / 65%;
  transform: rotate(-2deg);
}
.password-toggle-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}
.password-toggle.is-visible::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 1.7px;
  border-radius: 999px;
  background: currentColor;
  transform: rotate(-42deg);
}
.login-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0 12px;
  color: var(--text-secondary);
  font-size: 0.8rem;
}
.login-remember {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.login-remember input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
.login-save-hint {
  color: var(--text-tertiary);
  white-space: nowrap;
}
.login-submit { width: 100%; margin-top: 4px; }
.auth-footnote {
  margin: 12px 0 0;
  color: var(--text-tertiary);
  font-size: 0.78rem;
  line-height: 1.6;
}

/* ========== WORKSPACE ========== */
.workspace {
  display: flex; gap: 0;
  margin-top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h) - var(--input-bar-h));
  height: calc(100dvh - var(--topbar-h) - var(--input-bar-h));
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}
.result-area {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  align-items: center;
  padding: 26px 28px;
  overflow-y: auto;
  min-height: 0;
}
.workbench-intro {
  width: min(100%, 860px);
  display: none;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 0;
}
.workbench-kicker {
  display: inline-block;
  margin-bottom: 5px;
  color: var(--accent-text);
  font-size: 0.76rem;
  font-weight: 800;
}
.workbench-intro h1 {
  margin: 0;
  color: var(--text);
  font-size: 1.26rem;
  line-height: 1.3;
}
.workbench-intro p {
  max-width: 620px;
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 0.86rem;
  line-height: 1.6;
}
.workbench-flow {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 6px;
  padding-top: 5px;
}
.workbench-flow span {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.74rem;
  white-space: nowrap;
}
.result-canvas {
  flex: 1 0 auto;
  width: 100%;
  display: flex; align-items: center; justify-content: center;
  min-height: min(420px, 58vh);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(rgba(25, 33, 31, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 33, 31, 0.025) 1px, transparent 1px),
    var(--surface-subtle);
  background-size: 28px 28px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
  overflow: hidden;
}
.result-meta {
  display: block;
  width: min(100%, 860px);
  padding-top: 16px;
  padding-bottom: 4px;
  flex: 0 0 auto;
}

/* ========== PARAM PANEL ========== */
.param-panel {
  width: var(--param-w); flex-shrink: 0;
  padding: 22px 18px;
  border-left: 1px solid var(--border);
  background: #fff;
  overflow-y: auto;
  max-height: calc(100vh - var(--topbar-h) - var(--input-bar-h));
  position: sticky; top: var(--topbar-h);
}
.param-group {
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(221, 227, 226, 0.72);
}
.param-group:last-child { border-bottom: none; padding-bottom: 0; }
.param-label { display: block; font-size: 0.75rem; font-weight: 700; color: var(--text-tertiary); margin-bottom: 9px; text-transform: uppercase; letter-spacing: 0; }
.param-hint { margin: 0 0 8px; font-size: 0.75rem; color: var(--text-tertiary); }

.seg-row { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-row.size-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.seg-btn {
  padding: 7px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-subtle); color: var(--text-secondary); font-size: 0.8rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.seg-btn:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }
.seg-btn.active {
  background: var(--text); color: #fff;
  border-color: var(--text);
}
.seg-btn-size {
  min-height: 68px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 3px;
  text-align: left;
  line-height: 1.18;
}
.seg-btn-size span {
  font-weight: 700;
  color: var(--text);
}
.seg-btn-size small,
.seg-btn-size em {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-tertiary);
  font-size: 0.68rem;
  font-style: normal;
}
.seg-btn-size.active span,
.seg-btn-size.active small,
.seg-btn-size.active em {
  color: #fff;
}

/* reference upload */
.ref-drop {
  position: relative;
  min-height: 100px; border: 1px dashed var(--border); border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden;
  background: var(--surface-subtle);
  transition: border-color 0.15s, background 0.15s;
}
.ref-drop:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.ref-drop.dragover { border-color: var(--accent); background: var(--accent-bg); }
.ref-drop input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.ref-empty { color: var(--text-tertiary); font-size: 0.8rem; text-align: center; padding: 12px; }
.ref-drop img { width: 100%; height: auto; max-height: 180px; object-fit: cover; border-radius: var(--radius-sm); }
.ref-list {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.ref-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.ref-card img,
.ref-thumb-empty {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--surface-subtle);
}
.ref-thumb-empty {
  display: grid;
  place-items: center;
  color: var(--text-tertiary);
  font-size: 0.72rem;
}
.ref-card-meta {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 7px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}
.ref-card-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  color: var(--text);
}
.ref-card-meta em {
  flex-shrink: 0;
  color: var(--text-tertiary);
  font-style: normal;
}
.ref-remove {
  flex-shrink: 0;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 0.72rem;
  cursor: pointer;
}
.ref-remove:hover { text-decoration: underline; }
.ref-number-hint { margin-top: 8px; }
.ref-url-input {
  width: 100%; margin-top: 8px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-subtle); font-size: 0.8rem;
}
.ref-url-input:focus { outline: none; border-color: var(--border-focus); }
.ref-pick-actions { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.btn-secondary.slim { min-height: 30px; padding: 6px 10px; font-size: 0.78rem; }
.ref-actions { margin-top: 6px; }
.btn-text { background: none; border: none; color: var(--danger); font-size: 0.78rem; padding: 4px 0; }
.btn-text:hover { text-decoration: underline; }

/* ========== INPUT BAR ========== */
.input-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 24px rgba(25, 33, 31, 0.06);
}
.input-form {
  display: flex; align-items: flex-end; gap: 10px;
  max-width: 1120px; margin: 0 auto; position: relative;
}
.upload-btn {
  display: grid; place-items: center;
  width: 42px; height: 42px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text-secondary);
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.upload-btn:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }
.upload-btn input { display: none; }
.input-form textarea {
  flex: 1; min-height: 42px; max-height: 120px;
  padding: 10px 14px; resize: none;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text);
  font-size: 0.9rem; line-height: 1.5;
  box-shadow: inset 0 1px 2px rgba(25, 33, 31, 0.03);
}
.input-form textarea:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(31, 122, 109, 0.10); }
.gen-btn {
  height: 42px; padding: 0 24px; flex-shrink: 0;
  border: none; border-radius: var(--radius-md);
  background: var(--accent); color: #fff; font-weight: 600; font-size: 0.9rem;
  transition: background 0.15s, transform 0.15s;
}
.gen-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.gen-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.assistant-btn,
.polish-btn {
  height: 42px; padding: 0 16px; flex-shrink: 0;
  border-radius: var(--radius-md);
  font-weight: 600; font-size: 0.86rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.assistant-btn {
  display: inline-grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  line-height: 1.08;
  white-space: nowrap;
  border: 1px solid rgba(31, 122, 109, 0.30);
  background: rgba(31, 122, 109, 0.08);
  color: var(--accent-text);
}
.assistant-btn-price {
  font-size: 0.78em;
  font-weight: 700;
  color: rgba(31, 122, 109, 0.84);
}
.assistant-btn:hover { background: rgba(31, 122, 109, 0.14); border-color: rgba(31, 122, 109, 0.42); }
.assistant-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.polish-btn {
  border: 1px solid rgba(59, 111, 149, 0.30); border-radius: var(--radius-md);
  background: rgba(59, 111, 149, 0.08);
  color: #315f82;
}
.polish-btn:hover { background: rgba(59, 111, 149, 0.14); border-color: rgba(59, 111, 149, 0.42); }
.polish-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-loading { opacity: 0.6; pointer-events: none; }
.btn-loading::after { content: "..."; }
.char-count {
  position: absolute; right: 80px; bottom: 18px;
  font-size: 0.7rem; color: var(--text-tertiary); pointer-events: none;
}
.price-badge {
  height: 42px; min-width: 82px;
  display: grid; place-items: center;
  padding: 0 12px; flex-shrink: 0;
  border: 1px solid rgba(166, 99, 33, 0.22);
  border-radius: var(--radius-md);
  background: rgba(166, 99, 33, 0.08);
  color: var(--warning);
  font-weight: 700;
  font-size: 0.82rem;
  white-space: nowrap;
}

/* ========== RESULT STATES ========== */
.empty-state {
  text-align: center; max-width: 620px;
  padding: 34px 24px;
}
.empty-state::before {
  content: "";
  display: block;
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(31, 122, 109, 0.16), rgba(166, 99, 33, 0.10)),
    var(--surface);
  box-shadow: var(--shadow-sm);
}
.empty-state h3 { margin: 0 0 8px; font-size: 1.15rem; font-weight: 700; color: var(--text); }
.empty-state p { margin: 0 0 22px; color: var(--text-secondary); font-size: 0.86rem; }
.home-dashboard {
  width: min(100%, 760px);
  max-width: 760px;
}
.home-mode-summary {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}
.home-mode-summary span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.78rem;
}
.home-mode-summary b {
  color: var(--text);
  font-weight: 700;
}
.sample-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.sample-chip {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-secondary); font-size: 0.78rem;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
  max-width: 260px; text-align: left;
}
.sample-chip:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }

.pending-state { text-align: center; max-width: 480px; }
.pending-state h3 { margin: 0 0 6px; font-size: 1rem; color: var(--text); }
.pending-state p { margin: 0 0 20px; color: var(--text-secondary); font-size: 0.85rem; }
.progress-bar { height: 6px; border-radius: 3px; background: var(--surface-active); overflow: hidden; margin-bottom: 8px; }
.progress-bar span { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--accent), #3b6f95); transition: width 0.3s; }
.progress-info { color: var(--text-secondary); font-size: 0.8rem; }
.pending-tags { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 12px; }
.pending-tag { padding: 4px 10px; border-radius: 20px; background: var(--surface); font-size: 0.72rem; color: var(--text-tertiary); }

.pulse-placeholder {
  width: min(100%, 400px); aspect-ratio: 1;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: linear-gradient(135deg, var(--surface-subtle) 25%, var(--surface-active) 50%, var(--surface-subtle) 75%);
  background-size: 200% 200%;
  animation: pulse-bg 2s ease-in-out infinite;
  margin: 0 auto 20px;
}
@keyframes pulse-bg {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.media-display {
  width: min(100%, 800px);
  max-height: max(320px, calc(100vh - var(--topbar-h) - var(--input-bar-h) - 190px));
  max-height: max(320px, calc(100dvh - var(--topbar-h) - var(--input-bar-h) - 190px));
  margin: 0 auto;
  display: grid;
  place-items: center;
}
.media-button {
  position: relative;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
}
.media-display img, .media-display video {
  width: auto;
  max-width: 100%;
  max-height: max(320px, calc(100vh - var(--topbar-h) - var(--input-bar-h) - 190px));
  max-height: max(320px, calc(100dvh - var(--topbar-h) - var(--input-bar-h) - 190px));
  border-radius: var(--radius-md);
  background: var(--surface);
  object-fit: contain;
  box-shadow: var(--shadow-sm);
}
.media-hint {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(29, 36, 51, 0.66);
  color: #fff;
  font-size: 0.72rem;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.16s, transform 0.16s;
  pointer-events: none;
}
.media-button:hover .media-hint,
.media-button:focus-visible .media-hint {
  opacity: 1;
  transform: translateY(0);
}
.result-info {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border);
}
.info-tag { padding: 4px 9px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 0.75rem; color: var(--text-secondary); }
.info-tag.succeeded { color: var(--success); }
.info-tag.failed { color: var(--danger); }
.info-tag.processing, .info-tag.queued { color: #5ba8c8; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.centered-actions { justify-content: center; margin-top: 12px; }
.queue-link-btn { margin-top: 16px; }
.action-btn {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-secondary); font-size: 0.8rem;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.action-btn:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }
.action-btn.primary-action {
  border-color: transparent;
  background: var(--text);
  color: #fff;
  font-weight: 700;
}
.action-btn.primary-action:hover {
  background: var(--accent-hover);
  color: #fff;
}
.continue-edit-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid rgba(31, 122, 109, 0.16);
  border-radius: var(--radius-md);
  background: rgba(31, 122, 109, 0.06);
}
.quick-edit-chips {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.quick-edit-chip {
  padding: 5px 9px;
  border: 1px solid rgba(31, 122, 109, 0.18);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--accent-text);
  font-size: 0.76rem;
}
.quick-edit-chip:hover {
  background: rgba(31, 122, 109, 0.12);
  border-color: rgba(31, 122, 109, 0.36);
}

.result-prompt {
  margin-top: 10px; padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text-secondary); font-size: 0.82rem; line-height: 1.6;
  word-break: break-word;
  max-height: 8.4rem;
  overflow-y: auto;
}
.result-prompt-clickable {
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.result-prompt-clickable:hover {
  background: var(--surface-hover);
}

/* ========== OVERLAY + HISTORY DRAWER ========== */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(18, 25, 24, 0.46);
  opacity: 0; transition: opacity 0.2s;
  pointer-events: none;
}
.overlay.open { opacity: 1; pointer-events: auto; }
.history-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21;
  width: min(380px, 85vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -18px 0 40px rgba(25, 33, 31, 0.12);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex; flex-direction: column;
}
.history-drawer.open { transform: translateX(0); }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h3 { margin: 0; font-size: 1rem; }
.close-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text-secondary);
  font-size: 1.2rem; display: grid; place-items: center;
}
.close-btn:hover { background: var(--surface-hover); }
.drawer-tabs { display: flex; gap: 2px; padding: 8px 16px; }
.drawer-tab {
  flex: 1; padding: 6px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-secondary); font-size: 0.82rem;
  transition: background 0.15s, color 0.15s;
}
.drawer-tab.active { background: var(--text); color: #fff; }
.drawer-list { flex: 1; overflow-y: auto; padding: 8px 16px 16px; }
.drawer-search { padding: 4px 16px 8px; }
.drawer-search input {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-subtle); font-size: 0.8rem; color: var(--text);
}
.drawer-search input:focus { outline: none; border-color: var(--border-focus); }

.history-card {
  display: flex; gap: 10px; align-items: center;
  padding: 10px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); cursor: pointer; width: 100%; text-align: left;
  transition: background 0.15s, border-color 0.15s;
}
.history-card:hover { background: var(--surface-hover); }
.history-card.active { border-color: rgba(31, 122, 109, 0.42); background: var(--accent-bg); }
.history-thumb {
  width: 56px; height: 56px; flex-shrink: 0;
  border-radius: 8px; overflow: hidden;
  background: var(--bg);
}
.history-thumb img { width: 100%; height: 100%; object-fit: cover; }
.history-thumb-empty { width: 100%; height: 100%; display: grid; place-items: center; color: var(--text-tertiary); font-size: 0.65rem; }
.history-info { flex: 1; min-width: 0; }
.history-info strong { display: block; font-size: 0.82rem; font-weight: 500; }
.history-info p { margin: 3px 0 0; font-size: 0.75rem; color: var(--text-tertiary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-info .history-tags { display: flex; gap: 4px; margin-top: 4px; }
.history-info .history-tag { padding: 2px 6px; border-radius: 4px; background: var(--surface-subtle); font-size: 0.65rem; color: var(--text-tertiary); }

.empty-drawer { padding: 40px 16px; text-align: center; color: var(--text-tertiary); font-size: 0.85rem; }

/* ========== SETTINGS MODAL ========== */
.settings-modal, .admin-edit-modal, .admin-audit-modal, .detail-modal, .prompt-assistant-modal, .polish-modal, .redeem-modal {
  position: fixed; inset: 0; z-index: 30;
  width: min(540px, 92vw); max-height: 90vh;
  margin: auto; padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
  overflow-y: auto;
}
.admin-edit-modal { width: min(520px, 92vw); }
.admin-audit-modal { width: min(680px, 92vw); }
.detail-modal { width: min(1120px, 94vw); }
.prompt-assistant-modal { width: min(980px, 96vw); }
.polish-modal { width: min(760px, 94vw); }
.redeem-modal { width: min(460px, 92vw); }
.settings-modal::backdrop, .admin-edit-modal::backdrop, .admin-audit-modal::backdrop, .detail-modal::backdrop, .prompt-assistant-modal::backdrop, .polish-modal::backdrop, .redeem-modal::backdrop { background: rgba(18, 25, 24, 0.46); backdrop-filter: blur(2px); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--surface); z-index: 1;
}
.modal-header h3 { margin: 0; font-size: 1rem; font-weight: 700; }
.modal-subtitle { margin: 3px 0 0; color: var(--text-tertiary); font-size: 0.78rem; }
.modal-hint {
  margin: 16px 20px 0; padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(31, 122, 109, 0.14);
  background: var(--accent-bg);
  font-size: 0.8rem; color: var(--text-secondary); line-height: 1.6;
}
.settings-save-status {
  margin: 10px 20px 0;
  padding: 10px 14px;
  border: 1px solid rgba(33, 122, 85, 0.24);
  border-radius: var(--radius-sm);
  background: rgba(33, 122, 85, 0.08);
  color: var(--success);
  font-size: 0.8rem;
  font-weight: 700;
}
.settings-form { padding: 0 20px 20px; }
.admin-edit-form { padding-top: 18px; }
.setting-section { margin-top: 20px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field span { font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); }
.field input[type="text"], .field input[type="url"], .field input[type="password"], .field input[type="number"], .field select, .field textarea {
  padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-subtle); font-size: 0.85rem;
}
.setting-textarea {
  resize: vertical;
  min-height: 92px;
  color: var(--text);
  line-height: 1.5;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--border-focus); }
.field-check { flex-direction: row; align-items: center; justify-content: space-between; }
.field-check input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.btn-primary {
  padding: 9px 18px; border: none; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  padding: 9px 18px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--text-secondary);
}
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text); }
.btn-danger {
  padding: 9px 20px; border: 1px solid rgba(192, 57, 43, 0.3); border-radius: 8px;
  background: transparent; color: var(--danger);
}
.btn-danger:hover { background: rgba(192, 57, 43, 0.08); }
.topbar-btn-redeem {
  border-color: rgba(31, 122, 109, 0.28);
  background: rgba(31, 122, 109, 0.08);
  color: var(--accent);
}
.topbar-btn-redeem:hover {
  border-color: rgba(31, 122, 109, 0.4);
  background: rgba(31, 122, 109, 0.12);
}
.redeem-form {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.redeem-form label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--text-secondary);
  font-size: 0.78rem;
}
.redeem-form input {
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  background: var(--surface-subtle);
  color: var(--text);
  font: inherit;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.redeem-form input:focus {
  outline: none;
  border-color: var(--border-focus);
}
.redeem-status {
  margin: 0;
}
.redeem-status.success {
  border-color: rgba(31, 122, 109, 0.22);
  background: rgba(31, 122, 109, 0.08);
  color: var(--success);
  font-weight: 700;
}
.redeem-status.error {
  border-color: rgba(192, 57, 43, 0.22);
  background: rgba(192, 57, 43, 0.08);
  color: var(--danger);
  font-weight: 700;
}

/* ========== PROMPT POLISH ========== */
.polish-body {
  padding: 18px 20px 20px;
  display: grid;
  gap: 14px;
}
.polish-body .detail-prompt-box textarea {
  min-height: 120px;
}
.polish-result-panel {
  display: grid;
  gap: 10px;
}
.polish-status {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.polish-status.is-loading {
  border-color: rgba(58, 120, 206, 0.28);
  background: rgba(58, 120, 206, 0.08);
  color: #2d5d9f;
}
.polish-status.is-error {
  border-color: rgba(208, 74, 61, 0.24);
  background: rgba(208, 74, 61, 0.08);
  color: var(--danger);
}
.polish-actions {
  margin-top: 2px;
}
.polish-actions button {
  min-width: 118px;
}
.polish-revision-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}
.polish-revision-form .field {
  margin-bottom: 0;
}
.polish-revision-form textarea {
  min-height: 58px;
  max-height: 140px;
  resize: vertical;
}
.polish-revision-form button {
  min-width: 118px;
  white-space: nowrap;
}

/* ========== PROMPT ASSISTANT ========== */
.assistant-body {
  padding: 18px 20px 20px;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr);
  gap: 16px;
}
.assistant-chat-panel,
.assistant-profile-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.assistant-thread-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-tertiary);
  font-size: 0.78rem;
}
.compact-btn {
  padding: 6px 10px;
  font-size: 0.76rem;
}
.assistant-messages {
  min-height: 360px;
  max-height: min(54vh, 560px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}
.assistant-empty {
  height: 100%;
  min-height: 260px;
  display: grid;
  place-items: center;
  color: var(--text-tertiary);
  font-size: 0.86rem;
  text-align: center;
}
.assistant-message {
  width: fit-content;
  max-width: 86%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.assistant-message.user {
  margin-left: auto;
  border-color: rgba(31, 122, 109, 0.26);
  background: rgba(31, 122, 109, 0.08);
}
.assistant-message-role {
  margin-bottom: 4px;
  font-size: 0.72rem;
  color: var(--text-tertiary);
}
.assistant-message-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
  line-height: 1.55;
  font-size: 0.86rem;
}
.assistant-message-billing {
  margin-top: 6px;
  color: var(--text-tertiary);
  font-size: 0.72rem;
}
.assistant-suggestions {
  min-height: 34px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.assistant-suggestions button {
  padding: 7px 10px;
  border: 1px solid rgba(31, 122, 109, 0.22);
  border-radius: var(--radius-sm);
  background: rgba(31, 122, 109, 0.08);
  color: var(--accent-text);
  font-size: 0.78rem;
}
.assistant-suggestions button:hover { background: rgba(31, 122, 109, 0.14); }
.assistant-guide {
  display: grid;
  gap: 12px;
}
.assistant-question-block {
  display: grid;
  gap: 6px;
  padding: 2px 0 4px;
}
.assistant-progress {
  color: var(--text-tertiary);
  font-size: 0.75rem;
}
.assistant-question-block strong {
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.35;
}
.assistant-question-block p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.83rem;
  line-height: 1.6;
}
.assistant-seed,
.assistant-selected-scenario {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.8rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.assistant-seed b {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 0.76rem;
}
.assistant-revision-card {
  padding: 12px;
  border: 1px solid rgba(31, 122, 109, 0.2);
  border-radius: var(--radius-sm);
  background: rgba(31, 122, 109, 0.07);
}
.assistant-selected-scenario {
  display: grid;
  gap: 3px;
}
.assistant-selected-scenario strong {
  color: var(--text);
  font-size: 0.84rem;
}
.assistant-selected-scenario span {
  color: var(--text-tertiary);
}
.assistant-scenario-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.assistant-direction-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.assistant-direction-card {
  min-height: 92px;
  display: grid;
  gap: 6px;
  align-content: start;
  padding: 12px;
  border: 1px solid rgba(31, 122, 109, 0.22);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.assistant-direction-card:hover {
  border-color: rgba(31, 122, 109, 0.42);
  background: rgba(31, 122, 109, 0.06);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.assistant-direction-card strong {
  font-size: 0.86rem;
  line-height: 1.35;
}
.assistant-direction-card span {
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.45;
}
.assistant-brief-lead {
  padding-bottom: 2px;
}
.assistant-brief-questions {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(25, 33, 31, 0.08);
  border-radius: var(--radius-sm);
  background: #fff;
}
.assistant-brief-questions > span {
  color: var(--text-tertiary);
  font-size: 0.74rem;
  font-weight: 800;
}
.assistant-brief-questions button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-size: 0.76rem;
  text-align: left;
}
.assistant-brief-questions button:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}
.assistant-brief-questions b {
  flex: 0 0 auto;
  color: var(--text);
  font-size: 0.76rem;
}
.assistant-more-scenarios {
  color: var(--text-secondary);
  font-size: 0.78rem;
}
.assistant-more-scenarios summary {
  width: fit-content;
  cursor: pointer;
  color: var(--accent-text);
  font-weight: 700;
}
.assistant-more-scenarios .assistant-scenario-grid {
  margin-top: 10px;
}
.assistant-scenario-card {
  min-height: 82px;
  display: grid;
  gap: 5px;
  align-content: start;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.assistant-scenario-card:hover {
  border-color: rgba(31, 122, 109, 0.34);
  background: #fff;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.assistant-scenario-card.active {
  border-color: rgba(31, 122, 109, 0.42);
  background: rgba(31, 122, 109, 0.08);
}
.assistant-scenario-card strong {
  font-size: 0.86rem;
  line-height: 1.35;
}
.assistant-scenario-card span {
  color: var(--text-secondary);
  font-size: 0.76rem;
  line-height: 1.45;
}
.assistant-answer-log {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.assistant-answer-log span {
  max-width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-secondary);
  font-size: 0.76rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.assistant-answer-log b {
  margin-right: 5px;
  color: var(--text-tertiary);
  font-weight: 600;
}
.assistant-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}
.assistant-composer textarea {
  min-height: 58px;
  max-height: 160px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--text);
  line-height: 1.5;
}
.assistant-composer textarea:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(31, 122, 109, 0.10); }
.assistant-profile-toggle {
  display: none;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  text-align: left;
}
.assistant-profile {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}
.assistant-profile-row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
.assistant-profile-row span {
  color: var(--text-tertiary);
  font-size: 0.76rem;
}
.assistant-profile-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.45;
}
.assistant-result {
  padding: 12px;
  border: 1px solid rgba(31, 122, 109, 0.18);
  border-radius: var(--radius-md);
  background: rgba(31, 122, 109, 0.06);
}
.assistant-result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.assistant-result-meta span {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.72rem;
}
.assistant-result textarea {
  min-height: 150px;
}
.assistant-note {
  margin-top: 10px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  line-height: 1.55;
}
.assistant-tips {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--text-tertiary);
  font-size: 0.78rem;
  line-height: 1.55;
}
.assistant-actions {
  align-items: center;
  margin-top: 0;
}
.assistant-actions button {
  flex: 1 1 auto;
  min-width: 130px;
}
.assistant-admin-row {
  display: flex;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
}
.assistant-admin-row + .assistant-admin-row { margin-top: 10px; }
.assistant-admin-row:hover { background: var(--surface-hover); }
.assistant-admin-main { flex: 1; min-width: 0; }
.assistant-final-snippet {
  color: var(--text-secondary);
}
.assistant-admin-thread {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}
.assistant-admin-message {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.assistant-admin-message.user {
  border-color: rgba(31, 122, 109, 0.22);
  background: rgba(31, 122, 109, 0.08);
}
.assistant-admin-message strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.assistant-admin-message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
  line-height: 1.55;
}
.assistant-admin-message span {
  display: block;
  margin-top: 6px;
  color: var(--text-tertiary);
  font-size: 0.72rem;
}

/* ========== DETAIL MODAL ========== */
.detail-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  padding: 18px 20px 20px;
}
.detail-media {
  min-height: 420px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  overflow: hidden;
}
.detail-media img,
.detail-media video {
  max-width: 100%;
  max-height: min(70vh, 720px);
  object-fit: contain;
}
.detail-gallery {
  width: 100%;
  max-height: min(72vh, 760px);
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  overflow: auto;
}
.detail-result-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}
.detail-result-media {
  height: 220px;
  display: grid;
  place-items: center;
  background: var(--surface-subtle);
}
.detail-result-media img,
.detail-result-media video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.detail-result-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.detail-result-footer span {
  min-width: 0;
  word-break: break-word;
}
.detail-result-actions {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
.detail-empty {
  color: var(--text-tertiary);
  font-size: 0.9rem;
}
.detail-side {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.detail-meta-line {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
.detail-meta-line strong {
  color: var(--text);
}
.detail-meta-line span {
  color: var(--text-secondary);
  word-break: break-word;
}
.detail-error {
  padding: 10px 12px;
  border: 1px solid rgba(208, 74, 61, 0.22);
  border-radius: var(--radius-sm);
  background: rgba(208, 74, 61, 0.08);
  color: var(--danger);
  font-size: 0.82rem;
  word-break: break-word;
}
.detail-prompt-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.detail-prompt-box span {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 600;
}
.detail-prompt-box textarea {
  min-height: 180px;
  max-height: 40vh;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--text);
  line-height: 1.65;
}
.detail-prompt-box textarea:focus {
  outline: none;
  border-color: var(--border-focus);
}
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.detail-copy-btn {
  align-self: flex-start;
}
.audit-detail {
  padding: 18px 20px 20px;
}
.audit-detail-grid {
  margin-bottom: 14px;
}

/* ========== ADMIN ========== */
.admin-page {
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(var(--topbar-h) + 20px) 22px 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(246, 247, 248, 0.96)),
    var(--bg);
}
.admin-page-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.admin-sidebar {
  position: sticky;
  top: calc(var(--topbar-h) + 20px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow-sm);
}
.admin-sidebar-head {
  display: grid;
  gap: 3px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.admin-kicker {
  color: var(--accent-text);
  font-size: 0.74rem;
  font-weight: 800;
}
.admin-sidebar-head strong {
  font-size: 1rem;
}
.admin-sidebar-head small,
.admin-page-header p,
.admin-settings-host .section-head p {
  margin: 0;
  color: var(--text-tertiary);
  font-size: 0.78rem;
  line-height: 1.5;
}
.admin-main-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.admin-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-sm);
}
.admin-page-header h2 {
  margin: 2px 0 4px;
  font-size: 1.32rem;
  line-height: 1.28;
}
.admin-page-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}
.admin-body { padding: 0; }
.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.admin-stats-panel {
  grid-column: 1 / -1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.72);
}
.admin-stats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.admin-stats-head strong {
  display: block;
  font-size: 0.98rem;
}
.admin-stats-head span {
  display: block;
  margin-top: 3px;
  color: var(--text-tertiary);
  font-size: 0.76rem;
}
.admin-range-tabs {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
}
.admin-range-tabs button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: calc(var(--radius-sm) - 2px);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.78rem;
  cursor: pointer;
}
.admin-range-tabs button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}
.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 10px;
}
.admin-stat {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.9);
}
.admin-stat strong {
  display: block;
  overflow: hidden;
  font-size: 1.12rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-stat span { color: var(--text-secondary); font-size: 0.75rem; }
.admin-view-tabs {
  display: grid;
  gap: 6px;
}
.admin-view-tab {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  text-align: left;
}
.admin-view-tab.active {
  color: var(--accent);
  border-color: rgba(31, 122, 109, 0.22);
  background: rgba(31, 122, 109, 0.09);
}
.admin-view-tab:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.admin-toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.admin-create-user {
  display: grid;
  grid-template-columns: 1fr 1fr 120px 120px auto;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.88);
}
.admin-create-user input,
.admin-create-user select,
.admin-create-user .password-field,
.admin-toolbar input,
.admin-toolbar select {
  padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-subtle); color: var(--text);
}
.admin-create-user .password-field {
  padding: 0;
}
.admin-toolbar select { min-width: 140px; }
.admin-toolbar input { flex: 1; min-width: 150px; }
.admin-toolbar input[type="date"] {
  flex: 0 0 142px;
  min-width: 142px;
}
.admin-toolbar button { white-space: nowrap; }
.admin-create-user input:focus,
.admin-create-user select:focus,
.admin-toolbar input:focus,
.admin-toolbar select:focus { outline: none; border-color: var(--border-focus); }
.admin-list {
  display: flex; flex-direction: column; gap: 10px;
  max-height: none;
  overflow: visible;
  padding-right: 2px;
}
.admin-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.88);
}
.admin-section + .admin-section { margin-top: 18px; }
.admin-section h4 { margin: 0; font-size: 0.88rem; color: var(--text-secondary); }
.admin-settings-form-host .settings-form {
  padding: 0;
}
.admin-settings-host .modal-hint,
.admin-settings-host .settings-save-status {
  margin: 0;
}
.admin-settings-host .setting-section {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}
.admin-settings-host .modal-actions {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin-top: 14px;
  padding: 12px 0 0;
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,255,255,0.96) 38%);
}
.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}
.funnel-summary-grid,
.funnel-metrics,
.funnel-extra-grid,
.ip-summary-grid,
.segment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.funnel-summary-card,
.funnel-metric,
.ip-summary-card,
.segment-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.funnel-summary-card.active {
  border-color: rgba(31, 122, 109, 0.38);
  background: rgba(31, 122, 109, 0.08);
}
.funnel-summary-card strong,
.funnel-metric strong,
.ip-summary-card strong {
  display: block;
  font-size: 1.08rem;
}
.funnel-summary-card span,
.funnel-metric span,
.funnel-summary-card small,
.ip-summary-card span {
  display: block;
  color: var(--text-secondary);
  font-size: 0.74rem;
}
.segment-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.segment-card {
  display: grid;
  gap: 10px;
}
.segment-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.segment-card-head strong,
.segment-card-head span {
  display: block;
}
.segment-card-head strong {
  font-size: 0.92rem;
}
.segment-card-head span {
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 0.74rem;
  line-height: 1.5;
}
.segment-count {
  flex: 0 0 auto;
  min-width: 54px;
  text-align: right;
}
.segment-count b {
  display: block;
  font-size: 1.18rem;
}
.segment-count small {
  color: var(--text-tertiary);
  font-size: 0.72rem;
}
.segment-user-list {
  display: grid;
  gap: 6px;
}
.segment-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.segment-user-row div {
  min-width: 0;
}
.segment-user-row strong,
.segment-user-row span {
  display: block;
}
.segment-user-row strong {
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}
.segment-user-row span,
.segment-user-row small {
  color: var(--text-tertiary);
  font-size: 0.7rem;
}
.segment-user-row small {
  flex: 0 0 auto;
  text-align: right;
}
.ip-recent {
  display: grid;
  gap: 8px;
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.72);
}
.ip-recent strong {
  font-size: 0.82rem;
}
.ip-recent div {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ip-recent span {
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-active);
  color: var(--text-secondary);
  font-family: var(--mono);
  font-size: 0.74rem;
  overflow-wrap: anywhere;
}
.ip-list {
  display: grid;
  gap: 8px;
}
.ip-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) minmax(90px, auto);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.ip-rank {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-active);
  color: var(--text-secondary);
  font-size: 0.74rem;
  font-weight: 700;
}
.ip-main {
  min-width: 0;
}
.ip-main strong {
  display: block;
  font-family: var(--mono);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}
.ip-main span,
.ip-last {
  color: var(--text-tertiary);
  font-size: 0.72rem;
}
.ip-last {
  text-align: right;
  white-space: nowrap;
}
.risk-summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
}
.risk-row.warning {
  border-color: rgba(191, 119, 0, 0.34);
  background: rgba(255, 247, 230, 0.86);
}
.risk-row.high {
  border-color: rgba(190, 18, 60, 0.34);
  background: rgba(255, 241, 242, 0.88);
}
.risk-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}
.risk-flag {
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--surface-active);
  color: var(--text-secondary);
  font-size: 0.68rem;
}
.risk-flag.muted {
  color: var(--text-tertiary);
}
.risk-score {
  text-align: right;
}
.risk-score strong,
.risk-score span {
  display: block;
}
.risk-score strong {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}
.risk-score span {
  color: var(--text-tertiary);
  font-size: 0.72rem;
  white-space: nowrap;
}
.funnel-table {
  display: grid;
  gap: 8px;
}
.funnel-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.1fr) minmax(120px, 1fr) repeat(4, minmax(58px, 0.34fr));
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.funnel-step strong,
.funnel-step span,
.funnel-num strong,
.funnel-num span {
  display: block;
}
.funnel-step strong {
  font-size: 0.84rem;
}
.funnel-step span,
.funnel-num span {
  color: var(--text-tertiary);
  font-size: 0.72rem;
}
.funnel-num strong {
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}
.funnel-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-active);
}
.funnel-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #3b6f95);
}
.health-card {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
button.health-card {
  width: 100%;
  text-align: left;
}
.admin-nav-card {
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.admin-nav-card:hover {
  border-color: rgba(31, 122, 109, 0.32);
  background: var(--surface-hover);
  transform: translateY(-1px);
}
.health-card strong {
  display: block;
  font-size: 1rem;
}
.health-card span {
  color: var(--text-secondary);
  font-size: 0.74rem;
}
.health-warnings {
  display: grid;
  gap: 6px;
}
.health-warning,
.health-ok {
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  line-height: 1.5;
}
.health-warning {
  border: 1px solid rgba(208, 158, 42, 0.28);
  background: rgba(255, 196, 87, 0.12);
  color: var(--warning);
}
.health-ok {
  border: 1px solid rgba(35, 139, 102, 0.22);
  background: rgba(35, 139, 102, 0.09);
  color: var(--success);
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.admin-redemption-form {
  display: grid;
  grid-template-columns: 120px 100px minmax(160px, 1fr) minmax(160px, 1fr) auto;
  gap: 10px;
  align-items: end;
}
.admin-redemption-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--text-secondary);
  font-size: 0.76rem;
}
.admin-redemption-form input {
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--text);
}
.admin-redemption-form input:focus {
  outline: none;
  border-color: var(--border-focus);
}
.redemption-generated textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.55;
}
.redemption-generated small {
  color: var(--text-tertiary);
  font-size: 0.74rem;
}
.redemption-list {
  display: grid;
  gap: 8px;
}
.redemption-row,
.redemption-batch-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.redemption-row.disabled {
  opacity: 0.72;
}
.redemption-row.used {
  border-color: rgba(31, 122, 109, 0.18);
}
.redemption-row-main {
  min-width: 0;
}
.redemption-row .btn-danger {
  flex: 0 0 auto;
}
.admin-users { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.admin-user {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.admin-user.active {
  border-color: rgba(31, 122, 109, 0.42);
  background: var(--accent-bg);
}
.admin-user.deleted {
  opacity: 0.72;
}
.admin-user.suspended {
  border-color: rgba(208, 74, 61, 0.28);
  background: rgba(208, 74, 61, 0.05);
}
.admin-user > div:first-child { display: flex; gap: 8px; align-items: center; }
.admin-user-title {
  justify-content: space-between;
  flex-wrap: wrap;
}
.admin-user-title > div {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.admin-user-title strong,
.admin-user-title small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-user-title small {
  color: var(--text-tertiary);
  font-size: 0.72rem;
}
.admin-user-metrics {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 10px 0;
  color: var(--text-secondary);
  font-size: 0.76rem;
}
.admin-user-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin: -2px 0 10px;
  color: var(--text-tertiary);
  font-size: 0.72rem;
}
.admin-user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.admin-recharge-form { display: flex; gap: 8px; }
.admin-recharge-form input {
  min-width: 0; flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-subtle); color: var(--text);
}
.admin-job {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.admin-job:hover,
.admin-job:focus-visible {
  background: var(--surface-hover);
  border-color: rgba(31, 122, 109, 0.34);
}
.admin-job:focus-visible { outline: 2px solid rgba(31, 122, 109, 0.22); outline-offset: 2px; }
.admin-job-detail-btn { margin-left: auto; }
.admin-thumb {
  width: 82px; height: 82px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-subtle);
}
.admin-thumb img { width: 100%; height: 100%; object-fit: cover; }
.admin-thumb-empty {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  color: var(--text-tertiary); font-size: 0.72rem;
}
.admin-job-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.admin-prompt {
  margin: 8px 0;
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.55;
  word-break: break-word;
}
.admin-source-row { display: flex; flex-wrap: wrap; gap: 6px; }
.source-pill {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.72rem;
}
.source-pill.local { color: var(--success); background: rgba(45, 138, 110, 0.12); }
.source-pill.remote { color: #315f82; background: rgba(59, 111, 149, 0.12); }
.source-pill.base64 { color: #376f79; background: rgba(55, 111, 121, 0.12); }
.admin-meta {
  margin-top: 8px;
  color: var(--text-tertiary);
  font-size: 0.74rem;
}
.admin-error {
  margin-top: 8px;
  color: var(--danger);
  font-size: 0.78rem;
}
.audit-list,
.session-list {
  display: grid;
  gap: 8px;
}
.audit-row,
.session-row {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.4fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.audit-row.warning,
.session-row.warning {
  border-color: rgba(208, 158, 42, 0.28);
  background: rgba(255, 196, 87, 0.09);
}
.audit-row strong,
.session-row strong {
  display: block;
  font-size: 0.86rem;
}
.audit-row span,
.session-row span {
  display: block;
  min-width: 0;
  color: var(--text-tertiary);
  font-size: 0.75rem;
  word-break: break-word;
}
.ledger-list {
  display: grid;
  gap: 8px;
}
.history-ledger-list {
  padding: 2px;
}
.ledger-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.ledger-row > div {
  min-width: 0;
}
.ledger-row strong,
.ledger-row span {
  display: block;
}
.ledger-row span {
  margin-top: 2px;
  color: var(--text-tertiary);
  font-size: 0.74rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ledger-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ledger-meta span {
  margin: 0;
}
.ledger-amount {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.ledger-amount.positive { color: var(--success); }
.ledger-amount.negative { color: var(--danger); }

/* ========== TOAST ========== */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--input-bar-h) + 16px);
  transform: translateX(-50%) translateY(12px);
  opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: var(--radius-md);
  background: rgba(25, 33, 31, 0.96); color: #fff;
  font-size: 0.85rem; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ========== MOBILE PARAM TOGGLE ========== */
.mobile-param-toggle {
  position: fixed;
  bottom: calc(var(--input-bar-h) + 12px); left: 16px;
  z-index: 9;
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text-secondary); font-size: 0.8rem;
  box-shadow: var(--shadow-sm);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  body {
    -webkit-tap-highlight-color: rgba(31, 122, 109, 0.14);
  }
  .brand-name { display: none; }
  .status-pill { display: none; }
  .status-pill.status-button {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
  }
  .topbar {
    gap: 8px;
    padding: 0 12px;
    overflow: hidden;
  }
  .topbar-left {
    min-width: 0;
    flex-shrink: 0;
    gap: 8px;
  }
  .topbar-right {
    min-width: 0;
    flex: 1;
    justify-content: flex-end;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .topbar-right::-webkit-scrollbar { display: none; }
  .brand {
    width: auto;
    min-width: 42px;
    height: 30px;
    padding: 0 7px;
    font-size: 0.72rem;
  }
  .brand-link,
  .mode-btn,
  .topbar-btn,
  .status-pill.status-button,
  .close-btn,
  .drawer-tab,
  .action-btn,
  .quick-edit-chip,
  .btn-primary,
  .btn-secondary,
  .btn-danger,
  .btn-text,
  .seg-btn,
  .ref-remove,
  .mobile-param-toggle {
    min-height: 48px;
  }
  .brand-link,
  .mode-btn,
  .topbar-btn,
  .status-pill.status-button,
  .action-btn,
  .quick-edit-chip,
  .btn-primary,
  .btn-secondary,
  .btn-danger,
  .btn-text,
  .seg-btn,
  .ref-remove,
  .mobile-param-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .close-btn {
    width: 48px;
    height: 48px;
  }
  .mode-btn { padding: 5px 13px; }
  #refresh-btn { display: none; }
  .topbar-btn { padding: 5px 9px; font-size: 0.75rem; white-space: nowrap; }
  button,
  a,
  label,
  input,
  textarea,
  select {
    touch-action: manipulation;
  }
  input:not([type="checkbox"]),
  textarea,
  select,
  .drawer-search input,
  .ref-url-input {
    font-size: 16px;
  }
  .login-options {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }
  .login-save-hint { white-space: normal; }

  .workspace { flex-direction: column; }
  .param-panel {
    position: fixed; top: auto; bottom: var(--input-bar-h); left: 0; right: 0;
    width: 100%; max-height: 55vh;
    border-left: none; border-top: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    z-index: 8;
  }
  .param-panel.open { transform: translateY(0); }
  .mobile-param-toggle { display: inline-flex !important; }
  .mobile-param-toggle {
    align-items: center;
    justify-content: center;
    max-width: calc(100vw - 24px);
    padding: 0 16px;
    font-weight: 700;
    color: var(--text);
  }
  .seg-row { gap: 8px; }
  .seg-row:not(.size-row) .seg-btn {
    flex: 1 1 calc(50% - 4px);
  }
  #tier-switch .seg-btn {
    flex-basis: 100%;
  }
  .seg-btn {
    padding: 0 12px;
    text-align: center;
  }
  .seg-btn-size {
    min-height: 82px;
    padding: 10px 11px;
  }
  .ref-drop { min-height: 128px; }
  .ref-card-meta {
    min-height: 48px;
    padding: 6px 8px;
  }
  .ref-remove {
    min-width: 48px;
    padding: 0 8px;
  }
  .btn-secondary.slim {
    min-height: 48px;
    padding: 0 12px;
  }
  .ref-pick-actions .btn-secondary {
    width: 100%;
  }

  .result-area { padding: 16px; }
  .workbench-intro {
    width: 100%;
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
  }
  .workbench-intro h1 {
    font-size: 1.05rem;
  }
  .workbench-flow {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    padding-top: 0;
  }
  .workbench-flow span {
    text-align: center;
    padding-inline: 4px;
  }
  .result-canvas { min-height: min(360px, 54vh); }
  .media-display, .media-display img, .media-display video {
    max-height: max(240px, calc(100vh - var(--topbar-h) - var(--input-bar-h) - 150px));
    max-height: max(240px, calc(100dvh - var(--topbar-h) - var(--input-bar-h) - 150px));
  }

  .input-bar {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }
  .input-form {
    max-width: none;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto auto auto auto;
    grid-template-rows: auto 48px;
    align-items: center;
    gap: 8px;
  }
  .upload-btn {
    grid-column: 1;
    grid-row: 1 / span 2;
    align-self: end;
    width: 48px;
    height: 48px;
  }
  .input-form textarea {
    grid-column: 2 / -1;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    min-height: 48px;
  }
  .char-count {
    position: static;
    grid-column: 2;
    grid-row: 2;
    justify-self: start;
    align-self: center;
    min-width: 2.2rem;
  }
  .price-badge {
    grid-column: 3;
    grid-row: 2;
    height: 48px;
    min-width: 68px;
    padding: 0 8px;
    font-size: 0.72rem;
  }
  .polish-btn {
    grid-column: 5;
    grid-row: 2;
    height: 48px;
    padding: 0 10px;
    font-size: 0.78rem;
  }
  .assistant-btn {
    grid-column: 4;
    grid-row: 2;
    height: 48px;
    padding: 0 10px;
    font-size: 0.78rem;
  }
  .gen-btn {
    grid-column: 6;
    grid-row: 2;
    height: 48px;
    padding: 0 18px;
  }
  .result-actions .action-btn,
  .detail-result-actions .action-btn {
    flex: 1 1 calc(50% - 4px);
  }
  .result-actions .primary-action,
  .detail-result-actions .primary-action {
    flex-basis: 100%;
  }
  .continue-edit-panel {
    align-items: stretch;
  }
  .continue-edit-panel .primary-action {
    width: 100%;
  }
  .quick-edit-chips {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .quick-edit-chip {
    width: 100%;
    padding: 0 10px;
  }

  .history-drawer { width: 100vw; }
  .settings-modal, .admin-edit-modal, .admin-audit-modal, .detail-modal, .prompt-assistant-modal, .polish-modal, .redeem-modal {
    width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
  }
  .prompt-assistant-modal[open] {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .prompt-assistant-modal .modal-header {
    flex: 0 0 auto;
  }
  .settings-form { padding: 0 14px 18px; }
  .polish-body { padding: 14px; }
  .polish-actions button { flex: 1 1 100%; }
  .assistant-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 14px;
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .assistant-profile-panel {
    order: -1;
  }
  .assistant-messages {
    min-height: 200px;
    max-height: 34vh;
  }
  .assistant-scenario-grid {
    grid-template-columns: 1fr;
  }
  .assistant-direction-grid {
    grid-template-columns: 1fr;
  }
  .assistant-composer {
    grid-template-columns: 1fr;
  }
  .assistant-composer button {
    width: 100%;
  }
  .assistant-profile-toggle {
    display: block;
  }
  .assistant-profile-row {
    grid-template-columns: 70px minmax(0, 1fr);
  }
  .assistant-actions {
    position: static;
    padding-top: 0;
    background: var(--surface);
  }
  .assistant-actions button {
    min-width: 100%;
  }
  .modal-header { padding: 14px; }
  .modal-hint { margin: 14px 14px 0; }
  .field-grid { grid-template-columns: 1fr; gap: 8px; }
  .detail-body { grid-template-columns: 1fr; padding: 14px; }
  .detail-media { min-height: 280px; }
  .detail-media img,
  .detail-media video { max-height: 48vh; }
  .detail-gallery { grid-template-columns: 1fr; max-height: 52vh; }
  .detail-result-footer { align-items: flex-start; flex-direction: column; }
  .detail-result-actions { justify-content: flex-start; }
  .admin-page {
    padding: calc(var(--topbar-h) + 12px) 12px 18px;
  }
  .admin-page-shell {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .admin-sidebar {
    position: static;
  }
  .admin-view-tabs {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  .admin-view-tabs::-webkit-scrollbar { display: none; }
  .admin-view-tab {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .admin-page-header {
    flex-direction: column;
    padding: 14px;
  }
  .admin-page-actions,
  .admin-page-actions button {
    width: 100%;
  }
  .admin-stats,
  .admin-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-stats-head {
    align-items: stretch;
    flex-direction: column;
  }
  .admin-range-tabs {
    width: 100%;
  }
  .admin-range-tabs button {
    flex: 1 1 0;
    min-width: 0;
    padding: 0 8px;
  }
  .admin-body { padding: 0; }
  .admin-create-user { grid-template-columns: 1fr; }
  .admin-toolbar { flex-direction: column; }
  .admin-toolbar select,
  .admin-toolbar input,
  .admin-toolbar button { width: 100%; }
  .admin-view-tabs { overflow-x: auto; }
  .admin-redemption-form { grid-template-columns: 1fr; }
  .redemption-row,
  .redemption-batch-row {
    align-items: flex-start;
    flex-direction: column;
  }
  .redemption-row .btn-danger,
  .redemption-batch-row .btn-danger { width: 100%; }
  .admin-list {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
  .admin-section {
    padding: 12px;
    border-radius: var(--radius-md);
  }
  .admin-users { grid-template-columns: 1fr; }
  .admin-job { grid-template-columns: 64px minmax(0, 1fr); }
  .admin-thumb { width: 64px; height: 64px; }
  .audit-row,
  .session-row,
  .funnel-row,
  .ip-row {
    grid-template-columns: 1fr;
    align-items: flex-start;
  }
  .ip-last { text-align: left; }
  .risk-score { text-align: left; }
  .segment-card-head,
  .segment-user-row {
    align-items: flex-start;
    flex-direction: column;
  }
  .segment-count,
  .segment-user-row small {
    text-align: left;
  }
  .ledger-row {
    grid-template-columns: 1fr;
    align-items: flex-start;
  }
  .ledger-amount {
    justify-self: start;
  }
}

@media (max-width: 768px) and (hover: none) and (pointer: coarse) {
  button:active,
  .upload-btn:active,
  .action-btn:active,
  .history-card:active,
  .ref-card:active {
    filter: brightness(0.96);
  }
}

@media (max-width: 600px) {
  .input-form {
    grid-template-columns: 48px minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto 48px 48px;
  }
  .upload-btn {
    grid-column: 1;
    grid-row: 1;
  }
  .input-form textarea {
    grid-column: 2 / 4;
    grid-row: 1;
  }
  .char-count { display: none; }
  .assistant-btn {
    grid-column: 1 / 3;
    grid-row: 2;
    min-width: 0;
  }
  .polish-btn {
    grid-column: 3;
    grid-row: 2;
    min-width: 0;
  }
  .price-badge {
    grid-column: 1;
    grid-row: 3;
    min-width: 0;
    padding: 0 6px;
  }
  .gen-btn {
    grid-column: 2 / 4;
    grid-row: 3;
    width: 100%;
  }
}

@media (max-width: 380px) {
  .topbar {
    padding: 0 8px;
    gap: 6px;
  }
  .topbar-left,
  .topbar-right { gap: 5px; }
  .brand {
    width: auto;
    min-width: 38px;
    height: 28px;
    padding: 0 6px;
    font-size: 0.68rem;
  }
  .mode-switch { padding: 2px; }
  .mode-btn { padding: 4px 9px; font-size: 0.78rem; }
  .status-pill.status-button { padding: 3px 7px; font-size: 0.7rem; }
  .topbar-btn { padding: 4px 7px; font-size: 0.7rem; }
  .topbar-btn-redeem { display: inline-flex; }
  .input-bar { padding-left: 8px; padding-right: 8px; }
  .input-form {
    grid-template-columns: 48px minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
  }
  .upload-btn { width: 48px; height: 48px; }
  .price-badge {
    padding: 0 6px;
  }
  .assistant-btn,
  .polish-btn {
    min-width: 0;
    padding: 0 6px;
    font-size: 0.74rem;
  }
  .gen-btn {
    padding: 0 14px;
  }
  .mobile-param-toggle {
    left: 10px;
    padding: 0 12px;
  }
}

@media (min-width: 769px) {
  .mobile-param-toggle { display: none !important; }
}

/* ========== FOCUS-VISIBLE ========== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none;
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }
    width: 48px;
    height: 48px;
  }
  .upload-btn {
    width: 48px;
    height: 48px;
  }
