/* Shared application shell. View content remains server-rendered and authorized. */
body { overflow-x: visible; }
body.admin-theme { background: #0b1120; }
body.admin-theme::before { display: none; }
.shell { max-width: 1500px; padding-bottom: max(48px, env(safe-area-inset-bottom)); }
.app-admin .shell { max-width: 1840px; margin-left: 248px; padding: 24px 32px 56px; }
.app-admin .topbar { border-radius: 16px; background: #121c2e; box-shadow: none; }
.app-admin .brand-note { max-width: 620px; font-size: 13px; }
.app-admin .card, .app-admin .surface { background: #121c2e; border-radius: 16px; box-shadow: none; }
.app-admin .page-header { align-items: flex-start; }
.app-admin h1 { font-size: clamp(26px, 3vw, 38px); letter-spacing: -.035em; }
.app-admin h2 { font-size: 20px; }
.app-admin .page-header > .nav { max-width: 600px; }
.app-admin #app-content > .page-header > .nav a { padding: 8px 12px; font-size: 13px; }
.app-admin #app-content > .page-header:first-child > .nav:has(a[href="/admin/source-trials"]) { max-width: 600px; }
/* The full dashboard menu lives in the persistent sidebar. Context links on other views stay visible. */
.app-admin #app-content > .page-header:first-child > .nav:has(a[href="/admin/rate-limits"]):has(a[href="/admin/statistics"]) { display: none; }
.app-toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; min-width: 0; }
.app-toolbar button { min-height: 44px; padding: 9px 14px; border-radius: 10px; font-size: 13px; flex-shrink: 0; }
.app-state { flex: 1; min-width: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.app-state::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #22c55e; margin-right: 8px; }
.app-loading .app-state::before { background: #f59e0b; }
.app-loading::after { content: ''; position: fixed; z-index: 100; left: 0; right: 0; top: 0; height: 3px; background: #22d3ee; animation: app-progress 1.2s ease-in-out infinite; transform-origin: left; }
@keyframes app-progress { 0% { transform: scaleX(.05); } 50% { transform: scaleX(.8); } 100% { transform: scaleX(.05); } }
.app-sidebar { width: 248px; position: fixed; inset: 0 auto 0 0; padding: 24px 16px max(24px, env(safe-area-inset-bottom)); background: #0f192a; border-right: 1px solid #22324a; color: #e8eef7; overflow-y: auto; z-index: 60; overscroll-behavior: contain; }
.app-sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 28px; }
.app-brand { text-decoration: none; font-weight: 800; font-size: 18px; letter-spacing: .05em; }
.app-brand small { display: block; font-size: 11px; color: #9dafc9; font-weight: 400; margin-top: 5px; letter-spacing: 0; }
.app-sidebar .app-nav-search { display: grid; gap: 7px; color: #9dafc9; font-size: 12px; }
.app-sidebar input { width: 100%; min-height: 44px; border-radius: 10px; padding: 10px; background: #172338; border: 1px solid #2d3e58; color: #f4f7fb; font: inherit; }
.app-sidebar nav section { margin-top: 22px; }
.app-sidebar nav h2 { margin: 0 10px 8px; font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: #9dafc9; }
.app-sidebar nav a { display: flex; align-items: center; min-height: 44px; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: #cbd8eb; font-size: 13px; margin: 2px 0; }
.app-sidebar nav a:hover { background: #1a2a42; }
.app-sidebar nav a[aria-current="page"] { color: #67e8f9; background: #153447; font-weight: 700; }
.app-sidebar [hidden], [hidden] { display: none !important; }
.app-menu, .app-close, .app-backdrop { display: none; }
.app-notice { position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); right: 20px; z-index: 110; max-width: min(520px, calc(100vw - 32px)); padding: 16px 18px; display: flex; align-items: center; gap: 14px; border: 1px solid #376962; border-radius: 14px; color: #eafff8; background: #153b35; box-shadow: 0 12px 32px #0004; font-size: 14px; }
.app-notice.error { background: #482124; border-color: #985256; }
.app-notice button { color: inherit; padding: 4px 10px; min-height: 36px; border: 0; background: transparent; flex-shrink: 0; }
.skip-link { position: fixed; left: 16px; top: -100px; z-index: 120; padding: 12px; background: #153447; color: white; border-radius: 8px; }
.skip-link:focus { top: 12px; }
:focus-visible { outline: 2px solid var(--accent, #22d3ee); outline-offset: 4px; }
#app-content:focus { outline: none; }
button:disabled { opacity: .55; cursor: wait; transform: none; }
#app-view, #app-content, .card, .surface, .grid, .table-scroll-panel { min-width: 0; }
#app-content p, #app-content code, #app-content .mono, #app-content .field-help, #app-content .resource-title, #app-content .detail-item { overflow-wrap: anywhere; }
#app-content pre { max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; }
#app-content input:not([type="checkbox"]):not([type="radio"]), #app-content select, #app-content textarea { max-width: 100%; min-width: 0; }
#app-content textarea { resize: vertical; }
#app-content .table-scroll { max-width: 100%; }
#app-content table th { position: sticky; top: 0; background: var(--panel-strong); z-index: 1; }
#app-content td { overflow-wrap: anywhere; }
@media (max-width: 1100px) {
  .app-admin .shell { margin-left: 220px; padding: 20px; }
  .app-sidebar { width: 220px; }
  #app-content .grid.columns-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 900px) {
  .app-admin .shell { margin-left: 0; padding: 16px; }
  .app-sidebar { width: min(320px, calc(100vw - 40px)); visibility: hidden; transform: translateX(-100%); transition: transform 160ms ease, visibility 160ms; }
  .app-menu-open .app-sidebar { visibility: visible; transform: translateX(0); }
  .app-admin .app-menu, .app-close { display: inline-flex; }
  .app-close { min-width: 44px; min-height: 44px; padding: 8px; border-radius: 10px; background: #172338; color: #fff; }
  .app-menu-open { overflow: hidden; }
  .app-menu-open .app-backdrop { display: block; position: fixed; inset: 0; width: 100%; height: 100%; background: #0009; backdrop-filter: blur(3px); border: 0; border-radius: 0; z-index: 59; }
  #app-content .grid.columns-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 640px) {
  .shell, .app-admin .shell { padding: 12px 12px 36px; }
  .app-toolbar { gap: 8px; flex-wrap: wrap; }
  .app-state { order: 3; flex-basis: 100%; }
  .app-refresh { margin-left: auto; }
  .app-admin .topbar { padding: 14px; gap: 14px; }
  .app-admin .topbar .brand-note { display: none; }
  .app-admin .topbar .nav { display: flex; gap: 6px; flex-direction: row; }
  .app-admin .topbar .nav a { width: auto; flex: 1; padding: 10px; font-size: 12px; }
  #app-content .card, #app-content .surface { padding: 16px; border-radius: 14px; }
  #app-content .grid, #app-content .grid.columns-2, #app-content .grid.columns-3, #app-content .grid.columns-4 { grid-template-columns: minmax(0,1fr); }
  #app-content .page-header { gap: 12px; margin-bottom: 18px; }
  #app-content h1 { font-size: 27px; }
  #app-content .metric, #app-content .dashboard-value { font-size: 30px; }
  #app-content .nav { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
  #app-content .nav > *, #app-content .nav form button { min-width: 0; width: 100%; }
  #app-content button, #app-content .button, #app-content select { min-height: 44px; }
  #app-content input:not([type="checkbox"]):not([type="radio"]), #app-content textarea, #app-content select { font-size: 16px; }
  #app-content input[type="checkbox"], #app-content input[type="radio"] { width: 20px; height: 20px; flex-shrink: 0; }
  /* Every cell and every action is retained. Tables become labeled records. */
  #app-content .table-scroll { max-height: none; overflow: visible; border: 0; }
  #app-content .table-scroll table, #app-content table { display: block; width: 100%; min-width: 0 !important; }
  #app-content table thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); }
  #app-content table tbody, #app-content table tfoot { display: block; }
  #app-content table tr { display: block; margin-bottom: 14px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 12px; }
  #app-content table td, #app-content table th { display: block; padding: 10px 0; width: auto !important; min-width: 0 !important; max-width: 100%; white-space: normal !important; border-bottom: 1px solid var(--line); }
  #app-content table td:last-child { border-bottom: 0; }
  #app-content .app-data-row td::before { content: attr(data-label); display: block; color: var(--muted); font-size: 11px; font-weight: 700; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
  #app-content .table-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  #app-content .table-actions > * { flex: 1 1 140px; }
  #app-content .resource-header, #app-content .section-meta, #app-content .partner-shell { display: flex; flex-direction: column; align-items: stretch; }
  #app-content .resource-header > *, #app-content .section-meta > *, #app-content .partner-shell > * { min-width: 0; max-width: 100%; }
  .app-notice { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Status messages take their own space so they never cover controls. */
.app-notice { position: static; max-width: none; margin: 0 0 18px; box-shadow: none; }
#app-content > .card + .card, #app-content > .grid + .card { margin-top: 18px; }
@media (min-width: 641px) {
  #app-content .app-data-row td:first-child { min-width: 140px; }
  #app-content .app-data-row td:last-child { min-width: 160px; }
}
