/*
 * The v2 base and the shared pieces every screen builds on, loaded before the
 * screen stylesheets (Propshaft loads them by name). Values come from
 * tokens.css.
 */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

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

:focus-visible { outline: none; box-shadow: var(--focus-ring); }

main {
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 28px 36px 48px;
}

.mono { font-family: var(--font-mono); }

/* Page header: a small line over the title, actions on the right. */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-header-text { display: flex; flex-direction: column; gap: 4px; }
.page-title { margin: 0; font-size: var(--text-2xl); font-weight: 600; letter-spacing: var(--tracking-tight); }
.page-kicker { font-size: var(--text-meta); color: var(--text-tertiary); }
.page-crumbs { display: flex; gap: 6px; font-size: var(--text-meta); color: var(--text-muted); }
.page-crumbs a { color: var(--accent); }

.stack { display: flex; flex-direction: column; gap: 22px; }
/* Lets a wide table scroll inside its card instead of widening the page. */
.stack > *, .stack > form > * { min-width: 0; }

/* Buttons: primary black, secondary outlined, disabled dashed. Labels never wrap. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-control);
  font-size: var(--text-base);
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--text-primary); color: #fff; }
.btn-primary:hover { color: #fff; background: #000; }
.btn-secondary { background: var(--bg-surface); color: var(--text-primary); box-shadow: inset 0 0 0 1px var(--border-input); }
.btn-secondary:hover { color: var(--text-primary); background: var(--bg-muted-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { color: #fff; }
.btn:disabled,
.btn[aria-disabled="true"] {
  background: transparent;
  color: var(--text-muted);
  box-shadow: none;
  outline: 1px dashed var(--border-disabled);
  outline-offset: -1px;
  cursor: not-allowed;
}
.btn-xs { height: 28px; padding: 0 10px; border-radius: var(--radius-control-sm); font-size: var(--text-meta); }
.btn-sm { height: 30px; padding: 0 12px; border-radius: var(--radius-control-sm); font-size: var(--text-meta); }
.btn-md { height: 34px; }
.btn-lg { height: 36px; padding: 0 16px; border-radius: var(--radius-control-lg); }
.btn-xl { height: 40px; padding: 0 18px; font-size: var(--text-md); }
.btn-block { width: 100%; }

.link-quiet { color: var(--text-tertiary); font-size: var(--text-meta); white-space: nowrap; }

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; font-size: var(--text-base); font-weight: 500; }
.input {
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--bg-surface);
  box-shadow: inset 0 0 0 1px var(--border-input);
  font-weight: 400;
}
.input-sm { height: 34px; padding: 0 10px; font-size: var(--text-base); }
.input:focus { outline: none; box-shadow: var(--focus-ring); }
.field-error { font-size: var(--text-meta); font-weight: 400; color: var(--danger-fg); }

/* Chips: Flag tiers carry a glyph so colour is never the only signal. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-chip);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  background: var(--bg-muted);
  color: var(--text-secondary);
}
.chip-high { background: var(--tier-high-bg); color: var(--tier-high-fg); }
.chip-high::before { content: "\25C6" / ""; }
.chip-low { background: var(--tier-low-bg); color: var(--tier-low-fg); }
.chip-low::before { content: "\25CB" / ""; }
.chip-carried { background: var(--carried-bg); color: var(--carried-fg); }
.chip-carried::before { content: "\21BB" / ""; }

/* Status: a 6px dot and always a word. */
.status-dot { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-meta); color: var(--text-secondary); white-space: nowrap; }
.status-dot::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--status-pending-ring); }
.status-dot-done::before { background: var(--status-done); box-shadow: none; }
.status-dot-sent::before { background: var(--status-sent); box-shadow: none; }
.status-dot-running { color: var(--accent); }
.status-dot-running::before { background: var(--status-running); box-shadow: 0 0 0 3px var(--status-running-halo); }
.status-dot-failed { color: var(--danger-fg); }
.status-dot-failed::before { background: var(--status-failed); box-shadow: none; }

/* Cards, stat tiles and banners */
.card { background: var(--bg-surface); border: 1px solid var(--border-card); border-radius: var(--radius-card); }
.stat-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat-tile { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--border-card); border-radius: var(--radius-tile); }
.stat-tile-label { font-size: var(--text-meta); color: var(--text-tertiary); }
.stat-tile-value { font-size: var(--text-2xl); font-weight: 600; }
.stat-tile-value small { font-size: var(--text-md); font-weight: 400; color: var(--text-faint); }
.stat-tile-danger { border-color: transparent; background: var(--danger-tile-bg); }
.stat-tile-danger .stat-tile-label { color: oklch(0.45 0.15 27); }
.stat-tile-danger .stat-tile-value { color: oklch(0.45 0.17 27); }
@media (max-width: 48rem) { .stat-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.banner { padding: 12px 16px; border-radius: var(--radius-tile); font-size: var(--text-base); }
.banner-success { background: var(--success-bg); color: var(--success-fg); }
.banner-warning { background: var(--warning-bg); color: var(--warning-fg); }
.banner-danger { background: var(--danger-bg); color: var(--danger-fg); }

/* Tables: a bordered card that scrolls sideways on its own. */
.table-card { position: relative; background: var(--bg-surface); border: 1px solid var(--border-card); border-radius: var(--radius-card); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-table); }
.table th {
  padding: 10px 18px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-row);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 400;
  text-align: left;
  white-space: nowrap;
}
.table td { padding: 14px 18px; border-bottom: 1px solid var(--border-row); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-sub { display: block; font-size: var(--text-sm); color: var(--text-muted); }

/* Dialogs: a native <dialog>, closed by Cancel or a click on the scrim. */
.ui-dialog {
  width: min(480px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius-dialog);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-dialog);
}
.ui-dialog::backdrop { background: var(--scrim); }
.ui-dialog-body { display: flex; flex-direction: column; gap: 16px; padding: 22px 24px; }
.ui-dialog-title { margin: 0; font-size: var(--text-xl); font-weight: 600; }
.ui-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--border-row); }

/* Toast: bottom centre, hides itself after a moment. */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  max-width: calc(100vw - 32px);
  margin: 0;
  padding: 10px 16px;
  border-radius: var(--radius-tile);
  background: var(--text-primary);
  color: #fff;
  font-size: var(--text-base);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  transform: translateX(-50%);
  transition: opacity 0.2s ease;
}
.toast[hidden] { display: none; }
.toast.toast-leaving { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

@media (max-width: 48rem) {
  main { padding: 20px 16px 40px; }
}

.muted { color: var(--text-muted); font-size: var(--text-meta); }

/* A button that reads as a link: Fetch, Refetch, Retry inside a row. */
.link-action {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: var(--text-meta);
  white-space: nowrap;
  cursor: pointer;
}
.link-action:hover { color: var(--accent-hover); text-decoration: underline; }
.table-empty { margin: 0; padding: 18px; }

.stack-sm { display: flex; flex-direction: column; gap: 12px; }
.section-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-heading h2 { margin: 0; font-size: var(--text-lg); font-weight: 600; }
.empty-card { margin: 0; padding: 18px; border: 1px dashed var(--border-input); border-radius: var(--radius-card); font-size: var(--text-base); color: var(--text-tertiary); }
.chip-md { height: 24px; padding: 0 9px; font-size: var(--text-meta); }
.status-dot-lg { gap: 7px; font-size: 15px; font-weight: 600; color: var(--text-body); }
.status-dot-lg::before { width: 7px; height: 7px; }
.link-action-md { font-size: var(--text-base); }
.btn-light { background: #fff; color: var(--text-primary); }
.btn-light:hover { background: var(--bg-muted-3); color: var(--text-primary); }
.btn-ghost-dark { background: transparent; color: #fff; box-shadow: inset 0 0 0 1px var(--text-secondary); }
.btn-ghost-dark:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.field-label { font-size: var(--text-base); font-weight: 500; }
.field-hint { display: block; margin-top: 2px; font-size: var(--text-sm); font-weight: 400; color: var(--text-muted); }
.textarea { height: auto; min-height: 72px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.info-note { margin: 0; padding: 10px 12px; border-radius: var(--radius-control); background: var(--bg-muted-2); font-size: var(--text-meta); line-height: 1.5; color: var(--text-secondary); }
.dialog-copy { margin: 0; font-size: var(--text-base); line-height: 1.55; color: var(--text-body); }
.ui-dialog form { margin: 0; }
.ui-dialog-actions form { margin: 0; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
.fetch-action { margin: 0; }
.pagination { display: flex; align-items: center; gap: 16px; margin: 0; font-size: var(--text-base); color: var(--text-tertiary); }
.empty { color: var(--text-muted); }

/* Read by screen readers, not shown. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Rails wraps fields with errors in a div; keep the field itself in the form's layout. */
.field_with_errors { display: contents; }

/* An alert on its own: a red banner. Inside a field it stays a line of red text. */
.alert { color: var(--danger-fg); }
p.alert:not(.banner), ul.alert:not(.banner) {
  margin: 0;
  padding: 12px 16px;
  border-radius: var(--radius-tile);
  background: var(--danger-bg);
  font-size: var(--text-base);
}
ul.alert:not(.banner) { padding-left: 32px; }

