/* ==========================================================================
   Gantry — Industrial UI stylesheet
   Clean, square, hairline-ruled. One signal colour. Mobile first.
   Fonts: IBM Plex Sans + IBM Plex Mono
   <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600&display=swap" rel="stylesheet">
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  /* Neutrals */
  --g-graphite: #17181A;   /* ink, dark surfaces */
  --g-graphite-2: #26282B; /* dark hover / active */
  --g-graphite-3: #3A3C40; /* dark rules */
  --g-steel: #55575C;      /* secondary text (AA on panel) */
  --g-steel-light: #A3A5A9;/* secondary text on dark */
  --g-rule: #D3D3CE;       /* hairlines, empty tracks */
  --g-rule-soft: #DCDCD8;  /* row dividers */
  --g-rule-strong: #C9C9C4;/* input / bar borders */
  --g-concrete: #E9E9E6;   /* page ground */
  --g-panel: #F6F6F4;      /* cards, panels */
  --g-white: #FFFFFF;

  /* Signal (accent) — use as FILL with graphite text */
  --g-signal: #FF5B14;
  --g-signal-text: #C2410C; /* orange when used as text on light ground */

  /* Status — always paired with a text label */
  --g-ok: #3A6EA5;
  --g-risk: #F06418;
  --g-off: #B3261E;

  /* Semantic aliases */
  --g-bg: var(--g-concrete);
  --g-surface: var(--g-panel);
  --g-text: var(--g-graphite);
  --g-text-muted: var(--g-steel);
  --g-border: var(--g-rule);

  /* Type */
  --g-font-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --g-font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --g-fs-display: 2.5rem;  /* 40 */
  --g-fs-h1: 2rem;         /* 32 */
  --g-fs-h2: 1.25rem;      /* 20 */
  --g-fs-h3: 0.9375rem;    /* 15 */
  --g-fs-body: 0.875rem;   /* 14 */
  --g-fs-small: 0.8125rem; /* 13 */
  --g-fs-label: 0.6875rem; /* 11 */

  /* Space (4px base) */
  --g-s1: 4px;  --g-s2: 8px;  --g-s3: 12px; --g-s4: 16px;
  --g-s5: 20px; --g-s6: 24px; --g-s8: 32px; --g-s10: 40px; --g-s14: 56px;

  /* Shape */
  --g-radius: 0px;
  --g-radius-sm: 2px;
  --g-hair: 1px solid var(--g-border);
  --g-touch: 44px;

  --g-hatch: repeating-linear-gradient(135deg, #DCDCD8 0 4px, #E9E9E6 4px 8px);
}

/* Optional dark theme */
[data-theme="dark"] {
  --g-bg: #0F1011;
  --g-surface: #17181A;
  --g-text: #F6F6F4;
  --g-text-muted: #A3A5A9;
  --g-border: #3A3C40;
  --g-signal-text: #FF7A3D;
  --g-hatch: repeating-linear-gradient(135deg, #26282B 0 4px, #17181A 4px 8px);
}

/* 2. Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--g-bg);
  color: var(--g-text);
  font-family: var(--g-font-sans);
  font-size: var(--g-fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.15; }
h1 { font-size: var(--g-fs-h1); letter-spacing: -0.01em; }
h2 { font-size: var(--g-fs-h2); }
h3 { font-size: var(--g-fs-h3); }

a { color: var(--g-text); text-underline-offset: 3px; }
a:hover { color: var(--g-text-muted); }

:focus-visible { outline: 2px solid var(--g-signal); outline-offset: 2px; }

/* 3. Typography utilities -------------------------------------------------- */
.g-mono    { font-family: var(--g-font-mono); }
.g-num     { font-variant-numeric: tabular-nums; }
.g-muted   { color: var(--g-text-muted); }
.g-display { font-size: var(--g-fs-display); font-weight: 600; line-height: 1; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.g-label {
  font-family: var(--g-font-mono);
  font-size: var(--g-fs-label);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--g-text-muted);
}
.g-id { font-family: var(--g-font-mono); font-size: 0.75rem; color: var(--g-text-muted); }
.g-sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* 4. App shell: sidebar + content, stacks on phones ------------------------ */
.g-app { display: flex; flex-wrap: wrap; min-height: 100vh; }

.g-sidebar {
  flex: 1 1 232px;
  display: flex; flex-direction: column; gap: 28px;
  padding: var(--g-s5) var(--g-s4);
  background: var(--g-graphite);
  color: var(--g-concrete);
}
.g-main {
  flex: 999 1 560px;
  min-width: 0;
  display: flex; flex-direction: column; gap: var(--g-s6);
  padding: 28px 36px 48px;
}

.g-brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }
.g-brand__mark {
  width: 28px; height: 28px; display: grid; place-items: center;
  background: var(--g-signal);
}
.g-brand__mark::after {
  content: ""; width: 12px; height: 12px; border: 2px solid var(--g-graphite);
}

.g-nav { display: flex; flex-direction: column; gap: 2px; }
.g-nav__item {
  display: flex; align-items: center; gap: var(--g-s3);
  min-height: var(--g-touch); padding: 10px 12px;
  color: #C9CACC; text-decoration: none;
  border-left: 3px solid transparent;
}
.g-nav__item:hover { background: var(--g-graphite-2); color: var(--g-panel); }
.g-nav__item[aria-current="page"] {
  background: var(--g-graphite-2); color: var(--g-panel);
  border-left-color: var(--g-signal);
}
.g-nav__index { font-family: var(--g-font-mono); font-size: 11px; color: #8A8C90; }

@media (max-width: 760px) {
  .g-nav { flex-direction: row; overflow-x: auto; }
  .g-nav__item { white-space: nowrap; }
  .g-sidebar__foot { display: none; }
  .g-main { padding: var(--g-s4); }
}

/* Page header */
.g-pagehead {
  display: flex; flex-wrap: wrap; gap: var(--g-s4);
  align-items: flex-end; justify-content: space-between;
}
.g-toolbar {
  display: flex; flex-wrap: wrap; gap: var(--g-s3);
  align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--g-rule-strong);
  border-bottom: 1px solid var(--g-rule-strong);
}

/* 5. Layout grids ---------------------------------------------------------- */
.g-grid-kpi   { display: grid; gap: var(--g-s3); grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.g-grid-cards { display: grid; gap: var(--g-s3); grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g-stack      { display: flex; flex-direction: column; gap: var(--g-s3); }

/* 6. Surfaces -------------------------------------------------------------- */
.g-card {
  background: var(--g-surface);
  border: var(--g-hair);
  border-radius: var(--g-radius);
  padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
}
.g-card--dark { background: var(--g-graphite); border-color: var(--g-graphite); color: var(--g-panel); }
.g-card--dark .g-label { color: var(--g-steel-light); }
.g-card__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--g-s2); }

.g-kpi { gap: 10px; }
.g-kpi__value { font-size: var(--g-fs-display); font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.g-kpi__unit  { font-size: 16px; font-weight: 500; color: var(--g-text-muted); }

/* Section rule (spec-sheet header) */
.g-rule-head { border-bottom: 2px solid var(--g-graphite); padding-bottom: var(--g-s2); }

/* 7. Buttons --------------------------------------------------------------- */
.g-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--g-s2);
  min-height: var(--g-touch); padding: 0 18px;
  font: inherit; font-size: var(--g-fs-body); font-weight: 500;
  border: 1px solid var(--g-graphite); border-radius: var(--g-radius);
  background: transparent; color: var(--g-text);
  cursor: pointer; text-decoration: none;
  transition: background-color .12s, color .12s;
}
.g-btn:hover { background: var(--g-graphite); color: var(--g-panel); }
.g-btn--primary { background: var(--g-signal); border-color: var(--g-signal); color: var(--g-graphite); font-weight: 600; }
.g-btn--primary:hover { background: #E84E0C; color: var(--g-graphite); }
.g-btn--dark { background: var(--g-graphite); color: var(--g-panel); }
.g-btn--dark:hover { background: var(--g-graphite-2); }
.g-btn--icon { width: var(--g-touch); padding: 0; }
.g-btn--block { width: 100%; min-height: 52px; font-size: 15px; }
.g-btn:disabled { opacity: .45; cursor: not-allowed; }

/* Segmented control / filter group */
.g-segmented { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--g-graphite); }
.g-segmented > button {
  min-height: 36px; padding: 0 14px; border: 0;
  background: transparent; color: var(--g-text);
  font: inherit; font-size: var(--g-fs-small); font-weight: 500; cursor: pointer;
}
.g-segmented > button[aria-pressed="true"] { background: var(--g-graphite); color: var(--g-panel); }

/* Chips (horizontal scroll on mobile) */
.g-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.g-chip {
  flex: none; min-height: 40px; padding: 0 14px;
  border: 1px solid var(--g-graphite); background: transparent; color: var(--g-text);
  font: inherit; font-size: var(--g-fs-small); font-weight: 500; cursor: pointer;
}
.g-chip[aria-pressed="true"] { background: var(--g-graphite); color: var(--g-panel); }
.g-chip__count { font-family: var(--g-font-mono); font-size: 11px; opacity: .75; }

/* 8. Forms ----------------------------------------------------------------- */
.g-field { display: flex; flex-direction: column; gap: 6px; }
.g-input, .g-select, .g-textarea {
  min-height: var(--g-touch); padding: 0 12px;
  font: inherit; font-size: var(--g-fs-body); color: var(--g-text);
  background: var(--g-white); border: 1px solid var(--g-graphite); border-radius: var(--g-radius);
}
.g-textarea { padding: 10px 12px; min-height: 96px; }
.g-input:focus, .g-select:focus, .g-textarea:focus { outline: 2px solid var(--g-signal); outline-offset: -1px; }
.g-search {
  display: flex; align-items: center; gap: var(--g-s2);
  min-height: var(--g-touch); padding: 0 12px;
  background: var(--g-panel); border: 1px solid var(--g-rule-strong);
}
.g-search input { border: 0; background: transparent; font: inherit; outline: none; min-width: 0; flex: 1; }
.g-check { display: flex; align-items: center; gap: 10px; min-height: var(--g-touch); border-top: 1px solid var(--g-rule-soft); }
.g-check input { width: 18px; height: 18px; accent-color: var(--g-graphite); }

/* 9. Tags, status ---------------------------------------------------------- */
.g-tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 7px;
  font-family: var(--g-font-mono); font-size: 11px; letter-spacing: .04em;
  background: var(--g-rule); color: var(--g-graphite);
}
.g-tag--signal  { background: var(--g-signal); }
.g-tag--dark    { background: var(--g-graphite); color: var(--g-panel); }
.g-tag--outline { background: transparent; border: 1px solid currentColor; }

.g-status { display: inline-flex; align-items: center; gap: 7px; font-size: var(--g-fs-small); }
.g-status::before { content: ""; width: 9px; height: 9px; background: var(--g-ok); }
.g-status--risk::before { background: var(--g-risk); }
.g-status--off::before  { background: var(--g-off); }

/* 10. Data viz primitives -------------------------------------------------- */
/* Stage tracker: <div class="g-stages"><span class="is-done"></span>…<span class="is-current"></span>…</div> */
.g-stages { display: flex; gap: 3px; }
.g-stages > span { flex: 1; height: 8px; background: var(--g-rule); }
.g-stages > .is-done    { background: var(--g-graphite); }
.g-stages > .is-current { background: var(--g-signal); }

/* Progress bar: <div class="g-bar"><div class="g-bar__fill" style="width:58%"></div></div> */
.g-bar { height: 6px; background: var(--g-rule-soft); position: relative; }
.g-bar__fill { height: 100%; background: var(--g-graphite); }
.g-bar--hatched { height: 14px; background: var(--g-hatch); }
.g-bar--hatched .g-bar__fill { background: var(--g-graphite); }
.g-bar__fill--signal { background: var(--g-signal); }
.g-bar__marker { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--g-graphite); }

/* Labelled bar row: label | bar | value */
.g-barrow { display: grid; grid-template-columns: 110px 1fr 44px; gap: 10px; align-items: center; font-size: var(--g-fs-small); }
.g-barrow > :last-child { font-family: var(--g-font-mono); text-align: right; font-variant-numeric: tabular-nums; }

/* Heatmap */
.g-heat { display: grid; grid-template-columns: 92px repeat(6, minmax(0, 1fr)); gap: 3px; align-items: center; }
.g-heat__cell {
  height: 38px; display: grid; place-items: center;
  font-family: var(--g-font-mono); font-size: 11px;
  background: var(--g-rule); color: var(--g-graphite);
}
.g-heat__cell--high { background: var(--g-steel); color: var(--g-panel); }
.g-heat__cell--over { background: var(--g-signal); font-weight: 600; }

/* Gate timeline */
.g-gates { list-style: none; margin: 0; padding: 0; }
.g-gate { display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; position: relative; padding-bottom: 14px; }
.g-gate::before { /* connector */
  content: ""; position: absolute; left: 13px; top: 24px; bottom: 0; width: 2px; background: var(--g-rule-strong);
}
.g-gate:last-child::before { display: none; }
.g-gate__node {
  width: 24px; height: 24px; display: grid; place-items: center;
  border: 2px solid #A3A5A9; font-family: var(--g-font-mono); font-size: 10px; color: var(--g-steel);
}
.g-gate.is-done    .g-gate__node { background: var(--g-graphite); border-color: var(--g-graphite); color: var(--g-panel); }
.g-gate.is-done::before          { background: var(--g-graphite); }
.g-gate.is-current .g-gate__node { background: var(--g-signal); border-color: var(--g-signal); color: var(--g-graphite); }
.g-gate.is-current .g-gate__title { font-weight: 600; }

/* Date block */
.g-date { display: flex; flex-direction: column; align-items: center; width: 52px; padding: 4px 0; border: 1px solid var(--g-graphite); }
.g-date__mon { font-family: var(--g-font-mono); font-size: 10px; }
.g-date__day { font-size: 18px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }

/* Avatar */
.g-avatar {
  display: inline-grid; place-items: center; width: 28px; height: 28px;
  background: var(--g-rule-soft); font-family: var(--g-font-mono); font-size: 11px;
}

/* 11. Tables --------------------------------------------------------------- */
.g-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.g-table { width: 100%; min-width: 980px; border-collapse: collapse; font-size: var(--g-fs-body); }
.g-table th {
  text-align: left; font-weight: 500; padding: 10px 8px;
  font-family: var(--g-font-mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--g-text-muted);
}
.g-table td { padding: 14px 8px; border-top: 1px solid var(--g-rule-soft); vertical-align: middle; }
.g-table th:first-child, .g-table td:first-child { padding-left: 18px; }
.g-table th:last-child,  .g-table td:last-child  { padding-right: 18px; }
.g-table tbody tr:hover { background: var(--g-white); }
.g-table .is-warn { color: var(--g-signal-text); font-weight: 600; }

/* 12. Mobile components ---------------------------------------------------- */
.g-appbar {
  height: 60px; display: flex; align-items: center; gap: 10px;
  padding: 0 8px 0 16px; background: var(--g-graphite); color: var(--g-panel);
  position: sticky; top: 0; z-index: 10;
}
.g-tabbar {
  position: sticky; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  height: 72px; padding-bottom: env(safe-area-inset-bottom);
  background: var(--g-panel); border-top: 1px solid var(--g-rule-strong);
}
.g-tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 11px; color: var(--g-steel); text-decoration: none;
  border-top: 3px solid transparent; margin-top: -1px;
}
.g-tabbar a[aria-current="page"] { color: var(--g-graphite); font-weight: 600; border-top-color: var(--g-signal); }

.g-actionbar {
  position: sticky; bottom: 0; display: flex; gap: var(--g-s2);
  padding: 12px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--g-panel); border-top: 1px solid var(--g-rule-strong);
}

.g-projectcard {
  display: flex; flex-direction: column; gap: 12px; padding: 14px;
  background: var(--g-surface); border: var(--g-hair);
  color: var(--g-text); text-decoration: none;
}
.g-projectcard:hover { border-color: var(--g-graphite); }
.g-projectcard__title { font-size: 17px; font-weight: 600; }
.g-projectcard__meta {
  display: flex; justify-content: space-between;
  font-family: var(--g-font-mono); font-size: 11px; color: var(--g-text-muted);
}

/* Kanban: horizontal snap columns on mobile */
.g-board { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 16px; }
.g-board__col { flex: none; width: min(300px, 82vw); scroll-snap-align: start; display: flex; flex-direction: column; gap: 8px; }

/* 13. Motion preference ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
