/* ──────────────────────────────────────────────────────────────
   Books plan gate — locked sidebar items, locked-page panels,
   usage meters and the upgrade modal body.
   Paired with /books/plan-gate.js. All colours come from the
   dashboard's :root palette so this inherits the theme.
   ────────────────────────────────────────────────────────────── */

/* Padlock glyph shared by the CSS-only lock markers below. */
:root {
  --plan-lock-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'><rect x='4' y='11' width='16' height='10' rx='2'/><path d='M8 11V7a4 4 0 0 1 8 0v4'/></svg>");
}

/* ── Sidebar: a locked module keeps its place but reads as locked ── */
.sb-item[data-plan-locked] { opacity: 0.62; }
.sb-item[data-plan-locked]:hover { opacity: 0.85; }
.sb-lock {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  color: var(--amber, #F59E0B);
}
.sb-lock svg { width: 11px; height: 11px; }
.sidebar.collapsed .sb-lock { display: none; }

/* ── Locked page panel (replaces the page body) ── */
.plan-lock-panel {
  max-width: 620px;
  margin: 32px auto;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #E2E8F0);
  border-radius: var(--r-md, 12px);
  padding: 32px 30px;
  text-align: center;
  box-shadow: var(--shadow-xs, 0 1px 2px rgba(15, 23, 42, 0.06));
}
.plan-lock-badge svg { width: 11px; height: 11px; flex: 0 0 auto; }
.plan-lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  background: var(--amber-lt, #FEF3C7);
  color: #92610A;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.plan-lock-title {
  margin: 16px 0 8px;
  font-family: 'Space Grotesk', 'Figtree', sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--text, #0F172A);
}
.plan-lock-copy {
  margin: 0 auto;
  max-width: 460px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-2, #475569);
}
.plan-lock-current {
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-3, #94A3B8);
}
.plan-lock-actions {
  margin-top: 22px;
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.plan-lock-btn {
  background: var(--emerald, #00B87C);
  color: #fff;
  border: none;
  border-radius: var(--r-sm, 8px);
  padding: 0 18px;
  height: 38px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s ease;
}
.plan-lock-btn:hover { background: var(--emerald-dk, #009A67); }
.plan-lock-btn.secondary {
  background: transparent;
  color: var(--text-2, #475569);
  border: 1px solid var(--border-dk, #CBD5E1);
}
.plan-lock-btn.secondary:hover { background: var(--surface-2, #F8FAFD); }

/* ── Usage meter banner (approaching / at a cap) ── */
.plan-usage-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 16px;
  padding: 11px 14px;
  border-radius: var(--r-sm, 8px);
  font-size: 12.5px;
  background: var(--amber-lt, #FEF3C7);
  border: 1px solid #FCD34D;
  color: #7C5808;
}
.plan-usage-banner[data-plan-usage-level="reached"] {
  background: var(--rose-lt, #FFF1F2);
  border-color: #FDA4AF;
  color: #9F1239;
}
.plan-usage-banner strong { font-weight: 700; }
.plan-usage-banner .plan-usage-spacer { flex: 1 1 auto; }
.plan-usage-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ── Reports index: locked rows ── */
.report-index-row[data-plan-locked] { opacity: 0.6; }
.report-plan-pill {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--amber-lt, #FEF3C7);
  color: #92610A;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  vertical-align: middle;
}

/* ── Upgrade modal body ── */
.plan-upgrade-copy {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-2, #475569);
  margin: 0 0 14px;
}
.plan-upgrade-meta {
  background: var(--surface-2, #F8FAFD);
  border: 1px solid var(--border, #E2E8F0);
  border-radius: var(--r-sm, 8px);
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--text-2, #475569);
}
.plan-upgrade-meta div + div { margin-top: 6px; }
.plan-upgrade-meta b { color: var(--text, #0F172A); }
.plan-upgrade-actions {
  margin-top: 18px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* Elements the gate hid because the active plan does not include them. */
[data-plan-hidden="1"] { display: none !important; }

/* Buttons whose action the plan does not include (CSV/Excel export).
   Left clickable on purpose — the click explains the upgrade. */
.btn[data-plan-locked-action] { opacity: 0.62; }
.btn[data-plan-locked-action]:hover { opacity: 0.85; }
.btn[data-plan-locked-action]::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 11px;
  margin-left: 6px;
  background-color: currentColor;
  -webkit-mask: var(--plan-lock-mask) center / contain no-repeat;
  mask: var(--plan-lock-mask) center / contain no-repeat;
  opacity: 0.85;
}

/* ══════════════════════════════════════════════════════════════════
   Subscription lifecycle — topbar plan pill, the expired-subscription
   modal, the read-only grace chrome and the switch-to-Free confirmation.

   Same rule as above: every colour is a dashboard token, so a theme change
   upstream lands here too. States come from the server (`entitlements.billing
   .state` / `.lockMode`); nothing here guesses a date.
   ══════════════════════════════════════════════════════════════════ */

/* ── Topbar pill: the account's plan, and the one action it needs ── */
.plan-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 10px 0 9px;
  border-radius: 999px;
  border: 1px solid var(--border, #E2E8F0);
  background: var(--surface-2, #F8FAFD);
  color: var(--text-2, #475569);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
  max-width: 260px;
}
.plan-pill:hover { border-color: var(--border-dk, #CBD5E1); background: #fff; }
.plan-pill:focus-visible { outline: 2px solid var(--sky, #0EA5E9); outline-offset: 2px; }
.plan-pill[hidden] { display: none; }
.plan-pill-dot {
  width: 6px; height: 6px; border-radius: 999px; flex: 0 0 auto;
  background: var(--emerald, #00B87C);
}
.plan-pill-label { overflow: hidden; text-overflow: ellipsis; }
.plan-pill-action {
  flex: 0 0 auto;
  padding-left: 8px;
  margin-left: 1px;
  border-left: 1px solid currentColor;
  opacity: 0.6;
  font-weight: 700;
}
.plan-pill[data-plan-tone="ok"]    { color: var(--emerald-dk, #009A67); background: var(--emerald-lt, #E6F9F3); border-color: #B7EBD9; }
.plan-pill[data-plan-tone="warn"]  { color: #92610A; background: var(--amber-lt, #FEF3C7); border-color: #FCD34D; }
.plan-pill[data-plan-tone="warn"] .plan-pill-dot { background: var(--amber, #F59E0B); }
.plan-pill[data-plan-tone="alert"] {
  color: #9F1239; background: var(--rose-lt, #FFF1F2); border-color: #FDA4AF;
}
.plan-pill[data-plan-tone="alert"] .plan-pill-dot { background: var(--rose, #F43F5E); }
.plan-pill[data-plan-tone="muted"] .plan-pill-dot { background: var(--text-3, #94A3B8); }
/* Skeleton until entitlements resolve, so the pill never flashes a wrong plan. */
.plan-pill--loading { pointer-events: none; opacity: 0.75; }
.plan-pill--loading .skel { width: 82px; height: 9px; }
@media (max-width: 900px) {
  .plan-pill .plan-pill-action { display: none; }
  .plan-pill { max-width: 168px; }
}

/* ── Topbar Upgrade / Subscribe CTA ─────────────────────────────────────
   A real button rather than a status chip: this is the one control a
   customer reaches for when they want to change plan, so it must read as a
   button even when the plan pill next to it is a quiet "renews 12 Nov".
   Deliberately keeps its label at every width (the pill drops its action
   text on narrow screens — this must not). */
.plan-upgrade-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--r-sm, 8px);
  border: 1.5px solid var(--emerald, #00B87C);
  background: var(--emerald, #00B87C);
  color: #fff;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.plan-upgrade-btn svg { width: 14px; height: 14px; flex: 0 0 auto; }
.plan-upgrade-btn:hover {
  background: var(--emerald-dk, #009A67);
  border-color: var(--emerald-dk, #009A67);
  box-shadow: 0 4px 14px rgba(0, 184, 124, 0.4);
  transform: translateY(-1px);
}
.plan-upgrade-btn:focus-visible { outline: 2px solid var(--sky, #0EA5E9); outline-offset: 2px; }
.plan-upgrade-btn[hidden] { display: none; }
/* A lapse is the one case the CTA must shout about. */
.plan-upgrade-btn[data-plan-tone="alert"] {
  background: var(--rose, #F43F5E);
  border-color: var(--rose, #F43F5E);
}
.plan-upgrade-btn[data-plan-tone="alert"]:hover {
  background: #E11D48;
  border-color: #E11D48;
  box-shadow: 0 4px 14px rgba(244, 63, 94, 0.4);
}

/* ── Expired-subscription modal (header-triggered flow) ── */
.plan-expiry { text-align: center; padding: 2px 2px 0; }
.plan-expiry-hero {
  width: 76px; height: 76px;
  margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 22px;
  color: var(--sky, #0EA5E9);
  background:
    radial-gradient(120% 120% at 50% 0%, #EAF6FE 0%, var(--surface-2, #F8FAFD) 70%);
  border: 1px solid var(--border, #E2E8F0);
}
.plan-expiry-hero svg { width: 40px; height: 40px; }
.plan-expiry-heading {
  margin: 0 0 8px;
  font-family: 'Space Grotesk', 'Figtree', sans-serif;
  font-size: 19px; font-weight: 700; color: var(--text, #0F172A);
}
.plan-expiry-copy {
  margin: 0 auto; max-width: 470px;
  font-size: 13.5px; line-height: 1.65; color: var(--text-2, #475569);
}
.plan-expiry-note {
  margin: 12px auto 0; max-width: 470px;
  font-size: 12px; line-height: 1.55; color: var(--text-3, #94A3B8);
}
.plan-expiry-facts {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  margin: 16px 0 2px;
}
.plan-expiry-facts > div {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 116px;
  padding: 9px 12px;
  border-radius: var(--r-sm, 8px);
  background: var(--surface-2, #F8FAFD);
  border: 1px solid var(--border, #E2E8F0);
}
.plan-expiry-facts span {
  font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
  text-transform: uppercase; color: var(--text-3, #94A3B8);
}
.plan-expiry-facts b { font-size: 12.5px; color: var(--text, #0F172A); }
.plan-expiry-actions {
  margin-top: 20px;
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
}
.plan-expiry-foot { margin: 14px 0 0; font-size: 12px; color: var(--text-3, #94A3B8); }
.plan-expiry-foot a { color: var(--sky, #0EA5E9); font-weight: 600; text-decoration: none; }
.plan-expiry-foot a:hover { text-decoration: underline; }

/* ── Read-only grace: the module stays, its write actions go ── */
.plan-readonly-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 14px;
  padding: 11px 14px;
  border-radius: var(--r-sm, 8px);
  background: var(--sky-lt, #E0F2FE);
  border: 1px solid #7DD3FC;
  color: #075985;
  font-size: 12.5px;
}
.plan-readonly-eye { display: inline-flex; }
.plan-readonly-eye svg { width: 14px; height: 14px; }
.plan-readonly-banner strong { font-weight: 700; }
.plan-readonly-banner .plan-readonly-spacer { flex: 1 1 auto; }
.plan-readonly-link,
.plan-readonly-switch {
  border: none; background: none; padding: 0;
  font: inherit; font-weight: 700; color: inherit;
  text-decoration: underline; cursor: pointer;
}
.plan-readonly-switch { color: var(--text-2, #475569); text-decoration: none; opacity: 0.85; }
.plan-readonly-switch:hover { opacity: 1; text-decoration: underline; }
/* A readable-but-frozen module reads calmer than a padlocked one. */
.sidebar [data-plan-locked][data-plan-readonly] { opacity: 0.78; }
.sidebar [data-plan-locked][data-plan-readonly] .sb-lock { color: var(--sky, #0EA5E9); }

/* ── Switch-to-Free confirmation ── */
.plan-down { font-size: 13.5px; color: var(--text-2, #475569); }
.plan-down-head { display: flex; gap: 12px; align-items: flex-start; }
.plan-down-warn {
  flex: 0 0 auto;
  width: 30px; height: 30px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--amber-lt, #FEF3C7); color: #92610A;
}
.plan-down-warn svg { width: 17px; height: 17px; }
.plan-down-copy { margin: 3px 0 0; line-height: 1.65; }
.plan-down-lose {
  margin-top: 16px;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: var(--r-sm, 8px);
  background: var(--surface-2, #F8FAFD);
  padding: 12px 14px;
}
.plan-down-lose-title {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.5px;
  text-transform: uppercase; color: var(--text-3, #94A3B8);
  margin-bottom: 8px;
}
.plan-down-lose-list {
  margin: 0; padding: 0; list-style: none;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.plan-down-lose-list li {
  font-size: 12px; font-weight: 600; color: var(--text-2, #475569);
  background: #fff;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 999px;
  padding: 4px 10px;
}
.plan-down-alert {
  margin-top: 14px;
  padding: 11px 13px;
  border-radius: var(--r-sm, 8px);
  background: var(--amber-lt, #FEF3C7);
  border: 1px solid #FCD34D;
  color: #7C5808;
  font-size: 12.5px;
  line-height: 1.6;
}
.plan-down-alert a { color: inherit; font-weight: 700; text-decoration: underline; margin-left: 6px; }
.plan-down-mode {
  margin-top: 14px;
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 12.5px; line-height: 1.55; color: var(--text-2, #475569);
  cursor: pointer;
}
.plan-down-mode input { margin-top: 2px; accent-color: var(--emerald, #00B87C); }
.plan-down-error {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: var(--r-sm, 8px);
  background: var(--rose-lt, #FFF1F2);
  border: 1px solid #FDA4AF;
  color: #9F1239;
  font-size: 12.5px;
  text-align: left;
}
.plan-down-done-badge {
  width: 46px; height: 46px; margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px;
  background: var(--emerald-lt, #E6F9F3); color: var(--emerald-dk, #009A67);
}
.plan-down-done-badge svg { width: 22px; height: 22px; }
