/* Restorly components — Direction C "Clear".
 * Depends on tokens.css. Class names are the contract: port them 1:1 to templ components.
 * Fonts are self-hosted from /static/fonts (see DESIGN.md §2) — never loaded from a CDN in the agent panel.
 */

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--bg); }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: var(--leading-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; font-weight: var(--weight-semibold); }
a:hover { color: var(--link-hover); text-decoration: underline; }

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

.mono { font-family: var(--font-mono); font-size: 0.93em; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Typography ---------- */
.display, h1.display {
  font-family: var(--font-display);
  font-weight: var(--weight-black);
  letter-spacing: -0.02em;
  line-height: var(--leading-tight);
  margin: 0;
}
.page-title { font-family: var(--font-display); font-size: var(--text-3xl); font-weight: var(--weight-black); letter-spacing: -0.02em; line-height: 1.1; margin: 0; }
.section-title { font-family: var(--font-display); font-size: var(--text-xl); font-weight: var(--weight-bold); margin: 0; }
.label { font-size: var(--text-xs); color: var(--text-subtle); letter-spacing: 0.02em; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--touch-target);
  padding: 0 var(--space-5);
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font: inherit; font-weight: var(--weight-semibold); font-size: var(--text-md);
  cursor: pointer; text-decoration: none;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn--primary { background: var(--primary); color: var(--on-primary); }
.btn--primary:hover { background: var(--primary-hover); color: var(--on-primary); }
.btn--secondary { background: var(--surface-2); color: var(--text); }
.btn--secondary:hover { background: var(--border); color: var(--text); }
.btn--ghost { background: transparent; color: var(--text); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--danger { background: var(--danger-fg); color: var(--surface); }
.btn--sm { min-height: 36px; padding: 0 var(--space-4); font-size: var(--text-sm); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* ---------- Status chips (always icon + text, never colour alone) ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-pill);
  font-size: 13px; font-weight: var(--weight-bold); line-height: 1.4; white-space: nowrap;
}
.chip svg { width: 13px; height: 13px; flex-shrink: 0; }
.chip--passed  { background: var(--success-bg); color: var(--success-fg); }
.chip--warning { background: var(--warning-bg); color: var(--warning-fg); }
.chip--failed  { background: var(--danger-bg);  color: var(--danger-fg); }
.chip--running { background: var(--info-bg);    color: var(--info-fg); }
.chip--paused, .chip--skipped, .chip--offline { background: var(--neutral-bg); color: var(--neutral-fg); }
.chip--highlight { background: var(--highlight); color: var(--on-highlight); }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-height);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-6);
  padding: 0 var(--space-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar__left { display: flex; align-items: center; gap: var(--space-6); min-width: 0; }
.topbar__right { display: flex; align-items: center; gap: var(--space-3); }

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-family: var(--font-display); font-weight: var(--weight-bold); font-size: 21px; }
.brand:hover { text-decoration: none; color: var(--text); }
.brand__mark { width: 32px; height: 32px; border-radius: 9px; background: var(--primary); display: inline-flex; align-items: center; justify-content: center; color: var(--on-primary); }
.brand__mark svg { width: 19px; height: 19px; }
/* The wordmark (owner, 2026-10-05; ADR 0088): "Restorly" as outlines, the o an
   arrow turning back. No tile: letters in the text colour, the o in the link
   colour, so it follows light and dark. .brand__mark is the earlier mark on
   a tile, kept for the reference screens. */
.brand__logo { display: block; height: 28px; width: auto; }
.brand__letters { fill: currentColor; }
.brand__o { fill: var(--link); }

.nav { display: flex; gap: var(--space-1); }
.nav__item { padding: 8px 12px; white-space: nowrap; border-radius: var(--radius-pill); color: var(--text-muted); font-size: var(--text-md); font-weight: var(--weight-semibold); }
.nav__item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav__item[aria-current="page"] { background: var(--surface-2); color: var(--link); }

.select {
  font: inherit; font-weight: var(--weight-semibold); color: var(--text);
  min-height: 40px; padding: 0 var(--space-3);
  border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface);
}
.avatar { width: 36px; height: 36px; border-radius: var(--radius-pill); background: var(--highlight); color: var(--on-highlight); display: inline-flex; align-items: center; justify-content: center; font-weight: var(--weight-bold); font-size: var(--text-sm); }

.icon-btn { width: 40px; height: 40px; border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface); color: var(--text); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Page layout ---------- */
.page { padding: var(--space-7) var(--space-10); display: flex; flex-direction: column; gap: var(--space-6); max-width: var(--content-max); margin: 0 auto; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) var(--side-panel); gap: var(--space-6); align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap-grid); }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap-grid); }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row--between { justify-content: space-between; }

@media (max-width: 1360px) {
  .segmented button { padding: 6px 10px; }
}
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page { padding: var(--space-5) var(--space-4); }
  .topbar { padding: 0 var(--space-4); }
  .nav { display: none; } /* replaced by a menu button on small screens */
}

/* ---------- Cards and panels ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--card-pad); box-shadow: var(--shadow-card); display: flex; flex-direction: column; gap: var(--space-3); }
.card__head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.card__title { font-size: var(--text-lg); font-weight: var(--weight-bold); margin: 0; }
.card__meta { font-size: var(--text-sm); color: var(--text-muted); }
.card__meta .mono { white-space: nowrap; }

.hero-status { background: var(--surface); border-radius: var(--radius-xl); padding: var(--space-6) var(--space-8); display: flex; justify-content: space-between; align-items: center; gap: var(--space-10); border: 1px solid var(--border); }
.hero-status__headline { font-family: var(--font-display); font-size: var(--text-3xl); font-weight: var(--weight-black); letter-spacing: -0.02em; line-height: 1.1; margin: 0; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat__label { font-size: var(--text-xs); color: var(--text-subtle); }
.stat__value { font-size: 16px; font-weight: var(--weight-bold); }

.list { display: flex; flex-direction: column; }
.list__item { display: flex; flex-direction: column; gap: 4px; padding: var(--space-3) 0; border-bottom: 1px solid var(--surface-2); }
.list__item:last-child { border-bottom: 0; }

/* ---------- Tables (Databases, Runs, Audit log) ---------- */
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.table th { text-align: left; font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--text-subtle); padding: var(--space-3) var(--row-pad-x); border-bottom: 1px solid var(--border); background: var(--surface); }
.table td { padding: var(--row-pad-y) var(--row-pad-x); font-size: var(--text-sm); border-bottom: 1px solid var(--surface-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { font-family: var(--font-mono); text-align: right; }

/* ---------- Banners (licence, update, offline runner) ---------- */
.banner { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) var(--space-5); border-radius: var(--radius-md); font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.banner--info    { background: var(--info-bg);    color: var(--info-fg); }
.banner--warning { background: var(--warning-bg); color: var(--warning-fg); }
.banner--danger  { background: var(--danger-bg);  color: var(--danger-fg); }

/* ---------- Progress ---------- */
.progress { height: 6px; border-radius: var(--radius-pill); background: var(--progress-track); overflow: hidden; }
.progress__bar { height: 100%; background: var(--progress-fill); border-radius: var(--radius-pill); transition: width var(--dur-base) var(--ease); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.field__hint { font-size: var(--text-xs); color: var(--text-subtle); }
.field__error { font-size: var(--text-xs); color: var(--danger-fg); font-weight: var(--weight-semibold); }
.input, .textarea {
  font: inherit; color: var(--text); background: var(--surface);
  min-height: var(--touch-target); padding: 0 var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
}
.textarea { padding: var(--space-3); min-height: 120px; font-family: var(--font-mono); font-size: var(--text-sm); }
.input[aria-invalid="true"] { border-color: var(--danger-fg); }
/* File inputs: the button centred in the field, in our style (panel and website). */
.input[type="file"] { display: block; width: 100%; max-width: 100%; min-width: 0; padding: 5px; line-height: 32px; font-size: var(--text-sm); color: var(--text-muted); cursor: pointer; }
.input[type="file"]::file-selector-button { font: inherit; font-weight: var(--weight-semibold); color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 var(--space-3); height: 32px; margin-right: var(--space-3); cursor: pointer; vertical-align: middle; }
.input[type="file"]:hover::file-selector-button { border-color: var(--border-strong); }
.input[type="file"]:disabled { cursor: not-allowed; opacity: .6; }

/* Naming-pattern live preview */
.match-list { font-family: var(--font-mono); font-size: var(--text-sm); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.match-list__row { display: grid; grid-template-columns: minmax(0, 1fr) 140px 170px 90px; gap: var(--space-3); padding: 8px var(--space-3); border-bottom: 1px solid var(--surface-2); }
.match-list__row--newest { background: var(--success-bg); color: var(--success-fg); }
.match-list__row--unmatched { color: var(--text-subtle); text-decoration: line-through; }

/* ---------- Theme switch ---------- */
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--radius-pill); background: var(--surface-2); }
.segmented button { font: inherit; font-size: var(--text-sm); font-weight: var(--weight-semibold); border: 0; background: transparent; color: var(--text-muted); padding: 6px 12px; border-radius: var(--radius-pill); cursor: pointer; min-height: 32px; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); }
