/*
 * Alading Matting - Pixian.AI Style (Design System v5)
 *
 * - Base: white/light-gray + deep indigo-purple
 * - Font: Inter (sans-serif)
 * - Logo: Finn "Make Me Smile" character image
 * - i18n: EN / ZH-CN / ZH-TW with language selector
 * - Animations: cute emoji bounce for loading states, confetti on success
 * - Checkerboard: pure white + gray only
 */

:root {
  /* ---- Snow White Base ---- */
  --snow-50:   #FFFFFF;
  --snow-100:  #FAFAFB;
  --snow-200:  #F4F3F7;
  --snow-300:  #EDEAF1;

  /* ---- Deep Indigo-Purple Text ---- */
  --ink-900: #1E1535;
  --ink-800: #2D1B4D;
  --ink-700: #3D2A63;
  --ink-600: #5B4A78;
  --ink-500: #7B6B94;
  --ink-400: #A095B5;

  /* ---- Indigo Primary (buttons, links, active states) ---- */
  --vio-700: #4338CA;
  --vio-600: #4F46E5;
  --vio-500: #6366F1;
  --vio-100: #EDE9FE;
  --vio-50:  #F5F3FF;

  /* ---- Functional Colors ---- */
  --green-700: #059669;  --green-50:  #ECFDF5;
  --red-700:   #DC2626;  --red-50:    #FEF2F2;
  --blue-700:  #2563EB;  --blue-50:   #EFF6FF;

  /* ---- Borders ---- */
  --line:        #E5E0EB;
  --line-strong: #D6CEE0;
  --line-focus:  #A78BFA;

  /* ---- Border Radius Scale ---- */
  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 24px;
  --r-pill: 999px;

  /* ---- Shadow / Elevation Scale ---- */
  --sh-1: 0 1px 2px rgba(30,21,53,.03), 0 2px 8px rgba(30,21,53,.04);
  --sh-2: 0 4px 14px rgba(30,21,53,.07), 0 2px 4px rgba(30,21,53,.04);
  --sh-3: 0 12px 36px rgba(30,21,53,.10), 0 4px 12px rgba(30,21,53,.06);

  /* ---- Font: Sans-serif everywhere ---- */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;

  /* ---- Spacing Rhythm ---- */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background-color: var(--snow-100);
  color: var(--ink-600);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 {
  margin: 0; font-weight: 700; color: var(--ink-800);
  letter-spacing: -.02em;
}
h1 { font-size: 40px; line-height: 1.15; }
h2 { font-size: 26px; line-height: 1.25; }
h3 { font-size: 17px; }
p { margin: 0; }
.muted { color: var(--ink-500); font-size: 14px; }
[hidden] { display: none !important; }

/* ---------- Brand Logo (Finn Image) ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  height: 52px; width: auto; border-radius: 12px;
  object-fit: contain;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(67,56,202,.22);
}
.brand-logo-sm {
  height: 42px; width: auto; border-radius: 10px;
  object-fit: contain;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(67,56,202,.18);
}
.brand-name {
  font-weight: 700; font-size: 18px;
  color: var(--ink-900); letter-spacing: -.01em;
}

/* ---------- Top Bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1160px; margin: 0 auto; height: 60px;
  display: flex; align-items: center; gap: 24px; padding: 0 24px;
}
.nav { display: flex; gap: 2px; flex: 1; }
.nav-item {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: none; padding: 8px 14px; border-radius: var(--r-xs);
  font-size: 13.5px; color: var(--ink-500); cursor: pointer; font-family: inherit;
  transition: color .15s, background .15s; position: relative; font-weight: 500;
}
.nav-item svg { width: 17px; height: 17px; flex: none; }
.nav-item:hover { background: var(--snow-200); color: var(--ink-800); }
.nav-item.is-active { color: var(--vio-700); font-weight: 600; background: var(--vio-50); }
.nav-item.is-active::after {
  content: ""; position: absolute; left: 14px; right: 14px; bottom: -1px; height: 2px;
  background: var(--vio-600); border-radius: 2px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { font-size: 13px; color: var(--ink-500); font-weight: 500; }

/* ---------- Language Selector ---------- */
.lang-selector {
  position: relative;
}
.lang-btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1.5px solid var(--line-strong); border-radius: var(--r-pill);
  background: var(--snow-50); padding: 5px 11px;
  cursor: pointer; font-family: inherit; font-size: 13px;
  color: var(--ink-600); transition: all .15s;
  font-weight: 500;
}
.lang-btn:hover {
  border-color: var(--vio-300);
  background: var(--snow-100);
}
.lang-flag { font-size: 16px; line-height: 1; }
.lang-label { font-size: 12px; font-weight: 700; min-width: 20px; }
.lang-btn svg { width: 10px; height: 10px; opacity: .45; transition: transform .2s; }
.lang-btn[aria-expanded="true"] svg,
.lang-selector:hover .lang-btn svg { transform: rotate(180deg); opacity: .7; }
.lang-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--snow-50); border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); box-shadow: var(--sh-2);
  padding: 4px; z-index: 30; min-width: 150px;
}
.lang-option {
  display: flex; align-items: center; gap: 8px;
  width: 100%; border: 0; background: none;
  padding: 8px 12px; border-radius: var(--r-xs);
  font-family: inherit; font-size: 13.5px; color: var(--ink-700);
  cursor: pointer; transition: background .12s; text-align: left;
  font-weight: 500;
}
.lang-option:hover { background: var(--vio-50); color: var(--vio-700); }
.lang-option span:first-child { font-size: 16px; }

/* ---------- Avatar ---------- */
.avatar-sm {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--snow-300); cursor: pointer; overflow: hidden;
  background-size: cover; background-position: center;
  border: 1.5px solid var(--line); transition: border-color .15s, transform .15s;
  flex-shrink: 0;
}
/* Gray user-icon placeholder when no avatar */
.avatar-sm:not(.has-avatar) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23A095B5' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 21c0-4 4-6 8-6s8 2 8 6'/%3E%3C/svg%3E");
  background-size: 65%; background-repeat: no-repeat; background-position: center;
}
.avatar-sm:hover { border-color: var(--vio-500); transform: scale(1.08); }
.avatar-sm.has-avatar { border-color: var(--line-strong); }

.avatar-lg-wrap { position: relative; display: inline-block; cursor: pointer; }
.avatar-lg {
  width: 88px; height: 88px; border-radius: 50%;
  background: var(--snow-300);
  background-size: cover; background-position: center;
  border: 3px solid var(--snow-50);
  box-shadow: 0 0 0 2px var(--line-strong), var(--sh-2);
  transition: box-shadow .2s;
}
.avatar-lg:not(.has-avatar) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23A095B5' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 21c0-4 4-6 8-6s8 2 8 6'/%3E%3C/svg%3E");
  background-size: 45%; background-repeat: no-repeat; background-position: center;
}
.avatar-lg.has-avatar { box-shadow: 0 0 0 2px var(--vio-500), var(--sh-2); }
.avatar-lg:hover { box-shadow: 0 0 0 2px var(--vio-500), var(--sh-2); }
.avatar-badge {
  position: absolute; bottom: -2px; left: 50%; transform: translateX(-50%);
  background: var(--vio-700); color: #fff;
  font-size: 11px; padding: 3px 11px; border-radius: var(--r-pill);
  white-space: nowrap; opacity: 0; transition: opacity .2s; pointer-events: none;
  box-shadow: var(--sh-1); font-weight: 600;
}
.avatar-lg-wrap:hover .avatar-badge { opacity: 1; }

/* ---------- Buttons (Pill Style) ---------- */
.btn {
  font-family: var(--font-sans); font-size: 14px; font-weight: 600;
  border-radius: var(--r-pill); border: 1px solid transparent;
  padding: 9px 22px; cursor: pointer; transition: all .18s;
  white-space: nowrap; display: inline-flex;
  align-items: center; justify-content: center; gap: 7px; line-height: 1;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 16px; height: 16px; }
.btn-primary {
  background: var(--vio-700); color: #fff;
  box-shadow: 0 2px 8px rgba(67,56,202,.30);
}
.btn-primary:hover { background: var(--vio-600); box-shadow: 0 4px 14px rgba(67,56,202,.35); }
.btn-primary:disabled { background: var(--snow-300); color: var(--ink-400); box-shadow: none; cursor: not-allowed; }
.btn-danger {
  background: var(--red-700); color: #fff;
  box-shadow: 0 2px 8px rgba(220,38,38,.25);
}
.btn-danger:hover { background: #B91C1C; box-shadow: var(--sh-2); }
.btn-danger:disabled { background: var(--snow-300); color: var(--ink-400); box-shadow: none; cursor: not-allowed; }
.btn-ghost {
  background: var(--snow-50); color: var(--ink-600); border-color: var(--line-strong);
  border-radius: var(--r-xs);
}
.btn-ghost:hover { background: var(--snow-200); color: var(--ink-800); border-color: var(--line-strong); }
.btn-sm { padding: 7px 16px; font-size: 13px; }
.btn-block { width: 100%; }
.link {
  border: 0; background: none; color: var(--vio-700); cursor: pointer;
  font-family: inherit; font-size: inherit; padding: 0; font-weight: 600;
}
.link:hover { text-decoration: underline; }

/* ---------- Form Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field.grow { flex: 1; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-700); }
.field input, .field select {
  font-family: var(--font-sans); font-size: 14.5px; color: var(--ink-900);
  padding: 10px 14px; border: 1.5px solid var(--line-strong); border-radius: var(--r-xs);
  background: var(--snow-50); outline: none; transition: border-color .18s, box-shadow .18s;
}
.field input:focus, .field select:focus {
  border-color: var(--vio-500); box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.field input::placeholder { color: var(--ink-400); }
.input-locked {
  background: var(--snow-200); color: var(--ink-500);
  border-color: var(--line-strong); cursor: not-allowed;
  opacity: .75;
}
.input-sm { padding: 7px 11px; font-size: 13px; }
.hint { font-size: 13px; color: var(--ink-400); }
.pwd-ok { font-size: 13px; color: var(--green-700); font-weight: 600; }
.form-error {
  font-size: 13px; color: var(--red-700); background: var(--red-50);
  border: 1px solid #FECACA; border-radius: var(--r-xs); padding: 10px 14px; margin-bottom: 14px;
}

/* ---------- Login Page ---------- */
.auth-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(180deg, var(--snow-50) 0%, var(--snow-100) 100%);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--snow-50);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 44px 36px 38px; box-shadow: var(--sh-3);
  position: relative;
}
.auth-card .brand { margin-bottom: 28px; }
.auth-card .brand-logo { height: 40px; width: auto; border-radius: 10px; }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-sub { color: var(--ink-500); font-size: 14px; margin-bottom: 28px; }
.auth-switch { margin-top: 22px; font-size: 14px; color: var(--ink-500); text-align: center; }
#auth-lang-selector { margin-top: 18px; display: flex; justify-content: center; }
#auth-lang-dropdown { left: 50%; transform: translateX(-50%); right: auto; z-index: 9999; }

/* ---------- Footer ---------- */
.site-footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 12px 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 12.5px; color: var(--ink-300);
  z-index: 15;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.footer-brand { font-weight: 700; color: var(--ink-500); font-size: 13px; }
.footer-copy { letter-spacing: .01em; }

/* ---------- Main Content Area ---------- */
.main { max-width: 1160px; margin: 0 auto; padding: 36px 24px 100px; }
.work-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 20px; margin-bottom: 28px; flex-wrap: wrap;
}
.work-head .muted { margin-top: 6px; max-width: 520px; }

/* Mode Toggle - Card-style selector */
.mode-group {
  display: inline-flex; background: var(--snow-200);
  border-radius: var(--r-pill); padding: 3px; gap: 2px;
  border: 1px solid var(--line);
}
.mode-btn {
  border: 0; background: none; font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--ink-500); padding: 7px 18px; border-radius: var(--r-pill); cursor: pointer;
  transition: all .18s;
}
.mode-btn.is-active {
  background: var(--snow-50); color: var(--ink-900);
  box-shadow: var(--sh-1);
}

.api-banner {
  background: var(--vio-50); border: 1px solid var(--vio-100);
  color: var(--ink-700);
  border-radius: var(--r-sm); padding: 13px 16px; font-size: 14px; margin-bottom: 18px;
  box-shadow: var(--sh-1);
}

/* ---------- Upload Zone (Pixian Style: dashed large area + file icons) ---------- */
.dropzone {
  border: 2px dashed var(--line-strong); border-radius: var(--r-lg);
  background: var(--snow-50);
  padding: 56px 28px; text-align: center;
  color: var(--ink-400); cursor: pointer;
  transition: border-color .25s, background .25s, box-shadow .25s;
  outline: none; position: relative; overflow: hidden;
}
.dropzone::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(99,102,241,.04) 0%, transparent 70%);
  pointer-events: none; opacity: 0; transition: opacity .25s;
}
.dropzone:hover::before, .dropzone:focus-visible::before, .dropzone.is-over::before { opacity: 1; }
.dropzone:hover, .dropzone:focus-visible, .dropzone.is-over {
  border-color: var(--vio-500); background: var(--vio-50);
  box-shadow: var(--sh-2);
}
.dz-title {
  color: var(--vio-500); font-size: 22px; font-weight: 700; margin-top: 16px;
  font-style: italic; letter-spacing: -.01em;
}
.dz-link { color: var(--vio-700); font-weight: 700; font-style: normal; }
.dz-sub { color: var(--ink-400); font-size: 13px; margin-top: 8px; }

/* File type icon group in upload zone */
.dz-icons {
  display: flex; gap: 10px; justify-content: center; margin-bottom: 8px;
}
.dz-icon-file {
  width: 46px; height: 56px; border: 1.5px solid var(--line-strong);
  border-radius: 8px; background: var(--snow-50);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; box-shadow: var(--sh-1);
}
.dz-icon-file svg { width: 22px; height: 22px; color: var(--ink-400); }
.dz-icon-file span { font-size: 10px; color: var(--ink-400); font-weight: 600; }

/* ---------- Results Header ---------- */
.results-head {
  display: flex; justify-content: space-between; align-items: center;
  margin: 32px 0 16px; gap: 12px; flex-wrap: wrap;
}
.results-left { display: flex; align-items: center; gap: 14px; }
.results-actions { display: flex; gap: 8px; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-500); cursor: pointer; user-select: none; font-weight: 500; }
.check input { accent-color: var(--vio-700); width: 16px; height: 16px; cursor: pointer; }

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

.card {
  background: var(--snow-50); border: 1px solid var(--line); border-radius: var(--r-md);
  overflow: hidden; position: relative; transition: box-shadow .22s, transform .18s, border-color .18s;
  box-shadow: var(--sh-1);
}
.card:hover { box-shadow: var(--sh-2); transform: translateY(-3px); border-color: var(--line-strong); }
.card-thumb {
  aspect-ratio: 4 / 3; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center; cursor: zoom-in;
  background: var(--snow-200);
}
.card-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }

/*
 * Transparent preview checkerboard — pure white & gray only
 * White cell #FFFFFF / Gray cell #E8E8E8
 */
.checker, .card-thumb.checker {
  background-image:
    linear-gradient(45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(-45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8e8e8 75%),
    linear-gradient(-45deg, transparent 75%, #e8e8e8 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #ffffff;
}
.card-thumb.plain { background: var(--snow-200); }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }

/* Card name: editable input */
.card-name {
  font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--ink-900);
}
.card-name-input {
  font-size: 13.5px; font-weight: 600;
  width: 100%; padding: 5px 9px; border: 1.5px solid transparent;
  border-radius: var(--r-xs); color: var(--ink-900); outline: none;
  background: transparent; transition: border-color .15s, background .15s, box-shadow .15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-name-input:hover { border-color: var(--line); background: var(--snow-100); }
.card-name-input:focus {
  border-color: var(--vio-500); background: var(--snow-50);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
  white-space: normal; overflow: visible;
}

/* File size label */
.card-size-row { display: flex; justify-content: flex-start; }
.card-size { font-size: 11.5px; color: var(--ink-400); font-weight: 400; }

.card-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card-actions { display: flex; gap: 5px; }
.icon-btn {
  border: 1px solid var(--line-strong); background: var(--snow-50); border-radius: 8px;
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--ink-500); padding: 0; transition: all .15s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { color: var(--vio-700); background: var(--vio-50); border-color: var(--vio-100); }
.icon-btn.danger:hover { color: var(--red-700); background: var(--red-50); border-color: #FECACA; }
.icon-btn:active { transform: translateY(1px); }

.card-check {
  position: absolute; top: 10px; left: 10px; z-index: 2;
  width: 18px; height: 18px; accent-color: var(--vio-700); cursor: pointer;
}
.status {
  font-size: 11.5px; padding: 3px 9px; border-radius: var(--r-pill); font-weight: 600;
}
.status.processing { background: var(--blue-50); color: var(--blue-700); }
.status.done { background: var(--green-50); color: var(--green-700); }
.status.error { background: var(--red-50); color: var(--red-700); }

/* Processing overlay with emoji animation */
.thumb-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center; background: rgba(250,250,251,.88);
  color: var(--ink-600); font-size: 12.5px; backdrop-filter: blur(2px);
}

/* Clean spinner for processing states */
.spin {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--vio-600);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg);} }

.empty {
  text-align: center; color: var(--ink-400); padding: 60px 0; font-size: 14px;
  border: 2px dashed var(--line); border-radius: var(--r-md); margin-top: 18px;
  background: var(--snow-50);
}

/* Skeleton loader */
.card.skeleton { height: 250px; border: 1px solid var(--line); position: relative; overflow: hidden; background: var(--snow-200); }
.card.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.75) 50%, transparent 70%);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%);} to { transform: translateX(100%);} }

/* ---------- Settings Card ---------- */
.settings-card {
  background: var(--snow-50); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 28px; max-width: 720px; width: 100%;
  box-shadow: var(--sh-1); margin: 0 auto;
}
.setting-row { display: flex; gap: 16px; margin-bottom: 6px; flex-wrap: wrap; }
.setting-label { font-weight: 600; font-size: 14px; color: var(--ink-800); }

/* ---------- Profile ---------- */
.profile-card { max-width: 640px; width: 100%; margin: 0 auto; }
.profile-avatar-row {
  display: flex; flex-direction: column; align-items: center; margin-bottom: 26px; gap: 8px;
}
.profile-divider {
  height: 1px; background: linear-gradient(to right, transparent, var(--line-strong), transparent);
  margin: 26px 0;
}

/* ---------- Admin Panel ---------- */
.admin-card { max-width: 960px; width: 100%; margin: 0 auto; }
.admin-stats { display: flex; gap: 20px; margin-bottom: 24px; }
.stat-box {
  background: var(--snow-50); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 20px 28px; text-align: center; flex: 1; box-shadow: var(--sh-1);
}
.stat-num {
  display: block; font-size: 32px; font-weight: 700;
  color: var(--vio-700); line-height: 1.15;
}
.stat-label { font-size: 13px; color: var(--ink-400); margin-top: 4px; }
.admin-filter { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.admin-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: var(--sh-1); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th {
  background: var(--snow-200); padding: 12px 14px; text-align: left;
  font-weight: 600; color: var(--ink-700); border-bottom: 1px solid var(--line);
  white-space: nowrap; position: sticky; top: 0;
}
.admin-table td {
  padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle;
}
.admin-table tbody tr { transition: background .15s; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover td { background: var(--vio-50); }
.table-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  object-fit: cover; vertical-align: middle; margin-right: 7px;
  border: 1px solid var(--line);
}
.badge-admin {
  background: var(--vio-100); color: var(--vio-700);
  font-size: 11px; padding: 3px 9px; border-radius: var(--r-pill); font-weight: 600;
  border: 1px solid rgba(99,102,241,.18);
}
/* Admin panel preview thumbnail */
.admin-table th.col-prev { width: 74px; }
.rec-thumb {
  width: 58px; height: 58px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line); background: #ffffff;
  display: flex; align-items: center; justify-content: center;
}
.rec-thumb img { width: 100%; height: 100%; object-fit: contain; }
/* Admin thumbnail checkerboard also uses white+gray */
.rec-thumb.checker {
  background-image:
    linear-gradient(45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(-45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8e8e8 75%),
    linear-gradient(-45deg, transparent 75%, #e8e8e8 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-color: #ffffff;
}
.link-sm { font-size: 12px; padding: 0 2px; vertical-align: baseline; }
.admin-pagination { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.admin-pagination .btn { min-width: 36px; padding: 7px 11px; }

/* ---------- Toast Notifications ---------- */
.toast-wrap {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center;
}
.toast {
  background: var(--ink-900); color: var(--snow-50); font-size: 13.5px;
  padding: 11px 24px; border-radius: var(--r-pill); box-shadow: var(--sh-3);
  animation: toast-in .25s ease-out; font-weight: 500;
}
.toast.error { background: var(--red-700); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px);} to { opacity: 1; transform: none;} }

/* ---------- Image Viewer Modal ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; }
.viewer-backdrop { position: absolute; inset: 0; background: rgba(30,21,53,.40); backdrop-filter: blur(3px); }
.viewer-body {
  position: relative; max-width: 1000px; margin: 5dvh auto 0; background: var(--snow-50);
  border-radius: var(--r-lg); padding: 22px 24px 26px; max-height: 90dvh; overflow: auto;
  box-shadow: var(--sh-3); border: 1px solid var(--line);
}
.viewer-head {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px;
  font-weight: 700; font-size: 16px; color: var(--ink-900);
}
.viewer-panes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.viewer-panes figure { margin: 0; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; background: #ffffff; }
.viewer-panes img { width: 100%; display: block; max-height: 62dvh; object-fit: contain; }
.viewer-panes figcaption {
  font-size: 13px; color: var(--ink-500); text-align: center; padding: 10px; background: var(--snow-50);
  border-top: 1px solid var(--line); font-family: var(--font-sans);
}
/* Viewer result pane also uses white+gray checkerboard */
.viewer-panes figure.checker {
  background-image:
    linear-gradient(45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(-45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8e8e8 75%),
    linear-gradient(-45deg, transparent 75%, #e8e8e8 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #ffffff;
}

/* ---------- Confetti Canvas ---------- */
#confetti-canvas {
  position: fixed; inset: 0; z-index: 60;
  pointer-events: none; width: 100%; height: 100%;
}

/* ---------- Motion Reduction ---------- */
@media (prefers-reduced-motion: reduce) {
  .spin { animation: none; }
  .btn:active { transform: none; }
  .card:hover { transform: none; }
  .card.skeleton::after { animation: none; }
}

/* ---------- Responsive (mobile adaptation, desktop untouched) ---------- */
@media (max-width: 768px) {
  /* ---- Topbar: compact, logo only ---- */
  .topbar-inner { padding: 0 14px; gap: 14px; height: 54px; }
  .brand-name { display: none; }
  .brand-logo-sm { height: 34px; border-radius: 8px; }
  .nav { gap: 0; flex: 1; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav-item { padding: 8px 7px; flex-shrink: 0; }
  .nav-item span { display: none; }
  .nav-item svg { width: 20px; height: 20px; }
  .topbar-right { gap: 6px; flex-shrink: 0; }
  .user-chip { display: none; }
  #btn-logout { padding: 6px 12px; font-size: 12px; }
  .lang-label { display: none; }
  .lang-btn { padding: 5px 8px; }
  .lang-flag { font-size: 15px; }
  .avatar-sm { width: 28px; height: 28px; }

  /* ---- Main content ---- */
  .main { padding: 16px 12px 80px; }
  h1 { font-size: 26px; }
  h2 { font-size: 20px; }
  h3 { font-size: 15px; }

  /* ---- work-head: title + mode-group ---- */
  .work-head { gap: 12px; margin-bottom: 20px; }
  .work-head .muted { max-width: 100%; }

  /* ---- Mode group: horizontal scroll, no wrap ---- */
  .mode-group {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    max-width: 100%;
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  .mode-group::-webkit-scrollbar { display: none; }
  .mode-btn { white-space: nowrap; flex-shrink: 0; padding: 7px 14px; }

  /* ---- Dropzone: smaller padding ---- */
  .dropzone { padding: 32px 16px; }
  .dz-title { font-size: 18px; margin-top: 12px; }
  .dz-sub { font-size: 12px; }
  .dz-icons { gap: 6px; margin-bottom: 6px; }
  .dz-icon-file { width: 38px; height: 46px; }
  .dz-icon-file svg { width: 18px; height: 18px; }
  .dz-icon-file span { font-size: 9px; }

  /* ---- Results head: actions scroll horizontally ---- */
  .results-head { gap: 8px; margin: 24px 0 14px; }
  .results-actions {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  .results-actions::-webkit-scrollbar { display: none; }
  .results-actions .btn { flex-shrink: 0; }

  /* ---- Grid: 2 columns on mobile ---- */
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .card-body { padding: 10px 12px 12px; }
  .card-name { font-size: 12.5px; }
  .card-name-input { font-size: 12.5px; }
  .icon-btn { width: 26px; height: 26px; }
  .icon-btn svg { width: 13px; height: 13px; }
  .card-actions { gap: 4px; }
  .card-meta { flex-wrap: wrap; gap: 4px; row-gap: 4px; }
  .card-meta .muted { font-size: 10.5px; white-space: nowrap; }

  /* ---- Settings / Profile / Admin cards: full width ---- */
  .settings-card { padding: 18px 16px; max-width: 100%; }
  .profile-card { max-width: 100%; }
  .admin-card { max-width: 100%; }
  .setting-row { gap: 10px; }

  /* ---- Engine group in settings: horizontal scroll ---- */
  #engine-group {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    max-width: 100%;
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  #engine-group::-webkit-scrollbar { display: none; }
  #engine-group .mode-btn { white-space: nowrap; flex-shrink: 0; }

  /* ---- Admin panel ---- */
  .admin-stats { gap: 8px; }
  .stat-box { padding: 12px 10px; }
  .stat-num { font-size: 22px; }
  .admin-filter { gap: 8px; flex-wrap: wrap; }
  .admin-table { font-size: 12px; }
  .admin-table th, .admin-table td { padding: 9px 10px; }
  .rec-thumb { width: 44px; height: 44px; }
  .admin-pagination .btn { min-width: 32px; padding: 6px 10px; font-size: 12px; }

  /* ---- Viewer modal: full screen on mobile ---- */
  .viewer-body { padding: 14px 14px 18px; margin: 0; max-height: 100dvh; border-radius: 0; }
  .viewer-panes { grid-template-columns: 1fr; gap: 12px; }
  .viewer-panes img { max-height: 38dvh; }
  .viewer-head { font-size: 14px; margin-bottom: 14px; }

  /* ---- Profile avatar ---- */
  .avatar-lg { width: 72px; height: 72px; }
  .profile-divider { margin: 20px 0; }

  /* ---- Footer ---- */
  .site-footer { font-size: 11px; padding: 8px 0; gap: 6px; }
  .footer-brand { font-size: 12px; }

  /* ---- Toast ---- */
  .toast { font-size: 13px; padding: 10px 18px; }
  .toast-wrap { bottom: 50px; width: 100%; padding: 0 16px; }
  .toast { max-width: 100%; }

  /* ---- Empty state ---- */
  .empty { padding: 40px 0; font-size: 13px; }
}

@media (max-width: 480px) {
  .auth-card { padding: 28px 20px 24px; }
  .auth-card .brand-logo { height: 36px; }
  .auth-card h1 { font-size: 22px; }
  .dropzone { padding: 24px 12px; }
  .dz-title { font-size: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .card-body { padding: 8px 10px 10px; }
  .card-name { font-size: 12px; }
  .icon-btn { width: 24px; height: 24px; }
  .icon-btn svg { width: 12px; height: 12px; }
  .card-meta .muted { font-size: 10px; }
  .topbar-inner { padding: 0 10px; gap: 8px; }
  .main { padding: 14px 10px 80px; }
  .stat-box { padding: 10px 8px; }
  .stat-num { font-size: 20px; }
}
