/* Publisher Portal styles. Every value comes from tokens.css (generated from replica/design/tokens.json). */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: var(--font-sans); font-size: var(--fs-base); line-height: var(--lh-base); color: var(--c-text); background: var(--c-canvas); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--c-link); }
:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.on-dark :focus-visible { outline-color: var(--c-focus-on-dark); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: var(--s-2); top: -60px; z-index: 100; background: var(--c-surface); padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); }
.skip-link:focus { top: var(--s-2); }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--c-text-muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--font-mono); font-size: var(--fs-sm); }
.stack { display: grid; gap: var(--s-4); }
.row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.prose { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }

/* ---------- shell: header bar, left sidebar, content */
.shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); grid-template-rows: var(--header-h) 1fr; grid-template-areas: "head head" "nav main"; }
.topbar { grid-area: head; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-4); background: var(--c-header-bg); color: var(--c-on-header); }
.wordmark { margin-right: auto; color: var(--c-on-header); font-size: var(--fs-md); font-weight: 700; text-decoration: none; letter-spacing: .01em; }
.topbar .who { font-size: var(--fs-sm); color: var(--c-on-header-muted); }
.sidebar { grid-area: nav; position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); display: flex; flex-direction: column; background: var(--c-nav-bg); color: var(--c-nav-text); padding: var(--s-2) 0; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: var(--s-3); height: 44px; padding: 0 var(--s-4); color: var(--c-nav-text); text-decoration: none; font-weight: 500; border-left: 3px solid transparent; }
.nav-item:hover { background: var(--c-nav-active); }
.nav-item[aria-current="page"] { background: var(--c-nav-active); border-left-color: var(--c-focus-on-dark); }
.nav-item:focus-visible { outline-offset: -2px; }
.manager { margin-top: auto; padding: var(--s-4); border-top: 1px solid var(--c-nav-active); font-size: var(--fs-sm); display: grid; gap: var(--s-1); }
.manager h2 { margin: 0 0 var(--s-2); font-size: var(--fs-xs); font-weight: 600; color: var(--c-on-header-muted); text-transform: uppercase; letter-spacing: .06em; }
.manager .avatar { width: 40px; height: 40px; border-radius: var(--r-pill); background: var(--c-nav-active); display: grid; place-items: center; font-weight: 700; margin-bottom: var(--s-1); }
.manager a { color: var(--c-nav-text); overflow-wrap: anywhere; }
.content { grid-area: main; min-width: 0; padding: var(--gutter); }
@media (max-width: 900px) {
  .shell { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .manager { display: none; }
}
@media (max-width: 640px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: var(--header-h) auto 1fr; grid-template-areas: "head" "nav" "main"; }
  .sidebar { position: static; height: auto; flex-direction: row; padding: 0; overflow-x: auto; }
  .nav-item { flex: 1 0 auto; border-left: 0; border-bottom: 3px solid transparent; }
  .nav-item[aria-current="page"] { border-bottom-color: var(--c-focus-on-dark); }
  .topbar .who { display: none; }
  .content { padding: var(--s-3); }
}

/* ---------- page header */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-4); margin: 0 0 var(--s-4); }
.page-head h1 { margin: 0 auto 0 0; font-size: var(--fs-lg); line-height: var(--lh-lg); font-weight: var(--fw-lg); }

/* ---------- panels (dashboard widgets and section boxes) */
.panel { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md); box-shadow: var(--shadow-card); min-width: 0; display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; gap: var(--s-2); min-height: 44px; padding: 0 var(--s-2) 0 var(--s-4); background: var(--c-grid-head); border-bottom: 1px solid var(--c-border); border-radius: var(--r-md) var(--r-md) 0 0; }
.panel-head h2 { margin: 0 auto 0 0; font-size: var(--fs-md); line-height: var(--lh-md); font-weight: var(--fw-md); }
.panel-body { padding: var(--s-4); min-width: 0; }
.panel-body.flush { padding: 0; }
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: var(--s-4); align-items: start; }

/* ---------- stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s-3); margin-bottom: var(--s-4); }
.tile { border: 1px solid var(--c-border); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); background: var(--c-surface); }
.tile p { margin: 0; }
.tile .label { display: block; font-size: var(--fs-xs); font-weight: var(--fw-xs); color: var(--c-text-muted); }
.tile .value { display: block; font-size: var(--fs-xl); line-height: var(--lh-xl); font-weight: var(--fw-xl); font-variant-numeric: tabular-nums; }
.up { color: var(--c-success); }
.down { color: var(--c-danger); }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); height: var(--control-h); padding: 0 var(--s-4); border: 1px solid transparent; border-radius: var(--r-pill); font-size: var(--fs-sm); font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn-sm { height: var(--control-h-sm); padding: 0 var(--s-3); }
.btn-primary { background: var(--c-accent); color: var(--c-on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--c-accent-hover); }
.btn-secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border-input); }
.btn-secondary:hover:not(:disabled) { background: var(--c-surface-alt); }
.btn-ghost { background: transparent; color: var(--c-text); }
.btn-ghost:hover:not(:disabled) { background: var(--c-surface-alt); }
.on-dark .btn-ghost { color: var(--c-on-header); }
.on-dark .btn-ghost:hover:not(:disabled) { background: var(--c-nav-active); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn[aria-busy="true"]::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: var(--r-md); background: transparent; color: var(--c-text-muted); cursor: pointer; position: relative; text-decoration: none; }
.icon-btn:hover { background: var(--c-surface-alt); color: var(--c-text); }
.icon-btn[data-tip]:hover::after, .icon-btn[data-tip]:focus-visible::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); padding: 2px 8px; border-radius: var(--r-sm); background: var(--c-header-bg); color: var(--c-on-header); font-size: var(--fs-xs); white-space: nowrap; pointer-events: none; z-index: 5; }

/* ---------- forms */
.field { display: grid; gap: var(--s-1); min-width: 0; }
.field > label, .field > legend { font-size: var(--fs-sm); font-weight: 600; }
.help { font-size: var(--fs-xs); color: var(--c-text-muted); margin: 0; }
.error { font-size: var(--fs-sm); color: var(--c-danger); margin: 0; }
.input, .select, .textarea { width: 100%; min-height: var(--control-h); padding: 0 var(--s-2); border: 1px solid var(--c-border-input); border-radius: var(--r-sm); background: var(--c-bg); }
.textarea { padding: var(--s-2); min-height: 96px; font-family: var(--font-mono); font-size: var(--fs-sm); resize: vertical; }
.input[readonly] { background: var(--c-surface-alt); }
.input[aria-invalid="true"] { border-color: var(--c-danger); box-shadow: 0 0 0 1px var(--c-danger); }
.input-group { display: flex; gap: var(--s-2); align-items: center; }
.input-group .input { flex: 1; min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--s-3) var(--s-4); }
.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: var(--s-2) var(--s-3); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-border); }
.toolbar .grow { flex: 1 1 220px; }
.toolbar .narrow { width: 96px; }
.toolbar .actions { display: flex; gap: var(--s-2); margin-left: auto; }

/* ---------- data grid */
.grid-wrap { overflow-x: auto; max-width: 100%; }
.grid { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.grid th, .grid td { height: var(--row-h); padding: 0 var(--s-3); border-bottom: 1px solid var(--c-border); text-align: left; white-space: nowrap; }
.grid .num { text-align: right; }
.grid thead th { position: sticky; top: 0; z-index: 1; background: var(--c-grid-head); font-weight: 600; }
.grid tbody tr:nth-child(even) { background: var(--c-surface-alt); }
.grid tbody tr:hover { background: var(--c-accent-soft); }
.grid tfoot td { font-weight: 700; background: var(--c-grid-head); border-bottom: 0; }
.grid .wrap { white-space: normal; min-width: 220px; }
.grid .actions { display: flex; justify-content: flex-end; gap: var(--s-1); }
.grid .link-cell { min-width: 240px; }
.link-button { border: 0; background: none; padding: 0; color: var(--c-link); text-decoration: underline; cursor: pointer; text-align: left; font-weight: 600; }
.empty { padding: var(--s-6) var(--s-4); text-align: center; color: var(--c-text-muted); }
.empty .btn { margin-top: var(--s-3); }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-4); border-top: 1px solid var(--c-border); font-size: var(--fs-sm); }
.pager .summary { margin-left: auto; color: var(--c-text-muted); }

/* ---------- tabs */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--c-border); overflow-x: auto; padding: 0 var(--s-2); }
.tab { height: 40px; padding: 0 var(--s-3); border: 0; border-bottom: 2px solid transparent; background: none; font-size: var(--fs-sm); font-weight: 600; color: var(--c-text-muted); white-space: nowrap; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
.tab:hover { color: var(--c-text); }
.tab[aria-selected="true"] { color: var(--c-accent); border-bottom-color: var(--c-accent); }
.tab:focus-visible { outline-offset: -2px; }

/* ---------- pills */
.pill { display: inline-flex; align-items: center; padding: 2px var(--s-2); border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.pill-success { background: var(--c-success-soft); color: var(--c-success); }
.pill-danger { background: var(--c-danger-soft); color: var(--c-danger); }
.pill-warning { background: var(--c-warning-soft); color: var(--c-warning); }
.pill-neutral { background: var(--c-surface-alt); color: var(--c-text-muted); border: 1px solid var(--c-border); }
.pill-info { background: var(--c-accent-soft); color: var(--c-on-accent-soft); }

/* ---------- alerts, toasts, skeletons */
.alert { display: flex; gap: var(--s-2); align-items: flex-start; padding: var(--s-3); border: 1px solid; border-radius: var(--r-sm); font-size: var(--fs-sm); }
.alert-info { background: var(--c-accent-soft); color: var(--c-on-accent-soft); border-color: var(--c-border); }
.alert-success { background: var(--c-success-soft); color: var(--c-success); }
.alert-warning { background: var(--c-warning-soft); color: var(--c-warning); }
.alert-danger { background: var(--c-danger-soft); color: var(--c-danger); }
.toasts { position: fixed; right: var(--s-4); bottom: var(--s-4); z-index: 60; display: grid; gap: var(--s-2); }
.toast { padding: var(--s-2) var(--s-4); border-radius: var(--r-md); background: var(--c-header-bg); color: var(--c-on-header); box-shadow: var(--shadow-pop); font-size: var(--fs-sm); }
.skeleton { display: block; height: 12px; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--c-surface-alt), var(--c-grid-head), var(--c-surface-alt)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton, .btn[aria-busy="true"]::before { animation: none; } }

/* ---------- dialogs */
.modal { width: min(var(--modal-w), calc(100vw - 32px)); max-height: 90vh; padding: 0; border: 0; border-radius: var(--r-md); background: var(--c-surface); color: var(--c-text); box-shadow: var(--shadow-pop); }
.modal::backdrop { background: color-mix(in srgb, var(--c-overlay) 55%, transparent); }
.modal-head { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); background: var(--c-header-bg); color: var(--c-on-header); }
.modal-head h2 { margin: 0 auto 0 0; font-size: var(--fs-md); overflow-wrap: anywhere; }
.modal-head .icon-btn { color: var(--c-on-header); }
.modal-head .icon-btn:hover { background: var(--c-nav-active); }
.modal-head .icon-btn:focus-visible { outline-color: var(--c-focus-on-dark); }
.modal-body { padding: var(--s-4); overflow: auto; max-height: calc(90vh - 104px); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-top: 1px solid var(--c-border); }
@media (max-width: 640px) { .modal { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; } .modal-body { max-height: calc(100dvh - 104px); } }
.preview-frame { width: 100%; height: 60vh; border: 1px solid var(--c-border); border-radius: var(--r-sm); background: var(--c-bg); }

/* ---------- details list */
.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: var(--s-3) var(--s-4); margin: 0; }
.details dt { font-size: var(--fs-xs); font-weight: 500; color: var(--c-text-muted); }
.details dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: var(--s-4); }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
.list-plain { margin: 0; padding-left: var(--s-5); }
.list-plain li { margin: var(--s-1) 0; }

/* ---------- sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: var(--s-4); }
.signin .panel { width: min(400px, 100%); }
.signin h1 { margin: 0; font-size: var(--fs-lg); }
.modal-head .muted { color: var(--c-on-header-muted); }
.tiles { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.tile { min-width: 0; }
.tile .value { overflow-wrap: anywhere; }
@media (max-width: 640px) { .tile .value { font-size: var(--fs-lg); line-height: var(--lh-lg); } }

/* ---------- brand logo (from Settings) */
.wordmark { display: inline-flex; align-items: center; gap: var(--s-2); }
.brand-logo { height: 28px; width: auto; max-width: 160px; object-fit: contain; }
.signin .brand-logo { height: 40px; max-width: 200px; justify-self: start; }
.terms-text { max-height: 50vh; overflow: auto; padding: var(--s-3); border: 1px solid var(--c-border); border-radius: var(--r-sm); background: var(--c-surface-alt); white-space: pre-line; overflow-wrap: anywhere; }
