:root {
  --bg: #140630;
  --panel: #1e0a44;
  --panel-2: #2a1160;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f5f0ff;
  --muted: #bfb2e0;
  --accent: #ff5c8a;
  --violet: #7b61ff;
  --gold: #ffc857;
  --green: #34d399;
  --red: #ff4d6d;
  --side: 232px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(circle at top left, #2a0f66, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
}
.hidden { display: none !important; }
.accent { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); min-height: 1.2em; }
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.center-text { text-align: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; }
.narrow { width: 100%; max-width: 380px; }
h1 { margin: 0 0 4px; font-size: 26px; }
h2 { margin: 0 0 12px; font-size: 20px; }
h3 { margin: 18px 0 8px; font-size: 16px; }
label { display: block; margin: 14px 0; color: var(--muted); font-size: 13px; }
input, select, textarea {
  width: 100%; margin-top: 6px; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit;
}
button {
  font: inherit; border: 0; border-radius: 12px; padding: 10px 16px; cursor: pointer;
  color: var(--text); background: var(--panel-2);
}
button.primary { background: var(--accent); font-weight: 700; }
button.danger { background: var(--red); font-weight: 700; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.small { padding: 6px 10px; font-size: 13px; }
button:disabled { opacity: 0.5; cursor: default; }
.wide { width: 100%; margin-top: 8px; }
code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; font-size: 13px; }

/* ---------- Layout: side bar on desktop, bottom bar on phones ---------- */
.shell { display: flex; min-height: 100vh; }
.side {
  width: var(--side); flex: none; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: rgba(20, 6, 48, 0.85); border-right: 1px solid var(--line); padding: 18px 12px;
}
.brand { font-weight: 800; font-size: 19px; padding: 0 8px 16px; display: flex; align-items: center; gap: 8px; }
.badge-top { font-size: 11px; font-weight: 800; background: var(--gold); color: #1b0b3a; border-radius: 6px; padding: 2px 7px; }
.nav-group { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: transparent;
  color: var(--muted); padding: 9px 10px; border-radius: 10px;
}
.nav-item .ico { width: 20px; text-align: center; }
.nav-item.active { background: var(--panel-2); color: var(--text); font-weight: 700; }
.nav-item .pill { margin-left: auto; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 12px; align-items: center;
  padding: 12px 20px; background: rgba(20, 6, 48, 0.92); border-bottom: 1px solid var(--line); backdrop-filter: blur(8px);
}
.topbar form { flex: 1; max-width: 560px; }
.topbar input { margin: 0; border-radius: 999px; padding: 9px 16px; }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-left: auto; white-space: nowrap; }
.who b { color: var(--text); }
.role-chip { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 8px; background: var(--panel-2); color: var(--accent); }
.tab { padding: 20px; max-width: 1200px; width: 100%; margin: 0 auto; }
.tab-title { font-size: 22px; font-weight: 800; margin: 0 0 14px; }
.bottom { display: none; }

@media (max-width: 760px) {
  .side { display: none; }
  .topbar { padding: 10px 12px; }
  .who .role-chip { display: none; }
  .tab { padding: 12px 12px 90px; }
  .bottom {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 8;
    background: rgba(20, 6, 48, 0.97); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom button { flex: 1; background: transparent; color: var(--muted); padding: 6px 2px; font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .bottom button .ico { font-size: 19px; }
  .bottom button.active { color: var(--text); font-weight: 700; }
  .more-sheet { position: fixed; inset: 0; z-index: 9; background: rgba(0, 0, 0, 0.5); display: flex; align-items: flex-end; }
  .more-sheet .sheet { width: 100%; background: var(--bg); border-radius: 18px 18px 0 0; padding: 12px 12px 24px; max-height: 70vh; overflow-y: auto; }
}

/* ---------- Pieces ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; align-items: flex-end; flex-wrap: wrap; }
.toolbar input, .toolbar select { margin: 0; max-width: 420px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.stat .n { font-size: 28px; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 13px; }
.stat.red { border-color: rgba(255, 77, 109, 0.5); }
.stat.gold { border-color: rgba(255, 200, 87, 0.5); }
.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex; gap: 12px; align-items: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; cursor: pointer;
}
.row:hover { border-color: rgba(255, 255, 255, 0.25); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { color: var(--muted); font-size: 13px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none; object-fit: cover;
}
.avatar.big { width: 64px; height: 64px; font-size: 32px; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 8px; background: var(--panel-2); margin-right: 4px; white-space: nowrap; }
.tag.red { background: rgba(255, 77, 109, 0.25); color: #ffb3c1; }
.tag.gold { background: rgba(255, 200, 87, 0.2); color: var(--gold); }
.tag.green { background: rgba(52, 211, 153, 0.2); color: var(--green); }
.pill { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 8px 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td { padding: 6px 4px; border-bottom: 1px solid var(--line); }

.drawer { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 10; display: flex; justify-content: flex-end; }
.drawer-body {
  width: 100%; max-width: 520px; height: 100%; overflow-y: auto; background: var(--bg);
  border-left: 1px solid var(--line); padding: 20px; position: relative;
}
.close { position: absolute; right: 16px; top: 16px; }
.toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 12px; max-width: 90vw;
}
.setting-card {
  margin-top: 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
}
.setting-title { font-weight: 700; }
.setting-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.qr { background: #fff; border-radius: 14px; padding: 10px; width: 220px; margin: 12px auto; }
.qr svg { width: 100%; height: auto; display: block; }

/* Diamonds */
.dia-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .dia-grid { grid-template-columns: 1fr; } }
.wallet {
  background: linear-gradient(135deg, #5b2bb5, #8a2f86); border-radius: 18px; padding: 18px; margin-bottom: 16px;
}
.wallet .big { font-size: 34px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.meter { height: 8px; background: rgba(0, 0, 0, 0.3); border-radius: 8px; margin: 12px 0 6px; overflow: hidden; }
.meter > div { height: 100%; background: var(--gold); border-radius: 8px; }
.wallet .facts { display: flex; justify-content: space-between; font-size: 13px; color: #f0e6ff; flex-wrap: wrap; gap: 4px 12px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.seg button { padding: 7px 12px; font-size: 13px; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 700; }
.amount { color: var(--gold); font-weight: 800; white-space: nowrap; }
.struck { opacity: 0.55; }
.struck .title { text-decoration: line-through; }
.person-check { display: flex; gap: 12px; align-items: center; background: var(--panel-2); border-radius: 14px; padding: 12px; margin: 8px 0; }

.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; margin: 8px 0; }
.checks label { display: flex; gap: 8px; align-items: center; margin: 0; padding: 8px 10px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); color: var(--text); cursor: pointer; }
.checks input { width: auto; margin: 0; accent-color: var(--accent); }
.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos figure { margin: 0; text-align: center; }
.photos img { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; display: block; margin-bottom: 4px; }

/* Watching (officers) */
.watch { position: fixed; inset: 0; z-index: 30; background: #07020f; display: flex; flex-direction: column; padding: 12px; gap: 10px; }
.watch-top { display: flex; gap: 10px; align-items: center; font-weight: 700; }
.watch-top .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-grid { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; overflow: auto; }
.tile { position: relative; background: var(--panel); border-radius: 14px; overflow: hidden; min-height: 180px; display: flex; align-items: center; justify-content: center; }
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.tile .label { position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, 0.55); padding: 2px 8px; border-radius: 8px; font-size: 12px; }
.tile.speaking { outline: 3px solid var(--green); }
.tile .voice { font-size: 42px; }

/* The owner's panel uses gold for its main buttons. */
body.gold { --accent: #ffc857; }
body.gold button.primary, body.gold .seg button.on { color: #1b0b3a; }
