/* The CRM's one stylesheet (GYMLOG-737). The colours, radii and the system
   font are my.trenno.app's light tokens (gymlog-web src/styles/tokens.css),
   so the two pages read as one house; plain layout, no framework. One
   breakpoint: under 800px the sidebar becomes a top bar with the sections
   in a scrolling row, and every table becomes a stack of cards (each cell
   shows its column's label from data-label). */
:root {
  color-scheme: light;
  --ground: #f8f9fa;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #333333;
  --text-2: #666666;
  --text-3: #888888;
  --primary: #3a86ff;
  --primary-pressed: #2f74e6;
  --primary-tint: rgba(58, 134, 255, 0.1);
  --danger: #d93025;
  --danger-tint: rgba(217, 48, 37, 0.1);
  --ok: #1e8e3e;
  --ok-tint: rgba(30, 142, 62, 0.12);
  --warn: #b26a00;
  --warn-tint: rgba(232, 113, 10, 0.14);
  --hover: rgba(0, 0, 0, 0.04);
  --tile: #f1f4f9;
  --radius-card: 12px;
  --radius-control: 8px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08);
  --sidebar: 232px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--ground);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--ground); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
p { margin: 0 0 12px; }
code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text-2); word-break: break-all; }
.muted, .sub { color: var(--text-3); }
.sub { display: block; font-size: 12px; margin-top: 2px; }
.boot { padding: 48px; color: var(--text-3); text-align: center; }
[hidden] { display: none !important; }

/* Controls */
.button, select, input, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-control); padding: 8px 12px; min-height: 36px;
}
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; font-weight: 550; white-space: nowrap; }
.button:hover { background: var(--hover); text-decoration: none; }
.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-pressed); }
.button.quiet { border-color: transparent; background: transparent; color: var(--text-2); padding: 6px 8px; min-height: 0; }
.button.wide { width: 100%; }
.button.disabled, .button:disabled { opacity: 0.45; cursor: default; pointer-events: none; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .button:focus-visible, a:focus-visible, tr:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}
textarea { width: 100%; resize: vertical; min-height: 92px; }
select { max-width: 220px; }
.form-error { color: var(--danger); background: var(--danger-tint); border-radius: var(--radius-control); padding: 8px 12px; margin: 12px 0 0; }

/* Before the shell: sign-in, 403, messages */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); padding: 28px; display: grid; gap: 10px; }
.gate-card h1 { margin-bottom: 2px; }
.gate-brand { margin: 0; font-weight: 700; color: var(--primary); letter-spacing: 0.01em; }
.gate-code { margin: 0; font-size: 44px; line-height: 1; font-weight: 750; color: var(--text-3); }
.gate-text, .gate-account { margin: 0 0 6px; color: var(--text-2); }
.gate-account { font-weight: 550; color: var(--text); word-break: break-all; }
.gate-divider { margin: 6px 0 0; text-align: center; color: var(--text-3); font-size: 12px; }
.gate-form { display: grid; gap: 10px; }
.gate-form input { width: 100%; }

/* The shell */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 16px; padding: 20px 12px; background: var(--surface); border-right: 1px solid var(--border); }
.brand { font-size: 16px; font-weight: 700; color: var(--text); padding: 0 10px; }
.brand:hover { text-decoration: none; }
.sections { display: grid; gap: 2px; }
.sections a { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: var(--radius-control); color: var(--text); font-weight: 550; }
.sections a:hover { background: var(--hover); text-decoration: none; }
.sections a.current { background: var(--primary-tint); color: var(--primary-pressed); }
.nav-label { flex: 1; }
.nav-count { color: var(--text-3); font-weight: 450; font-variant-numeric: tabular-nums; }
.nav-badge { font-size: 11px; font-weight: 650; padding: 1px 7px; border-radius: 999px; background: var(--primary); color: #fff; }
.account { margin-top: auto; display: grid; gap: 4px; padding: 0 10px; justify-items: start; }
.account-email { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.account .button { margin-left: -8px; }
.build { font-size: 11px; }
.outlet { padding: 28px 32px 56px; max-width: 1360px; width: 100%; outline: none; }
.outlet.loading { opacity: 0.55; transition: opacity 0.15s 0.15s; }

/* A page */
.back { display: inline-block; margin-bottom: 10px; color: var(--text-2); font-weight: 550; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-count { margin: 4px 0 0; color: var(--text-2); }
.page-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.search { display: flex; gap: 6px; flex: 1 1 280px; max-width: 460px; }
.search input { flex: 1; min-width: 0; }
.tabs { display: inline-flex; gap: 2px; padding: 3px; background: var(--tile); border-radius: 10px; }
.tab { padding: 6px 12px; border-radius: 7px; color: var(--text-2); font-weight: 550; white-space: nowrap; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.current { background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); }
.tab-count { color: var(--text-3); font-weight: 450; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.split-picture { grid-template-columns: minmax(0, 1fr) 300px; }
.columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); padding: 18px 20px; margin-bottom: 20px; }
.card > :last-child { margin-bottom: 0; }
.card.error { border-color: var(--danger); }
.empty { padding: 28px 20px; text-align: center; color: var(--text-3); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius-card); }
.later { color: var(--text-3); font-size: 13px; margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 14px 16px; display: grid; gap: 2px; }
.tile-value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile-label { color: var(--text-2); font-size: 12px; }

/* Tables */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); overflow: hidden; margin-bottom: 16px; }
.card .table-card { box-shadow: none; margin-bottom: 0; }
.card .table-card + p { margin: 12px 0 0; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); padding: 10px 14px; background: var(--ground); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--hover); }
.wide { width: 40%; }
.nowrap { white-space: nowrap; }
th.number, td.number { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td code { word-break: normal; white-space: nowrap; }
.excerpt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--text-2); }
.picture-cell { width: 92px; }
.picture { display: block; background: var(--tile); border-radius: 8px; overflow: hidden; }
.picture img { display: block; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.picture-thumb { width: 64px; height: 44px; }
.picture-large { width: 100%; aspect-ratio: 4 / 3; border: 1px solid var(--border); border-radius: var(--radius-card); }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-bottom: 20px; }
.pager-status { color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Values */
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--tile); color: var(--text-2); white-space: nowrap; }
a.chip:hover { text-decoration: none; background: var(--primary-tint); }
.chip-new { background: var(--primary-tint); color: var(--primary-pressed); }
.chip-reviewed, .chip-warn { background: var(--warn-tint); color: var(--warn); }
.chip-fixed { background: var(--ok-tint); color: var(--ok); }
.fields { margin: 0; display: grid; gap: 0; }
.field { display: grid; grid-template-columns: 168px minmax(0, 1fr); gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: 0; }
.split > .card .field { grid-template-columns: 124px minmax(0, 1fr); }
dt { color: var(--text-2); }
dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.prose, .report-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.report-text { font-size: 15px; line-height: 1.55; }
.steps, .links { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.status-form { display: grid; gap: 12px; }
.choices { display: inline-flex; gap: 2px; padding: 3px; background: var(--tile); border-radius: 10px; justify-self: start; }
.choice { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 550; color: var(--text-2); }
.choice:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); }
.choice input { min-height: 0; margin: 0; accent-color: var(--primary); }
.form-row { display: flex; align-items: center; gap: 12px; }
.saved { color: var(--ok); font-weight: 550; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.history li { display: grid; gap: 1px; padding-left: 12px; border-left: 2px solid var(--border); }
.history-when { color: var(--text-2); font-size: 12px; }
.history-note { white-space: pre-wrap; overflow-wrap: anywhere; }

@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0; flex: 1; }
  .account { margin: 0; padding: 0; display: flex; align-items: center; gap: 4px; min-width: 0; }
  .account-email, .build { display: none; }
  .sections { order: 3; flex-basis: 100%; display: flex; gap: 4px; overflow-x: auto; margin: 0 -16px; padding: 0 16px 2px; scrollbar-width: none; }
  .sections a { flex-shrink: 0; padding: 7px 10px; }
  .outlet { padding: 18px 16px 40px; }
  .page-header { flex-direction: column; gap: 8px; }
  .split, .split-picture, .columns { grid-template-columns: minmax(0, 1fr); }
  .split-picture > div:last-child { order: -1; max-width: 220px; }
  .tabs { max-width: 100%; overflow-x: auto; }
  select { max-width: none; flex: 1 1 150px; }
  .search { max-width: none; flex-basis: 100%; }
  .field, .split > .card .field { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pager { justify-content: space-between; }

  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  table, tbody, tr, td { display: block; width: auto; }
  tr { padding: 10px 14px; border-bottom: 1px solid var(--border); }
  tr:last-child { border-bottom: 0; }
  td, th.number, td.number { padding: 3px 0; border: 0; text-align: left; white-space: normal; display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 10px; }
  td::before { content: attr(data-label); color: var(--text-3); font-size: 12px; padding-top: 1px; }
  .cell { min-width: 0; }
  td.wide { width: auto; }
  .picture-cell { width: auto; }
}
