/* ==========================================================================
   TracelyCRM Admin — tokens shared with the app, dense layout for operators.
   ========================================================================== */

:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-alt: #f4f4f5;
  --surface-hover: #f1f1f3;
  --border: #e6e6e9;
  --border-strong: #d4d4d8;
  --text: #09090b;
  --text-muted: #52525b;
  --text-subtle: #71717a;
  --brand: #1d4fd7;
  --brand-strong: #1740ae;
  --brand-ink: #12306f;
  --brand-tint: #eef2ff;
  --green: #12805c;
  --green-tint: #e3f5ec;
  --amber: #9c6200;
  --amber-tint: #fdf3dc;
  --red: #c92a42;
  --red-tint: #fdecee;
  --violet: #6440d6;
  --violet-tint: #efeafc;
  --slate-tint: #f1f1f3;
  --nav-bg: #fbfbfc;
  --nav-active: #ececef;
  --chart-bar: #1d4fd7;
  --chart-grid: #ececef;
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(9, 9, 11, .04);
  --shadow-lg: 0 2px 6px rgba(9, 9, 11, .06), 0 20px 44px -16px rgba(9, 9, 11, .24);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-alt: #141414;
  --surface-hover: #1a1a1a;
  --border: #1f1f1f;
  --border-strong: #2e2e2e;
  --text: #ededed;
  --text-muted: #a3a3a3;
  --text-subtle: #7a7a7a;
  --brand: #4c8dff;
  --brand-strong: #79a8ff;
  --brand-ink: #c3d6ff;
  --brand-tint: #0e1626;
  --green: #4cc38f;
  --green-tint: #0a2117;
  --amber: #e8b44a;
  --amber-tint: #261c06;
  --red: #f47c8e;
  --red-tint: #2a0e13;
  --violet: #a78bfa;
  --violet-tint: #18122e;
  --slate-tint: #171717;
  --nav-bg: #050505;
  --nav-active: #1c1c1c;
  --chart-bar: #4c8dff;
  --chart-grid: #1c1c1c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .6);
  --shadow-lg: 0 0 0 1px rgba(255, 255, 255, .04), 0 24px 56px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.011em; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
[hidden] { display: none !important; }
.icon { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.loading { color: var(--text-muted); padding: 40px 0; text-align: center; }

/* ---------- shell ------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }
.nav {
  position: fixed; inset: 0 auto 0 0; width: 224px; z-index: 40;
  display: flex; flex-direction: column; background: var(--nav-bg); border-right: 1px solid var(--border);
}
.nav__brand { display: flex; align-items: center; gap: 9px; padding: 18px 18px 14px; color: var(--text); font-weight: 700; font-size: 15px; letter-spacing: -.02em; }
.nav__brand:hover { text-decoration: none; }
.nav__brand em { font-style: normal; font-weight: 600; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--brand); background: var(--brand-tint); padding: 2px 6px; border-radius: 5px; margin-left: 2px; }
.nav__list { flex: 1; display: flex; flex-direction: column; gap: 1px; padding: 6px 10px; }
.nav__item { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: var(--radius-sm); color: var(--text-muted); font-weight: 500; }
.nav__item .icon { color: var(--text-subtle); }
.nav__item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav__item.is-active { background: var(--nav-active); color: var(--text); font-weight: 600; }
.nav__item.is-active .icon { color: var(--brand); }
.nav__foot { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.nav__theme { border: 0; background: none; font: inherit; font-size: 12.5px; color: var(--text-muted); text-align: left; padding: 4px 2px; cursor: pointer; }
.nav__theme:hover { color: var(--text); }
.nav__me { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.nav__me-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav__me-email { font-size: 12px; color: var(--text-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 35; }

.main { flex: 1; min-width: 0; margin-left: 224px; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 18px 28px 6px; }
.top__menu { display: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: var(--radius-sm); width: 36px; height: 36px; cursor: pointer; font-size: 16px; }
.top__titles { flex: 1; min-width: 0; }
.top__title { font-size: 20px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.top__sub { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }
.top__sub:empty { display: none; }
.top__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.content { padding: 14px 28px 64px; display: flex; flex-direction: column; gap: 16px; max-width: 1400px; width: 100%; }

@media (max-width: 900px) {
  .nav { transform: translateX(-100%); transition: transform .18s ease; }
  .nav.is-open { transform: none; box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .top { padding: 14px 16px 4px; }
  .top__menu { display: inline-grid; place-items: center; }
  .content { padding: 12px 16px 48px; }
}

/* ---------- primitives --------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover:not(:disabled) { background: var(--surface-hover); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--brand-strong); border-color: var(--brand-strong); }
:root[data-theme='dark'] .btn--primary { color: #000; }
.btn--danger { color: var(--red); }
.btn--danger:hover:not(:disabled) { background: var(--red-tint); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn--sm { padding: 4px 10px; font-size: 12.5px; }
.btn--block { width: 100%; }

.input, .select, .textarea {
  font: inherit; font-size: 13.5px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 10px; min-width: 0;
}
.textarea { width: 100%; min-height: 90px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field__label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field__hint { font-size: 12px; color: var(--text-subtle); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); min-width: 0; }
.card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 18px 0; }
.card__title { font-size: 14px; font-weight: 650; }
.card__sub { margin: 2px 0 0; font-size: 12.5px; color: var(--text-muted); }
.card__body { padding: 14px 18px 18px; }
.card__body--flush { padding: 10px 0 0; }

.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .grid--2, .grid--3 { grid-template-columns: minmax(0, 1fr); } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------- KPI tiles ----------------------------------------------------- */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.kpi__label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.kpi__value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi__foot { font-size: 12px; color: var(--text-subtle); margin-top: 2px; }

/* ---------- badges -------------------------------------------------------- */

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 650; border: 1px solid transparent; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--plain::before { display: none; }
.badge--trialing { background: var(--brand-tint); color: var(--brand-ink); }
.badge--active { background: var(--green-tint); color: var(--green); }
.badge--complimentary { background: var(--violet-tint); color: var(--violet); }
.badge--cancelling, .badge--past_due { background: var(--amber-tint); color: var(--amber); }
.badge--on_hold, .badge--suspended, .badge--disabled { background: var(--red-tint); color: var(--red); }
.badge--expired, .badge--not_started, .badge--muted { background: var(--slate-tint); color: var(--text-muted); }
.badge--admin { background: var(--brand-tint); color: var(--brand-ink); }

/* ---------- tables -------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11.5px; font-weight: 650; color: var(--text-subtle); text-transform: uppercase; letter-spacing: .04em; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table th:first-child, .table td:first-child { padding-left: 18px; }
.table th:last-child, .table td:last-child { padding-right: 18px; }
.table .r { text-align: right; }
.table tbody tr.is-link { cursor: pointer; }
.table tbody tr.is-link:hover td { background: var(--surface-hover); }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--text-subtle); }
.empty { padding: 32px 18px; text-align: center; color: var(--text-muted); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters .input { width: 260px; max-width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); font: inherit; font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; cursor: pointer; }
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.is-active { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip__n { margin-left: 4px; opacity: .7; font-variant-numeric: tabular-nums; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 18px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-muted); }

.tabs { display: inline-flex; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.tabs button { border: 0; background: none; font: inherit; font-size: 13px; font-weight: 600; padding: 5px 12px; border-radius: 6px; color: var(--text-muted); cursor: pointer; }
.tabs button.is-active { background: var(--text); color: var(--surface); }

/* ---------- lists & detail ---------------------------------------------- */

.list { display: flex; flex-direction: column; }
.list__item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 18px; border-top: 1px solid var(--border); font-size: 13px; }
.list__item:first-child { border-top: 0; }
.list__item a { color: var(--text); font-weight: 600; }
.dl { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 8px 14px; margin: 0; font-size: 13px; }
.dl dt { color: var(--text-subtle); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.callout { border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; background: var(--brand-tint); color: var(--brand-ink); }
.callout--warn { background: var(--amber-tint); color: var(--amber); }
.callout--bad { background: var(--red-tint); color: var(--red); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--border); }

/* ---------- charts -------------------------------------------------------- */

.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart__grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart__axis { fill: var(--text-subtle); font-size: 11px; font-family: var(--font); }
.chart__bar { fill: var(--chart-bar); }
.chart__hit { fill: transparent; cursor: default; outline: none; }
.chart__hit:hover + .chart__bar, .chart__hit:focus + .chart__bar { opacity: .75; }
.chart__hit:focus-visible { stroke: var(--brand); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; transform: translate(-50%, calc(-100% - 8px));
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: 6px 10px; font-size: 12px; white-space: nowrap;
}
.tooltip strong { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.tooltip span { color: var(--text-muted); }
.table-view summary { cursor: pointer; font-size: 12.5px; color: var(--text-muted); margin-top: 10px; }
.table-view .table { margin-top: 6px; }

.hbar { display: grid; grid-template-columns: 80px minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13px; padding: 6px 0; }
.hbar__track { height: 10px; background: var(--surface-alt); border-radius: 999px; overflow: hidden; }
.hbar__fill { height: 100%; background: var(--chart-bar); border-radius: 999px; min-width: 2px; }
.hbar__val { font-variant-numeric: tabular-nums; color: var(--text-muted); white-space: nowrap; }
.hbar__val strong { color: var(--text); }

/* ---------- modal & toast ------------------------------------------------- */

.overlay { position: fixed; inset: 0; background: rgba(16, 20, 30, .55); display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 90; overflow-y: auto; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 460px; }
.modal__head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-size: 15px; font-weight: 650; }
.modal__body { padding: 18px 20px 4px; }
.modal__body p { margin: 0 0 14px; color: var(--text-muted); }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }

.toasts { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--green); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 10px 14px; font-size: 13px; max-width: 380px; }
.toast--error { border-left-color: var(--red); }

/* ---------- sign-in ------------------------------------------------------- */

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 28px; }
.auth-card__brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; margin-bottom: 18px; }
.auth-card__brand em { font-style: normal; font-weight: 600; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--brand); background: var(--brand-tint); padding: 2px 6px; border-radius: 5px; }
.auth-card__title { font-size: 20px; }
.auth-card__sub { margin: 4px 0 18px; color: var(--text-muted); font-size: 13px; }
.auth-card .input { width: 100%; }
.auth-card__error { background: var(--red-tint); color: var(--red); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px; margin-bottom: 14px; }

/* ---------- one-time secrets ------------------------------------------- */

.secret-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.secret { flex: 1; min-width: 0; font-family: var(--mono); font-size: 16px; letter-spacing: .04em; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-alt); border: 1px solid var(--border); overflow-wrap: anywhere; user-select: all; }
