/* Admin panel — shares the brand palette but is a separate, simpler shell. */

:root {
  --c-royal:        #3447AA;
  --c-royal-deep:   #1F2A6B;
  --c-royal-night:  #0E1442;
  --c-royal-soft:   #5A6CC9;
  --c-pink:         #FBEAEB;
  --c-pink-deep:    #E9B9C0;
  --txt:            #f5f7fb;
  --hint:           #b8c0d4;
  --card-bg:        rgba(255,255,255,0.06);
  --card-border:    rgba(255,255,255,0.16);
  --shadow:         0 14px 36px rgba(15, 21, 60, 0.45),
                    0 1px 0 rgba(255,255,255,0.12) inset;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--txt);
  background:
    radial-gradient(900px 600px at 8% -10%, rgba(52, 71, 170, 0.32), transparent 60%),
    radial-gradient(800px 600px at 110% 8%, rgba(233, 185, 192, 0.14), transparent 60%),
    radial-gradient(900px 700px at 50% 120%, rgba(31, 42, 107, 0.55), transparent 60%),
    var(--c-royal-night);
  min-height: 100vh;
}

.d-none { display: none !important; }
.muted { color: var(--hint); }
.small { font-size: 11.5px; }
.text-center { text-align: center; }

/* Subtle moving gradient blobs in the background. */
.bg-anim { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.bg-anim span {
  position: absolute;
  top: 50%; left: 50%;
  width: 48vmax; height: 48vmax;
  margin: -24vmax 0 0 -24vmax;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.35;
  mix-blend-mode: screen;
}
.bg-anim span:nth-child(1) { background: #3447AA; animation: orbit-a 56s ease-in-out infinite; }
.bg-anim span:nth-child(2) { background: #5A6CC9; animation: orbit-b 64s ease-in-out infinite; }
.bg-anim span:nth-child(3) { background: #1F2A6B; animation: orbit-c 48s ease-in-out infinite; }
@keyframes orbit-a { 0%,100%{transform:translate(-32vw,-22vh) scale(1)} 50%{transform:translate(28vw,20vh) scale(1.1)} }
@keyframes orbit-b { 0%,100%{transform:translate(30vw,-18vh) scale(1.1)} 50%{transform:translate(-26vw,10vh) scale(1.05)} }
@keyframes orbit-c { 0%,100%{transform:translate(0vw,28vh) scale(1.2)} 50%{transform:translate(-24vw,-8vh) scale(1)} }

/* ----------------- Cards & forms ----------------- */
.card {
  position: relative;
  z-index: 1;
  background:
    linear-gradient(var(--card-bg), var(--card-bg)),
    #1a2566;
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter:        blur(22px) saturate(180%);
}
.card-title    { margin: 0 0 4px; font-size: 18px; font-weight: 700; letter-spacing: -0.2px; }
.card-subtitle { margin: 22px 0 8px; font-size: 14px; font-weight: 600; }
.muted, .hint { color: var(--hint); }
.hint { font-size: 12px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 12px;
}
.field > span { font-size: 12px; color: var(--hint); font-weight: 600; }
.field input, .field textarea, .field select {
  background-color: rgba(0,0,0,0.25);
  border: 1px solid var(--card-border);
  color: var(--txt);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  width: 100%;
  font-family: inherit;
}
.field input:focus, .field textarea:focus { border-color: rgba(251,234,235,0.45); }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check input:not([type="checkbox"]) { width: auto; }
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---- Selects: style the closed control AND the popup option list so it reads
   on-theme (dark royal) instead of the plain white-on-grey OS default. Custom
   caret via background SVG; native arrow removed with appearance:none. ---- */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: rgba(0,0,0,0.25);
  color: var(--txt);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  font-family: inherit;
  cursor: pointer;
  /* caret — filled triangle so it renders reliably across browsers */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23cfd7ea' d='M0 0h10L5 6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px !important;
}
select:hover { border-color: rgba(251,234,235,0.35); }
select:focus { border-color: rgba(251,234,235,0.55); outline: none; }
/* The popup list. Firefox honours these fully; Chromium/WebKit honour
   background/color on most platforms — a big readability win over the default
   grey. Larger padding + line-height makes options easier to hit. */
select option {
  background-color: #141c4d;   /* deep royal — light text reads clearly on it */
  color: var(--txt);
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.7;
}
select option:checked {
  background: #3447AA;
  color: #fff;
  font-weight: 700;
}
select option:hover,
select option:focus { background-color: #2c3a8f; color: #fff; }

/* ---- Custom checkboxes: bigger, on-theme, obvious checked state. ---- */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin: 0;
  border: 2px solid var(--card-border);
  border-radius: 6px;
  background: rgba(0,0,0,0.25);
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}
input[type="checkbox"]:hover { border-color: rgba(251,234,235,0.5); }
input[type="checkbox"]:focus-visible { outline: 2px solid rgba(90,108,201,0.8); outline-offset: 2px; }
input[type="checkbox"]:checked {
  background: linear-gradient(135deg, var(--c-royal), var(--c-royal-soft));
  border-color: var(--c-royal-soft);
}
/* Checkmark drawn with a rotated border. */
input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 11px;
  border: solid #fff;
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}
/* Labels wrapping a checkbox get a pointer so the whole row is clickable. */
label.field.check { cursor: pointer; }

.btn-primary, .btn-warn, .btn-ghost, .btn-danger {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary {
  background: linear-gradient(135deg, var(--c-royal), var(--c-royal-soft));
  color: var(--c-pink);
  border-color: rgba(251,234,235,0.4);
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-warn   { background: rgba(220, 160, 50, 0.25); color: #ffe4b8; border-color: rgba(220,160,50,0.55); }
.btn-danger { background: rgba(200, 60, 80, 0.25); color: #ffdbe1; border-color: rgba(200,60,80,0.55); }
.btn-ghost  { background: rgba(255,255,255,0.06); color: var(--txt); border-color: var(--card-border); }
.btn-ghost:hover { background: rgba(255,255,255,0.12); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.error {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(200, 50, 70, 0.18);
  border: 1px solid rgba(255, 150, 165, 0.4);
  color: #ffd6dc;
  font-size: 13px;
}

code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: rgba(0,0,0,0.3); padding: 1px 6px; border-radius: 4px; }

/* ----------------- Login ----------------- */
.card-wrap {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 360px; }
.login-card .btn-primary { width: 100%; margin-top: 4px; }

/* ----------------- Shell (dashboard layout) ----------------- */
/* Two columns: a fixed collapsible sidebar on the left, scrolling main on the
   right. --sb-w drives the sidebar width and animates on collapse. */
.shell {
  position: relative;
  z-index: 1;
  --sb-w: 210px;
  display: grid;
  grid-template-columns: var(--sb-w) 1fr;
  gap: 14px;
  padding: 14px;
  min-height: 100vh;
  box-sizing: border-box;
  transition: grid-template-columns 0.25s ease;
}
.shell.sidebar-collapsed { --sb-w: 64px; }

.shell-sidebar {
  position: sticky;
  top: 14px;
  align-self: start;
  height: calc(100vh - 28px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 10px;
  border-radius: 14px;
  overflow: hidden;
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 8px;
  border-bottom: 1px solid var(--card-border);
}
.brand { font-size: 16px; font-weight: 700; white-space: nowrap; }
.sidebar-toggle {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: var(--txt);
  cursor: pointer;
  font-size: 16px; line-height: 1;
  font-family: inherit;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.12); }
.sidebar-toggle-icon { transition: transform 0.25s ease; }
.shell.sidebar-collapsed .sidebar-toggle-icon { transform: rotate(180deg); }

.shell-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  /* Don't grow to fill the sidebar — that pushed the logout/who block to the
     very bottom. Sit at natural height so the foot follows the last nav item;
     can still shrink + scroll if the list ever outgrows the sidebar. */
  flex: 0 1 auto;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  background: transparent;
  border-radius: 10px;
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: var(--txt); }
.nav-item.active {
  background: linear-gradient(135deg, var(--c-royal), var(--c-royal-soft));
  color: var(--c-pink);
}
.nav-icon {
  flex: 0 0 auto;
  width: 22px;
  font-size: 17px;
  text-align: center;
  line-height: 1;
}
.nav-label { transition: opacity 0.15s ease; }

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  padding-top: 8px;
  border-top: 1px solid var(--card-border);
}
#who-name { font-size: 12px; color: var(--hint); padding: 0 4px; }
.sidebar-foot .btn-ghost {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
}
.sidebar-foot .btn-ghost .nav-icon { font-size: 15px; }

.shell-main { min-width: 0; display: flex; flex-direction: column; gap: 14px; }

/* Collapsed: hide every text label + the brand word, center the icons. The
   nav items stay clickable (title attr provides a tooltip). */
.shell.sidebar-collapsed .nav-label,
.shell.sidebar-collapsed .brand-label,
.shell.sidebar-collapsed #who-name { display: none; }
.shell.sidebar-collapsed .nav-item,
.shell.sidebar-collapsed .sidebar-foot .btn-ghost {
  justify-content: center;
  gap: 0;
  padding-left: 0; padding-right: 0;
}
.shell.sidebar-collapsed .sidebar-top { justify-content: center; }
.shell.sidebar-collapsed .brand { font-size: 18px; }

@media (max-width: 640px) {
  .shell { --sb-w: 64px; }
  .shell .nav-label, .shell .brand-label, .shell #who-name { display: none; }
  .shell .nav-item, .shell .sidebar-foot .btn-ghost {
    justify-content: center; gap: 0; padding-left: 0; padding-right: 0;
  }
}

/* The active page-card grows with its content; the window handles scrolling
   so no inner section gets its own scrollbar. */
.page {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.page.d-none { display: none !important; }
.page > .page-head,
.page > .card-title {
  flex: 0 0 auto;
}

/* ----------------- Settings ----------------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.setting {
  padding: 14px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: rgba(0,0,0,0.15);
}

/* ----------------- Store ----------------- */
.store-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.store-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--card-border);
}
.store-row .emoji { font-size: 22px; line-height: 1; }
.store-row .info  { flex: 1; min-width: 0; }
.store-row .info b { display: block; font-size: 14px; }
.store-row .info .desc { color: var(--hint); font-size: 12px; }
.store-row .badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
}
.store-row .badge.off { background: rgba(200, 60, 80, 0.25); color: #ffd6dc; }
.store-row .actions { display: flex; gap: 6px; }

/* ----------------- Read-only table (deleted users audit log) ----------------- */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: var(--fg);
}
.admin-table thead th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--hint);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.02);
  white-space: nowrap;
}
.admin-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  vertical-align: top;
  white-space: nowrap;
}
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.admin-table td.muted { color: var(--hint); }
.admin-table .text-center { text-align: center; }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  line-height: 1.4;
}
.badge-info { background: rgba(80, 160, 240, 0.22); color: #cfe4ff; }
.badge-warn { background: rgba(240, 170, 60, 0.22); color: #ffe3b0; }

/* ----------------- Slide-in drawer
   Rendered at <body> level (not nested inside cards with backdrop-filter,
   which would otherwise create a containing block trapping position:fixed).
   Right side, full viewport height. Mobile: full width. Desktop >=720px: 30vw
   (min 360px, max 520px). Action buttons sit in the sticky header. */
.drawer-root {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 32, 0.62);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
  align-items: stretch;
  padding: 0;
  animation: fade-in 0.18s ease;
}
[dir="rtl"] .drawer-root { justify-content: flex-start; }
.drawer-root.d-none { display: none !important; }
/* While any drawer/modal is open, lock the page behind it so only the drawer
   scrolls (the backdrop covers the viewport; the body must not scroll). */
body:has(.drawer-root:not(.d-none)) { overflow: hidden; }

.drawer-panel {
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  border-radius: 0;
  padding-top: 0;
  display: flex;
  flex-direction: column;
  /* Whole panel scrolls (the header stays sticky at the top). Individual
     sections no longer scroll internally, so all content — however many
     transactions — flows in one scroll and the drawer scrolls to reveal it. */
  overflow-y: auto;
  overflow-x: hidden;
  /* Subtle scrollbar (Firefox); WebKit styled below via ::-webkit-scrollbar. */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.22) transparent;
  box-shadow: -16px 0 40px rgba(0, 0, 0, 0.45);
  animation: slide-in-right 0.22s cubic-bezier(.2,.9,.3,1.2);
}
.drawer-panel::-webkit-scrollbar { width: 8px; }
.drawer-panel::-webkit-scrollbar-track { background: transparent; }
.drawer-panel::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.18);
  border-radius: 8px;
}
.drawer-panel::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }
[dir="rtl"] .drawer-panel {
  box-shadow: 16px 0 40px rgba(0, 0, 0, 0.45);
  animation-name: slide-in-left;
}

@media (min-width: 720px) {
  .drawer-panel {
    width: 36vw;
    min-width: 400px;
    max-width: 580px;
  }
}

@keyframes slide-in-right { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide-in-left  { from { transform: translateX(-40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade-in        { from { opacity: 0; } to { opacity: 1; } }

/* Sticky header inside the drawer hosts the action buttons (Save/Cancel). */
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  margin: 0 -20px 12px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--card-border);
  background:
    linear-gradient(rgba(255,255,255,0.05), rgba(255,255,255,0.05)),
    #1a2566;
  flex: 0 0 auto;
  position: sticky;
  top: 0;
  z-index: 1;
}
.drawer-head .card-title { margin: 0; }
.drawer-head-actions {
  display: inline-flex;
  gap: 6px;
  flex-shrink: 0;
}

/* The form / body content scrolls with the whole panel (see .drawer-panel). */
.drawer-panel > form,
.drawer-panel > .drawer-balances,
.drawer-panel > .drawer-actions,
.drawer-panel > .card-subtitle,
.drawer-panel > ul,
.drawer-panel > #ud-more {
  flex: 0 0 auto;
}
.drawer-panel > form {
  flex: 0 0 auto;
}
.drawer-panel #ud-txns {
  flex: 0 0 auto;
}

/* ----------------- Users ----------------- */
#user-search,
#pur-search {
  width: 280px;
  max-width: 60vw;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: rgba(0,0,0,0.25);
  color: var(--txt);
  font-size: 13px;
}
.users-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.user-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--card-border);
  cursor: pointer;
  transition: background 0.15s ease;
}
.user-row:hover { background: rgba(255,255,255,0.06); }

/* Users pagination bar */
.users-pager {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.users-pages { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.users-page-btn { min-width: 34px; padding: 5px 9px; }
.users-page-btn.is-current {
  background: var(--accent, #4c8dff);
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}
.users-gap { padding: 0 4px; opacity: 0.6; }
.users-count { margin-left: auto; font-size: 12px; }
.user-row .who-text b { font-size: 14px; }
.user-row .who-text .uid { color: var(--hint); font-size: 11.5px; }
.user-row .bals {
  display: flex; gap: 10px; font-size: 13px; color: #ffe7c2;
}

.missions-admin-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
}
.mission-admin-card {
  padding: 14px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: rgba(0,0,0,0.18);
}
.mission-admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.mission-admin-head h3 {
  margin: 0;
  font-size: 16px;
}
.mission-admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.mission-admin-card h4 {
  margin: 14px 0 8px;
  font-size: 14px;
}
.mission-msg {
  display: grid;
  grid-template-columns: 180px 1fr 1fr 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.mission-msg-text {
  min-height: 132px;
  resize: vertical;
  background-color: rgba(0,0,0,0.25);
  border: 1px solid var(--card-border);
  color: var(--txt);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  width: 100%;
  font-family: inherit;
  line-height: 1.45;
}
.mission-msg-text:focus {
  border-color: rgba(251,234,235,0.45);
}
.mission-dm-card {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: rgba(0,0,0,0.22);
}
.mission-dm-card > .card-title { margin: 0 0 4px; }
.mission-dm-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}
.mission-dm {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.mission-dm > .checkline,
.mission-dm > .hint {
  grid-column: 1 / -1;
  margin: 0;
}
.mission-dm-text {
  min-height: 96px;
  resize: vertical;
  background-color: rgba(0,0,0,0.25);
  border: 1px solid var(--card-border);
  color: var(--txt);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  width: 100%;
  font-family: inherit;
  line-height: 1.45;
}
.mission-dm-text:focus {
  border-color: rgba(251,234,235,0.45);
}
.checkline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--txt);
  font-size: 13px;
}
.compact-field { max-width: 220px; }

@media (max-width: 900px) {
  .mission-msg { grid-template-columns: 1fr; }
  .mission-dm { grid-template-columns: 1fr; }
}

/* User drawer — referral overview block */
.ud-referral { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.ud-ref-row { display: flex; align-items: baseline; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.ud-ref-label { color: var(--hint); min-width: 92px; font-size: 12px; }
.ud-ref-code { letter-spacing: 0.5px; user-select: all; overflow-wrap: anywhere; }
.ud-ref-list { list-style: none; padding: 0 0 0 4px; margin: 2px 0 0; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.ud-ref-list li { overflow-wrap: anywhere; }
.ud-ref-list small, .ud-ref-row small { color: var(--hint); }
.ud-ref-empty { font-size: 12.5px; padding-left: 4px; }

.drawer-balances {
  display: flex;
  gap: 14px;
  margin: 12px 0;
}
.bal {
  flex: 1;
  padding: 10px 12px;
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  border: 1px solid var(--card-border);
  font-size: 16px;
  font-weight: 700;
}
.drawer-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.grant-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.grant-row #ud-grant-memo { grid-column: 1 / -1; }
.grant-row #ud-grant       { grid-column: 1 / -1; }
.grant-row input {
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: rgba(0,0,0,0.25);
  color: var(--txt);
  font-size: 13px;
}

.txn-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.txn-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--card-border);
  font-size: 13px;
}
.txn-row:last-child { border-bottom: 0; }
.txn-row .left { min-width: 0; overflow-wrap: anywhere; }
.txn-row .left b { display: block; font-size: 13px; }
.txn-row .left small { color: var(--hint); font-size: 11px; }
.txn-row .amt { font-weight: 700; white-space: nowrap; }
.txn-row .amt.credit { color: #b8f1d4; }
.txn-row .amt.debit  { color: #ffc8d0; }

/* ----------------- Toasts (admin) ----------------- */
.toast-stack {
  position: fixed;
  bottom: 16px;
  left: 12px; right: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
  max-width: 460px;
  margin: 0 auto;
}
.toast {
  pointer-events: auto;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: tin 0.25s ease;
}
.toast.success { background: rgba(34, 158, 96, 0.85); border: 1px solid rgba(120, 235, 175, 0.5); color: #f0fff7; }
.toast.error   { background: rgba(200, 50, 70, 0.85); border: 1px solid rgba(255, 150, 165, 0.5); color: #fff0f3; }
.toast.info    { background: rgba(52, 71, 170, 0.85); border: 1px solid rgba(251, 234, 235, 0.4); color: var(--c-pink); }
@keyframes tin { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ----------------- Stats page ----------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.stat-card {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--card-border);
}
.stat-label { color: var(--hint); font-size: 11.5px; font-weight: 600; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; }

.broadcast-form { display: block; }

/* Users page head: stack search + sort cleanly */
.page-head-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
#user-sort,
#user-page-size,
#user-timezone,
#pur-sort,
#pur-page-size {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background-color: rgba(0,0,0,0.25);
  color: var(--txt);
  font-size: 13px;
}

/* ----------------- Broadcast v2 ----------------- */
.bc-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bc-section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--hint);
  margin: 4px 0 0;
}
.bc-lang-tabs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 900px) {
  .bc-lang-tabs { grid-template-columns: 1fr 1fr 1fr; }
}
.bc-textarea-cell label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
  margin-bottom: 4px;
}
.bc-textarea-cell textarea {
  width: 100%;
  min-height: 110px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: rgba(0,0,0,0.25);
  color: var(--txt);
  font-size: 13px;
  resize: vertical;
}
.bc-textarea-fa textarea {
  direction: rtl;
  text-align: right;
  font-family: "Vazirmatn", system-ui, sans-serif;
}
.bc-textarea-fa label { text-align: right; }
.bc-filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(0,0,0,0.14);
  border: 1px solid var(--card-border);
}
.bc-filter-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
@media (min-width: 700px) {
  .bc-filter-row.bc-filter-row-2 { grid-template-columns: 1fr 1fr; }
}
.bc-and-chip {
  align-self: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  background: rgba(90, 120, 200, 0.22);
  color: #cfe0ff;
  border: 1px solid rgba(140, 170, 240, 0.35);
  width: max-content;
  margin: 2px auto;
}
.bc-audience-wrap {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(0,0,0,0.14);
}
.bc-audience-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--card-border);
  flex-wrap: wrap;
}
.bc-audience-scroll {
  max-height: 340px;
  overflow-y: auto;
}
.bc-audience-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.bc-audience-table thead th {
  position: sticky;
  top: 0;
  background: rgba(20, 24, 40, 0.98);
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hint);
  border-bottom: 1px solid var(--card-border);
  z-index: 1;
}
.bc-audience-table tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: middle;
}
.bc-audience-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.bc-audience-table th:first-child,
.bc-audience-table td:first-child {
  width: 34px;
  text-align: center;
}
.bc-send-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 0 0;
}
.bc-select-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(90, 120, 200, 0.15);
  border: 1px solid rgba(140, 170, 240, 0.28);
  font-size: 12.5px;
  color: var(--txt);
}
.bc-select-count strong { color: #cfe0ff; }
.bc-cap-warn {
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(230, 170, 50, 0.15);
  border: 1px solid rgba(230, 170, 50, 0.45);
  color: #ffd88a;
  font-size: 12px;
}
.bc-send-bar .spacer { flex: 1; }

/* Confirm drawer */
.bc-confirm-langs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.bc-lang-pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  border: 1px solid var(--card-border);
  background: rgba(0,0,0,0.2);
}
.bc-lang-pill strong { color: #cfe0ff; margin-left: 4px; }
.bc-lang-en { border-color: rgba(90, 160, 240, 0.5); }
.bc-lang-de { border-color: rgba(230, 200, 90, 0.5); }
.bc-lang-fa { border-color: rgba(90, 220, 160, 0.5); }
.bc-confirm-samples {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bc-confirm-lang-block {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--card-border);
}
.bc-confirm-lang-title {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--hint);
}
.bc-confirm-sample-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12.5px;
  line-height: 1.55;
}
.bc-confirm-sample-list li { margin-bottom: 2px; word-break: break-word; }

/* Schedule drawer + scheduled-broadcasts list */
.bc-schedule-when {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.bc-schedule-when .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bc-schedule-when input[type="datetime-local"],
.bc-schedule-when select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background-color: rgba(0,0,0,0.25);
  color: var(--tg-text, #eee);
  font-size: 13px;
}
#bc-schedule-preview {
  margin: 4px 0 0 0;
  font-size: 12.5px;
}

.bc-scheduled-panel {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--card-border);
}
.bc-scheduled-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.bc-scheduled-body {
  overflow-x: auto;
}
.bc-scheduled-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.bc-scheduled-table th,
.bc-scheduled-table td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--card-border);
}
.bc-scheduled-table th {
  color: var(--muted, #8892a0);
  font-weight: 600;
}
.bc-scheduled-cancel {
  padding: 4px 8px;
  font-size: 12px;
}

/* STAGING marker: a thick red frame around the whole admin viewport so the
   staging clone is unmistakable. Only drawn when admin.js sets
   data-staging="1" (i.e. the server reports settings.staging is true).
   pointer-events:none so it never eats clicks. */
html[data-staging="1"] body::after {
  content: "";
  position: fixed;
  inset: 0;
  border: 6px solid #ff2d2d;
  pointer-events: none;
  z-index: 99999;
}

/* ----------------- Sidebar live-connection status ----------------- */
.admin-rt {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  margin: 4px 6px 8px;
  border-radius: 10px;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--card-border);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
}
.rt-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}
.admin-rt[data-state="connecting"] { color: #ffcc55; }
.admin-rt[data-state="connecting"] .rt-dot { animation: rt-pulse 1s ease-in-out infinite; }
.admin-rt[data-state="online"]  { color: #5ff0a6; }
.admin-rt[data-state="online"] .rt-dot { animation: rt-breathe 2.4s ease-in-out infinite; }
.admin-rt[data-state="offline"] { color: #ff7676; }
@keyframes rt-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}
@keyframes rt-breathe {
  0%, 100% { opacity: 1;   box-shadow: 0 0 4px currentColor; }
  50%      { opacity: 0.55; box-shadow: 0 0 10px currentColor; }
}
.shell.sidebar-collapsed .admin-rt {
  justify-content: center;
  padding: 6px 0;
}
.shell.sidebar-collapsed .admin-rt .rt-label { display: none; }

/* ----------------- "Live" badge on the stats page head ----------------- */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: #5ff0a6;
}
.live-badge .rt-dot { animation: rt-breathe 2.4s ease-in-out infinite; }
.live-badge[data-state="off"] { color: #ff7676; }
.live-badge[data-state="off"] .rt-dot { animation: none; }

/* ----------------- Stats charts ----------------- */
.chart-card {
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--card-border);
  margin-top: 16px;
}
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.chart-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.chart-presets {
  display: inline-flex;
  gap: 4px;
}
.chart-preset {
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: rgba(0,0,0,0.25);
  color: var(--txt);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.chart-preset.is-active {
  background: #5ff0a6;
  color: #0b1220;
  border-color: #5ff0a6;
}
.chart-range {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--hint);
}
.chart-range input[type="date"],
.chart-key {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background-color: rgba(0,0,0,0.25);
  color: var(--txt);
  font-size: 12px;
}
/* Keep the shared select caret (the global `select` rule provides it); just
   make room for it on the compact chart selector. */
.chart-key { padding-right: 30px !important; }
.chart-canvas-wrap {
  position: relative;
  height: 300px;
  margin-top: 10px;
}


/* ----------------- Data table (Purchases page) ----------------- */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--card-border); }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead th {
  text-align: left;
  padding: 10px 12px;
  background: rgba(0,0,0,0.28);
  color: var(--hint);
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  border-bottom: 1px solid var(--card-border);
}
.data-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  vertical-align: top;
}
.data-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.pur-user, .pur-name, .pur-uid { display: block; }
.pur-name { font-size: 12px; }
.pur-uid { font-size: 11px; }

/* ---------------- Admins page (root-only) ---------------- */
.ta-r { text-align: right; }
.au-pages {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 4px;
}
.au-page-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.au-page-check input { margin: 0; }
.au-pages-cell { font-size: 12px; color: var(--muted, #9aa4b2); }
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
}
.pill-ok  { background: rgba(46, 160, 67, 0.18); color: #7ee787; }
.pill-off { background: rgba(248, 81, 73, 0.16); color: #ff8a8a; }

