:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e38;
  --text: #e6e8ec;
  --muted: #8b909c;
  --accent: #4f8cff;
  --accent-hover: #6ba3ff;
  --green: #3ecf8e;
  --green-bright: #22e88f;
  --red: #ff5c5c;
  --red-hover: #ff7a7a;
  --amber: #f5a623;
}

* { box-sizing: border-box; }

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

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

nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

nav .brand { font-weight: 600; }
nav .links a { margin-right: 16px; color: var(--muted); }
nav .links a.active { color: var(--text); font-weight: 600; }
nav form { display: inline; }
nav button.link-btn {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0;
}
nav button.link-btn:hover { color: var(--text); text-decoration: underline; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 12px; }

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

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
th[data-sort-col]:hover { color: var(--text); }
table.normal-case th { text-transform: none; letter-spacing: normal; font-size: 13px; }
tr:hover td { background: rgba(255,255,255,0.02); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  margin: 2px 4px 2px 0;
}
.badge-active { background: rgba(62,207,142,0.15); color: var(--green); }
/* Slightly brighter than badge-active — used only for the Stripe status
   column, on "Active" (actually paying) specifically, so it reads as a
   step up from "Trialing" (which keeps the regular badge-active green)
   rather than looking identical at a glance. */
.badge-active-bright { background: rgba(34,232,143,0.18); color: var(--green-bright); }
.badge-pending, .badge-warning { background: rgba(245,166,35,0.15); color: var(--amber); }
.badge-disabled, .badge-revoked { background: rgba(255,92,92,0.15); color: var(--red); }
.badge-inactive { background: rgba(139,144,156,0.15); color: var(--muted); }
.badge-info { background: rgba(79,140,255,0.15); color: var(--accent); }
.badge-level-gold { background: rgba(212,175,55,0.18); color: #d4af37; }
.badge-level-silver { background: rgba(192,197,206,0.18); color: #c0c5ce; }
.badge-level-lifetime { background: rgba(167,139,250,0.18); color: #a78bfa; }

.filters { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; }
.filters select { width: auto; }

.search-wrap { position: relative; flex: 1; }
.search-wrap input { padding-right: 40px; }
.search-clear {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.search-clear:hover { color: var(--text); }

.note-dismiss {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.note-dismiss:hover { color: var(--red); }

input[type=text], input[type=email], input[type=password], select, textarea {
  background: #0f1115;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
}
textarea { min-height: 70px; font-family: inherit; }

label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.field { margin-bottom: 10px; }

/* Label-left/field-right row, used throughout the subscriber profile to
   save the line a stacked label would otherwise take — the label keeps
   its own width, the field takes whatever's left. Date inputs stay at
   their natural compact width instead of stretching full-width. */
.field-inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.field-inline > label { margin-bottom: 0; white-space: nowrap; flex-shrink: 0; }
.field-inline input[type=text], .field-inline input[type=email], .field-inline select { flex: 1 1 160px; min-width: 0; }
.field-inline input[type=date] { width: auto; flex: 0 0 auto; }

/* Three button tones, used the same way everywhere in the app: primary
   (blue) for the constructive/"do this" action in a group — Save, Enable,
   Generate, Grant, Add, external links (Stripe, Welcome email); secondary
   (bordered) for neutral/read-only utility — Check, Sync, Copy, Cancel
   (dismiss a form), Import, Search; danger (red) for anything that removes
   or cancels access. Picking a button's color is picking which of those
   three it is — nothing is styled by exception. */
button, .btn {
  background: var(--accent);
  border: 1px solid transparent;
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s ease, border-color 0.15s ease, filter 0.15s ease;
}
button:hover, .btn:hover { background: var(--accent-hover); }

button.secondary, .btn.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
button.secondary:hover, .btn.secondary:hover { background: rgba(79, 140, 255, 0.1); border-color: var(--accent); color: #fff; }

button.danger, .btn.danger { background: var(--red); }
button.danger:hover, .btn.danger:hover { background: var(--red-hover); }

button.small, .btn.small { padding: 4px 10px; font-size: 12px; }

/* Immediate "pressed" feedback on click/tap, before the request even goes out. */
button:active, .btn:active {
  transform: translateY(1px);
  filter: brightness(0.85);
}

/* Once a form actually submits, the clicked button dims and locks until the
   page navigates away (see the submit listener in partials/foot.ejs) — a
   full page load always resets this back to normal. */
button.is-loading, .btn.is-loading,
button:disabled, .btn:disabled {
  opacity: 0.55;
  cursor: wait;
  filter: grayscale(0.4);
}

/* "Emails" button on a subscriber's profile — click opens a menu of every
   Gmail-compose template (see the "Emails" page), instead of one link per
   template. */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 190px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 20;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a {
  display: block;
  padding: 8px 10px;
  border-radius: 5px;
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
}
.dropdown-menu a:hover { background: rgba(79, 140, 255, 0.12); }

.link-danger {
  background: none;
  border: none;
  padding: 0;
  color: var(--red);
  font-size: 13px;
  cursor: pointer;
}
.link-danger:hover { text-decoration: underline; }

.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.checkbox-row input { width: auto; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; max-height: 220px; overflow-y: auto; }
.flash-success { background: rgba(62,207,142,0.12); color: var(--green); border: 1px solid rgba(62,207,142,0.3); }
.flash-error { background: rgba(255,92,92,0.12); color: var(--red); border: 1px solid rgba(255,92,92,0.3); }

.muted { color: var(--muted); }
.empty { color: var(--muted); font-style: italic; padding: 20px 0; }

.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box { width: 320px; }

.subscriber-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.subscriber-header h1 { margin-bottom: 2px; }

.dashboard-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.dashboard-actions form { display: inline; }

.check-all-group { display: inline-flex; align-items: center; gap: 7px; }
.check-all-group form { display: inline; }
.check-all-toggle { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 0; font-size: 12px; text-transform: none; letter-spacing: normal; color: var(--muted); cursor: pointer; white-space: nowrap; }
.check-all-toggle input[type="checkbox"] { margin: 0; cursor: pointer; }
.check-all-toggle:hover { color: var(--text); }

.stats-strip { display: flex; flex-wrap: wrap; gap: 28px; padding: 12px 20px; margin-bottom: 12px; }
.stat-tile { min-width: 100px; }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; }

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
  margin-bottom: 20px;
}
.profile-grid .card { margin-bottom: 0; }
.profile-grid .span-2 { grid-column: 1 / -1; }

/* Statistics page */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.stats-grid .card { margin-bottom: 0; }
.stats-grid .span-2 { grid-column: 1 / -1; }

.proportion-bar { display: flex; height: 22px; border-radius: 6px; overflow: hidden; background: var(--border); margin-top: 10px; }
.proportion-segment { height: 100%; }
.proportion-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.proportion-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

.revenue-bars { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }
.revenue-bar-row { display: flex; align-items: center; gap: 12px; }
.revenue-bar-label { width: 130px; font-size: 13px; color: var(--muted); flex-shrink: 0; }
.revenue-bar-track { flex: 1; background: var(--border); border-radius: 6px; height: 20px; overflow: hidden; }
.revenue-bar-fill { height: 100%; border-radius: 6px; transition: width 0.3s ease; }
.revenue-bar-value { width: 110px; text-align: right; font-weight: 600; flex-shrink: 0; }

.stat-compare { font-size: 13px; margin-top: 6px; }
.stat-compare.up { color: var(--green); }
.stat-compare.down { color: var(--red); }
.stat-compare.flat { color: var(--muted); }

.signup-chart { display: flex; align-items: flex-end; gap: 4px; height: 150px; margin-top: 18px; }
.signup-chart-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.signup-chart-count { font-size: 10px; color: var(--muted); margin-bottom: 3px; }
.signup-chart-bar { width: 100%; max-width: 30px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 3px; }
.signup-chart-label { font-size: 10px; color: var(--muted); margin-top: 6px; white-space: nowrap; }
.name-row { display: flex; gap: 12px; }
.name-row .field { flex: 1; }

/* Inner two-column split inside the Profile card: contact fields on the
   left, Notes/Billing review note/Reminders on the right — keeps them
   next to Email/TradingView username instead of taking up separate cards
   further down the page. */
.profile-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; margin-top: 10px; }

@media (max-width: 720px) {
  .profile-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .profile-two-col { grid-template-columns: 1fr; }
}

.access-list { list-style: none; padding: 0; margin: 0; }
.access-list li { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.access-list li:last-child { border-bottom: none; }

.log-list { list-style: none; padding: 0; margin: 0; }
.log-list li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.log-list li:last-child { border-bottom: none; }
.log-list .log-meta { color: var(--muted); }
