:root {
  --bg: #0e141b;
  --bg-2: #131c26;
  --card: #18222e;
  --card-2: #1e2a38;
  --card-hover: #233244;
  --border: #283647;
  --border-strong: #37495e;
  --text: #e4ebf2;
  --muted: #8a9bb0;
  --faint: #5d6f84;
  --accent: #66c0f4;
  --accent-strong: #3d9fe0;
  --danger: #e5625c;
  --ok: #5bc48a;
  --bronze: #d08a4c;
  --silver: #c5cfda;
  --gold: #f2c14e;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: radial-gradient(1200px 500px at 50% -120px, #1b2b3d 0%, var(--bg) 70%) no-repeat, var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }

/* ---------------- Layout ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 10px max(16px, calc((100vw - 1200px) / 2));
  background: rgba(14, 20, 27, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 17px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand strong { color: var(--gold); }
.nav { display: flex; gap: 4px; overflow-x: auto; }
.nav a { color: var(--muted); padding: 7px 12px; border-radius: 8px; white-space: nowrap; font-weight: 550; }
.nav a:hover { color: var(--text); background: var(--card); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--card-2); box-shadow: inset 0 -2px 0 var(--accent); }

.container { max-width: 1200px; margin: 0 auto; padding: 28px 16px 64px; }

.section { margin-top: 36px; }
.two-col { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 0 24px; align-items: start; }
.two-col .grid-employees { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head .hint { color: var(--muted); font-size: 13px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin: 6px 0 0; }

.card {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.pad { padding: 18px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.empty { color: var(--muted); padding: 28px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius); }

.grid { display: grid; gap: 14px; }
.grid-employees { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid-badges { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid-items { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

/* ---------------- Stats ---------------- */
.stat { padding: 16px 18px; }
.stat .value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.stat.gold .value { color: var(--gold); }

/* ---------------- Avatars ---------------- */
.avatar {
  --size: 48px;
  width: var(--size); height: var(--size); flex: none;
  border-radius: 50%; object-fit: cover;
  background: var(--card-hover);
  display: inline-grid; place-items: center;
  font-weight: 700; font-size: calc(var(--size) * 0.38); color: #fff;
  border: 2px solid var(--border-strong);
}
.avatar.lg { --size: 112px; border-width: 3px; }
.avatar.sm { --size: 32px; border-width: 1px; }
.avatar.xs { --size: 24px; border-width: 1px; }

/* ---------------- Employee cards ---------------- */
.emp-card { display: flex; gap: 14px; align-items: center; padding: 14px; color: var(--text); transition: background .15s, border-color .15s, transform .15s; }
.emp-card:hover { background: var(--card-hover); border-color: var(--border-strong); text-decoration: none; transform: translateY(-1px); }
.emp-card .name { font-weight: 650; }
.emp-card .title { color: var(--muted); font-size: 13px; }
.emp-card .body { min-width: 0; flex: 1; }
.emp-card .rank { color: var(--faint); font-weight: 700; font-size: 13px; width: 22px; text-align: right; }

.tier-counts { display: flex; gap: 10px; margin-top: 6px; font-size: 13px; font-variant-numeric: tabular-nums; }
.tier-counts span { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; box-shadow: inset 0 -2px 3px rgba(0, 0, 0, .35); }
.dot.bronze { background: var(--bronze); }
.dot.silver { background: var(--silver); }
.dot.gold { background: var(--gold); }
.dot.none { background: var(--border-strong); }

.progress { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--bronze), var(--gold)); border-radius: 3px; }

/* ---------------- Badge tiles ---------------- */
.badge-img { display: block; width: 100%; height: auto; aspect-ratio: 1; }
.badge-tile {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 14px 10px 12px; color: var(--text); position: relative;
  transition: background .15s, transform .15s, border-color .15s;
}
.badge-tile:hover { background: var(--card-hover); border-color: var(--border-strong); text-decoration: none; transform: translateY(-2px); }
.badge-tile .badge-img { width: 104px; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .45)); transition: transform .2s; }
.badge-tile:hover .badge-img { transform: scale(1.05); }
.badge-tile .name { font-weight: 600; margin-top: 8px; font-size: 14px; }
.badge-tile .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.badge-tile.locked .name { color: var(--muted); }
.badge-tile.locked .badge-img { filter: none; opacity: .8; }

.tier-pips { display: flex; gap: 5px; justify-content: center; margin-top: 6px; }
.tier-pips .dot { width: 9px; height: 9px; }

.tier-label { font-weight: 650; }
.tier-label.bronze { color: var(--bronze); }
.tier-label.silver { color: var(--silver); }
.tier-label.gold { color: var(--gold); }

/* ---------------- Profile ---------------- */
.profile { display: flex; gap: 24px; align-items: center; padding: 24px; flex-wrap: wrap; }
.profile .info { flex: 1; min-width: 220px; }
.profile .info .title { color: var(--muted); margin-top: 4px; }
.profile .score { text-align: center; padding: 0 12px; }
.profile .score .value { font-size: 42px; font-weight: 750; color: var(--gold); line-height: 1; }
.profile .score .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; }
.profile .tier-counts { font-size: 15px; gap: 16px; margin-top: 10px; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border-strong); background: transparent; color: var(--muted);
  padding: 5px 12px; border-radius: 999px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #07121c; font-weight: 600; }

/* ---------------- Item detail ---------------- */
.item-hero { padding: 24px; }
.item-hero .crumbs { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.tiers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 20px; }
.tier-card { padding: 16px; text-align: center; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); }
.tier-card img { width: 130px; max-width: 100%; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .5)); }
.tier-card .criteria { color: var(--muted); font-size: 13px; margin-top: 6px; min-height: 1.5em; }
.tier-card .count { font-size: 13px; margin-top: 8px; }

.item-card { display: flex; gap: 14px; align-items: center; padding: 12px 14px; color: var(--text); transition: background .15s, border-color .15s; }
.item-card:hover { background: var(--card-hover); border-color: var(--border-strong); text-decoration: none; }
.item-card img { width: 72px; height: 72px; flex: none; filter: drop-shadow(0 3px 8px rgba(0, 0, 0, .45)); }
.item-card .name { font-weight: 650; }
.item-card .desc { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
tr:last-child td { border-bottom: 0; }
td .who { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; }
td img.mini-badge { width: 40px; height: 40px; vertical-align: middle; }
tr.locked td { opacity: .55; }
.nowrap { white-space: nowrap; }

/* ---------------- Feed ---------------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed img.mini-badge { width: 40px; height: 40px; flex: none; }
.feed .text { flex: 1; min-width: 0; }
.feed .when { color: var(--faint); font-size: 12px; white-space: nowrap; }

/* ---------------- Forms & buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--card-2); color: var(--text);
}
.btn:hover { background: var(--card-hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: linear-gradient(180deg, #74c8f8, var(--accent-strong)); border-color: var(--accent-strong); color: #06121d; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(229, 98, 92, .12); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--card-2); }

form.stack, .stack { display: grid; gap: 14px; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
label.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=date], input[type=password], input[type=number], input[type=search], select, textarea {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type=file] { font-size: 13px; color: var(--muted); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.tier-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.tier-picker label {
  display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer;
  padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--bg);
  font-size: 13px; font-weight: 600; color: var(--muted); min-width: 90px;
}
.tier-picker img { width: 56px; height: 56px; }
.tier-picker input { position: absolute; opacity: 0; pointer-events: none; }
.tier-picker label:has(input:checked) { border-color: var(--accent); background: rgba(102, 192, 244, .1); color: var(--text); }
.tier-picker label:has(input:focus-visible) { outline: 2px solid var(--accent); }

.preview-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.preview-row figure { margin: 0; text-align: center; }
.preview-row img { width: 96px; height: 96px; }
.preview-row figcaption { font-size: 12px; color: var(--muted); }

.admin-layout { display: grid; grid-template-columns: 200px 1fr; gap: 20px; margin-top: 20px; align-items: start; }
.tabs { display: grid; gap: 4px; position: sticky; top: 76px; }
.tabs button {
  text-align: left; font: inherit; font-weight: 600; color: var(--muted);
  background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 9px 12px; cursor: pointer;
}
.tabs button:hover { color: var(--text); background: var(--card); }
.tabs button.active { color: var(--text); background: var(--card-2); border-color: var(--border); box-shadow: inset 3px 0 0 var(--accent); }
.admin-panel { display: grid; gap: 20px; min-width: 0; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row img.mini-badge { width: 44px; height: 44px; flex: none; }
.list-row .actions { display: flex; gap: 6px; }

.login { max-width: 420px; margin: 40px auto; }
code, pre { font-family: "Cascadia Code", Consolas, "SF Mono", Menlo, monospace; font-size: 13px; }
pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; margin: 8px 0 0; white-space: pre-wrap; word-break: break-all; }
code.inline { background: var(--bg); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); }

/* ---------------- Toasts ---------------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { background: var(--card-2); border: 1px solid var(--border-strong); border-left: 4px solid var(--ok); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.spinner { color: var(--muted); padding: 40px; text-align: center; }

@media (max-width: 760px) {
  .topbar { gap: 12px; flex-wrap: wrap; }
  .brand span { display: none; }
  .admin-layout, .two-col { grid-template-columns: 1fr; }
  .tabs { position: static; grid-auto-flow: column; overflow-x: auto; }
  .tabs button.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .tiers { grid-template-columns: 1fr; }
  .profile { justify-content: center; text-align: center; }
  .profile .tier-counts { justify-content: center; }
  h1 { font-size: 24px; }
}
