/* Public read-only site styling.
 *
 * Served from /static and allowed by the CSP's style-src 'self'. There is deliberately no
 * inline style attribute anywhere in the templates: 'unsafe-inline' would undo most of what
 * the CSP is for.
 *
 * Desktop-first, per plan 5.2 - the audience is office staff on computers, and the only
 * responsive concern that matters is that wide tables scroll inside their own container
 * rather than stretching the page.
 */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1b1f24;
  --ink-soft: #5b6570;
  --line: #dfe3e8;
  --accent: #2f5fa8;
  --alert: #b3261e;
  --warn-bg: #fff7e6;
  --warn-line: #e6c07a;
  --ok: #1f7a44;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

/* ---------------------------------------------------------------- header */

.site-header {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1.5rem;
}

.site-nav { display: flex; flex-wrap: wrap; gap: 1rem; align-items: baseline; }

.site-nav .brand { font-weight: 700; font-size: 1.05rem; }

.site-nav a { color: var(--ink); text-decoration: none; }
.site-nav a:hover { color: var(--accent); text-decoration: underline; }

.site-note { margin: 0; color: var(--ink-soft); font-size: 0.82rem; }

.site-main { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }

.site-footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
  border-top: 1px solid var(--line);
}

.footer-meta { margin: 0.25rem 0 0; }

/* ---------------------------------------------------------------- panels */

.panel, .headline {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

h1 { font-size: 1.35rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.6rem; }

.breadcrumb { font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 0.75rem; }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

.hint { color: var(--ink-soft); font-size: 0.85rem; }
.empty { color: var(--ink-soft); font-style: italic; }

.caveat {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.75rem;
  background: #f2f5fa;
  border-left: 3px solid var(--accent);
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.warn-note {
  margin: 0.75rem 0;
  padding: 0.6rem 0.75rem;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 6px;
  font-size: 0.88rem;
}

.error-note {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.75rem;
  border-left: 3px solid var(--alert);
  background: #fdf3f2;
  font-size: 0.9rem;
}

.error-panel { text-align: left; }
.error-panel h1 { font-size: 2.5rem; color: var(--alert); margin-bottom: 0.25rem; }
.error-message { font-size: 1rem; }

.not-recorded { color: var(--ink-soft); font-style: italic; }
.strong { font-weight: 700; }
.alert { color: var(--alert); font-weight: 700; }

/* ---------------------------------------------------------------- stats */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1rem 0 0;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  background: #fbfcfd;
}

.stat h2 { font-size: 0.88rem; font-weight: 600; color: var(--ink-soft); margin: 0; }

.stat-value {
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 0.25rem 0;
  font-variant-numeric: tabular-nums;
}

.stat-primary { border-color: #c3d2ea; background: #f5f8fd; }
.stat-primary .stat-value { color: var(--accent); }
.stat-alert .stat-value { color: var(--alert); }

.stat-note { margin: 0; font-size: 0.78rem; color: var(--ink-soft); }

.stat-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.5rem 1.5rem;
  margin: 0.75rem 0 0;
}

.stat-list > div {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 1px dotted var(--line);
  padding: 0.2rem 0;
}

.stat-list dt { color: var(--ink-soft); font-size: 0.88rem; }
.stat-list dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }

.window-label { margin: 0.75rem 0 0; font-size: 0.9rem; }

/* ---------------------------------------------------------------- tables */

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th, .data-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table thead th {
  background: #f2f4f7;
  font-weight: 600;
  white-space: nowrap;
}

.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: #fafbfc; }
.data-table a { color: var(--accent); text-decoration: none; }
.data-table a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ tags */

.tag-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 0.5rem; }

.tag {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: #eef1f5;
  color: var(--ink-soft);
  font-size: 0.75rem;
  white-space: nowrap;
}

.tag-legacy { background: #f0e9f7; color: #6b3fa0; }
.tag-external { background: #e6f2f7; color: #23607a; }
.tag-platform { background: #e7f2ea; color: var(--ok); }
.tag-warn { background: var(--warn-bg); color: #8a5b00; border: 1px solid var(--warn-line); }

.state { font-weight: 600; white-space: nowrap; }
.state-queued { color: var(--ink-soft); }
.state-completed, .state-running { color: var(--ok); }
.state-failed { color: var(--alert); }
.state-stopped, .state-cancelled { color: #8a5b00; }
.state-safety_limited { color: #8a5b00; }

/* ----------------------------------------------------------------- forms */

.range-form, .search-form, .jump-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0;
  font-size: 0.88rem;
}

input[type="date"], input[type="search"], input[type="number"] {
  padding: 0.3rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  font: inherit;
  font-size: 0.88rem;
}

input[type="number"] { width: 5.5rem; }

button {
  padding: 0.32rem 0.85rem;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }

.link-button {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.88rem;
}

.link-button:hover { border-color: var(--accent); }
.link-button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.link-button.disabled {
  color: var(--ink-soft);
  background: #f2f3f5;
  border-style: dashed;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------ grid */

.scope-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
}

.grid-summary { font-size: 0.9rem; color: var(--ink-soft); margin: 0.5rem 0 1rem; }

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.image-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.image-card img {
  display: block;
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: #eef0f3;
}

.thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  background: repeating-linear-gradient(45deg, #f2f3f5, #f2f3f5 8px, #e9ebef 8px, #e9ebef 16px);
  color: var(--ink-soft);
  font-size: 0.8rem;
  text-align: center;
  padding: 0.5rem;
}

.image-meta { margin: 0; padding: 0.5rem 0.6rem; font-size: 0.76rem; }

.image-meta > div {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.1rem 0;
  border-bottom: 1px dotted #eef0f3;
}

.image-meta > div:last-child { border-bottom: 0; }
.image-meta dt { color: var(--ink-soft); flex: 0 0 auto; }

.image-meta dd {
  margin: 0;
  text-align: right;
  overflow-wrap: anywhere;
  max-width: 62%;
}

.image-meta a { color: var(--accent); }

/* ------------------------------------------------------------------ pager */

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1rem;
  font-size: 0.88rem;
}

.pager a, .pager .current, .pager .gap {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  text-decoration: none;
  background: #fff;
}

.pager a { color: var(--accent); }
.pager a:hover { border-color: var(--accent); }

.pager .current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.pager .gap { border: 0; background: none; color: var(--ink-soft); }

.jump-form { margin-left: auto; }

@media (max-width: 640px) {
  .stat-value { font-size: 1.7rem; }
  .jump-form { margin-left: 0; }
}

/* =============================================================== admin surface
 *
 * Appended rather than kept in a second stylesheet so one file, allowed once by
 * style-src 'self', covers both surfaces. The admin app serves it from
 * /admin/static/manager.css and the public app from /static/manager.css; same bytes,
 * two mount points, one CSP rule.
 */

body.admin { background: #f4f5f7; }

.login-panel { max-width: 30rem; margin: 3rem auto; }

.stacked-form { display: flex; flex-direction: column; gap: 0.4rem; max-width: 30rem; }

.stacked-form label { font-size: 0.85rem; color: var(--ink-soft); margin-top: 0.4rem; }

.stacked-form input[type="text"],
.stacked-form input[type="password"],
.stacked-form input[type="search"],
.stacked-form textarea {
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  font: inherit;
  font-size: 0.92rem;
  width: 100%;
}

.stacked-form textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.stacked-form button { align-self: flex-start; margin-top: 0.6rem; }

.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0.5rem 0; }

/* A per-row form cannot be nested inside the bulk form - HTML forbids it - so the row forms
 * are rendered empty and their submit buttons reach them through the form attribute. */
.hidden-form { display: none; }

.bulk-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0.6rem; margin-bottom: 0.6rem;
  background: #f2f4f7; border-radius: 6px; font-size: 0.88rem;
}

.row-actions { display: flex; flex-wrap: wrap; gap: 0.3rem; }

.row-actions button {
  padding: 0.18rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent);
}

.row-actions button:hover { border-color: var(--accent); }

.report-block {
  margin: 0; padding: 0.7rem 0.85rem;
  background: #1b1f24; color: #e8eaed;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem; line-height: 1.5;
  overflow-x: auto; white-space: pre;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem; }

.detail-cell { max-width: 22rem; }
.kv { display: inline-block; margin-right: 0.5rem; white-space: nowrap; font-size: 0.8rem; }
.kv b { font-weight: 600; color: var(--ink-soft); }

.action-list { list-style: none; padding: 0; margin: 0.5rem 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }

.ok-note {
  margin: 0.75rem 0; padding: 0.6rem 0.75rem;
  background: #eef7f0; border: 1px solid #b7dcc2; border-radius: 6px; font-size: 0.9rem;
}

/* Visually hidden but present for screen readers; the select-all column has no header text. */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

code {
  padding: 0.1rem 0.3rem; border-radius: 3px;
  background: #eef0f3; font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ----------------------------------------------------- admin dashboard */

.admin .site-header {
  min-height: 64px;
  padding: 0.8rem max(1.25rem, calc((100vw - 1200px) / 2));
  justify-content: space-between;
  box-shadow: 0 1px 3px rgb(20 31 46 / 5%);
}

.admin .site-nav { gap: 1.35rem; }
.admin .site-nav .brand { margin-right: 1.3rem; color: #162033; font-size: 1.08rem; }
.admin .site-nav a { color: #516071; font-size: 0.9rem; }
.admin .site-nav a:hover { color: #315dca; text-decoration: none; }

.dashboard-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 0.3rem 0 1.15rem;
}

.dashboard-heading h1 { margin: 0; color: #172033; font-size: 1.55rem; }
.dashboard-heading p { margin: 0.15rem 0 0; color: #7a8796; font-size: 0.88rem; }

.primary-action {
  display: inline-block;
  padding: 0.62rem 1rem;
  border-radius: 7px;
  background: #3263d5;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 4px 12px rgb(50 99 213 / 18%);
}

.primary-action:hover { background: #2856c1; }

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.dashboard-stat {
  min-height: 128px;
  padding: 1rem 1.15rem;
  border: 1px solid #e5e9ef;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 2px 9px rgb(33 45 63 / 4%);
}

.dashboard-stat-primary { border-top: 3px solid #3263d5; }
.dashboard-stat-danger { border-top: 3px solid #d64c4c; }
.dashboard-stat-label { margin: 0; color: #667487; font-size: 0.84rem; }
.dashboard-stat-value {
  margin: 0.2rem 0 0.1rem;
  color: #182235;
  font-size: 2rem;
  line-height: 1.25;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.dashboard-stat-primary .dashboard-stat-value { color: #3263d5; }
.dashboard-stat-danger .dashboard-stat-value { color: #c63d3d; }
.dashboard-stat-note { margin: 0; color: #9aa4b1; font-size: 0.76rem; }

.dashboard-columns {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 0.95fr);
  gap: 1rem;
  align-items: start;
}

.dashboard-card {
  border: 1px solid #e5e9ef;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 2px 9px rgb(33 45 63 / 4%);
}

.dashboard-card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  min-height: 72px;
  padding: 1rem 1.15rem 0.8rem;
  border-bottom: 1px solid #edf0f4;
}

.dashboard-card-heading h2 { margin: 0; color: #1a2436; font-size: 1rem; }
.dashboard-card-heading p { margin: 0.15rem 0 0; color: #8b96a5; font-size: 0.76rem; }
.dashboard-card-heading > a { color: #3263d5; text-decoration: none; font-size: 0.82rem; }

.dashboard-table thead th { background: #fafbfd; color: #768296; font-size: 0.76rem; }
.dashboard-table th, .dashboard-table td { padding: 0.72rem 0.8rem; }
.dashboard-table td { color: #4a5668; }
.dashboard-table tbody tr:last-child td { border-bottom: 0; }
.dashboard-condition { max-width: 19rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.08rem 0.38rem;
  border-radius: 999px;
  background: #eef3fb;
  color: #526b92;
  font-size: 0.66rem;
  line-height: 1.35;
  vertical-align: 0.08rem;
}
.dashboard-count strong, .dashboard-count small { display: block; }
.dashboard-count small { margin-top: 0.12rem; color: #8b96a5; font-size: 0.68rem; font-weight: 400; }

.state-starting, .state-importing, .state-stopping { color: #3263d5; }

.failure-count {
  min-width: 1.75rem;
  height: 1.75rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: #fff0ef;
  color: #c33f3a;
  font-weight: 700;
  font-size: 0.8rem;
  line-height: 1.75rem;
  text-align: center;
}

.failure-list { list-style: none; padding: 0; margin: 0; }
.failure-list li { padding: 0.85rem 1.15rem; border-bottom: 1px solid #edf0f4; }
.failure-title { display: flex; justify-content: space-between; gap: 0.6rem; }
.failure-title a { color: #243248; text-decoration: none; font-weight: 600; font-size: 0.84rem; }
.failure-title span { flex: 0 0 auto; color: #c33f3a; font-size: 0.72rem; }
.failure-list p { margin: 0.25rem 0; color: #6f7a89; font-size: 0.78rem; }
.failure-list small { color: #a0a8b3; font-size: 0.72rem; }

.resolved-failures { padding: 0.7rem 1.15rem; color: #6f7a89; font-size: 0.78rem; }
.resolved-failures summary { cursor: pointer; color: #556276; }
.resolved-failures p { margin: 0.5rem 0 0; }

.dashboard-empty { padding: 2.1rem 1rem; text-align: center; color: #7d8999; }
.dashboard-empty p { margin: 0 0 0.35rem; }
.dashboard-empty a { color: #3263d5; }
.dashboard-empty-success { color: #4d8060; }

.dashboard-shortcuts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin: 1rem 0 1.25rem;
}

.dashboard-shortcuts a {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.85rem 1rem;
  border: 1px solid #e5e9ef;
  border-radius: 9px;
  background: #fff;
  color: #29364b;
  text-decoration: none;
}
.dashboard-shortcuts a:hover { border-color: #b9c9ed; box-shadow: 0 3px 10px rgb(50 99 213 / 7%); }
.dashboard-shortcuts strong { font-size: 0.86rem; }
.dashboard-shortcuts span { color: #8b96a5; font-size: 0.74rem; }

@media (max-width: 900px) {
  .dashboard-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-columns { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .admin .site-header { align-items: flex-start; }
  .admin .site-note { width: 100%; }
  .dashboard-heading { align-items: flex-start; flex-direction: column; }
  .dashboard-stats { grid-template-columns: 1fr 1fr; gap: 0.65rem; }
  .dashboard-stat { min-height: 108px; padding: 0.8rem; }
  .dashboard-stat-value { font-size: 1.55rem; }
  .dashboard-shortcuts { grid-template-columns: 1fr; }
}
