/* Shared theme for all admin pages. */
:root {
  --admin-navy: #111827;
  --admin-navy-soft: #1f2937;
  --admin-red: #e43b2c;
  --admin-blue: #0075b2;
  --admin-bg: #f5f7fa;
  --admin-line: #dce3eb;
  --admin-ink: #243247;
  --admin-muted: #59677b;
  --admin-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --admin-shadow: 0 2px 8px rgba(17,24,39,.035);
}

* { box-sizing: border-box; }

body.admin-body {
  margin: 0;
  font-family: var(--admin-font);
  font-size: 14px;
  line-height: 1.6;
  background: var(--admin-bg);
  color: var(--admin-ink);
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.admin-sidebar {
  width: 256px;
  flex-shrink: 0;
  background: var(--admin-navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  scrollbar-width: thin;
}
.admin-sidebar__brand { display: flex; align-items: center; gap: 10px; margin-bottom: 30px; }
.admin-sidebar__brand img { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; }
.admin-sidebar__brand strong { display: block; font-size: 15px; line-height: 1.2; }
.admin-sidebar__brand span { display: block; font-size: 11px; color: #9ca3af; }
.admin-sidebar__navigation { flex: 1 0 auto; }
.admin-sidebar__secondary { border-top: 1px solid rgba(255,255,255,.1); padding-top: 16px; margin-top: 24px; }
.admin-nav__heading { color: #9ca3af; font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; padding: 0 14px; margin-bottom: 12px; }
.admin-nav { list-style: none; margin: 0; padding: 0; }
.admin-nav li + li { margin-top: 4px; }
.admin-nav a, .admin-nav summary {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 8px;
  color: #cbd2e1; text-decoration: none; font-size: 14px; font-weight: 600;
}
.admin-nav a:hover, .admin-nav summary:hover { background: rgba(255,255,255,.06); color: #fff; }
.admin-nav a.is-active { background: #263b53; color: #fff; box-shadow: inset 3px 0 #73b9ec; }
.admin-nav summary { cursor: pointer; list-style: none; }
.admin-nav summary::-webkit-details-marker { display: none; }
.admin-nav__group.has-active-child > summary { color: #fff; }
.admin-nav__chevron { margin-left: auto; font-size: 22px; line-height: 1; transition: transform .15s ease; }
.admin-nav__group[open] > summary .admin-nav__chevron { transform: rotate(90deg); }
.admin-nav__children { list-style: none; margin: 6px 0 10px 22px; padding: 0 0 0 12px; border-left: 1px solid #42516a; }
.admin-nav__children a { padding: 9px 12px; font-size: 13px; font-weight: 500; justify-content: space-between; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.admin-nav .nav-icon { width: 18px; text-align: center; }
.admin-sidebar__quote {
  font-size: 12px; font-style: italic; color: #9ca3af;
  border-top: 1px solid rgba(255,255,255,.1); padding-top: 16px; margin-top: 16px;
}
.admin-sidebar__foot { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.admin-sidebar__foot a { color: #cbd2e1; text-decoration: none; font-size: 13px; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.admin-sidebar__foot a:hover { color: #fff; }

/* --- Main column --- */
.admin-main { flex: 1; min-width: 0; padding: 32px 36px 60px; }
.admin-topbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.admin-topbar h1 { margin: 0; font-size: 28px; font-weight: 650; letter-spacing: -.035em; line-height: 1.25; }
.admin-topbar p { margin: 8px 0 0; color: var(--admin-muted); font-size: 14px; max-width: 85ch; }
.admin-topbar__right { display: flex; align-items: center; gap: 14px; }
.admin-chip { background: #fff; border: 1px solid var(--admin-line); border-radius: 8px; padding: 8px 14px; font-size: 13px; color: var(--admin-muted); }
.admin-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--admin-navy); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }

/* --- Stat cards --- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card { background: #fff; border: 1px solid var(--admin-line); border-radius: 12px; padding: 22px; box-shadow: var(--admin-shadow); }
.stat-card__icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; margin-bottom: 10px; }
.stat-card__num { font-size: 30px; font-weight: 650; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat-card__label { font-size: 13px; color: var(--admin-muted); font-weight: 600; }
.stat-card__meta { font-size: 12px; color: #16a34a; font-weight: 700; margin-top: 4px; }

/* --- Panels / grid --- */
.admin-grid { display: grid; grid-template-columns: 2fr 2fr 2fr; gap: 16px; margin-bottom: 22px; }
.admin-grid--split { display: grid; grid-template-columns: 3fr 1.3fr; gap: 16px; }
.panel { background: #fff; border: 1px solid var(--admin-line); border-radius: 12px; padding: 24px; box-shadow: var(--admin-shadow); }
.panel h2 { margin: 0 0 12px; font-size: 19px; font-weight: 650; line-height: 1.35; letter-spacing: -.02em; }
.panel h3 { margin: 0 0 16px; font-size: 16px; font-weight: 650; line-height: 1.4; }
.panel p { margin: 0 0 16px; color: var(--admin-muted); max-width: 95ch; }
.panel p:last-child { margin-bottom: 0; }
.admin-main a:not(.btn):not(.settings-tabs a):not(.source-pill) { color: var(--admin-blue); text-underline-offset: 3px; }
.panel .panel-link { font-size: 12px; color: var(--admin-red); text-decoration: none; font-weight: 700; }

.legend-list { list-style: none; margin: 12px 0 0; padding: 0; font-size: 12px; }
.legend-list li { display: flex; justify-content: space-between; padding: 4px 0; }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; }

.bar-list { list-style: none; margin: 0; padding: 0; }
.bar-list li { margin-bottom: 12px; font-size: 13px; }
.bar-list .bar-row { display: flex; justify-content: space-between; margin-bottom: 4px; color: var(--admin-muted); }
.bar-track { background: var(--admin-line); border-radius: 6px; height: 7px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--admin-blue); }

/* --- Tables --- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 14px; }
.admin-table { width: 100%; min-width: 640px; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: var(--admin-shadow); }
.admin-table th, .admin-table td { padding: 16px 18px; border-bottom: 1px solid var(--admin-line); text-align: left; font-size: 14px; }
.admin-table td { vertical-align: top; }
.admin-table th { background: #edf2f7; color: #46556b; font-weight: 600; font-size: 12px; }
.admin-table tbody tr:not(.source-details):hover { background: #f8fafc; }
.admin-table tbody tr:last-child td { border-bottom: 0; }
.lead-name { display: flex; align-items: center; gap: 10px; }
.lead-avatar { width: 30px; height: 30px; border-radius: 50%; background: #eef1f8; color: var(--admin-navy); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; }
.source-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: #f4f6fb; font-size: 12px; font-weight: 600; border: none; cursor: pointer; }
.badge { display: inline-block; padding: 4px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; line-height: 1.5; }
.badge-new { background: #dbeafe; color: #1e40af; }
.badge-contacted { background: #fef3c7; color: #92400e; }
.badge-registered { background: #dcfce7; color: #166534; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }
select.status-select { min-height: 36px; font-size: 13px; }
.view-link { color: var(--admin-blue); text-decoration: none; font-size: 12px; font-weight: 700; }
tr.source-details td { background: #fafbff; padding: 16px 18px; }
.source-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 24px; font-size: 13px; overflow-wrap: anywhere; color: var(--admin-muted); }
.source-grid__wide { grid-column: 1 / -1; }
.source-grid strong { color: var(--admin-ink); }

/* --- Activity / quick actions --- */
.quick-actions { list-style: none; margin: 0; padding: 0; }
.quick-actions li + li { margin-top: 4px; }
.quick-actions a { display: flex; align-items: center; gap: 10px; padding: 8px 4px; text-decoration: none; color: var(--admin-ink); font-size: 13px; font-weight: 600; border-radius: 8px; }
.quick-actions a:hover { background: #f4f6fb; }
.quick-actions .dot { width: 8px; height: 8px; border-radius: 50%; }

.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--admin-line); }
.activity-item:last-child { border-bottom: none; }
.activity-icon { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.activity-title { font-size: 13px; font-weight: 700; }
.activity-sub { font-size: 12px; color: var(--admin-muted); }
.activity-time { font-size: 11px; color: #9aa1b3; margin-left: auto; white-space: nowrap; }

/* --- Filters / forms --- */
.filters { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; padding: 16px; background: #fff; border: 1px solid var(--admin-line); border-radius: 12px; }
.filters input { flex: 1 1 240px; min-width: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; background: var(--admin-blue); color: #fff; border: 1px solid transparent; border-radius: 8px; padding: 10px 18px; font: 600 14px/1.4 var(--admin-font); cursor: pointer; text-decoration: none; }
.btn:hover:not(:disabled) { background: #005e91; }
.btn-secondary { background: #fff; color: var(--admin-ink); border: 1px solid var(--admin-line); }
.btn-secondary:hover:not(:disabled) { background: #edf2f7; }
.btn-danger { background: #b91c1c; }
.btn-danger:hover:not(:disabled) { background: #991b1b; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

:where(.admin-body, .admin-login) input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
:where(.admin-body, .admin-login) select,
:where(.admin-body, .admin-login) textarea {
  min-height: 42px; max-width: 100%; padding: 10px 12px;
  border: 1px solid #c5cfdb; border-radius: 8px; background: #fff;
  color: var(--admin-ink); font: 400 14px/1.5 var(--admin-font);
}
:where(.admin-body, .admin-login) textarea { min-height: 110px; resize: vertical; }
:where(.admin-body, .admin-login) input::placeholder,
:where(.admin-body, .admin-login) textarea::placeholder { color: #69778b; opacity: 1; }
:where(.admin-body, .admin-login) input[type="checkbox"],
:where(.admin-body, .admin-login) input[type="radio"] { width: 16px; height: 16px; accent-color: var(--admin-blue); vertical-align: middle; }
:where(.admin-body, .admin-login) :is(input, select, textarea):focus { border-color: var(--admin-blue); }
:where(.admin-body, .admin-login) :is(a, button, summary, input, select, textarea):focus-visible { outline: 3px solid #57a3d4; outline-offset: 3px; }
.admin-main label, .login-box label { font-size: 14px; font-weight: 600; color: var(--admin-ink); }
.admin-main code { font-size: .9em; overflow-wrap: anywhere; }

.settings-form .field { margin-bottom: 18px; }
.settings-form label { display: block; margin-bottom: 8px; }
.settings-form .hint { font-size: 13px; color: var(--admin-muted); margin: 8px 0 16px; }
.settings-form input[type="text"], .settings-form input[type="email"], .settings-form input[type="url"] {
  width: 100%;
}
.settings-section { margin-bottom: 28px; padding-bottom: 24px; border-bottom: 1px solid var(--admin-line); }
.settings-section h3 { margin-bottom: 18px; }
.settings-form > .settings-section { max-width: 820px; }
.alert { padding: 14px 18px; border-radius: 10px; font-size: 14px; font-weight: 500; margin-bottom: 20px; overflow-wrap: anywhere; }
.alert-success { background: #dcfce7; color: #166534; }

/* --- Mobile top bar + off-canvas drawer (hidden on desktop) --- */
.admin-mobile-bar { display: none; }
.admin-sidebar-backdrop { display: none; }

@media (max-width: 780px) {
  body.admin-body { flex-direction: column; }
  .admin-main .admin-avatar { display: none; }

  .admin-mobile-bar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 30;
    background: var(--admin-navy); color: #fff;
    padding: 12px 16px;
  }
  .admin-mobile-bar__toggle {
    display: flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 34px; height: 34px; padding: 0; border: 0; background: none; cursor: pointer;
  }
  .admin-mobile-bar__toggle span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; }
  .admin-mobile-bar__brand { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
  .admin-mobile-bar__brand img { width: 26px; height: 26px; border-radius: 6px; }
  .admin-mobile-bar__brand strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .admin-avatar--sm { width: 30px; height: 30px; font-size: 11px; flex-shrink: 0; }

  .admin-sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 40;
    height: 100dvh; visibility: hidden;
    transform: translateX(-100%); transition: transform .25s ease;
  }
  body.admin-nav-open .admin-sidebar { visibility: visible; transform: translateX(0); box-shadow: 8px 0 24px rgba(0,0,0,.25); }
  body.admin-nav-open .admin-sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 35; background: rgba(17,24,39,.55);
  }
  body.admin-nav-open { overflow: hidden; }
}

@media (max-width: 1100px) {
  .admin-grid, .admin-grid--split { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .admin-main { padding: 16px 14px 40px; }
  .admin-topbar { flex-direction: column; align-items: stretch; }
  .admin-topbar__right { justify-content: space-between; }
  .admin-topbar h1 { font-size: 22px; }
  .stat-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat-card { padding: 14px; }
  .stat-card__num { font-size: 21px; }
  .panel { padding: 14px 16px; }
  .filters { flex-direction: column; }
  .filters input { flex: auto; }
  .filters input, .filters select, .filters .btn { width: 100%; }
  :where(.admin-body, .admin-login) input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
  :where(.admin-body, .admin-login) select,
  :where(.admin-body, .admin-login) textarea { font-size: 16px; }
  select.status-select { font-size: 16px; }
  .source-grid { grid-template-columns: 1fr; }
  .mj-pagination { flex-wrap: wrap; }
}


.settings-form select, .settings-form textarea { width: 100%; }
.template-library-list { display: grid; gap: 18px; }
.template-library-entry { border: 1px solid var(--admin-line); border-radius: 10px; padding: 20px; overflow-wrap: anywhere; }
.template-library-entry form { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 12px; }
.template-library-entry form label { margin: 0; }
.template-library-notes { white-space: pre-wrap; }
.settings-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.settings-tabs a { padding: 9px 16px; border: 1px solid #d9dde3; border-radius: 8px; background: #fff; color: #374151; font-weight: 600; font-size: 14px; text-decoration: none; }
.settings-tabs a:hover { border-color: #9ca3af; }
.settings-tabs a.is-active { border-color: var(--admin-blue); background: var(--admin-blue); color: #fff; }

.alert-error { background: #fee2e2; color: #991b1b; }
.mj-sync-status { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; font-size: 14px; overflow-wrap: anywhere; }
.mj-sync-status__error { color: #991b1b; }
.mj-sync-details { margin-top: 24px; }
.mj-sync-details > summary { cursor: pointer; font-size: 15px; font-weight: 600; }
.mj-sync-details > summary .mj-sync-status__error { display: inline-block; margin-left: 12px; font-size: 13px; font-weight: 500; }
.mj-sync-details > .mj-sync-status { margin: 18px 0 0; padding-top: 18px; border-top: 1px solid var(--admin-line); }
.mj-members-table { min-width: 960px; }
.mj-members-table td small { display: block; margin-top: 4px; color: var(--admin-muted); overflow-wrap: anywhere; }
.mj-members-table td strong { display: block; }
.mj-members-table .source-grid strong { display: inline; }
.mj-details-toggle { padding: 4px 10px; font-size: 12px; white-space: nowrap; }
.mj-empty { text-align: center !important; padding: 30px !important; }
.mj-pagination { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; font-size: 13px; color: var(--admin-muted); }
.mj-pagination > div { display: flex; gap: 8px; }

.affiliate-panel, .referral-panel { margin-bottom: 24px; }
.affiliate-form, .claim-form { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 16px 0; }
.affiliate-rate { width: 140px; }
.affiliate-code { overflow-wrap: anywhere; }
.affiliate-form--stacked { display: grid; justify-items: start; max-width: 820px; }
.affiliate-form--stacked > input:not([type="hidden"]), .affiliate-form--stacked > select { width: 100%; }
.affiliate-form--settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 20px; max-width: 820px; }
.affiliate-form--settings .field { min-width: 0; }
.affiliate-form--settings label { display: block; margin-bottom: 8px; }
.affiliate-form--settings input:not([type="hidden"]), .affiliate-form--settings select { width: 100%; }
.affiliate-form--settings .form-actions { grid-column: 1 / -1; }
.admin-table .affiliate-form label { flex-basis: 100%; font-size: 13px; }
.referral-panel td { overflow-wrap: anywhere; }
.referral-claim { padding: 20px; margin-bottom: 20px; border: 1px solid var(--admin-line); border-radius: 10px; overflow-wrap: anywhere; }
.claim-form .field { flex: 1 1 260px; min-width: 0; }
.claim-form label { display: block; margin-bottom: 8px; }
.claim-form .field input, .claim-form .field select { width: 100%; }
.claim-form .form-actions { display: flex; flex-wrap: wrap; gap: 12px; width: 100%; }
.referral-audit { padding-bottom: 16px; border-bottom: 1px solid var(--admin-line); overflow-wrap: anywhere; }
.mj-financial-form { display: grid; gap: 16px; max-width: 820px; padding: 16px 0; }
.mj-financial-form label { display: block; }
.mj-financial-form :is(input:not([type="hidden"]):not([type="checkbox"]), select, textarea) { display: block; width: 100%; margin-top: 6px; }
.mj-members-table pre { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 420px; font-size: 12px; }
.mj-members-table details { margin-top: 12px; }
.mj-members-table details form { display: grid; gap: 10px; padding: 12px 0; }
.mj-members-table td > form { display: grid; gap: 10px; }
.admin-login { margin: 0; padding: 48px 16px; min-height: 100vh; background: var(--admin-bg); color: var(--admin-ink); font: 14px/1.6 var(--admin-font); }
.login-box { width: 100%; max-width: 420px; margin: 5vh auto; background: #fff; padding: 32px; border: 1px solid var(--admin-line); border-radius: 16px; box-shadow: var(--admin-shadow); }
.login-box__brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; font-weight: 600; }
.login-box__brand img { width: 40px; height: 40px; border-radius: 8px; }
.login-box h1 { margin: 0 0 8px; font-size: 26px; font-weight: 650; letter-spacing: -.03em; }
.login-box > p { color: var(--admin-muted); margin: 0 0 24px; }
.login-box label { display: block; margin-bottom: 8px; }
.login-box input:not([type="hidden"]) { width: 100%; margin-bottom: 20px; }
.login-box .btn { width: 100%; }
@media (max-width: 600px) {
  .affiliate-form--settings { grid-template-columns: 1fr; }
  .affiliate-form:not(.admin-table .affiliate-form) { align-items: stretch; }
  .affiliate-form:not(.admin-table .affiliate-form) > select { width: 100%; }
  .claim-form > input:not([type="hidden"]), .claim-form > select { width: 100%; }
  .login-box { padding: 24px; margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .admin-sidebar, .admin-nav__chevron { transition: none; }
}
