/* ── TSG CSS Tokens ─────────────────────────────────────────────────────── */
:root {
  --tsg-navy:        #263285;
  --tsg-blue:        #0069B4;
  --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;
  --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);
  --color-success:   #16A34A;
  --color-warning:   #D97706;
  --color-danger:    #DC2626;
  --font-heading:    'Century Gothic', CenturyGothic, 'Questrial', sans-serif;
  --font-body:       'Century Gothic', CenturyGothic, 'Questrial', sans-serif;
  --font-mono:       'JetBrains Mono', monospace;
  --text-xs:   0.72rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;
  --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;
  --sidebar-width:  230px;
  --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.14);
  --topbar-bg:   var(--tsg-navy);
  --topbar-text: var(--tsg-white);
  --sidebar-bg:  var(--tsg-gray-100);
  --sidebar-active-bg:   var(--tsg-blue-pale);
  --sidebar-active-text: var(--tsg-navy);
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::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.55; }
a { color: var(--tsg-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Access Gate ────────────────────────────────────────────────────────── */
.gate-overlay {
  position: fixed; inset: 0; background: var(--tsg-navy);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.gate-card {
  background: var(--tsg-white); border-radius: var(--radius-lg);
  padding: var(--space-12) var(--space-8); width: 100%; max-width: 440px;
  box-shadow: var(--shadow-lg); text-align: center;
}
.gate-logo { margin-bottom: var(--space-4); }
.gate-logo__tsg {
  font-family: var(--font-heading); font-weight: 700; font-size: 2.4rem;
  color: var(--tsg-navy); letter-spacing: 0.08em; display: block;
}
.gate-logo__tagline { font-size: var(--text-xs); color: var(--color-muted); letter-spacing: 0.1em; text-transform: uppercase; }
.gate-title { font-family: var(--font-heading); font-size: var(--text-2xl); font-weight: 700; color: var(--tsg-navy); margin-top: var(--space-2); }
.gate-sub { font-size: var(--text-sm); color: var(--color-muted); margin-top: var(--space-1); margin-bottom: var(--space-6); }
.gate-form { text-align: left; }
.gate-label { display: block; font-size: var(--text-sm); font-weight: 600; color: var(--tsg-navy); margin-bottom: var(--space-1); margin-top: var(--space-3); }
.gate-input {
  width: 100%; padding: var(--space-2) var(--space-3);
  border: 1.5px solid var(--color-border); border-radius: var(--radius-md);
  font-family: var(--font-body); font-size: var(--text-sm);
  transition: border-color 0.15s;
}
.gate-input:focus { outline: none; border-color: var(--tsg-blue); }
.gate-error { color: var(--color-danger); font-size: var(--text-sm); margin-top: var(--space-2); }
.gate-btn { width: 100%; margin-top: var(--space-6); justify-content: center; padding: var(--space-3); font-size: var(--text-base); }
.gate-footer { margin-top: var(--space-6); font-size: var(--text-xs); color: var(--color-muted); line-height: 1.7; }

/* ── 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__brand { display: flex; align-items: baseline; gap: var(--space-3); }
.tsg-topbar__wordmark { font-family: var(--font-heading); font-weight: 700; font-size: var(--text-xl); letter-spacing: 0.06em; }
.tsg-topbar__app-name { font-size: var(--text-sm); opacity: 0.85; }
.tsg-topbar__user { display: flex; align-items: center; gap: var(--space-3); }
.topbar-user-badge { font-size: var(--text-sm); opacity: 0.85; }
.tsg-role-badge {
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.04em;
  padding: 3px 10px; border-radius: 999px;
  background: rgba(255,255,255,0.15); color: var(--tsg-white);
}

/* ── 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-family: var(--font-body); font-size: var(--text-sm); font-weight: 500;
  cursor: pointer; border: none; transition: opacity 0.15s, box-shadow 0.15s;
  white-space: nowrap; text-decoration: none;
}
.tsg-btn:hover { opacity: 0.88; text-decoration: none; }
.tsg-btn--primary { background: var(--color-accent); color: var(--tsg-white); }
.tsg-btn--ghost { background: transparent; color: var(--topbar-text); border: 1.5px solid rgba(255,255,255,0.35); }
.tsg-btn--ghost-dark { background: transparent; color: var(--tsg-navy); border: 1.5px solid var(--tsg-blue-light); }
.tsg-btn--outline { background: transparent; color: var(--tsg-blue); border: 1.5px solid var(--tsg-blue); }

/* ── Page Header ────────────────────────────────────────────────────────── */
.page-header { margin-bottom: var(--space-8); }
.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-base); color: var(--color-muted); margin-top: var(--space-1); }
.empty-state { text-align: center; color: var(--color-muted); padding: var(--space-8); font-size: var(--text-sm); }

/* ── Hub Main / Project Grid ────────────────────────────────────────────── */
.hub-main { margin-top: var(--topbar-height); padding: var(--space-8); max-width: 1100px; margin-left: auto; margin-right: auto; }
.project-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-6);
}
.project-card {
  display: block; background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, transform 0.15s; color: var(--color-text);
}
.project-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); text-decoration: none; }
.project-card__bar {
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  color: var(--tsg-white); background: var(--tsg-blue); letter-spacing: 0.04em;
  padding: var(--space-2) var(--space-6);
}
.project-card__body { padding: var(--space-6); }
.project-card__name { font-family: var(--font-heading); font-weight: 700; font-size: var(--text-xl); color: var(--tsg-navy); }
.project-card__loc { font-size: var(--text-sm); color: var(--color-muted); margin-top: var(--space-1); }
.project-card__enter { font-size: var(--text-sm); font-weight: 600; color: var(--tsg-blue); margin-top: var(--space-4); }
.badge-access {
  display: inline-block; margin-top: var(--space-2); font-size: var(--text-xs); font-weight: 600;
  padding: 2px 9px; border-radius: 999px; background: var(--tsg-blue-pale); color: var(--tsg-navy);
}

/* TSG staff vs Subcontractor, at a glance, in the Manage Access table.
   Derived from is_admin / any project's Internal flag — not a stored field. */
.role-pill {
  display: inline-block; margin-left: var(--space-2); font-size: var(--text-xs); font-weight: 700;
  letter-spacing: 0.02em; padding: 2px 8px; border-radius: 999px; vertical-align: middle;
}
.role-pill--tsg { background: var(--tsg-navy); color: var(--tsg-white); }
.role-pill--sub { background: var(--tsg-gray-100); color: var(--tsg-gray-600); }

/* ── Hub Tabs ───────────────────────────────────────────────────────────── */
.hub-tabs { display: flex; gap: var(--space-2); margin-bottom: var(--space-6); border-bottom: 1px solid var(--color-border); }
.hub-tab {
  background: none; border: none; cursor: pointer; padding: var(--space-3) var(--space-4);
  font-family: var(--font-body); font-size: var(--text-sm); font-weight: 600; color: var(--color-muted);
  border-bottom: 2px solid transparent;
}
.hub-tab--active { color: var(--tsg-navy); border-bottom-color: var(--tsg-blue); }

/* ── Cards / Forms (shared with admin panel) ───────────────────────────── */
.tsg-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow-sm); }
.form-section-bar {
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.06em; color: var(--tsg-navy);
  text-transform: uppercase; border-bottom: 1px solid var(--color-border); padding-bottom: var(--space-2); margin-bottom: var(--space-3);
}
.form-input {
  padding: var(--space-2) var(--space-3); border: 1.5px solid var(--color-border); border-radius: var(--radius-md);
  font-family: var(--font-body); font-size: var(--text-sm);
}
.form-input:focus { outline: none; border-color: var(--tsg-blue); }
.table-scroll { overflow-x: auto; }

/* ── Admin Table ────────────────────────────────────────────────────────── */
.admin-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.admin-table th, .admin-table td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-border); text-align: left; white-space: nowrap; }
.admin-table th { background: var(--tsg-gray-50); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-muted); }
.admin-input, .admin-select {
  padding: var(--space-1) var(--space-2); border: 1.5px solid var(--color-border); border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: var(--text-sm); width: 100%;
}
.add-user-card { margin-top: var(--space-6); }
.add-user-row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.add-user-row .form-input { flex: 1; min-width: 160px; }

.admin-access-row td { background: var(--tsg-gray-50); white-space: normal; }
.admin-access-panel {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-2) var(--space-4); padding: var(--space-2) 0;
}
.admin-access-item { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.admin-access-item__name { font-size: var(--text-sm); color: var(--color-text); }

/* ── Modal (permission editor) ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 500; display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
}
.modal-card {
  background: var(--tsg-white); border-radius: var(--radius-lg);
  padding: var(--space-8); max-width: 560px; width: 100%;
  max-height: 90vh; overflow-y: auto; position: relative;
  box-shadow: var(--shadow-lg);
}
.modal-close {
  position: absolute; top: var(--space-4); right: var(--space-4);
  background: none; border: none; font-size: 1.1rem; cursor: pointer;
  color: var(--color-muted); padding: var(--space-1);
}
.modal-close:hover { color: var(--color-text); }

.preset-row { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2) var(--space-4); margin-bottom: var(--space-4); }
.perm-check { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.perm-internal-row {
  display: flex; align-items: center; gap: var(--space-2); padding-top: var(--space-3);
  margin-top: var(--space-2); border-top: 1px solid var(--color-border); font-size: var(--text-sm); font-weight: 600;
}
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-3); margin-top: var(--space-6); }

/* ── Tracker (admin-only, cross-project record dashboard) ─────────────── */
.tracker-subtabs { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }
.tracker-subtab {
  padding: var(--space-2) var(--space-4); border: 1.5px solid var(--color-border); border-radius: 999px;
  background: var(--tsg-white); color: var(--color-text); font-size: var(--text-sm); font-weight: 600; cursor: pointer;
}
.tracker-subtab--active { background: var(--tsg-navy); border-color: var(--tsg-navy); color: var(--tsg-white); }

.filter-bar { display: flex; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.filter-select, .filter-search {
  padding: var(--space-2) var(--space-3); border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md); font-family: var(--font-body); font-size: var(--text-sm);
  background: var(--tsg-white);
}
.filter-search { min-width: 220px; flex: 1; }
.filter-select:focus, .filter-search:focus { outline: none; border-color: var(--tsg-blue); }

/* Bounded height + sticky header/actions column, same pattern already
   proven on every project's own log tables. */
.table-scroll--bounded { overflow: auto; max-height: 65vh; }
.tracker-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.tracker-table thead tr { background: var(--tsg-navy); color: var(--tsg-white); }
.tracker-table th {
  padding: var(--space-3); text-align: left; font-weight: 600; font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap;
  position: sticky; top: 0; z-index: 1; background: var(--tsg-navy); color: var(--tsg-white);
}
.tracker-table td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.tracker-table tbody tr:nth-child(even) { background: var(--tsg-gray-50); }
.tracker-table tbody tr:hover { background: var(--tsg-blue-pale); }
.tracker-table th.col-actions { right: 0; }
.tracker-table td.col-actions { position: sticky; right: 0; background: var(--tsg-white); box-shadow: -4px 0 6px -4px rgba(0,0,0,0.15); }
.empty-state { text-align: center; color: var(--color-muted); padding: var(--space-8); font-size: var(--text-sm); }

.tracker-project-pill {
  display: inline-block; font-size: var(--text-xs); font-weight: 600; padding: 2px 8px;
  border-radius: 999px; background: var(--tsg-blue-pale); color: var(--tsg-navy); white-space: nowrap;
}

.badge {
  display: inline-block; padding: 2px var(--space-2); border-radius: 999px;
  font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
}
.badge--open        { background: #FFFACD; color: #856404; }
.badge--pending     { background: #FFFACD; color: #856404; }
.badge--in-progress { background: #D6EAF8; color: #1B4F72; }
.badge--complete    { background: #D6F0D6; color: #155724; }
.badge--closed      { background: #E0E0E0; color: #555; }
.badge--on-hold     { background: #FFF3CD; color: #856404; }
.badge--routine     { background: #E8EEF7; color: var(--tsg-navy); }
.badge--urgent      { background: #FFF3CD; color: #856404; }
.badge--critical    { background: #FAD7D7; color: #721C24; }
.badge--danger      { background: #F5C6CB; color: #58151C; font-weight: 700; }

/* Wider variant of the shared .modal-card, for the tracker's record-detail
   view — enough room for a two-column field grid like the project pages. */
.modal-card--wide { max-width: 740px; }
.modal-toolbar { display: flex; justify-content: flex-end; padding-right: 36px; margin-bottom: var(--space-3); }
.modal-field { margin-bottom: var(--space-3); }
.modal-label { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--tsg-navy); }
.modal-value { font-size: var(--text-sm); color: var(--color-text); margin-top: 2px; line-height: 1.6; white-space: pre-wrap; }
.modal-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); margin-bottom: var(--space-4); }
.modal-divider { border: none; border-top: 1px solid var(--color-border); margin: var(--space-4) 0; }
.modal-section-bar { background: var(--tsg-navy); color: var(--tsg-white); font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.06em; padding: var(--space-1) var(--space-3); border-radius: var(--radius-sm); margin-bottom: var(--space-3); }

.form-textarea {
  padding: var(--space-2) var(--space-3); border: 1.5px solid var(--color-border); border-radius: var(--radius-md);
  font-family: var(--font-body); font-size: var(--text-sm); resize: vertical; line-height: 1.6;
}
.form-textarea:focus { outline: none; border-color: var(--tsg-blue); }

/* ── Comments (Tracker record-detail modal) ────────────────────────────── */
.comments-section { margin-top: var(--space-6); padding-top: var(--space-4); border-top: 1px solid var(--color-border); }
.comment-item { padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border); }
.comment-item:last-child { border-bottom: none; }
.comment-meta { font-size: var(--text-xs); color: var(--color-muted); margin-bottom: 2px; }
.comment-author { font-weight: 700; color: var(--tsg-navy); }
.comment-body { font-size: var(--text-sm); color: var(--color-text); white-space: pre-wrap; line-height: 1.5; }
.comment-add-row { display: flex; gap: var(--space-2); margin-top: var(--space-3); align-items: flex-end; }
.comment-add-row .form-textarea { flex: 1; }
