:root {
  --bg: #f4f5f7;
  --surface: #fff;
  --border: #e2e5ec;
  --border-soft: #eef0f4;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #2d6cdf;
  --primary-dark: #2358bb;
  --danger: #d64545;
  --accent: #ffc94d;
  --sidebar-bg: #1c2230;
  --sidebar-text: #aeb6c8;
  --sidebar-w: 232px;
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---- Layout ---- */

body.with-sidebar { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  padding: 18px 12px 14px;
}

.brand {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 17px;
  padding: 4px 10px 16px;
}
.brand span { color: var(--accent); }
.brand small {
  font-size: 11px;
  font-weight: 600;
  color: var(--sidebar-text);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-left: 4px;
}

.nav { flex: 1; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6c7689;
  padding: 0 10px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-icon { width: 20px; text-align: center; font-size: 15px; }

.sidebar-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px 10px 0;
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-user {
  color: var(--sidebar-text);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-logout { color: #fff; font-size: 13px; text-decoration: none; opacity: .8; }
.sidebar-logout:hover { opacity: 1; }

.wrap {
  flex: 1;
  min-width: 0;
  max-width: 1360px;
  margin: 0 auto;
  padding: 28px 32px 48px;
}
body.bare .wrap { padding: 24px 16px; }

@media (max-width: 800px) {
  body.with-sidebar { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: 12px; }
  .nav { flex-direction: row; gap: 10px; overflow-x: auto; padding: 4px 0; }
  .nav-group { flex-direction: row; gap: 2px; }
  .nav-label { display: none; }
  .nav-link { white-space: nowrap; padding: 6px 10px; }
  .sidebar-foot { padding-top: 8px; }
  .wrap { padding: 16px; }
}

/* ---- Typography & page head ---- */

h1 { font-size: 22px; margin: 0 0 12px; }
h1 a { color: inherit; }
h2 { font-size: 15px; margin: 0 0 12px; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; }

.muted { color: var(--muted); font-size: 14px; }

/* ---- Cards ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
}

.card-narrow { max-width: 360px; margin: 60px auto; }
.card-narrow form { display: flex; flex-direction: column; gap: 10px; }

/* ---- Forms & buttons ---- */

input[type="text"], input[type="password"], input[type="email"], select {
  padding: 8px 10px;
  border: 1px solid #cfd4e0;
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: #fff;
}
input:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.btn {
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: var(--border);
  color: var(--text);
  text-decoration: none;
  display: inline-block;
}
.btn:hover { filter: brightness(.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); filter: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { padding: 4px 10px; font-size: 12px; }

.btn-discord {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  background: #5865f2;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  border-radius: var(--radius-sm);
}
.btn-discord:hover { background: #4752c4; }

.inline-form { display: inline-flex; gap: 8px; }
.upload-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.stack-form { display: flex; flex-direction: column; gap: 12px; max-width: 420px; }
.stack-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.stack-form button { align-self: flex-start; }

/* ---- Lists ---- */

.game-list { list-style: none; padding: 0; margin: 0; }
.game-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}
.game-list li:hover { border-color: var(--primary); }
.game-list a {
  display: block;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
}

/* ---- Tables ---- */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.table-scroll .file-table { border: none; border-radius: 0; }

.file-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.file-table th, .file-table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 14px;
}
.file-table tbody tr:last-child td { border-bottom: none; }
.file-table tbody tr:hover { background: #fafbfd; }
.file-table th {
  background: #fafbfc;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
}
.file-table a { color: var(--primary); text-decoration: none; word-break: break-all; }
.row-actions { white-space: nowrap; text-align: right; }

/* ---- Flash & chips ---- */

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }
.flash-success { background: #e3f6e8; color: #1c6b34; }
.flash-error { background: #fde8e8; color: #9b2222; }

.chip {
  display: inline-block;
  background: var(--border-soft);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  color: #4b5563;
  margin: 1px 2px 1px 0;
  white-space: nowrap;
}
.chip-warn { background: #fdf0d5; color: #8a5a00; }
.chip-ok { background: #e3f6e8; color: #1c6b34; }

/* ---- Characters (Blokies sprites) ---- */

.char-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.char-head h2 { margin: 0; }
.char-head code { font-size: 12px; font-weight: 400; }

.sprite-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.sprite-tile {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}
.sprite-tile img {
  width: 100%;
  height: 96px;
  object-fit: contain;
  background:
    repeating-conic-gradient(#f0f1f4 0% 25%, #fafbfc 0% 50%) 0 0 / 16px 16px;
  border-radius: 6px;
}
.sprite-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin: 6px 0;
  font-size: 13px;
}
.sprite-actions { display: flex; justify-content: center; gap: 6px; }
.sprite-missing { border-style: dashed; }
.sprite-hole {
  height: 96px;
  border-radius: 6px;
  background: #fafbfc;
}

.held-list { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.held-list li { padding: 4px 0; border-top: 1px solid var(--border-soft); }
.held-list li:first-child { border-top: none; }
.held-list code { color: var(--muted); font-size: 12px; }

/* ---- Jawi spelling audit ---- */

.filterbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filterbar input[type="text"] { min-width: 220px; }

.jawi-cell {
  font-family: "Noto Naskh Arabic", "Geeza Pro", "Al Bayan", "Amiri", serif;
  font-size: 24px;
  line-height: 1.6;
  white-space: nowrap;
}
.jawi-input {
  font-family: "Noto Naskh Arabic", "Geeza Pro", "Al Bayan", "Amiri", serif;
  font-size: 18px;
  min-width: 140px;
}

.occ { margin-top: 6px; }
.occ summary { cursor: pointer; font-size: 12px; }
.occ ul { list-style: none; padding: 6px 0 0; margin: 0; }
.occ li {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 4px 0;
  border-top: 1px solid var(--border-soft);
  font-size: 13px;
}
.occ code { font-size: 12px; color: var(--muted); }
.row-actions .inline-form { display: flex; }
.row-actions .jawi-input { width: 300px; }

/* ---- Parents / purchases / metrics (business pages) ---- */

.chip-err { background: #fde8e8; color: #9b2222; }
a.chip { text-decoration: none; }
a.chip:hover { filter: brightness(.96); }
.chip-active { background: var(--primary); color: #fff; }

.search-form { display: flex; gap: 8px; margin-bottom: 16px; max-width: 480px; }
.search-form input[type="search"] { flex: 1; }

.filter-row { display: flex; gap: 4px; margin: 16px 0 10px; }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
.row-actions form { display: inline-block; margin-left: 4px; }

.kv-table th { text-align: left; padding: 4px 16px 4px 0; color: var(--muted); font-weight: 500; }
.kv-table td { padding: 4px 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat {
  background: #fff;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-num { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); }

.metrics-table .bar {
  display: inline-block;
  height: 10px;
  background: var(--primary);
  opacity: .35;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}
.metrics-table .bar-money { background: #1c6b34; }
.metrics-table .bar-kids { background: #8a5a00; }

/* ---- Mobile overrides that must beat component rules above ---- */

@media (max-width: 800px) {
  .file-table { display: block; overflow-x: auto; }
}
