/* ============================================================================
   serp — console & admin application shell (sidebar + topbar + content),
   stat cards, playground layout. Depends on tokens+base.
   ========================================================================== */

.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────── */
.app__side { border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side__brand { display: flex; align-items: center; gap: 8px; height: var(--topbar-h); padding: 0 16px; border-bottom: 1px solid var(--border); font-family: var(--font-serif); font-size: 16px; }
.side__brand .brand__mark { width: 15px; height: 15px; background: var(--brand-grad); -webkit-mask: url(/assets/mark.svg) center / contain no-repeat; mask: url(/assets/mark.svg) center / contain no-repeat; }
.side__scope { font-family: var(--font-mono); font-size: var(--fs-label); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-secondary); padding: 14px 16px 6px; }
.side__nav { display: flex; flex-direction: column; padding: 4px 8px; gap: 1px; overflow-y: auto; }
.side__link { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--r); color: var(--text-secondary); font-size: 13px; transition: background-color var(--ease), color var(--ease); }
.side__link:hover { background: var(--surface-2); color: var(--text); }
.side__link[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.side__link[aria-current="page"] .side__ico { color: var(--brand); }
.side__ico { width: 15px; height: 15px; flex: none; color: var(--text-muted); }
.side__foot { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--border); font-size: var(--fs-meta); color: var(--text-secondary); }

/* ── Account sessions ────────────────────────── */
.session-list { display: grid; gap: 10px; }
.session-card { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: start; gap: 14px; padding: 15px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
.session-card__icon { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--border); border-radius: var(--r); color: var(--text-secondary); background: var(--surface-2); }
.session-card__icon svg { width: 19px; height: 19px; }
.session-card__main { min-width: 0; }
.session-card__title { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 14px; font-weight: 600; }
.session-card__facts { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 11px; }
.session-card__fact { min-width: 130px; }
.session-card__label { display: block; margin-bottom: var(--sp-2); color: var(--text-muted); font-size: var(--fs-meta); }
.session-card__value { font-size: 12px; color: var(--text-secondary); overflow-wrap: anywhere; }
.session-card__ua { margin-top: 10px; color: var(--text-muted); font-size: var(--fs-meta); }
.session-card__ua code { display: block; margin-top: var(--sp-2); overflow-wrap: anywhere; white-space: pre-wrap; }
.session-card__action { align-self: start; }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.access-path-list { display: grid; gap: 8px; }
.access-path-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
.access-path-item code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.access-filters { margin-bottom: 16px; }
@media (max-width: 640px) {
  .session-card { grid-template-columns: 34px minmax(0, 1fr); gap: 10px; padding: 12px; }
  .session-card__icon { width: 34px; height: 34px; }
  .session-card__action { grid-column: 2; }
}

/* ── Main ─────────────────────────────────────── */
.app__main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; height: var(--topbar-h); padding: 0 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(8px); z-index: var(--z-sticky); }
.topbar__title { font-family: var(--font-serif); font-size: 16px; }
.topbar__spacer { margin-left: auto; }
.lang-switch { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--border); border-radius: var(--r); padding: 2px; }
.lang-switch__btn { font-family: var(--font-mono); font-size: 11px; line-height: 1; padding: 5px 7px; border: 0; border-radius: 2px; background: transparent; color: var(--text-secondary); cursor: pointer; transition: color var(--ease), background-color var(--ease); }
.lang-switch__btn:hover { color: var(--text); }
.lang-switch__btn[aria-current="true"] { background: var(--surface-3); color: var(--text); }

.content { padding: var(--sp-5) 20px var(--sp-8); max-width: var(--wrap); width: 100%; }
.content__head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-5); flex-wrap: wrap; }
.content__title { font-family: var(--font-serif); font-size: var(--fs-h2); line-height: var(--lh-h2); }
.content__sub { margin-top: var(--sp-2); color: var(--text-secondary); }

/* ── Grid helpers ─────────────────────────────── */
.grid { display: grid; gap: var(--sp-4); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }

/* ── Billing plan cards ──────────────────────── */
.billing-plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 14px; align-items: stretch; }
.billing-checkout-body { gap: 16px; }
.billing-plan { display: flex; min-width: 0; flex-direction: column; padding: 20px; border: 1px solid var(--border); border-radius: var(--r-sharp); background: var(--surface); transition: border-color var(--ease), box-shadow var(--ease); }
.billing-plan:hover { border-color: var(--border-strong); box-shadow: 0 8px 24px color-mix(in srgb, var(--text) 6%, transparent); }
.billing-plan__heading { min-height: 26px; }
.billing-plan__name { font-family: var(--font-serif); font-size: 18px; line-height: 26px; font-weight: 500; }
.billing-plan__price { display: flex; align-items: baseline; gap: 5px; margin-top: 12px; }
.billing-plan__price strong { font-family: var(--font-serif); font-size: 30px; line-height: 38px; font-weight: 500; font-variant-numeric: tabular-nums; }
.billing-plan__price span { color: var(--text-secondary); font-size: var(--fs-meta); }
.billing-plan__description { min-height: 3.2em; margin-top: var(--sp-2); color: var(--text-secondary); font-size: 12px; line-height: 1.6; }
.billing-plan__details { display: grid; gap: 10px; margin: 16px 0; padding: 14px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.billing-plan__detail { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; font-size: 12px; }
.billing-plan__detail span { color: var(--text-secondary); }
.billing-plan__detail strong { color: var(--text); font-weight: 500; text-align: right; }
.billing-plan__action { width: 100%; margin-top: auto; }

/* ── Stat card ────────────────────────────────── */
.stat { border: 1px solid var(--border); border-radius: var(--r-sharp); padding: 16px; }
.stat__label { font-family: var(--font-mono); font-size: var(--fs-label); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); }
.stat__value { margin-top: 8px; font-family: var(--font-serif); font-size: 26px; line-height: 32px; font-variant-numeric: tabular-nums; }
.stat__delta { margin-top: var(--sp-2); font-size: var(--fs-meta); color: var(--text-secondary); }
.stat__delta--up { color: var(--ok); }
.stat__delta--down { color: var(--danger); }

/* ── Toolbar ──────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar__spacer { margin-left: auto; }
.usage-toolbar { flex-wrap: nowrap; }
.usage-toolbar__control { box-sizing: border-box; flex: 0 0 132px; width: 132px; height: 40px; }
.usage-toolbar__export { display: inline-flex; align-items: center; justify-content: center; padding: 8px 12px; font-size: 13px; line-height: 18px; }

/* ── Secret reveal (API key) ──────────────────── */
.secret { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 13px; background: var(--surface-inset); border: 1px solid var(--border-strong); border-radius: var(--r); padding: 8px 10px; }
.secret code { flex: 1; overflow-x: auto; white-space: nowrap; }

/* ── Playground ───────────────────────────────── */
.pg { display: grid; grid-template-columns: 380px 1fr; gap: var(--sp-4); align-items: start; }
.pg__form { border: 1px solid var(--border); border-radius: var(--r-sharp); padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
.pg__out { border: 1px solid var(--border); border-radius: var(--r-sharp); overflow: hidden; min-height: 420px; display: flex; flex-direction: column; }
.pg__out-bar { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); font-family: var(--font-mono); font-size: var(--fs-label); color: var(--text-secondary); }
.pg__out-body { flex: 1; overflow: auto; padding: 14px; background: var(--surface-inset); }

@media (min-width: 961px) {
  .pg__form {
    position: sticky;
    top: calc(var(--topbar-h) + var(--sp-4));
    max-height: calc(100vh - var(--topbar-h) - 2 * var(--sp-4));
    max-height: calc(100dvh - var(--topbar-h) - 2 * var(--sp-4));
    overflow-y: auto;
    scrollbar-gutter: stable;
  }
}

/* ── Bar chart (pure CSS) ─────────────────────── */
.chart-scroll { min-width: 0; overflow-x: auto; overscroll-behavior-x: contain; }
.chart { display: flex; align-items: stretch; gap: 4px; height: 188px; min-width: 100%; }
.chart__day { display: flex; flex: 1 0 28px; min-width: 28px; flex-direction: column; align-items: stretch; text-align: center; }
.chart__plot { position: relative; display: flex; align-items: flex-end; justify-content: center; height: 140px; margin-top: 20px; }
.chart__value { position: absolute; bottom: calc(var(--bar-height) + 2px); left: 50%; max-width: calc(100% + 12px); overflow: hidden; color: var(--text-secondary); font-size: 10px; line-height: 14px; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; transform: translateX(-50%); }
.chart__bar { display: block; width: min(100%, 20px); background: var(--brand); border-radius: 1px; min-height: 2px; opacity: 0.85; transition: opacity var(--ease); }
.chart__bar:hover { opacity: 1; }
.chart__date { margin-top: 8px; color: var(--text-secondary); font-size: 10px; line-height: 16px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart-scroll + [data-chart-empty] { margin-top: 12px; }
/* Engine totals keep names and counts visible, including a single engine. */
.engine-chart { display: grid; gap: 16px; }
.engine-chart[hidden] { display: none; }
.engine-chart__row { display: grid; grid-template-columns: minmax(56px, 80px) minmax(0, 1fr) max-content; align-items: center; gap: 16px; }
.engine-chart__label { overflow-wrap: anywhere; }
.engine-chart__track { height: 12px; background: var(--border); border-radius: 1px; overflow: hidden; }
.engine-chart__bar { display: block; height: 100%; background: var(--brand); opacity: 0.85; }
.engine-chart__count { font-variant-numeric: tabular-nums; text-align: right; }
.contact-message-body { margin-top: 20px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── Responsive ───────────────────────────────── */
@media (max-width: 960px) {
  .grid--4 { grid-template-columns: repeat(2, 1fr); }
  .pg { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .app__side { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .side__brand { border-bottom: 0; flex-shrink: 0; }
  .side__scope, .side__foot { display: none; }
  .side__nav { flex-direction: row; flex-shrink: 0; overflow: visible; }
  .side__link { flex-shrink: 0; white-space: nowrap; }
  .grid--3, .grid--2 { grid-template-columns: minmax(0, 1fr); }
  .grid--3 > *, .grid--2 > * { min-width: 0; }
  .billing-plan-grid { grid-template-columns: 1fr; }
  .billing-plan__description { min-height: 0; }
}
@media (max-width: 480px) {
  .topbar { gap: 8px; padding-inline: 12px; }
  .topbar__title { flex-shrink: 0; white-space: nowrap; }
  .topbar > .muted { min-width: 0; max-width: 9.5ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ── Admin guard (hidden until role verified) ── */
html.admin-guard { visibility: hidden; }

/* ── Pricing rule rows (admin) ───────────────── */
.pr-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.pr-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px 34px; gap: 8px; align-items: center; }
.pr-row__del { padding: 0; width: 34px; line-height: 1; }
.pr-preview { margin-top: 16px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface-2); }
.pr-preview__title { font-size: var(--fs-meta); color: var(--text-secondary); margin-bottom: 8px; }
.pr-preview__body { display: flex; flex-direction: column; gap: var(--sp-2); }
.pr-preview__line { font-family: var(--font-mono); font-size: var(--fs-meta); color: var(--text-secondary); line-height: 1.9; }
.pr-preview__line b { color: var(--text); font-weight: 500; }
