/*
 * UnlimitedModel.com — Backend App UI (ONE component layer)
 *
 * The user dashboard (.user-shell) and the super admin (.admin-shell) are the
 * SAME shell: 232px sidebar · 60px topbar · 24px page padding · one card, one
 * button, one input, one table. Every rule below is scoped to both shells at
 * once so the two backends can never drift apart again.
 *
 * This file owns the shell, navigation, topbar, page header, stat cards,
 * tables/toolbars/pagination and the empty/loading surfaces. Page-specific
 * content stays in user-dashboard.css / admin.css; generic controls (button,
 * input, card, modal, toast, badge) stay in components.css.
 *
 * Load order: tokens → app-shell → base → components →
 * components-modals-dropdowns → app-ui → pages → landing → user/admin.
 *
 * No !important. No negative margins. No magic offsets: every measurement
 * comes from a token or is a documented component dimension.
 */

/* ===========================================
   1. SHELL TOKENS — declared once, for both backends
   Every value below is either the shared :root token or a dimension that is
   identical in the user dashboard and the super admin. Nothing here is
   re-declared per shell, so the two backends cannot drift apart.
   =========================================== */
.user-shell,
.admin-shell {
  --sidebar-width: 232px;
  --topbar-height: 60px;
  --page-bg: var(--app-bg);
  --surface: #ffffff;
  --border: var(--border-default);
  --page-pad: 24px;
  --stack-gap: 24px;
  --grid-gap: 16px;
  /* Aliases kept so admin markup that still references them resolves to the
     same surface/border as everything else. */
  --card-bg: #ffffff;
  --border-color: var(--border-default);
  /* Labels, stat sub-values, and table metadata are informational text: the
     marketing muted tone (#98a2b3) fails WCAG AA on the app canvas, so both
     backends resolve muted to the secondary shade instead. */
  --text-muted: var(--text-secondary);
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-2xl: 24px;
  /* Page background resolves through the shell so the canvas never falls
     back to the white marketing surface. */
  background: var(--page-bg);
}

/* ===========================================
   2. SHELL LAYOUT — sidebar | main (topbar + page outlet)
   =========================================== */
.dashboard-shell,
.admin-layout {
  display: flex;
  width: 100%;
  min-width: 0;
  background: var(--page-bg);
}

/* The user shell keeps its own scroll container (chat + tabs scroll inside);
   the admin shell lets the window scroll. Both start at 0,0 — no offset. */
.dashboard-shell {
  height: 100dvh;
  overflow: hidden;
}

.dashboard-main,
.admin-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--page-bg);
}

/* The public marketing header must not exist behind the backend shell:
   without this the fixed header + its 69px spacer push the whole app down. */
body.is-app-view .site-header,
body.is-app-view .site-header-spacer,
body:has(#page-dashboard.active) .site-header,
body:has(#page-dashboard.active) .site-header-spacer {
  display: none;
}

/* The legacy mobile header duplicated the topbar and pushed the sidebar 67px
   off the left edge. The topbar toggle owns the mobile drawer now. */
.mobile-header { display: none; }

/* ===========================================
   3. SIDEBAR — 232px, white, 60px logo row, 12px nav padding
   =========================================== */
.dashboard-sidebar,
.admin-sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0 var(--space-3) var(--space-4);
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
}

.dashboard-sidebar,
.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
}

.sidebar-logo,
.admin-logo {
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  margin-bottom: var(--space-3);
  text-decoration: none;
  flex-shrink: 0;
}

.sidebar-logo-img,
.admin-logo-wordmark {
  display: block;
  width: 184px;
  max-width: 100%;
  height: auto;
}

.sidebar-nav,
.admin-sidebar-nav {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--space-3) 0;
  background: transparent;
}

.sidebar-nav-group,
.admin-shell .nav-section {
  margin-bottom: var(--space-5);
}

.sidebar-nav-group:last-child,
.admin-shell .nav-section:last-child {
  margin-bottom: 0;
}

/* Section heading: 11px uppercase, muted, 24px row, 20px above the group */
.sidebar-nav-title,
.admin-shell .nav-title {
  font-size: 11px;
  font-weight: var(--font-semibold);
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  min-height: 24px;
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  margin-bottom: var(--space-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: transparent;
}

/* Nav item: 40px, 8px radius, 12px inline padding, 2px gaps */
.sidebar-nav-item,
.admin-shell .nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  margin-bottom: 2px;
  border-radius: var(--radius-control);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: var(--font-medium);
  line-height: 1.4;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-nav-item:hover,
.admin-shell .nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-nav-item:focus-visible,
.admin-shell .nav-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.sidebar-nav-item.active,
.admin-shell .nav-link.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: var(--font-semibold);
}

.sidebar-nav-item.active:hover,
.admin-shell .nav-link.active:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* 18px icons, always on the same optical axis */
.sidebar-nav-item .nav-icon,
.admin-shell .nav-link .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.sidebar-nav-item .nav-icon svg,
.admin-shell .nav-link .icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
}

.sidebar-nav-item .nav-label,
.admin-shell .nav-link .nav-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar footer: community link + account block, 12px inset, hairline top */
.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.sidebar-community-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-control);
  font-size: 12.5px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-community-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-community-link .nav-icon,
.sidebar-community-link .icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-community-link .nav-icon svg,
.sidebar-community-link .icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
}

.sidebar-footer-account {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Subscribe callout under the logo (user shell only) */
.dashboard-subscribe-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  border-radius: var(--radius-control);
  background: var(--accent-light);
  border: 1px solid var(--border);
  color: var(--text-primary);
  text-decoration: none;
  transition: background var(--transition-fast);
}

.dashboard-subscribe-link:hover {
  background: var(--accent-light);
}

.dashboard-subscribe-link .subscribe-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dashboard-subscribe-link .subscribe-title {
  font-size: 12.5px;
  font-weight: var(--font-semibold);
  line-height: 1.35;
}

.dashboard-subscribe-link .subscribe-detail {
  font-size: 11.5px;
  line-height: 1.35;
  /* Sits on the accent tint, where the secondary tone falls under 4.5:1. */
  color: var(--text-primary);
}

/* ===========================================
   4. TOPBAR — 60px, white, hairline bottom, 24px inline padding
   =========================================== */
.dashboard-topbar,
.admin-topbar {
  height: var(--topbar-height);
  flex: 0 0 var(--topbar-height);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--page-pad);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 120;
  box-sizing: border-box;
}

/* The topbar carries the page NAME only — never a second copy of the page
   description (that lives in the page lede below). */
.dashboard-topbar-title,
.admin-topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}

.dashboard-topbar-title h1,
.admin-topbar-title h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Admin pages have no in-page header, so the topbar keeps the description. */
.admin-topbar-title {
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
}

.admin-topbar-title p {
  font-size: 12.5px;
  line-height: 1.3;
  color: var(--text-secondary);
  margin: 0;
}

.dashboard-topbar-actions,
.admin-topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.dashboard-topbar-badge,
.admin-badge-top {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: 26px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  font-size: 12px;
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  white-space: nowrap;
}

.dashboard-topbar-toggle,
.admin-topbar-toggle {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}

.dashboard-topbar-toggle:focus-visible,
.admin-topbar-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ===========================================
   5. PAGE OUTLET — 24px padding, 24px section rhythm
   =========================================== */
.app-shell-content,
.admin-page {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--stack-gap);
  padding: var(--page-pad);
  width: 100%;
  max-width: none;
  margin: 0;
  box-sizing: border-box;
}

.dashboard-tab {
  display: none;
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  flex-direction: column;
  gap: var(--stack-gap);
  overflow: hidden auto;
}

.dashboard-tab.is-visible {
  display: flex;
}

/* A tab never squashes its own content below its natural height. */
.dashboard-tab > *:not(.chat-shell) {
  flex-shrink: 0;
}

/* ===========================================
   6. PAGE HEADER — one title, one lede, one action row
   =========================================== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
}

.page-header-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.page-header-title,
.page-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: 0;
}

.page-header-subtitle,
.page-subtitle {
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* The page description row: page-level copy, no title repetition. */
.page-lede {
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text-secondary);
  max-width: var(--content-narrow-width);
  margin: 0;
}

/* ===========================================
   7. CARDS + STAT CARDS — one surface, one elevation
   =========================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
  overflow: hidden;
}

.card--padded { padding: var(--space-6); }
.card--compact { padding: var(--space-4); }
/* Cards that carry their own header/table row set padding on the children. */
.card--flush { padding: 0; }

.card > .card-header,
.card--padded > .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0 0 var(--space-3);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.card--flush > .card-header {
  padding: var(--space-4) var(--space-5);
  margin: 0;
}

.card--flush > .card-body { padding: var(--space-5); }

.card--flush > .card-footer {
  padding: var(--space-4) var(--space-5);
  margin: 0;
}

.card-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  line-height: 1.4;
  color: var(--text-primary);
  margin: 0;
}

.card-header .card-title { margin: 0; }
/* A card whose first child is the title keeps 16px before its content. */
.card > .card-title { margin-bottom: var(--space-4); }
/* Stacked cards inside a content wrapper keep a 16px rhythm. */
.user-shell .card + .card,
.admin-shell .card + .card { margin-top: var(--grid-gap); }

.dashboard-stats-grid,
.admin-shell .stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--grid-gap);
}

.dashboard-stat-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  min-width: 0;
}

.dashboard-stat-card-body { flex: 1; min-width: 0; }

.dashboard-stat-card-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-control);
  background: var(--bg-surface);
  color: var(--text-secondary);
}

.dashboard-stat-card-icon svg,
.dashboard-stat-card-icon i {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
}

.dashboard-stat-card.stat-success .dashboard-stat-card-icon { background: var(--success-bg); color: var(--success); }
.dashboard-stat-card.stat-info .dashboard-stat-card-icon { background: var(--info-bg); color: var(--info); }
.dashboard-stat-card.stat-warning .dashboard-stat-card-icon { background: var(--warning-bg); color: var(--warning); }

.dashboard-stat-card-label {
  font-size: 12px;
  font-weight: var(--font-medium);
  line-height: 1.4;
  color: var(--text-secondary);
}

.dashboard-stat-card-value {
  font-size: 20px;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.dashboard-stat-card-sub {
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===========================================
   8. TABLES — 44px header, 56px rows, 16px cells
   =========================================== */
.data-table,
.key-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th,
.key-table thead th {
  height: 44px;
  padding: 0 var(--space-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  text-align: left;
  white-space: nowrap;
}

.data-table td,
.key-table tbody td {
  height: 56px;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 13.5px;
  vertical-align: middle;
}

.data-table tbody tr:last-child td,
.key-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover td,
.key-table tbody tr:hover td { background: var(--bg-surface); }

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.data-table th.sortable:hover { color: var(--text-primary); }

.data-table th.sortable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.data-table th .sort-indicator {
  display: inline-flex;
  align-items: center;
  margin-left: var(--space-1);
  opacity: 0.35;
  vertical-align: middle;
}

.data-table th .sort-indicator svg { width: 14px; height: 14px; }

.data-table th.sorted .sort-indicator,
.data-table th.sortable:hover .sort-indicator { opacity: 1; color: var(--accent); }

/* ===========================================
   9. TABLE TOOLBARS + PAGINATION
   =========================================== */
.table-toolbar,
.key-list-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.table-search {
  position: relative;
  flex: 1;
  min-width: 180px;
  max-width: 320px;
}

/* Toolbar controls keep the ONE input anatomy but size to their content
   instead of stretching the full row. */
.table-toolbar select.input,
.key-list-toolbar select.input {
  width: auto;
  min-width: 140px;
  flex: 0 0 auto;
  padding-right: var(--space-6);
}

.table-search .input,
.table-search input { padding-left: 36px; }

.table-search-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  pointer-events: none;
}

.table-search-icon svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2; }

.table-count,
.key-list-count {
  margin-left: auto;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  white-space: nowrap;
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.table-pagination-info {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.table-pagination-controls {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.table-page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 var(--space-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.table-page-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.table-page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.table-page-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.table-page-btn.nav-btn svg { width: 16px; height: 16px; }
.table-page-ellipsis { padding: 0 var(--space-1); color: var(--text-muted); }

.data-table-wrap,
.table-wrap {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  /* Wide tables must stay reachable on narrow screens: scroll horizontally
     instead of clipping the overflow (which hid whole columns on phones). */
  overflow-x: auto;
  overflow-y: hidden;
}

/* Bare tables inside a table-wrap card (admin pages, billing history) use the
   SAME one table system as .data-table. */
.user-shell .table-wrap table,
.admin-shell .table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.user-shell .table-wrap th,
.admin-shell .table-wrap th {
  height: 44px;
  padding: 0 var(--space-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  text-align: left;
  white-space: nowrap;
}

.user-shell .table-wrap td,
.admin-shell .table-wrap td {
  height: 56px;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13.5px;
  color: var(--text-primary);
  vertical-align: middle;
}

.user-shell .table-wrap tbody tr:last-child td,
.admin-shell .table-wrap tbody tr:last-child td { border-bottom: none; }

.user-shell .table-wrap tbody tr:hover td,
.admin-shell .table-wrap tbody tr:hover td { background: var(--bg-surface); }

.data-table-scroll { width: 100%; overflow-x: auto; }

/* ===========================================
   10. EMPTY / LOADING STATES
   =========================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-6);
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--text-base);
  line-height: 1.5;
}

.empty-state svg,
.empty-state i {
  width: 24px;
  height: 24px;
  color: var(--text-muted);
  stroke: currentColor;
  stroke-width: 1.75;
}

.empty-state-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-control);
  background: var(--bg-surface);
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.empty-state-icon svg,
.empty-state-icon i { width: 20px; height: 20px; }

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin: 0;
}

.empty-state-message {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  max-width: 420px;
  margin: 0;
}

.empty-state-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-2);
}

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--grid-gap);
}

.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.skeleton-card {
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.skeleton-line {
  height: 12px;
  border-radius: var(--radius-sm);
  background: var(--border-subtle);
}

.skeleton-line + .skeleton-line { margin-top: var(--space-2); }
.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-80 { width: 80%; }
.skeleton-line.w-100 { width: 100%; }

.skeleton-line::after {
  content: "";
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, rgba(16, 24, 40, 0.05), transparent);
  animation: app-skeleton-sweep 1.4s var(--ease-out) infinite;
}

@keyframes app-skeleton-sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: app-spin 0.8s linear infinite;
}

.spinner-sm { width: 14px; height: 14px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

@keyframes app-spin { to { transform: rotate(360deg); } }

/* ===========================================
   11. CALLOUTS — subscription / upgrade surfaces
   =========================================== */
.dashboard-upgrade-callout,
.dashboard-access-banner,
.subscription-callout {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.dashboard-upgrade-callout.is-hidden,
.dashboard-access-banner { display: none; }

.dashboard-access-banner.visible { display: flex; }

.dashboard-upgrade-callout-icon,
.dashboard-access-banner .banner-icon,
.subscription-callout-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--accent);
}

.dashboard-upgrade-callout-icon svg,
.dashboard-upgrade-callout-icon i,
.dashboard-access-banner .banner-icon svg,
.subscription-callout-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
}

.dashboard-upgrade-callout-content,
.dashboard-access-banner .banner-content,
.subscription-callout-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dashboard-upgrade-callout-title,
.dashboard-access-banner .banner-content h2,
.subscription-callout-title {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  line-height: 1.4;
  color: var(--text-primary);
  margin: 0;
}

.dashboard-upgrade-callout-message,
.dashboard-access-banner .banner-content p,
.subscription-callout-message {
  font-size: var(--text-sm);
  line-height: 1.5;
  /* Tinted callout surface: keep AA contrast on the accent wash. */
  color: var(--text-primary);
  margin: 0;
}

.dashboard-upgrade-callout-action,
.dashboard-access-banner .btn,
.subscription-callout-action {
  flex-shrink: 0;
}

/* Subscription state pill (dashboard + account surfaces) */
.subscription-status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: 26px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: var(--font-semibold);
  white-space: nowrap;
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.subscription-status-badge svg,
.subscription-status-badge i { width: 12px; height: 12px; stroke: currentColor; stroke-width: 2.5; }

.subscription-status-badge.active { background: var(--success-bg); color: var(--success-strong); border-color: var(--success-border); }
.subscription-status-badge.pending { background: var(--warning-bg); color: var(--warning-strong); border-color: var(--warning-border); }
.subscription-status-badge.inactive { background: var(--error-bg); color: var(--error-strong); border-color: var(--error-border); }

/* ===========================================
   13. METRIC CARDS + TABLE SORT STATES
   (migrated from the legacy sheet so the backend keeps one card + one table)
   =========================================== */
.stat-card,
.metric-card,
.key-item,
.info-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
}

.metric-card--horizontal {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.metric-card-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-control);
  background: var(--bg-surface);
  color: var(--text-secondary);
}

.metric-card-icon svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; }

.metric-card-label {
  font-size: 12px;
  font-weight: var(--font-medium);
  color: var(--text-secondary);
}

.metric-card-value {
  font-size: 20px;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.metric-card-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.metric-card-trend {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: var(--font-semibold);
}

.metric-card-trend--up { color: var(--success); }
.metric-card-trend--down { color: var(--error); }
.metric-card-trend--neutral { color: var(--text-muted); }

.data-table th.sorted-asc .sort-indicator,
.data-table th.sorted-desc .sort-indicator { opacity: 1; color: var(--accent); }

.table-page-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.table-page-btn.nav-btn { padding: 0; width: 32px; }

/* ===========================================
   14. RESPONSIVE — smaller screens reduce padding, never increase it
   =========================================== */
@media (max-width: 1100px) {
  .dashboard-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Tablet: the sidebar becomes an off-canvas drawer and page padding steps
   down to 20px. */
@media (max-width: 1024px) {
  .user-shell,
  .admin-shell { --page-pad: 20px; }

  .dashboard-sidebar,
  .admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100dvh;
    z-index: var(--z-fixed, 300);
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    box-shadow: var(--shadow-xl);
  }

  .dashboard-shell.sidebar-open .dashboard-sidebar,
  .admin-shell.sidebar-open .admin-sidebar,
  .dashboard-sidebar.open,
  .admin-sidebar.open { transform: translateX(0); }

  .dashboard-topbar-toggle,
  .admin-topbar-toggle { display: inline-flex; }
}

/* Mobile: 16px padding, one column, compact titles. */
@media (max-width: 768px) {
  .user-shell,
  .admin-shell { --page-pad: 16px; }

  .dashboard-stats-grid { grid-template-columns: minmax(0, 1fr); }

  .dashboard-topbar-title h1,
  .admin-topbar-title h1 { font-size: 18px; }

  .page-header-title,
  .page-title { font-size: 20px; }

  .table-toolbar,
  .key-list-toolbar,
  .table-pagination { padding: var(--space-3); }

  .table-count,
  .key-list-count { margin-left: 0; }

  .table-search { max-width: none; }

  .page-header { flex-direction: column; align-items: stretch; }
}

/* Sidebar overlay used by both backends on mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-fixed, 300) - 1);
  background: var(--overlay-scrim);
}

.sidebar-overlay.open,
.sidebar-overlay.visible { display: block; }
