/* Console prototype layout. Requires packages/design tokens.css + components.css. */

.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }

/* Sidebar ---------------------------------------------------------------------- */
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 14px;
  padding: 18px 12px 14px; background: var(--surface-sunken); border-right: 1px solid var(--border); overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.brand-mark { width: 26px; height: 26px; flex: none; border-radius: 8px; background: var(--accent); box-shadow: inset 0 0 0 6px color-mix(in srgb, var(--accent) 70%, #FFFFFF); }
.brand-text { display: grid; line-height: 1.2; }
.brand-name { font-weight: 650; font-size: var(--text-md); letter-spacing: -0.01em; }
.brand-sub { font-size: var(--text-xs); color: var(--text-tertiary); }
.env-chip {
  display: inline-flex; align-self: flex-start; align-items: center; gap: 8px; margin: 0 8px;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--test-border);
  background: var(--test-soft); color: var(--test-ink); font-size: var(--text-xs); font-weight: 650;
}
.env-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.side-nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 10px; border-radius: var(--r-md);
  color: var(--text-secondary); text-decoration: none; font-size: var(--text-base); font-weight: 550;
  border: 1px solid transparent; transition: background-color 120ms var(--ease), color 120ms var(--ease);
}
.side-nav a svg { width: 18px; height: 18px; flex: none; }
.side-nav a:hover { background: var(--surface-hover); color: var(--text); }
.side-nav a[aria-current="page"] { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: var(--shadow-sm); font-weight: 600; }
.side-secondary { margin-top: 14px !important; padding-top: 14px !important; border-top: 1px solid var(--border); }
.account-card { margin-top: auto; padding: 12px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); }
.account-name { font-weight: 600; font-size: var(--text-sm); }
.account-role { font-size: var(--text-xs); color: var(--text-tertiary); }

/* Top bar ---------------------------------------------------------------------- */
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 0 32px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: var(--text-xl); letter-spacing: -0.015em; }
.topbar h1:focus { outline: none; }
.topbar h1:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.topbar-meta { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.as-of { font-size: var(--text-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.menu-button { display: none; }
.test-banner { padding: 9px 32px; background: var(--test-soft); color: var(--test-ink); border-bottom: 1px solid var(--test-border); font-size: var(--text-sm); }

/* Main ------------------------------------------------------------------------- */
.main { padding: 28px 32px 56px; }
.main:focus { outline: none; }
.main.is-loading { opacity: 0.55; transition: opacity 160ms var(--ease); }
.view { display: grid; gap: 20px; max-width: 1180px; }
.page-lead { color: var(--text-secondary); font-size: var(--text-md); }
.page-intro { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-intro .page-lead { max-width: 640px; }
.footnote { font-size: var(--text-sm); color: var(--text-tertiary); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.grid-2-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; align-items: start; }

.card-body { padding: 16px 20px 20px; }
.card-body:has(> .table-wrap) { padding: 0; }
.card-actions { display: flex; gap: 8px; flex: none; }
.card-sub { margin-top: 2px; }

/* KPIs ------------------------------------------------------------------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat {
  display: flex; flex-direction: column; gap: 4px; padding: 18px 20px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-sm);
}
.stat-label { font-size: var(--text-sm); font-weight: 550; color: var(--text-secondary); }
.stat-value { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; overflow-wrap: anywhere; }
.stat-detail { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: var(--text-sm); color: var(--text-secondary); }
.stat .sparkline, .stat .meter-wrap { margin-top: 10px; }

.meter { height: 8px; border-radius: 999px; overflow: hidden; background: var(--accent-soft); }
.meter-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 300ms var(--ease); }
.meter-warning { background: var(--warning-soft); }
.meter-warning .meter-fill { background: var(--warning); }
.meter-danger { background: var(--danger-soft); }
.meter-danger .meter-fill { background: var(--danger); }
.meter-status { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: var(--text-sm); color: var(--text-secondary); }
.meter-status svg { width: 16px; height: 16px; flex: none; }
.tone-warning { color: var(--warning); }
.tone-danger { color: var(--danger); }

.sparkline { display: block; }
.spark-line { fill: none; stroke: var(--series-muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spark-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }

/* Chart ------------------------------------------------------------------------ */
.chart { margin: 0; }
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.chart-title { font-size: var(--text-sm); font-weight: 600; }
.chart-sub { font-size: var(--text-xs); color: var(--text-tertiary); }
.chart-plot { position: relative; width: 100%; min-height: 220px; border-radius: var(--r-md); }
.chart-plot:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.chart-svg { display: block; overflow: visible; }
.chart-grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-axis { stroke: var(--border); stroke-width: 1; shape-rendering: crispEdges; }
.chart-tick { fill: var(--text-tertiary); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-label { fill: var(--text-secondary); font-size: 11px; font-weight: 600; }
.chart-bar { fill: var(--series-1); transition: fill 120ms var(--ease); }
.chart-bar.is-active { fill: var(--accent-hover); }
.chart-hit { fill: transparent; }
.chart-tip {
  position: absolute; z-index: 2; transform: translate(-50%, -100%); pointer-events: none; white-space: nowrap;
  padding: 7px 10px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md);
  font-size: var(--text-xs); color: var(--text-secondary);
}
.chart-tip strong { color: var(--text); font-size: var(--text-base); font-variant-numeric: tabular-nums; }
.chart-table-wrap { margin-top: 12px; }
.chart-table { font-size: var(--text-sm); }

/* Lists ------------------------------------------------------------------------ */
.checklist, .activity, .plain-list, .env-list, .origin-list { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; align-items: center; gap: 12px; padding: 9px 0; }
.check-dot { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; flex: none; border-radius: 50%; border: 1.5px solid var(--border-control); }
.check-dot svg { width: 14px; height: 14px; }
.checklist .is-done .check-dot { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.checklist .is-done .check-label { color: var(--text-secondary); }
.check-label { flex: 1; }
.activity li { display: flex; justify-content: space-between; gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.activity li:last-child { border-bottom: 0; }
.activity-time { color: var(--text-tertiary); font-size: var(--text-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
.plain-list li { padding: 6px 0; }
.env-list li { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.env-list li:first-child { padding-top: 4px; }
.env-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.env-name { font-weight: 600; }
.origin-list li + li { margin-top: 2px; }

/* Tables ----------------------------------------------------------------------- */
.table tbody tr:hover { background: var(--surface-hover); }
.table .is-muted td { color: var(--text-tertiary); }
.key-name { font-weight: 550; }
.key-sub { color: var(--text-tertiary); }
.key-cell { display: inline-flex; flex-wrap: wrap; align-items: baseline; justify-content: flex-end; gap: 4px 8px; }
.table td:first-child .key-cell { justify-content: flex-start; }
.actions-cell { text-align: right; white-space: nowrap; }
.keys-table th, .keys-table td[data-label="Created"], .keys-table td[data-label="Status"] { white-space: nowrap; }

/* Forms and dialogs ----------------------------------------------------------- */
.filter-row { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.filter-field { display: grid; gap: 6px; min-width: 240px; }
.segmented { border: 1px solid var(--border); margin: 0; }
.choice-group { border: 0; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.choice-card {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-lg);
  border: 1px solid var(--border-control); cursor: pointer; background: var(--surface);
}
.choice-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice-card input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.choice-card > span { display: grid; gap: 2px; }
.choice-stack { display: grid; gap: 8px; margin-top: 4px; }
.dialog-desc { margin-top: 6px; color: var(--text-secondary); font-size: var(--text-sm); }
.dialog-form .field + .field { margin-top: 16px; }
.reveal-row { display: flex; gap: 8px; }
.key-reveal { flex: 1; font-size: var(--text-sm); background: var(--surface-sunken); }
.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.form-status { font-size: var(--text-sm); color: var(--text-secondary); }
.alerts-form fieldset { border: 0; margin: 0; padding: 0; }
.error-state { max-width: 720px; }
.error-actions { margin-top: 10px; }
.empty { padding: 28px 20px; text-align: center; }
.empty-title { font-weight: 600; }

/* Billing ---------------------------------------------------------------------- */
.plan-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.plan-name { font-size: var(--text-lg); font-weight: 600; }
.plan-price { margin: 6px 0 4px; }
.price, .estimate-total { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; }
.fixture-note { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; font-size: var(--text-sm); color: var(--text-secondary); }
.facts { margin: 8px 0 0; display: grid; }
.facts > div { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.facts > div:last-child { border-bottom: 0; }
.facts dt { color: var(--text-secondary); font-size: var(--text-sm); }
.reserve-note { margin: 12px 0 0; font-size: var(--text-sm); }
.reserve-actions { margin-top: 12px; }
.demo-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.demo-form .field { flex: 1 1 220px; margin: 0; }
.demo-results { margin: 12px 0 0; padding: 0; list-style: none; }
.demo-results li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: var(--text-sm); overflow-wrap: anywhere; }
.facts dd { margin: 0; font-weight: 550; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pm { display: flex; align-items: center; gap: 14px; }
.pm-card { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 32px; border-radius: 7px; border: 1px solid var(--border-control); color: var(--text-secondary); }
.pm-line { font-weight: 600; }

.usage-body { display: grid; gap: 20px; transition: opacity 160ms var(--ease); }
.usage-body.is-refreshing { opacity: 0.5; }

.toast-region { pointer-events: none; }
.toast { pointer-events: auto; }
.toast svg { width: 16px; height: 16px; flex: none; }

/* Responsive ------------------------------------------------------------------- */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2-1 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 60; inset: 0 auto 0 0; width: min(280px, 86vw);
    transform: translateX(-100%); transition: transform 200ms var(--ease); box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: none; }
  .backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(23, 22, 21, 0.45); }
  .menu-button { display: inline-flex; margin-left: -8px; }
  .topbar { padding: 0 16px; min-height: 56px; }
  .test-banner { padding: 8px 16px; }
  .main { padding: 20px 16px 48px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .responsive-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .responsive-table, .responsive-table tbody, .responsive-table tr, .responsive-table td { display: block; width: 100%; }
  .responsive-table tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .responsive-table tbody tr:last-child { border-bottom: 0; }
  .responsive-table td { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 5px 0; border: 0; text-align: right; }
  .responsive-table td::before { content: attr(data-label); color: var(--text-tertiary); font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; text-align: left; padding-top: 2px; }
  .responsive-table td.num { text-align: right; }
  .responsive-table .actions-cell { justify-content: flex-end; padding-top: 10px; }
  .responsive-table .actions-cell::before { content: none; }
}
@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: minmax(0, 1fr); }
  .as-of { display: none; }
  .stat-value, .price, .estimate-total { font-size: 26px; }
  .filter-field { min-width: 0; width: 100%; }
  .page-intro .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .meter-fill, .chart-bar { transition: none; }
}

/* Sign-in / sign-up / link pages (server-rendered by apps/console/server/email-link-auth.js) */
.auth-body { margin: 0; min-height: 100vh; background: var(--bg, #F7F5F1); }
.auth-main { box-sizing: border-box; max-width: 440px; margin: 0 auto; padding: 48px 16px; }
.auth-card { display: grid; gap: 16px; }
.auth-brand { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; }
.auth-title { margin: 0; font-size: 1.5rem; line-height: 1.25; }
.auth-form { display: grid; gap: 14px; }
.auth-form .input { width: 100%; box-sizing: border-box; }
.auth-agree .choice { display: flex; gap: 10px; align-items: flex-start; line-height: 1.45; }
.auth-agree input { margin-top: 3px; }
.auth-errors { border-left: 3px solid #B42318; padding: 8px 12px; background: #FEF3F2; color: #7A271A; }
.auth-errors p, .auth-errors ul { margin: 0; }
.auth-errors ul { padding-left: 18px; }
.auth-alt, .auth-foot { margin: 0; font-size: 0.875rem; }
.auth-foot { margin-top: 16px; text-align: center; }
.account-card .sign-out { margin-top: 8px; }
.key-actions { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.outbox .card { margin-top: 16px; }
.outbox-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.875rem; }
/* Stripe test-mode billing (B3C1-D31) */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
@media (max-width: 767px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.plan-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.plan-option { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.plan-option .plan-name, .plan-option .plan-price { margin: 0; }
