:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #14181f;
  --muted: #6b7280;
  --border: #e4e7ec;
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --good: #047857;
  --good-bg: #ecfdf5;
  --warn: #b45309;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ── Buttons ── */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--ink);
  padding: 9px 16px; border-radius: 9px; font-weight: 600; font-size: 14px;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { border-color: #c7cbd3; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { color: var(--danger); border-color: #f3c2c2; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { padding: 6px 11px; font-size: 13px; }

/* ── Login ── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #eef0fb 0%, #f6f7f9 60%);
}
.login-card {
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow);
  padding: 36px 34px; width: 360px; border: 1px solid var(--border);
}
.login-card h1 { font-size: 21px; margin: 0 0 4px; }
.login-card p.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 9px; background: #fff;
}
.field input:focus { outline: none; border-color: var(--brand); }
.login-err {
  color: var(--danger); background: var(--danger-bg); border: 1px solid #f3c2c2;
  padding: 8px 11px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; display: none;
}

/* ── Shell ── */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 22px;
  background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
}
.topbar .brand { font-weight: 700; font-size: 16px; }
.topbar .brand span { color: var(--brand); }
.topbar .spacer { flex: 1; }
.quota-pill {
  display: flex; align-items: center; gap: 8px; background: var(--good-bg);
  border: 1px solid #b7e4cf; color: var(--good); padding: 6px 13px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
}
.quota-pill.empty { background: var(--danger-bg); border-color: #f3c2c2; color: var(--danger); }
.quota-pill b { font-size: 14px; }

.nav {
  display: flex; gap: 4px; padding: 10px 22px 0; background: var(--panel);
  border-bottom: 1px solid var(--border); position: sticky; top: 57px; z-index: 25;
}
.nav button {
  border: none; background: transparent; padding: 10px 16px; font-weight: 600;
  color: var(--muted); border-bottom: 2px solid transparent; font-size: 14px;
}
.nav button.active { color: var(--brand); border-bottom-color: var(--brand); }

.page { max-width: 1080px; margin: 26px auto; padding: 0 22px 80px; }
.page h2 { font-size: 19px; margin: 0 0 4px; }
.page .lead { color: var(--muted); margin: 0 0 22px; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
}
.section-title { font-weight: 700; font-size: 14px; margin: 0 0 12px; }

/* ── Burn banner ── */
.burn {
  border-radius: 10px; padding: 12px 15px; font-size: 14px; margin: 16px 0;
  background: #eef2ff; border: 1px solid #c7d2fe; color: #312e81;
}
.burn.empty { background: var(--danger-bg); border-color: #f3c2c2; color: var(--danger); }
.burn b { font-weight: 800; }

/* ── Grids ── */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px;
}
.grid-sm { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }

.tile {
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff;
  position: relative; transition: border-color .12s, box-shadow .12s;
}
.tile.selectable { cursor: pointer; }
.tile.selected { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.tile .thumb { aspect-ratio: 4/5; background: #f1f3f7; display: flex; align-items: center; justify-content: center; }
.tile .thumb img { width: 100%; height: 100%; object-fit: cover; }
.tile .thumb.empty { color: var(--muted); font-size: 12px; text-align: center; padding: 10px; }
.tile .cap { padding: 8px 10px; font-size: 12px; }
.tile .cap .name { font-weight: 600; line-height: 1.3; }
.tile .badge {
  position: absolute; top: 8px; left: 8px; background: var(--brand); color: #fff;
  width: 22px; height: 22px; border-radius: 999px; display: none; align-items: center;
  justify-content: center; font-size: 12px; font-weight: 700;
}
.tile.selected .badge { display: flex; }
.tile .spin {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.7);
}
.tile.ref-rejected .thumb img { opacity: .35; filter: grayscale(.7); }
.ref-badge {
  position: absolute; top: 8px; left: 8px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px;
}

.spinner {
  width: 22px; height: 22px; border: 3px solid #d7d9e0; border-top-color: var(--brand);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Forms ── */
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.input, select.input, textarea.input {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; background: #fff; width: 100%;
}
.input:focus { outline: none; border-color: var(--brand); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 999px;
  border: 1px solid var(--border); background: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.dropzone {
  border: 2px dashed #cdd2dc; border-radius: 12px; padding: 26px; text-align: center;
  color: var(--muted); background: #fafbfc; cursor: pointer;
}
.dropzone:hover { border-color: var(--brand); color: var(--brand); }

.muted { color: var(--muted); }
.hidden { display: none !important; }
.err { color: var(--danger); font-size: 13px; }
.ok { color: var(--good); font-size: 13px; }

/* ── Modal / wizard ── */
.overlay {
  position: fixed; inset: 0; background: rgba(15,18,28,.45); display: flex;
  align-items: center; justify-content: center; z-index: 60; padding: 20px;
}
.modal {
  background: #fff; border-radius: 16px; width: 480px; max-width: 100%; padding: 28px;
  box-shadow: 0 12px 40px rgba(16,24,40,.2);
}
.modal h2 { margin-top: 0; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #14181f; color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; z-index: 80; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── Lightbox ── */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.82); display: none;
  align-items: center; justify-content: center; z-index: 90; cursor: zoom-out;
}
.lightbox.show { display: flex; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }
