/* cdn-admin console styles — components built from otg-tokens.css var(--ds-*)
   only, composed the way examples/office-hub-reskin.html's `.after` layer
   does. No hex literals here except where a token has none.

   ponytail: font-family is intentionally NOT set here — otg-tokens.css maps
   --ds-font-ui to "Geist" and --ds-font-brand to "Space Mono", both
   self-hosted via /static/fonts.css (linked before this file in layout.tmpl),
   so `body { font-family: var(--ds-font-ui) }` below is the only place a
   family is referenced. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--ds-bg-page);
  color: var(--ds-text-primary);
  font-family: var(--ds-font-ui);
  font-size: 14px;
  line-height: 1.5;
}

a {
  color: var(--ds-link);
}

h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--ds-text-primary);
  margin: 0 0 4px;
}

.sub {
  font-size: 13px;
  color: var(--ds-text-muted);
  margin: 0;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 28px 64px;
}

/* ─── Topbar ──────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 28px;
  background: var(--ds-bg-sidebar);
  border-bottom: 1px solid var(--ds-border);
  /* The nav links + user chip + Log out button don't wrap or shrink (flex
     items default to min-width: auto), so below ~480px their combined
     content width exceeds the viewport. Scoping the overflow to the topbar
     itself (like .table-wrap) keeps it off the page: the bar scrolls
     internally instead of widening <body>. */
  overflow-x: auto;
}

.brand-mark {
  font-family: var(--ds-font-brand);
  font-weight: 700;
  font-size: 15px;
  color: var(--ds-text-primary);
  letter-spacing: -0.3px;
}

.topnav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.topnav a {
  display: inline-flex;
  align-items: center;
  padding: 7px 11px;
  border-radius: var(--ds-radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--ds-text-secondary);
  text-decoration: none;
}

.topnav a:hover {
  background: var(--ds-bg-hover);
  color: var(--ds-text-primary);
}

.logout-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.userchip {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ds-text-secondary);
}

/* ─── Page head ───────────────────────────────────────────────────────── */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.range-form {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12.5px;
  color: var(--ds-text-muted);
}

.range-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.range-form input,
.range-form select {
  border: 1px solid var(--ds-border-input, var(--ds-border));
  border-radius: var(--ds-radius-sm);
  padding: var(--ds-field-pad-y-sm) var(--ds-field-pad-x-sm);
  font-size: var(--ds-field-font-sm);
  font-family: inherit;
  background: var(--ds-bg-card);
  color: var(--ds-text-primary);
}

/* ─── KPI strip ───────────────────────────────────────────────────────── */

.signal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--ds-bg-card);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  box-shadow: var(--ds-shadow-card);
  margin-bottom: 22px;
  overflow: hidden;
}

.kpi {
  padding: 14px 16px;
  border-right: 1px solid var(--ds-border-light);
}

.kpi:last-child {
  border-right: none;
}

/* Traffic page only: 8 KPIs as 4 columns x 2 rows instead of one row of 7
   (the dashboard's .signal keeps its single row, unaffected by this
   modifier). Below 720px the generic .signal/.kpi mobile rules further down
   already collapse any .signal, including this one, to 2 columns. */
.signal-grid-4 .kpi .val {
  white-space: nowrap;
}

@media (min-width: 721px) {
  .signal-grid-4 {
    grid-template-columns: repeat(4, 1fr);
  }
  .signal-grid-4 .kpi {
    border-bottom: 1px solid var(--ds-border-light);
  }
  .signal-grid-4 .kpi:nth-child(4n) {
    border-right: none;
  }
  .signal-grid-4 .kpi:nth-last-child(-n+4) {
    border-bottom: none;
  }
}

.kpi .lab {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--ds-text-muted);
}

.kpi .val {
  font-size: 22px;
  font-weight: 600;
  margin-top: 6px;
  color: var(--ds-text-primary);
  font-variant-numeric: tabular-nums;
  font-family: var(--ds-font-brand);
}

/* ─── Cards / tables ──────────────────────────────────────────────────── */

.card {
  background: var(--ds-bg-card);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  box-shadow: var(--ds-shadow-card);
  margin-bottom: 22px;
}

.card-head {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ds-text-primary);
  padding: 13px 16px;
  border-bottom: 1px solid var(--ds-border-light);
}

/* A card's non-table content (e.g. the Global limits card): same horizontal
   padding as .card-head, own vertical rhythm via flex gap instead of each
   child's browser-default margin. */
.card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-body > p {
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--ds-text-muted);
  font-weight: 600;
  /* 12px, not 16px: with the Total bytes column the By-file table's nine
     columns otherwise overflow the card by ~13px and show a scrollbar. */
  padding: 10px 12px;
  border-bottom: 1px solid var(--ds-border-light);
  white-space: nowrap;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--ds-border-light);
  vertical-align: middle;
  color: var(--ds-text-secondary);
}

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

.table tbody tr:hover td {
  background: var(--ds-bg-hover);
}

.table td.mono {
  font-family: var(--ds-font-brand);
  font-size: 12px;
  color: var(--ds-text-primary);
}

.table td.empty {
  text-align: center;
  color: var(--ds-text-muted);
  padding: 24px 16px;
}

.sort-link {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: inherit;
  text-decoration: none;
}

.sort-link:hover {
  color: var(--ds-text-primary);
}

/* ─── Pagination ──────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px 16px;
  border-top: 1px solid var(--ds-border-light);
  font-size: 12.5px;
  color: var(--ds-text-muted);
}

.pagination .btn-disabled {
  opacity: .4;
  pointer-events: none;
}

.row-actions {
  white-space: nowrap;
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
}

.reason-input {
  width: 110px;
  border: 1px solid var(--ds-border-input, var(--ds-border));
  border-radius: var(--ds-radius-sm);
  padding: 4px 7px;
  font-size: 12px;
  font-family: inherit;
  background: var(--ds-bg-card);
  color: var(--ds-text-primary);
}

/* ─── Badges ──────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ds-text-secondary);
}

.badge-muted {
  color: var(--ds-text-muted);
  font-style: italic;
}

.badge-danger {
  color: var(--ds-error-text);
  background: var(--ds-error-light);
  padding: 2px 8px;
  border-radius: var(--ds-radius-sm);
}

.badge-success {
  color: var(--ds-success-text);
  background: var(--ds-success-light);
  padding: 2px 8px;
  border-radius: var(--ds-radius-sm);
}

/* ─── Buttons ─────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: var(--ds-control-font-md);
  font-weight: 600;
  padding: var(--ds-control-pad-y-md) var(--ds-control-pad-x-md);
  border-radius: var(--ds-radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

/* Keyboard focus ring, as the DS [data-ds-button]:focus-visible. */
.btn:focus-visible {
  outline: 2px solid var(--ds-primary);
  outline-offset: 2px;
}

.btn-sm {
  font-size: var(--ds-control-font-sm);
  padding: var(--ds-control-pad-y-sm) var(--ds-control-pad-x-sm);
}

.btn-primary {
  background: var(--ds-primary);
  color: var(--ds-on-primary);
}

.btn-primary:hover {
  background: var(--ds-primary-hover);
}

.btn-secondary {
  background: var(--ds-bg-section);
  color: var(--ds-text-primary);
  border-color: var(--ds-border);
}

.btn-secondary:hover {
  background: var(--ds-bg-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--ds-text-secondary);
  border-color: var(--ds-border);
}

.btn-ghost:hover {
  background: var(--ds-bg-hover);
  color: var(--ds-text-primary);
}

.btn-danger {
  background: var(--ds-error);
  color: #ffffff;
}

.btn-danger:hover {
  background: var(--ds-error-hover);
}

/* ─── Forms (login / upload) ──────────────────────────────────────────── */

.login-card,
.upload-card {
  max-width: 420px;
  padding: 28px;
  margin: 40px auto 0;
}

.login-card form,
.upload-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ds-text-secondary);
}

.field input {
  border: 1px solid var(--ds-border-input, var(--ds-border));
  border-radius: var(--ds-radius-sm);
  padding: var(--ds-field-pad-y-md) var(--ds-field-pad-x-md);
  font-size: var(--ds-field-font-md);
  font-family: inherit;
  background: var(--ds-bg-card);
  color: var(--ds-text-primary);
}

.field input:focus {
  outline: 2px solid var(--ds-primary-subtle);
  outline-offset: 1px;
  border-color: var(--ds-primary);
}

/* Global limits form (traffic.tmpl): three fields side by side (label above
   input via .field), the button in a fourth column aligned to the bottom of
   the inputs; stacks to one column (button below the fields) at the 720px
   breakpoint below. This base rule must stay above that media block: with
   equal selector specificity, source order (not media-query nesting) decides
   which wins, so a same-specificity override placed earlier in the file is
   dead. */
.limits-form { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 12px; align-items: end; border: 0; padding: 0; margin: 0; min-width: 0; }
.limits-form-actions { display: flex; }

.alert {
  border-radius: var(--ds-radius-md);
  padding: 9px 12px;
  font-size: 12.5px;
  margin: 14px 0 0;
}

.alert-error {
  background: var(--ds-error-light);
  color: var(--ds-error-text);
  box-shadow: inset 0 0 0 1px var(--ds-error);
}

/* ─── Toasts (layout.tmpl) ───────────────────────────────────────────────
   One-off event messages, styled like the DS Toast (OtgToaster). Placement
   deviates from the DS default (top-right) by the user's explicit choice:
   fixed at the top of the viewport, horizontally centered, above the top
   bar's nav and user chip (z-index popover tier). Durations as the DS
   helpers: success 3 s, warning 6 s. Hover/focus pauses the timer. */
.toast-region {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--ds-z-popover);
  width: max-content;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 14px;
  background: var(--ds-bg-card);
  color: var(--ds-text-primary);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  box-shadow: var(--ds-shadow-elevated);
  font-family: var(--ds-font-ui);
  font-size: 13px;
  line-height: 1.4;
  pointer-events: auto;
  animation-name: toast-slide;
  animation-timing-function: ease;
  animation-fill-mode: forwards;
}

/* .toast's display: flex beats the UA [hidden] rule; the close button sets
   hidden, so it needs its own (as .preview-overlay[hidden]). */
.toast[hidden] {
  display: none;
}

/* <main> only takes focus (tabindex=-1) as the landing point after a toast
   is dismissed; it is not a control, so no ring around the whole page. */
main:focus {
  outline: none;
}

.toast:hover,
.toast:focus-within {
  animation-play-state: paused;
}

.toast-success {
  animation-duration: 3s;
}

.toast-warning {
  animation-duration: 6s;
}

.toast-msg {
  min-width: 0;
  overflow-wrap: anywhere;
}

.toast-close {
  flex: none;
  background: none;
  border: 0;
  padding: 0 2px;
  font: inherit;
  font-size: 16px;
  line-height: 1;
  color: var(--ds-text-muted);
  cursor: pointer;
}

.toast-close:focus-visible {
  outline: 2px solid var(--ds-primary);
  outline-offset: 2px;
}

@keyframes toast-slide {
  0% { transform: translateY(calc(-100% - 16px)); opacity: 0; visibility: visible; }
  8%, 90% { transform: translateY(0); opacity: 1; visibility: visible; }
  100% { transform: translateY(calc(-100% - 16px)); opacity: 0; visibility: hidden; }
}

@keyframes toast-appear {
  0%, 99.9% { visibility: visible; }
  100% { visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation-name: toast-appear;
    animation-timing-function: step-end;
  }
}

/* ─── File preview modal ──────────────────────────────────────────────── */

.key-link {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-family: var(--ds-font-brand);
  font-size: 12px;
  color: var(--ds-link);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  /* Long keys (hash filenames) would widen the By-file table past the card;
     truncate with an ellipsis, the full key is in the title tooltip. */
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* By-file Key column: take whatever width the other eight columns leave and
   truncate to it, instead of a fixed 220px cap. A fixed cap overflowed the
   card by a few px as soon as one key was long enough to reach it. Below
   140px (narrow screens) the table scrolls inside .table-wrap as before. */
.table td.key-cell {
  width: 100%;
  max-width: 0;
  min-width: 140px;
}

.table td.key-cell .key-link {
  max-width: 100%;
}

.key-link:hover {
  color: var(--ds-primary-hover);
}

.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--ds-z-modal, 100);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.preview-overlay[hidden] {
  display: none;
}

.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 18, 16, 0.55);
}

.preview-box {
  position: relative;
  max-width: min(95vw, 1920px);
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  background: var(--ds-bg-card);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  box-shadow: var(--ds-shadow-modal);
  overflow: hidden;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--ds-border-light);
}

.preview-title {
  font-size: 12.5px;
  color: var(--ds-text-primary);
  word-break: break-all;
}

.preview-close {
  flex: none;
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  color: var(--ds-text-muted);
  cursor: pointer;
  border-radius: var(--ds-radius-sm);
}

.preview-close:hover {
  background: var(--ds-bg-hover);
  color: var(--ds-text-primary);
}

.preview-body {
  padding: 14px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-media {
  display: block;
  /* Small creatives are scaled up to at least 640px wide. Bounded by the
     viewport, not by %, since the box shrink-wraps the media itself. */
  min-width: min(640px, calc(95vw - 30px));
  max-width: 100%;
  max-height: calc(95vh - 90px);
  object-fit: contain;
  border-radius: var(--ds-radius-sm);
}

.preview-nomedia {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px;
  color: var(--ds-text-muted);
  font-size: 13px;
}

/* ─── Responsive ──────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .container {
    padding: 16px;
  }
  .signal {
    grid-template-columns: repeat(2, 1fr);
  }
  .kpi:nth-child(2n) {
    border-right: none;
  }
  .kpi {
    border-bottom: 1px solid var(--ds-border-light);
  }
  .limits-form {
    grid-template-columns: 1fr;
  }
}

/* ─── Files browser ───────────────────────────────────────────────────── */

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 2px 0 4px;
  font-size: 13px;
}

.crumbs a {
  color: var(--ds-link);
  overflow-wrap: anywhere;
}

.crumbs a[aria-current="page"] {
  color: var(--ds-text-primary);
  font-weight: 600;
}

.crumb-sep {
  color: var(--ds-text-muted);
}

/* Charts: OTG design-system chart tokens (DESIGN.md "Dataviz / Charts"). */
.chart-figure { margin: 0; padding: 8px 16px 12px; }
.chart-plot { position: relative; padding-right: 76px; }
.chart { display: block; width: 100%; height: 180px; }
.chart-empty { height: 180px; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--ds-chart-axis); }
.chart-line, .chart-line-2 { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-line { stroke: var(--ds-chart-series-1); }
.chart-line-2 { stroke: var(--ds-chart-series-2); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart-grid { stroke: var(--ds-chart-grid); vector-effect: non-scaling-stroke; }
.chart-limit { stroke: var(--ds-chart-axis); stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.chart-scale, .chart-axis { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; color: var(--ds-chart-axis); }
.chart-axis { margin-top: 4px; padding-right: 76px; }
.chart-offscale { font-style: italic; }
.chart-legend { display: flex; gap: 12px; }
.chart-key::before { content: ""; display: inline-block; width: 14px; margin-right: 4px; vertical-align: middle; border-top: 2px solid; }
.chart-line-key { color: var(--ds-chart-series-1); }
.chart-line-2-key { color: var(--ds-chart-series-2); }
.chart-line-2-key.chart-key::before { border-top-style: dashed; }
.chart-limit-key { color: var(--ds-chart-axis); }
.chart-limit-key.chart-key::before { border-top-style: dashed; }
.chart-last { position: absolute; right: 0; width: 70px; transform: translateY(-50%); font-family: var(--ds-font-brand); font-size: 11px; font-variant-numeric: tabular-nums; }
/* Hover crosshair (traffic.tmpl #chart-hover): the line sits behind the SVG
   (z-index 0 vs 1; the SVG has no background), dots and values above it. */
.chart-plot { touch-action: pan-y; }
.chart-plot .chart { position: relative; z-index: 1; }
.chart-cursor { position: absolute; top: 0; height: 180px; width: 0; border-left: 1px solid var(--ds-chart-axis); z-index: 0; pointer-events: none; }
.chart-dot { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; border: 2px solid var(--ds-bg-card); box-sizing: content-box; z-index: 2; pointer-events: none; }
.chart-line-dot { background: var(--ds-chart-series-1); }
.chart-line-2-dot { background: var(--ds-chart-series-2); }
.chart-hover-value, .chart-cursor-time { position: absolute; margin-left: 8px; padding: 1px 4px; border-radius: var(--ds-radius-sm); background: var(--ds-bg-card); font-family: var(--ds-font-brand); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; z-index: 3; pointer-events: none; }
.chart-hover-value { transform: translateY(-50%); }
.chart-cursor-time { top: 0; color: var(--ds-chart-axis); }
.chart-hover-value.flip, .chart-cursor-time.flip { margin-left: -8px; translate: -100% 0; }
.chart-data { margin-top: 8px; }
.chart-data summary { cursor: pointer; font-size: 12px; color: var(--ds-text-secondary); }
.chart-data .table-wrap { max-height: 480px; overflow-y: auto; }
