:root {
  /* === Brand Colors === */
  --tsg-navy:        #263285;   /* TSG Dark Blue — brand standard */
  --tsg-blue:        #0069B4;   /* TSG Light Blue — brand standard */
  --tsg-blue-light:  #CDD9EA;
  --tsg-blue-pale:   #E8EEF7;
  --tsg-white:       #FFFFFF;
  --tsg-gray-50:     #F8FAFC;
  --tsg-gray-100:    #F1F5F9;
  --tsg-gray-200:    #E2E8F0;
  --tsg-gray-400:    #94A3B8;
  --tsg-gray-600:    #475569;
  --tsg-gray-800:    #1E293B;
  --tsg-black:       #0F172A;

  /* === Semantic Colors === */
  --color-primary:   var(--tsg-navy);
  --color-accent:    var(--tsg-blue);
  --color-surface:   var(--tsg-white);
  --color-bg:        var(--tsg-gray-50);
  --color-border:    var(--tsg-gray-200);
  --color-text:      var(--tsg-gray-800);
  --color-muted:     var(--tsg-gray-600);
  /* Functional status colors — UI affordances only, never brand/decorative use */
  --color-success:   #16A34A;
  --color-warning:   #D97706;
  --color-danger:    #DC2626;

  /* === Typography === */
  --font-heading:    'Century Gothic', CenturyGothic, 'Questrial', sans-serif;
  --font-body:       'Century Gothic', CenturyGothic, 'Questrial', sans-serif;
  --font-mono:       'JetBrains Mono', monospace;

  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;

  /* === Spacing === */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* === Layout === */
  --sidebar-width:    220px;
  --topbar-height:    56px;
  --radius-sm:        4px;
  --radius-md:        8px;
  --radius-lg:        12px;
  --shadow-sm:        0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:        0 4px 12px rgba(0,0,0,0.10);
  --shadow-lg:        0 8px 24px rgba(0,0,0,0.12);

  /* === Topbar === */
  --topbar-bg:        var(--tsg-navy);
  --topbar-text:      var(--tsg-white);

  /* === Sidebar === */
  --sidebar-bg:       var(--tsg-gray-100);
  --sidebar-text:     var(--tsg-gray-800);
  --sidebar-active-bg: var(--tsg-blue-pale);
  --sidebar-active-text: var(--tsg-navy);
}

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

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
}

/* Topbar */
.tsg-topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--topbar-bg);
  color: var(--topbar-text);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-6);
  z-index: 100;
  box-shadow: var(--shadow-md);
}
.tsg-topbar__wordmark {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: var(--text-xl);
  letter-spacing: 0.05em;
}
.tsg-topbar__app-name {
  font-family: var(--font-heading);
  font-weight: 400;
  font-size: var(--text-lg);
  margin-left: var(--space-3);
  opacity: 0.85;
}
.tsg-topbar__user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
}

/* Layout */
.tsg-layout {
  display: flex;
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
}
.tsg-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--color-border);
  flex-shrink: 0;
  padding: var(--space-4) 0;
}
.tsg-main {
  flex: 1;
  padding: var(--space-8);
  overflow-y: auto;
  min-width: 0; /* let flex children shrink below their content's intrinsic width instead of overflowing */
}

/* Desktop default: the mobile-only location-jump <select> (shown instead, see the @media
   rule below) stays hidden here since the full link list below already covers this. */
.tsg-nav__mobile-locations { display: none; }

/* Locations group toggle (desktop sidebar) — collapsed by default (per mpierce, 2026-10-09:
   15 items made the sidebar too tall); .tsg-sidebar--locations-expanded shows the sub-items
   (see the @media (min-width: 721px) rule further down). Declared here, before the mobile
   @media block below, so that block's display:none for mobile wins the cascade there (same
   specificity, so source order decides) instead of this one. */
.tsg-nav__group-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: none; border: none; cursor: pointer; text-align: left;
  padding: var(--space-4) var(--space-4) var(--space-1);
  margin: 0 var(--space-2);
  font-family: inherit;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
}
.tsg-nav__group-toggle:hover { color: var(--color-text); }
.tsg-nav__group-chevron { transition: transform 0.15s; font-size: var(--text-sm); }
.tsg-sidebar--locations-expanded .tsg-nav__group-chevron { transform: rotate(90deg); }

/* Mobile: the sidebar's fixed width otherwise leaves almost no room for content
   (this is now an installable phone app, not just a desktop tool -- see the PWA
   install guide) -- stack the nav above the content and free up the full width. */
@media (max-width: 720px) {
  .tsg-layout { flex-direction: column; }
  .tsg-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-2) 0;
  }
  .tsg-nav { display: flex; overflow-x: auto; align-items: center; }
  .tsg-nav__link { white-space: nowrap; }
  .tsg-main { padding: var(--space-4); }
  /* 11 inline location links (~2500px of horizontal scrolling to reach the last one) and the
     desktop expand/collapse toggle don't work in this scrolling-row layout -- collapse them
     into one <select> instead (built in app.js's buildLocationNavLinks(), same data as the
     links below). */
  .tsg-nav__group-toggle, .tsg-nav__item--sub { display: none; }
  .tsg-nav__mobile-locations { display: flex; align-items: center; flex-shrink: 0; padding: 0 var(--space-2); }
  .tsg-nav__mobile-locations select { font-size: var(--text-sm); padding: var(--space-1) var(--space-2); }
}

/* Nav */
.tsg-nav { list-style: none; }
.tsg-nav__link {
  display: block;
  padding: var(--space-2) var(--space-4);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
  margin: 0 var(--space-2);
  transition: background 0.15s;
}
.tsg-nav__item--active .tsg-nav__link,
.tsg-nav__link:hover {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 500;
}
.tsg-nav__item--sub .tsg-nav__link { padding-left: var(--space-6); font-size: var(--text-xs); }

@media (min-width: 721px) {
  .tsg-nav__item--sub { display: none; }
  .tsg-sidebar--locations-expanded .tsg-nav__item--sub { display: list-item; }
}

/* Typography */
.tsg-heading { font-family: var(--font-heading); font-weight: 700; font-size: var(--text-3xl); color: var(--color-primary); }
.tsg-subhead { font-size: var(--text-lg); color: var(--color-muted); margin-top: var(--space-1); }

/* Buttons */
.tsg-btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s;
}
.tsg-btn:hover { opacity: 0.88; }
.tsg-btn--primary { background: var(--color-accent); color: var(--tsg-white); }
.tsg-btn--ghost { background: transparent; color: var(--topbar-text); border: 1px solid rgba(255,255,255,0.3); }

/* Cards */
.tsg-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

/* Views */
.tsg-view { display: none; }
.tsg-view.is-active { display: block; }

/* Ghost button on a light card (vs. the topbar, where --topbar-text is white) */
.tsg-btn--on-light { color: var(--color-primary); border: 1px solid var(--color-border); }

/* Form layout */
.tsg-form-section { margin-top: var(--space-6); }
.tsg-form-section:first-of-type { margin-top: var(--space-6); }
.tsg-form-section__title {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: var(--space-4);
}
fieldset.tsg-form-section { border: none; padding: var(--space-6); }
fieldset.tsg-form-section:disabled { opacity: 0.5; }
fieldset.tsg-form-section:disabled .tsg-input,
fieldset.tsg-form-section:disabled button { pointer-events: none; }

.tsg-field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.tsg-field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); }
.tsg-field[hidden] { display: none; }
.tsg-field--wide { grid-column: 1 / -1; }
.tsg-label { font-size: var(--text-sm); font-weight: 500; color: var(--color-text); }
.tsg-field__note { font-size: var(--text-xs); color: var(--color-muted); margin-top: var(--space-1); }

.tsg-input {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}
.tsg-input:focus { outline: 2px solid var(--color-accent); outline-offset: 1px; }
.tsg-input[readonly] { background: var(--tsg-gray-100); color: var(--color-muted); }
.tsg-input--cell { padding: var(--space-1) var(--space-2); width: 100%; }
textarea.tsg-input--cell {
  resize: none;
  overflow: hidden;
  min-height: 2.1em;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  vertical-align: top;
  display: block;
}
/* table-layout:auto doesn't reliably honor min-width set on <th> for column sizing --
   setting it on the cell's own content (the textarea) is what actually forces the column
   to grow, since browsers size auto-layout columns off cell content's intrinsic width. */
textarea.tsg-input--cell-wide { min-width: 130px; }
textarea.tsg-input--cell-description { min-width: 200px; }

.tsg-checkbox-row, .tsg-radio-row { display: flex; gap: var(--space-4); align-items: center; flex-wrap: wrap; }
.tsg-checkbox, .tsg-radio { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); cursor: pointer; }

.tsg-form-actions { display: flex; align-items: center; gap: var(--space-4); margin-top: var(--space-6); flex-wrap: wrap; }

/* Parts table */
.tsg-table-wrap { overflow-x: auto; }
.tsg-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
/* #parts-table and #manage-parts-table only: with the default "auto" layout, Chromium doesn't
   reliably size a column off a <textarea>'s own CSS width/min-width, so the parts tables' wide
   text columns kept getting squeezed. Fixed layout takes column widths straight from the header
   cells instead, but a block-level table's "auto" width still just fills its container (same
   as width:100%) regardless of table-layout, undoing that — so each gets a literal width equal
   to the sum of its declared column widths (update both together if columns change), letting
   it grow past a narrow wrapper; .tsg-table-wrap's overflow-x:auto then scrolls horizontally
   instead of squeezing anything. Other .tsg-table tables (My/All/Location Requests) keep auto
   layout — they have no per-column widths to honor. */
#parts-table { table-layout: fixed; width: 1250px; }
#manage-parts-table { table-layout: fixed; width: 1240px; }

.tsg-attachment-list { list-style: none; margin-top: var(--space-2); }
.tsg-attachment-list li {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-1) 0; font-size: var(--text-sm);
}
.tsg-attachment-list a { color: var(--color-primary); }
.tsg-attachment-list__size { color: var(--color-muted); font-size: var(--text-xs); white-space: nowrap; }
.tsg-attachment-list__remove {
  background: none; border: none; color: var(--color-muted); cursor: pointer;
  font-size: var(--text-sm); line-height: 1; padding: 0 var(--space-1);
}
.tsg-attachment-list__remove:hover { color: var(--color-text); }
.tsg-table th {
  text-align: left; padding: var(--space-2); border-bottom: 2px solid var(--color-border);
  font-weight: 600; color: var(--color-muted); white-space: nowrap;
}
.tsg-table td { padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--color-border); }
.tsg-ext-price { text-align: right; white-space: nowrap; }

/* Dashboard status tiles (dashboard.js) — click one to jump to that filtered list. */
.tsg-stat-tiles { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-3); }
.tsg-stat-tile {
  display: flex; flex-direction: column; gap: var(--space-1);
  min-width: 120px;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  text-decoration: none; color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tsg-stat-tile:hover { border-color: var(--color-accent); box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08); }
.tsg-stat-tile__count { font-size: var(--text-3xl); font-weight: 700; color: var(--color-primary); line-height: 1; }
.tsg-stat-tile__label { font-size: var(--text-sm); color: var(--color-muted); }

/* Toasts (toast.js) — non-blocking replacement for native alert() popups. */
.tsg-toast-container {
  position: fixed; top: var(--space-4); right: var(--space-4); z-index: 1000;
  display: flex; flex-direction: column; gap: var(--space-2); max-width: 420px;
}
.tsg-toast {
  background: var(--color-surface); border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.18);
  padding: var(--space-3) var(--space-4);
  display: flex; align-items: flex-start; gap: var(--space-3);
  border-left: 4px solid var(--color-border);
  animation: tsg-toast-in 0.15s ease-out;
}
.tsg-toast--leaving { opacity: 0; transition: opacity 0.2s; }
.tsg-toast--error { border-left-color: #dc2626; }
.tsg-toast--warning { border-left-color: #d97706; }
.tsg-toast--success { border-left-color: #16a34a; }
.tsg-toast__message { flex: 1; font-size: var(--text-sm); white-space: pre-line; }
.tsg-toast__close {
  background: none; border: none; cursor: pointer; color: var(--color-muted);
  font-size: var(--text-lg); line-height: 1; padding: 0;
}
.tsg-toast__close:hover { color: var(--color-text); }
@keyframes tsg-toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (max-width: 720px) {
  .tsg-toast-container { left: var(--space-4); right: var(--space-4); max-width: none; }
}
.tsg-row-remove {
  background: none; border: none; color: var(--color-danger); font-size: var(--text-lg);
  cursor: pointer; line-height: 1; padding: var(--space-1);
}

/* Manage Request — summary + workflow stages */
.tsg-summary-grid {
  display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
}
.tsg-summary-grid dt { font-weight: 600; color: var(--color-muted); }
.tsg-summary-grid dd { color: var(--color-text); }
.tsg-attestation {
  font-size: var(--text-sm); color: var(--color-text); background: var(--tsg-blue-pale);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); margin-top: var(--space-2);
}
.tsg-notify-preview {
  font-size: var(--text-xs); color: var(--color-muted); font-family: var(--font-mono);
  margin-top: var(--space-2);
}

.tsg-table-cell-check { text-align: center; }
.tsg-table-attestation { display: block; font-size: 0.65rem; color: var(--color-muted); margin-top: 2px; white-space: nowrap; }

/* Review preview */
.tsg-review-json {
  font-family: var(--font-mono); font-size: var(--text-xs); background: var(--tsg-gray-100);
  padding: var(--space-4); border-radius: var(--radius-sm); overflow-x: auto; white-space: pre-wrap;
}
