/* ═══════════════════════════════════════
   UMIMG — Premium Sidebar Layout
   Senior Developer Crafted
   ═══════════════════════════════════════ */

/* ── Root Variables ── */
:root {
  /* Sidebar — 蓝白配色 */
  --sidebar-width: 270px;
  --sidebar-collapsed-width: 0px;
  --sidebar-bg: #ffffff;
  --sidebar-surface: #f8fafc;
  --sidebar-text: #64748b;
  --sidebar-text-hover: #2563eb;
  --sidebar-text-active: #1d4ed8;
  --sidebar-accent: #2563eb;
  --sidebar-accent-glow: rgba(37, 99, 235, 0.2);
  --sidebar-accent-soft: rgba(37, 99, 235, 0.08);
  --sidebar-border: rgba(0, 0, 0, 0.06);
  --sidebar-divider: rgba(0, 0, 0, 0.06);

  /* Main Area */
  --main-bg: #f0f7ff;
  --main-surface: #ffffff;
  --main-surface-soft: #f8fafc;

  /* Text */
  --text: #1e293b;
  --text-soft: #475569;
  --text-muted: #94a3b8;

  /* UI Colors — 蓝白绿 */
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #10b981;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #ef4444;
  --danger-soft: #fef2f2;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.08);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.12);

  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  /* Transitions */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --duration: 0.25s;
}

/* ── Base Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--main-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

body.has-dialog,
body.is-generating {
  overflow: hidden;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--duration) var(--ease-out);
}

a:hover {
  color: var(--primary-dark);
}

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

button {
  border: 0;
  background: none;
}

button:not(:disabled) {
  cursor: pointer;
}

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

.hidden {
  display: none !important;
}

/* ═══════════════════════════════════════
   LAYOUT — Sidebar + Main Area
   ═══════════════════════════════════════ */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  box-shadow: 1px 0 8px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  transition: transform var(--duration) var(--ease);
}

/* ── Sidebar Header ── */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  min-height: 72px;
  border-bottom: 1px solid var(--sidebar-divider);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}

.sidebar-brand:hover {
  color: var(--sidebar-text-hover);
}

.sidebar-logo {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #60a5fa 0%, #2563eb 52%, #1d4ed8 100%);
  flex-shrink: 0;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.3);
}

.sidebar-logo svg {
  width: 26px;
  height: 26px;
  display: block;
}

.sidebar-logo .icon-frame,
.sidebar-logo .icon-line,
.sidebar-logo .icon-dot {
  fill: none;
  stroke: #ffffff;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-logo .ai-spark {
  fill: #93c5fd;
  stroke: #ffffff;
  stroke-width: 0.6;
}

.sidebar-logo .ai-spark.small {
  fill: #ffffff;
  stroke: none;
  opacity: 0.9;
}

.sidebar-brand-text {
  min-width: 0;
}

.sidebar-brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-brand-text small {
  display: block;
  margin-top: 1px;
  color: var(--sidebar-text);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ── Sidebar Navigation ── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
}

.sidebar-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--duration) var(--ease-out);
  cursor: pointer;
  overflow: hidden;
}

.sidebar-nav-item::before {
  content: '';
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--sidebar-accent);
  box-shadow: 0 0 12px var(--sidebar-accent-glow);
  transition: transform 0.2s var(--ease-out);
}

.sidebar-nav-item:hover {
  color: var(--sidebar-text-hover);
  background: var(--sidebar-accent-soft);
}

.sidebar-nav-item:active {
  transform: scale(0.98);
}

.sidebar-nav-item.active {
  color: var(--sidebar-text-active);
  background: var(--sidebar-accent-soft);
}

.sidebar-nav-item.active::before {
  transform: translateY(-50%) scaleY(1);
}

.sidebar-nav-item .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.sidebar-nav-item .nav-icon svg {
  width: 20px;
  height: 20px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-nav-item .nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-nav-item .nav-badge {
  min-width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0 6px;
  background: var(--sidebar-accent);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

/* Nav section label */
.sidebar-nav-section {
  padding: 16px 14px 6px;
  color: rgba(0, 0, 0, 0.25);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ── Sidebar Footer / User Section ── */
.sidebar-footer {
  border-top: 1px solid var(--sidebar-divider);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  text-decoration: none;
  transition: all var(--duration) var(--ease-out);
}

.sidebar-user:hover {
  color: var(--sidebar-text-hover);
  background: var(--sidebar-accent-soft);
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #60a5fa 0%, #2563eb 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-info strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-info span {
  display: block;
  color: var(--sidebar-text);
  font-size: 12px;
  font-weight: 500;
  margin-top: 1px;
}

/* Sidebar balance & actions */
.sidebar-balance {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 600;
}

.sidebar-balance strong {
  color: var(--sidebar-accent);
  font-weight: 800;
}

.sidebar-actions {
  display: flex;
  gap: 4px;
  padding: 0 10px 4px;
}

.sidebar-action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  border-radius: var(--radius-sm);
  padding: 0 10px;
  color: var(--sidebar-text);
  font-size: 12px;
  font-weight: 700;
  transition: all var(--duration) var(--ease-out);
}

.sidebar-action-btn:hover {
  color: var(--sidebar-text-hover);
  background: var(--sidebar-accent-soft);
}

.sidebar-action-btn.primary {
  color: var(--sidebar-accent);
  background: var(--sidebar-accent-soft);
}

.sidebar-action-btn.primary:hover {
  background: var(--sidebar-accent-glow);
}

.sidebar-action-btn .action-icon {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
}

.sidebar-action-btn .action-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Sidebar Toggle (mobile) ── */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--main-surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  align-items: center;
  justify-content: center;
  color: var(--text);
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
}

.sidebar-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--duration) var(--ease-out);
  pointer-events: none;
}

body.sidebar-open .sidebar-overlay {
  opacity: 1;
  pointer-events: auto;
}

/* ═══════════════════════════════════════
   MAIN CONTENT AREA
   ═══════════════════════════════════════ */

.main-area {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  padding: 28px 32px;
  background:
    radial-gradient(ellipse at 0% 0%, rgba(37, 99, 235, 0.04) 0%, transparent 50%),
    var(--main-bg);
  transition: margin-left var(--duration) var(--ease);
}

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

.main-area-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}

.main-area-header .eyebrow {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.main-area-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ═══════════════════════════════════════
   CARD COMPONENTS
   ═══════════════════════════════════════ */

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--main-surface);
  box-shadow: var(--shadow);
  padding: 24px;
  transition: box-shadow var(--duration) var(--ease-out);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card.section-card {
  margin-top: 20px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 44px;
  margin-bottom: 20px;
}

.card-head > div {
  min-width: 0;
}

.card-head .eyebrow {
  margin: 0 0 3px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 750;
  color: var(--text);
  letter-spacing: -0.01em;
}

.card-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════
   GRID LAYOUTS
   ═══════════════════════════════════════ */

.grid {
  display: grid;
  gap: 20px;
}

.two-col {
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
}

.narrow-left {
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
}

/* ═══════════════════════════════════════
   FORM ELEMENTS
   ═══════════════════════════════════════ */

.form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
}

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

.field-hint {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

input,
select,
textarea {
  width: 100%;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  outline: none;
  background: var(--main-surface);
  color: var(--text);
  transition: border-color var(--duration) var(--ease-out), box-shadow var(--duration) var(--ease-out), background var(--duration) var(--ease-out);
}

input:hover,
select:hover,
textarea:hover {
  border-color: #93c5fd;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  background: var(--main-surface);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

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

textarea {
  min-height: 130px;
  padding: 10px 12px;
  resize: vertical;
}

input[readonly] {
  background: var(--main-surface-soft);
  color: var(--text-muted);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%234b5563' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ═══════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════ */

.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  padding: 0 16px;
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  text-align: center;
  text-decoration: none;
  transition: all var(--duration) var(--ease-out);
  gap: 6px;
  white-space: nowrap;
}

.button.primary {
  background: linear-gradient(135deg, #60a5fa 0%, var(--primary) 100%);
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
}

.button.primary:hover {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.3);
  transform: translateY(-1px);
}

.button.primary:active {
  transform: translateY(0);
}

.button.secondary {
  border-color: var(--line);
  background: var(--main-surface);
  color: var(--text-soft);
}

.button.secondary:hover {
  border-color: #93c5fd;
  background: var(--primary-soft);
  color: var(--primary);
}

.button.secondary.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.button.secondary.disabled {
  pointer-events: none;
  opacity: 0.4;
}

.button.danger {
  border-color: #fecaca;
  background: var(--main-surface);
  color: var(--danger);
}

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

.button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

/* ═══════════════════════════════════════
   BADGES & STATUS
   ═══════════════════════════════════════ */

.badge,
.status {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--main-surface-soft);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
  border: 1px solid transparent;
}

.status.succeeded,
.alert.success,
.inline-message.success {
  background: var(--success-soft);
  color: #166534;
  border-color: #bbf7d0;
}

.status.failed,
.alert.error,
.inline-message.error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #fecaca;
}

.status.running,
.status.queued,
.alert.warning,
.inline-message.warning {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: #fed7aa;
}

.status.deleted {
  background: #f2f4f7;
  color: var(--text-muted);
  border-color: var(--line-strong);
}

/* ═══════════════════════════════════════
   ALERTS & MESSAGES
   ═══════════════════════════════════════ */

.alert,
.inline-message {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--main-surface);
  color: var(--text-soft);
  font-weight: 650;
}

.inline-message {
  margin: 16px 0 0;
}

.generation-notice {
  margin-bottom: 16px;
  border: 1px solid #f6d58b;
  border-radius: var(--radius);
  padding: 11px 14px;
  background: #fff8e6;
  color: #9a6700;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
}

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

/* ═══════════════════════════════════════
   MODE TOGGLE
   ═══════════════════════════════════════ */

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mode-toggle label {
  min-height: 40px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--main-surface);
  color: var(--text-soft);
  font-weight: 750;
  font-size: 14px;
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
}

.mode-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-toggle label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

/* ═══════════════════════════════════════
   EDIT UPLOAD
   ═══════════════════════════════════════ */

.edit-upload-box {
  position: relative;
  min-height: 88px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--main-surface-soft);
  transition: all var(--duration) var(--ease-out);
}

.edit-upload-box:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.edit-upload-box input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.edit-upload-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.edit-upload-box strong {
  display: block;
  color: var(--text);
  font-size: 14px;
  font-weight: 750;
}

.edit-upload-box small {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.edit-upload-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.edit-preview-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--main-surface-soft);
}

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

.edit-preview-item button {
  position: absolute;
  right: 4px;
  bottom: 4px;
  border: 0;
  border-radius: 4px;
  padding: 3px 6px;
  background: rgba(17, 24, 39, 0.75);
  color: #fff;
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
}

/* ═══════════════════════════════════════
   GENERATE ACTIONS
   ═══════════════════════════════════════ */

.generate-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 4px;
}

/* ═══════════════════════════════════════
   PREVIEW STAGE
   ═══════════════════════════════════════ */

.preview-card {
  display: grid;
  grid-template-rows: auto minmax(380px, 1fr);
}

.preview-stage {
  min-height: 380px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(45deg, rgba(208, 213, 221, 0.3) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(208, 213, 221, 0.3) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(208, 213, 221, 0.3) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(208, 213, 221, 0.3) 75%),
    #fafbfc;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.preview-stage img {
  width: 100%;
  height: 100%;
  max-height: 600px;
  object-fit: contain;
  background: #fff;
}

.empty-state,
.preview-loading {
  width: min(220px, 90%);
  min-height: 110px;
  display: grid;
  place-items: center;
  gap: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 18px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--text-muted);
  text-align: center;
  font-weight: 700;
}

.preview-loading span {
  font-size: 13px;
  font-weight: 600;
}

.preview-error {
  width: min(340px, 92%);
  min-height: 120px;
  display: grid;
  place-items: center;
  gap: 8px;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 18px;
  background: var(--danger-soft);
  color: var(--danger);
  text-align: center;
  font-weight: 700;
}

.preview-error span {
  color: #991b1b;
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.preview-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 999px;
  animation: spin 0.7s linear infinite;
}

/* ═══════════════════════════════════════
   HISTORY / RECORDS
   ═══════════════════════════════════════ */

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.history-list .record-card {
  height: auto;
  min-height: 220px;
  display: grid;
  grid-template-rows: 120px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  background: var(--main-surface);
  color: inherit;
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: all var(--duration) var(--ease-out);
}

.history-list .record-card:hover {
  border-color: #93c5fd;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.history-list .record-card:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.3);
  outline-offset: 2px;
}

.record-image {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(135deg, #eff6ff, #f8fafc);
  color: var(--text-muted);
  font-weight: 750;
}

.record-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.record-body {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 10px 12px;
}

.record-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 750;
}

.record-meta span:first-child {
  color: var(--primary);
}

.record-body p {
  max-height: 38px;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.record-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}

.record-body time {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-delete {
  min-height: 26px;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 0 8px;
  background: var(--main-surface);
  color: var(--danger);
  font-size: 11px;
  font-weight: 800;
  transition: all var(--duration) var(--ease-out);
}

.record-delete:hover {
  background: var(--danger-soft);
}

.history-empty-inline {
  grid-column: 1 / -1;
  min-height: 80px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  background: var(--main-surface-soft);
  font-weight: 700;
}

.records-page-card {
  margin-top: 0;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

.pagination span {
  color: var(--text-muted);
  font-weight: 650;
  font-size: 13px;
}

/* ═══════════════════════════════════════
   ADMIN
   ═══════════════════════════════════════ */

.admin-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
  padding: 8px;
  background: var(--main-surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--main-surface);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
}

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

.stat-card strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 28px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 760px;
  table-layout: fixed;
  border-collapse: collapse;
  background: var(--main-surface);
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

th {
  background: var(--main-surface-soft);
  color: var(--text-muted);
  font-weight: 800;
  font-size: 12px;
  white-space: nowrap;
}

tr.is-deleted td {
  background: #fafafa;
  color: var(--text-muted);
}

.table-thumb {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--main-surface-soft);
  color: var(--text-muted);
  padding: 0;
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
}

.table-thumb:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.table-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.inline-delete-form {
  display: inline-flex;
  margin: 0 0 0 6px;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(140px, 180px) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
}

.filter-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

.admin-prompt-cell {
  color: var(--text-soft);
  max-width: 340px;
}

.admin-record-row td {
  vertical-align: middle;
}

.admin-user-cell {
  max-width: 120px;
  font-weight: 750;
}

.admin-record-id {
  margin-right: 6px;
  color: var(--text);
  font-weight: 850;
}

.deleted-time {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.inline-admin-form,
.table-action-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0;
  vertical-align: middle;
}

.compact-input {
  width: 76px;
  height: 32px;
  border-radius: var(--radius-sm);
  padding: 0 8px;
  font-size: 12px;
}

.compact-input.password-input {
  width: 120px;
}

.user-identity {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.user-identity strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.user-identity > span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

/* ── Admin Data Table Column Widths ── */
[data-admin-records] {
  min-width: 1180px;
}
[data-admin-records] th:nth-child(1),
[data-admin-records] td:nth-child(1) { width: 110px; }
[data-admin-records] th:nth-child(2),
[data-admin-records] td:nth-child(2) { width: 92px; }
[data-admin-records] th:nth-child(3),
[data-admin-records] td:nth-child(3) { width: 130px; }
[data-admin-records] th:nth-child(4),
[data-admin-records] td:nth-child(4) { width: 88px; }
[data-admin-records] th:nth-child(5),
[data-admin-records] td:nth-child(5) { width: 92px; }
[data-admin-records] th:nth-child(7),
[data-admin-records] td:nth-child(7) { width: 176px; }
[data-admin-records] th:nth-child(8),
[data-admin-records] td:nth-child(8) { width: 150px; }

[data-admin-users] {
  min-width: 1080px;
}
[data-admin-users] th:nth-child(1),
[data-admin-users] td:nth-child(1) { width: 260px; }
[data-admin-users] th:nth-child(2),
[data-admin-users] td:nth-child(2) { width: 190px; }
[data-admin-users] th:nth-child(3),
[data-admin-users] td:nth-child(3),
[data-admin-users] th:nth-child(4),
[data-admin-users] td:nth-child(4),
[data-admin-users] th:nth-child(5),
[data-admin-users] td:nth-child(5) { width: 96px; }
[data-admin-users] th:nth-child(6),
[data-admin-users] td:nth-child(6) { width: 340px; }

[data-admin-codes] {
  min-width: 980px;
}
[data-admin-codes] th:nth-child(1),
[data-admin-codes] td:nth-child(1) { width: 190px; }
[data-admin-codes] th:nth-child(2),
[data-admin-codes] td:nth-child(2),
[data-admin-codes] th:nth-child(3),
[data-admin-codes] td:nth-child(3),
[data-admin-codes] th:nth-child(4),
[data-admin-codes] td:nth-child(4),
[data-admin-codes] th:nth-child(5),
[data-admin-codes] td:nth-child(5) { width: 96px; }
[data-admin-codes] th:nth-child(6),
[data-admin-codes] td:nth-child(6),
[data-admin-codes] th:nth-child(8),
[data-admin-codes] td:nth-child(8) { width: 170px; }
[data-admin-codes] th:nth-child(7),
[data-admin-codes] td:nth-child(7) { width: 120px; }

[data-shop-orders] {
  min-width: 780px;
}
[data-shop-orders] th:nth-child(1),
[data-shop-orders] td:nth-child(1) { width: 190px; }
[data-shop-orders] th:nth-child(2),
[data-shop-orders] td:nth-child(2) { width: 130px; }

/* ═══════════════════════════════════════
   DIALOGS / OVERLAYS
   ═══════════════════════════════════════ */

.redeem-dialog,
.record-dialog,
.generation-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(8px);
}

.generation-overlay {
  z-index: 10002;
  pointer-events: auto;
}

.redeem-panel,
.record-dialog-panel,
.generation-modal {
  width: min(420px, 100%);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-lg);
  background: var(--main-surface);
  box-shadow: var(--shadow-xl);
}

.record-dialog-panel {
  width: min(880px, 100%);
  max-height: min(820px, calc(100vh - 40px));
  overflow: auto;
}

.generation-modal {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 28px 24px;
  text-align: center;
}

.generation-modal h2 {
  font-size: 20px;
  font-weight: 800;
}

.generation-modal p {
  margin: 0;
  color: var(--text-muted);
  font-weight: 650;
}

.generation-loader {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  height: 40px;
}

.generation-loader span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--primary);
  animation: pulse 0.9s ease-in-out infinite;
}

.generation-loader span:nth-child(2) {
  animation-delay: 0.12s;
}
.generation-loader span:nth-child(3) {
  animation-delay: 0.24s;
}

.generation-progress {
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--primary-soft);
}

.generation-progress i {
  width: 40%;
  height: 100%;
  display: block;
  border-radius: inherit;
  background: linear-gradient(90deg, #60a5fa, var(--primary));
  animation: progress 1.3s ease-in-out infinite;
}

.redeem-head,
.record-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 16px 20px;
  background: var(--main-surface);
}

.record-dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
}

.redeem-form {
  padding: 20px;
}

.dialog-close {
  min-width: 64px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--main-surface);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
  transition: all var(--duration) var(--ease-out);
}

.dialog-close:hover {
  border-color: #93c5fd;
  background: var(--primary-soft);
  color: var(--primary);
}

.record-dialog-body {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.record-dialog-image {
  min-height: 380px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, #eff6ff, var(--main-surface-soft));
  color: var(--text-muted);
  font-weight: 750;
}

.record-dialog-image-button {
  width: 100%;
  height: 100%;
  min-height: inherit;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  background: transparent;
}

.record-dialog-image-button img,
.record-dialog-image img {
  width: 100%;
  height: 100%;
  max-height: 600px;
  object-fit: contain;
  background: #fff;
}

.record-input-images {
  display: grid;
  gap: 8px;
}

.record-input-images > span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.record-input-images [data-dialog-input-list] {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}

.record-input-image-button {
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--main-surface-soft);
  padding: 0;
  cursor: zoom-in;
}

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

.record-detail-grid {
  display: grid;
  grid-template-columns: minmax(100px, 0.6fr) minmax(160px, 1fr) minmax(100px, 0.6fr) minmax(320px, 2fr);
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.record-detail-grid div {
  min-height: 56px;
  display: grid;
  align-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--main-surface-soft);
}

.record-detail-grid span {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
}

.record-detail-grid strong {
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 13px;
}

.record-full-prompt {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--main-surface-soft);
}

.record-full-prompt span {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
}

.record-full-prompt p {
  max-height: 120px;
  overflow: auto;
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.6;
}

.record-error {
  grid-column: 1 / -1;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--danger-soft);
  color: var(--danger);
}

/* ── Image Viewer ── */
.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 10020;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(4px);
}

.image-viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.image-viewer-toolbar button,
.image-viewer-toolbar span {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius);
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  transition: background var(--duration) var(--ease-out);
}

.image-viewer-toolbar button:hover {
  background: rgba(255, 255, 255, 0.15);
}

.image-viewer-toolbar span {
  min-width: 60px;
}

.image-viewer-stage {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.4);
  cursor: grab;
}

.image-viewer-canvas {
  min-width: 100%;
  min-height: 100%;
  display: grid;
  place-items: center;
}

.image-viewer-stage.is-dragging {
  cursor: grabbing;
}

.image-viewer-stage img {
  display: block;
  max-width: none;
  max-height: none;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  user-select: none;
}

/* ═══════════════════════════════════════
   AUTH PAGES (no sidebar)
   ═══════════════════════════════════════ */

.page-auth .app-layout {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(37, 99, 235, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(37, 99, 235, 0.04) 0%, transparent 50%),
    var(--main-bg);
}

.page-auth .main-area {
  flex: 0 1 auto;
  width: auto;
  min-width: 0;
  margin-left: 0;
  padding: 0;
  background: none;
  min-height: auto;
}

.page-auth .main-area > .server-flash + .server-flash {
  /* stacked flashes handling */
}

.center-auth-page {
  width: 100%;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.center-auth-panel {
  width: min(420px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--main-surface);
  box-shadow: var(--shadow-lg);
}

.center-auth-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.center-auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

.center-auth-brand:hover {
  color: var(--text);
}

.center-auth-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #60a5fa 0%, #2563eb 52%, #1d4ed8 100%);
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.25);
}

.center-auth-mark svg {
  width: 24px;
  height: 24px;
  display: block;
}

.center-auth-mark .icon-frame,
.center-auth-mark .icon-line,
.center-auth-mark .icon-dot {
  fill: none;
  stroke: #ffffff;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ═══════════════════════════════════════
   JPT LAYER — Modal Dialogs & Toasts
   Added by Senior Developer
   ═══════════════════════════════════════ */

/* ── Toast Root ── */
.jpt-layer-root {
  position: fixed;
  inset: 0;
  z-index: 20000;
  pointer-events: none;
}

/* ── Toast Stack (top-right) ── */
.jpt-toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 20001;
  display: grid;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
  pointer-events: auto;
}

/* ── Toast Item ── */
.jpt-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  background: var(--main-surface);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 650;
  color: var(--text);
  animation: jpt-slide-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
}

.jpt-toast.is-leaving {
  animation: jpt-slide-out 0.18s cubic-bezier(0.4, 0, 1, 1) forwards;
}

.jpt-toast.success {
  border-color: #bbf7d0;
  background: var(--success-soft);
  color: #166534;
}

.jpt-toast.error {
  border-color: #fecaca;
  background: var(--danger-soft);
  color: var(--danger);
}

.jpt-toast.warning {
  border-color: #fed7aa;
  background: var(--warning-soft);
  color: var(--warning);
}

.jpt-toast.info {
  border-color: #bfdbfe;
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.jpt-toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.jpt-toast.success .jpt-toast-icon {
  background: #bbf7d0;
  color: #166534;
}

.jpt-toast.error .jpt-toast-icon {
  background: #fecaca;
  color: var(--danger);
}

.jpt-toast.warning .jpt-toast-icon {
  background: #fed7aa;
  color: var(--warning);
}

.jpt-toast.info .jpt-toast-icon {
  background: #bfdbfe;
  color: var(--primary-dark);
}

/* ── Modal Overlay ── */
.jpt-layer-overlay {
  position: fixed;
  inset: 0;
  z-index: 19999;
  display: grid;
  place-items: center;
  padding: 20px;
}

.jpt-layer-overlay.is-leaving {
  animation: jpt-fade-out 0.18s ease-in forwards;
}

/* ── Modal Panel ── */
.jpt-layer-panel {
  width: min(400px, calc(100vw - 40px));
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-lg);
  background: var(--main-surface);
  box-shadow: var(--shadow-xl);
  animation: jpt-scale-in 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

.jpt-layer-overlay.is-leaving .jpt-layer-panel {
  animation: jpt-scale-out 0.15s ease-in forwards;
}

/* ── Modal Header ── */
.jpt-layer-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 22px 16px;
}

.jpt-layer-icon {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.jpt-layer-panel.warning .jpt-layer-icon {
  background: var(--warning-soft);
  color: var(--warning);
}

.jpt-layer-panel.error .jpt-layer-icon {
  background: var(--danger-soft);
  color: var(--danger);
}

.jpt-layer-panel.info .jpt-layer-icon {
  background: var(--primary-soft);
  color: var(--primary);
}

.jpt-layer-panel.success .jpt-layer-icon {
  background: var(--success-soft);
  color: var(--success);
}

.jpt-layer-head > div {
  flex: 1;
  min-width: 0;
}

.jpt-layer-head h2 {
  margin: 0 0 4px;
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
}

.jpt-layer-head p {
  margin: 0;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.5;
  font-weight: 600;
}

/* ── Modal Actions ── */
.jpt-layer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 22px 20px;
}

.jpt-layer-actions .button {
  min-width: 80px;
}

/* ── Animations ── */
@keyframes jpt-slide-in {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes jpt-slide-out {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

@keyframes jpt-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes jpt-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes jpt-scale-in {
  from {
    transform: scale(0.92);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes jpt-scale-out {
  from {
    transform: scale(1);
    opacity: 1;
  }
  to {
    transform: scale(0.92);
    opacity: 0;
  }
}

.center-auth-mark .ai-spark {
  fill: #93c5fd;
  stroke: #ffffff;
  stroke-width: 0.6;
}

.center-auth-mark .ai-spark.small {
  fill: #ffffff;
  stroke: none;
  opacity: 0.9;
}

.center-auth-brand strong {
  display: block;
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}

.center-auth-brand small {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 1px;
}

.center-auth-tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--main-surface-soft);
  border-radius: var(--radius);
}

.center-auth-tabs a {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: 6px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: all var(--duration) var(--ease-out);
}

.center-auth-tabs a.active {
  background: var(--main-surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.center-auth-body {
  padding: 24px;
}

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

.center-auth-field {
  display: grid;
  gap: 6px;
}

.center-auth-field span {
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
}

.center-auth-field input {
  height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--main-surface);
  outline: none;
  transition: all var(--duration) var(--ease-out);
}

.center-auth-field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.center-auth-submit {
  width: 100%;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius);
  padding: 0 16px;
  background: linear-gradient(135deg, #60a5fa 0%, var(--primary) 100%);
  color: #fff;
  font-size: 15px;
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
  transition: all var(--duration) var(--ease-out);
}

.center-auth-submit:hover {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.3);
  transform: translateY(-1px);
}

.auth-wrap {
  min-height: 62vh;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(440px, 100%);
}

.auth-card.wide {
  width: min(640px, 100%);
}

.auth-card-head {
  margin-bottom: 20px;
}

.auth-card-head h2 {
  margin-bottom: 6px;
  font-size: 22px;
}

.auth-card-head span {
  color: var(--text-muted);
  font-weight: 650;
  font-size: 13px;
}

.auth-switch {
  margin: 16px 0 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}

.auth-switch a {
  font-weight: 700;
}

/* ═══════════════════════════════════════
   USER CENTER
   ═══════════════════════════════════════ */

.uc-info {
  display: grid;
  gap: 0;
}

.uc-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.uc-info-row:last-child {
  border-bottom: 0;
}

.uc-info-row span {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

.uc-info-row strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 750;
}

.uc-section {
  margin-top: 20px;
}

.uc-section h3 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}

.uc-step {
  margin-top: 14px;
}

.uc-divider {
  margin: 20px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

/* ═══════════════════════════════════════
   SHOP
   ═══════════════════════════════════════ */

.shop-header-card {
  margin-top: 0;
}

.package-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.package-card {
  position: relative;
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--main-surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: all var(--duration) var(--ease-out);
}

.package-card:hover {
  border-color: #93c5fd;
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
}

.package-card.popular {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12), var(--shadow-md);
}

.package-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #60a5fa, var(--primary));
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  z-index: 2;
}

.package-body {
  display: grid;
  gap: 16px;
  padding: 24px 22px;
}

.package-head {
  display: grid;
  gap: 6px;
}

.package-head h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 850;
  color: var(--text);
}

.package-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.package-price {
  margin: 4px 0;
}

.price-amount {
  font-size: 30px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.02em;
}

.package-credits {
  display: flex;
  align-items: center;
  gap: 6px;
}

.package-credits strong {
  font-size: 26px;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.package-credits span {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
}

.package-card .button {
  width: 100%;
  min-height: 42px;
  margin-top: 4px;
  font-size: 15px;
}

/* Buy Dialog */
.buy-summary {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.buy-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding: 0 4px;
}

.buy-summary-row span {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
}

.buy-summary-row strong {
  color: var(--text);
  font-size: 15px;
}

.buy-summary-row.total {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.buy-summary-row.total strong {
  font-size: 20px;
  color: var(--danger);
  font-weight: 900;
}

.pay-type-select {
  display: grid;
  gap: 8px;
  margin-bottom: 4px;
}

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

.pay-type-item {
  min-height: 40px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--main-surface);
  color: var(--text-soft);
  font-weight: 700;
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
}

.pay-type-item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pay-type-item:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

/* ── Toast Layer ── */
.jpt-layer-root {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 99999;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.jpt-toast-stack {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.jpt-toast {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--main-surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  animation: toastIn 0.3s var(--ease-out);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.jpt-toast.is-leaving {
  opacity: 0;
  transform: translateY(-8px) scale(0.96);
}

.jpt-toast.success { color: #166534; border-color: #bbf7d0; background: #f0fdf4; }
.jpt-toast.error   { color: var(--danger); border-color: #fecaca; background: #fef2f2; }
.jpt-toast.warning { color: var(--warning); border-color: #fed7aa; background: #fffbeb; }
.jpt-toast.info    { color: var(--text); border-color: var(--line); background: var(--main-surface); }

.jpt-toast-icon::before {
  content: '';
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 999px;
}

.jpt-toast.success .jpt-toast-icon::before { background: var(--success); }
.jpt-toast.error .jpt-toast-icon::before   { background: var(--danger); }
.jpt-toast.warning .jpt-toast-icon::before { background: var(--warning); }
.jpt-toast.info .jpt-toast-icon::before    { background: var(--text-muted); }

/* Modal overlay */
.jpt-layer-overlay {
  position: fixed;
  inset: 0;
  z-index: 99998;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease;
}

.jpt-layer-overlay.is-leaving {
  opacity: 0;
  transition: opacity 0.18s ease;
}

.jpt-layer-panel {
  width: min(380px, 100%);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-lg);
  background: var(--main-surface);
  box-shadow: var(--shadow-xl);
  animation: scaleIn 0.25s var(--ease-out);
}

.jpt-layer-panel.is-leaving {
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.jpt-layer-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 22px;
}

.jpt-layer-icon {
  flex-shrink: 0;
}

.jpt-layer-icon::before {
  content: '';
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 999px;
}

.jpt-layer-panel.success .jpt-layer-icon::before { background: var(--success-soft); border: 1px solid #bbf7d0; }
.jpt-layer-panel.error .jpt-layer-icon::before   { background: var(--danger-soft); border: 1px solid #fecaca; }
.jpt-layer-panel.warning .jpt-layer-icon::before { background: var(--warning-soft); border: 1px solid #fed7aa; }
.jpt-layer-panel.info .jpt-layer-icon::before    { background: var(--main-surface-soft); border: 1px solid var(--line); }

.jpt-layer-head h2 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}

.jpt-layer-head p {
  margin: 0;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.5;
}

.jpt-layer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 22px 20px;
}

/* ═══════════════════════════════════════
   SERVER FLASH
   ═══════════════════════════════════════ */

.server-flash.hidden {
  display: none;
}

/* ═══════════════════════════════════════
   PAGE NOTICE
   ═══════════════════════════════════════ */

.page-notice-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(8px);
}

.page-notice-panel {
  width: min(480px, 100%);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-lg);
  background: var(--main-surface);
  box-shadow: var(--shadow-xl);
}

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

.page-notice-head strong {
  font-size: 16px;
  font-weight: 800;
}

.page-notice-body {
  padding: 20px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

/* ═══════════════════════════════════════
   SETUP PAGE
   ═══════════════════════════════════════ */

.setup-card {
  width: min(880px, 100%);
  margin: 0 auto;
}

.setup-form {
  gap: 20px;
}

.setup-section {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--main-surface-soft);
}

.setup-section h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}

/* ── Code Create ── */
.code-create-card .card-head {
  margin-bottom: 14px;
}

.code-create-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 12px;
}

.code-create-form .button {
  min-width: 88px;
}

/* ── Misc ── */
.user-identity {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.user-identity strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.user-identity > span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
}

.inline-admin-form,
.table-action-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0;
  vertical-align: middle;
}

.compact-input {
  width: 76px;
  height: 32px;
  border-radius: var(--radius-sm);
  padding: 0 8px;
  font-size: 12px;
}

.compact-input.password-input {
  width: 120px;
}

/* ── Admin Data Table Column Widths ── */
[data-admin-records] {
  min-width: 1180px;
}

[data-admin-records] th:nth-child(1),
[data-admin-records] td:nth-child(1) {
  width: 110px;
}

[data-admin-records] th:nth-child(2),
[data-admin-records] td:nth-child(2) {
  width: 92px;
}

[data-admin-records] th:nth-child(3),
[data-admin-records] td:nth-child(3) {
  width: 130px;
}

[data-admin-records] th:nth-child(4),
[data-admin-records] td:nth-child(4) {
  width: 88px;
}

[data-admin-records] th:nth-child(5),
[data-admin-records] td:nth-child(5) {
  width: 92px;
}

[data-admin-records] th:nth-child(7),
[data-admin-records] td:nth-child(7) {
  width: 176px;
}

[data-admin-records] th:nth-child(8),
[data-admin-records] td:nth-child(8) {
  width: 150px;
}

[data-admin-users] {
  min-width: 1080px;
}

[data-admin-users] th:nth-child(1),
[data-admin-users] td:nth-child(1) {
  width: 260px;
}

[data-admin-users] th:nth-child(2),
[data-admin-users] td:nth-child(2) {
  width: 190px;
}

[data-admin-users] th:nth-child(3),
[data-admin-users] td:nth-child(3),
[data-admin-users] th:nth-child(4),
[data-admin-users] td:nth-child(4),
[data-admin-users] th:nth-child(5),
[data-admin-users] td:nth-child(5) {
  width: 96px;
}

[data-admin-users] th:nth-child(6),
[data-admin-users] td:nth-child(6) {
  width: 340px;
}

[data-admin-codes] {
  min-width: 980px;
}

[data-admin-codes] th:nth-child(1),
[data-admin-codes] td:nth-child(1) {
  width: 190px;
}

[data-admin-codes] th:nth-child(2),
[data-admin-codes] td:nth-child(2),
[data-admin-codes] th:nth-child(3),
[data-admin-codes] td:nth-child(3),
[data-admin-codes] th:nth-child(4),
[data-admin-codes] td:nth-child(4),
[data-admin-codes] th:nth-child(5),
[data-admin-codes] td:nth-child(5) {
  width: 96px;
}

[data-admin-codes] th:nth-child(6),
[data-admin-codes] td:nth-child(6),
[data-admin-codes] th:nth-child(8),
[data-admin-codes] td:nth-child(8) {
  width: 170px;
}

[data-admin-codes] th:nth-child(7),
[data-admin-codes] td:nth-child(7) {
  width: 120px;
}

[data-shop-orders] {
  min-width: 780px;
}

[data-shop-orders] th:nth-child(1),
[data-shop-orders] td:nth-child(1) {
  width: 190px;
}

[data-shop-orders] th:nth-child(2),
[data-shop-orders] td:nth-child(2) {
  width: 130px;
}

.deleted-time {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

/* ── Admin Version Footer ── */
.admin-version-footer {
  position: fixed;
  right: 24px;
  bottom: 16px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

/* ═══════════════════════════════════════
   SCROLLBAR STYLING
   ═══════════════════════════════════════ */

.history-list::-webkit-scrollbar,
.record-full-prompt p::-webkit-scrollbar,
.record-dialog-panel::-webkit-scrollbar,
.admin-nav::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar,
.main-area::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.history-list::-webkit-scrollbar-thumb,
.record-full-prompt p::-webkit-scrollbar-thumb,
.record-dialog-panel::-webkit-scrollbar-thumb,
.admin-nav::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--line-strong);
}

/* ═══════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════ */

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

@keyframes pulse {
  0%, 100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  50% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

@keyframes progress {
  0%   { transform: translateX(-110%); }
  100% { transform: translateX(260%); }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ═══════════════════════════════════════
   RESPONSIVE — Mobile
   ═══════════════════════════════════════ */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.3);
  }

  .sidebar-toggle {
    display: flex;
  }

  .sidebar-overlay {
    display: block;
  }

  .main-area {
    margin-left: 0;
    padding: 20px 16px;
    padding-top: 64px;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .narrow-left {
    grid-template-columns: 1fr;
  }

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

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

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

  .code-create-form {
    grid-template-columns: 1fr;
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }

  .record-detail-grid {
    grid-template-columns: 1fr 1fr;
  }

  .preview-card {
    position: static;
  }

  .history-list {
    grid-template-columns: repeat(2, 1fr);
  }

  .main-area-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .card {
    padding: 18px;
  }
}

@media (max-width: 480px) {
  .main-area {
    padding: 14px 12px;
    padding-top: 60px;
  }

  .history-list {
    grid-template-columns: 1fr;
  }

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

  .generate-actions {
    grid-template-columns: 1fr;
  }
}
