/* Apps (#/apps) and the app page (#/apps/:name): range filter, summary, apps table, requests per day, countries, rollout and comparison sections.
   Page-specific rules only: shared components live in app.css and charts.css, colors in tokens.css.
   Prefix every selector with this page's root class (see js/README.md, "CSS conventions"). */

/* ---------- Both pages ---------- */

/* Event rows (Recent key changes, History): the sentence, then who and when */
.page-apps .event-row,
.page-app .event-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px var(--space-3); align-items: start;
}
.page-apps .event-text,
.page-app .event-text { grid-column: 1; overflow-wrap: anywhere; }
.page-apps .event-meta,
.page-app .event-meta { grid-column: 1; font-size: var(--text-meta); color: var(--ink-3); }
.page-apps .event-app,
.page-app .event-app { font-weight: 600; }
.page-app .event-actions { grid-column: 2; grid-row: 1 / span 2; align-self: center; }

/* Countries: an optional lead line, the bar list, then the GeoLite2 note */
.page-apps .countries,
.page-app .countries { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.page-apps .countries-note,
.page-app .countries-note { font-size: var(--text-meta); color: var(--ink-3); }

.page-apps .apps-alert:empty,
.page-app .app-alert:empty { display: none; }

/* ---------- Apps ---------- */

/* Find a key and Add key share a row under the section title */
.page-apps [data-section="apps"] .section-actions { flex-basis: 100%; align-items: flex-start; }
.page-apps .finder { flex: 1 1 240px; max-width: 360px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.page-apps .finder-input { font-family: var(--mono); }
.page-apps .finder-input::placeholder { font-family: var(--font); }
.page-apps .finder-prefix { font-family: var(--mono); }
.page-apps .finder-status { font-size: var(--text-meta); color: var(--ink-3); }
.page-apps .finder-status:empty { display: none; }
@media (max-width: 639px) {
  .page-apps .finder { max-width: none; flex-basis: 100%; }
  .page-apps [data-section="apps"] .section-actions > .btn { width: 100%; min-height: var(--touch); }
}

.page-apps .apps-table thead th { white-space: normal; }
.page-apps .app-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--space-2); }
.page-apps .app-link { font-weight: 600; overflow-wrap: anywhere; }
.page-apps .app-versions { display: inline-flex; flex-wrap: wrap; gap: 4px; font-size: var(--text-meta); }

/* Requests with its inline bar: one scale for the whole column, growing from the cell's left edge */
.page-apps .requests-cell { display: flex; flex-direction: column; align-items: flex-end; min-width: 6.5em; }
.page-apps .requests-cell .inline-bar { align-self: flex-start; }
@media (max-width: 639px) {
  .page-apps .requests-cell { align-items: flex-start; }
}

/* Between phones and wide screens the table drops Change and latency (the app page has both) rather than scroll */
@media (min-width: 640px) and (max-width: 1023px) {
  .page-apps .apps-table .col-wide-only { display: none; }
  .page-apps .apps-table th, .page-apps .apps-table td { padding-left: 6px; padding-right: 6px; }
}

/* ---------- App page ---------- */

/* Migration: the hero (or ADMIN's note) beside the stage and checks */
.page-app .app-migration { display: grid; gap: var(--space-6); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .page-app .app-migration { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); } }
.page-app .app-side { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.page-app .app-stage { display: flex; flex-direction: column; gap: 4px; }
.page-app .app-stage-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.page-app .app-stage-label { font-weight: 600; }
.page-app .app-stage-text { font-size: var(--text-secondary); color: var(--ink-2); }
.page-app .app-side .subsection-title { margin-bottom: 0; }

.page-app .admin-note { display: flex; flex-direction: column; gap: var(--space-1); }
.page-app .admin-note-title { font-size: var(--text-section); font-weight: 600; }

/* Checks: shape + word, then the title and its one-line detail */
.page-app .checks { display: flex; flex-direction: column; }
.page-app .check {
  display: grid; grid-template-columns: 9.5em minmax(0, 1fr); gap: var(--space-3); align-items: start;
  padding: var(--space-2) 0; border-top: 1px solid var(--border);
}
.page-app .check:first-child { border-top: 0; padding-top: 0; }
.page-app .check .status { font-size: var(--text-secondary); }
.page-app .check-title { font-weight: 500; }
.page-app .check-detail { font-size: var(--text-secondary); color: var(--ink-2); overflow-wrap: anywhere; }
@media (max-width: 479px) {
  .page-app .check { grid-template-columns: minmax(0, 1fr); gap: 2px; }
}

.page-app .hours-hint:empty { display: none; }

/* v1 and v2 side by side */
.page-app .measure { display: flex; flex-direction: column; }
.page-app .measure-hint { font-size: var(--text-meta); color: var(--ink-3); font-weight: 400; }
.page-app .difference.is-worse { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 4px var(--space-2); }
@media (max-width: 639px) {
  .page-app .difference.is-worse { justify-content: flex-start; }
}
.page-app .wrong-version,
.page-app .good-line,
.page-app .regional-line {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--space-2);
  font-size: var(--text-secondary); color: var(--ink-2);
}
.page-app .regional-line { flex-wrap: nowrap; align-items: flex-start; }
.page-app .regional-line .status-icon { flex: none; margin-top: 2px; }

/* Server errors and latency sit side by side from 1024 px (.grid-2); each is its own section */
.page-app .app-pair > .section { min-width: 0; }

/* Requests by operation and the endpoints under each */
.page-app .ops-table thead th { white-space: normal; }
.page-app .endpoint { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.page-app .endpoints-table { font-size: var(--text-meta); }

.page-app .history-footer:empty,
.page-app .history-footer[hidden] { display: none; }
.page-app .history-footer { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-1); }
@media (max-width: 639px) {
  .page-app .event-row { grid-template-columns: minmax(0, 1fr); }
  .page-app .event-actions { grid-column: 1; grid-row: auto; }
}

/* The legend naming the inline bars' version colors, above the apps table */
.page-apps .apps-legend { margin-bottom: var(--space-2); align-items: center; }
.page-apps .apps-legend-lead { color: var(--ink-3); font-size: var(--text-meta); }

/* An unknown app: "No app named X" in the first section, nothing else below the header */
.page-app.is-unknown-app .filter-row,
.page-app.is-unknown-app .section:not([data-section="migration"]),
.page-app.is-unknown-app .app-pair { display: none; }

/* Touch targets on phones: History's Delete and Show older, and the operation rows' expand toggles */
@media (max-width: 767px) {
  .page-app .event-actions .btn,
  .page-app .history-footer .btn { min-height: var(--touch); }
  .page-app .ops-table .expand-button { width: var(--touch); height: var(--touch); margin: -10px 4px -10px -10px; }
}
