:root {
  --teal: #0d6b6b;
  --teal-bg: #dff2f2;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* An element's own display rule (e.g. .loading-overlay's `display: flex`)
   otherwise beats the browser's default `[hidden] { display: none }` UA
   style, since both are author-origin-equivalent specificity — without
   this, "hidden" elements like the loading overlay or toast would still
   render (and, worse, still intercept clicks) whenever they also carry a
   class that sets `display`. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.muted { color: var(--grey); font-size: 0.92em; }
.error-text { color: var(--red); font-size: 0.92em; }

/* ---------------- Buttons ---------------- */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 0.95em;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary { background: var(--action); color: #fff; }
.btn-primary:hover { background: var(--action-hover); }
.btn-ghost { background: transparent; color: var(--navy); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--grey-light); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-success { background: var(--green-bg); color: var(--green); }
.btn-sm { padding: 5px 10px; font-size: 0.85em; }
.btn-block { width: 100%; }

/* ---------------- Login screen ---------------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-dark) 100%);
}
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-logo { max-width: 160px; max-height: 70px; margin-bottom: 12px; }
.login-card h1 { font-size: 1.1em; margin: 0 0 2px; color: var(--navy); }
.login-card h2 { margin: 18px 0 4px; color: var(--ink); }
#login-error { margin-top: 12px; }

/* ---------------- Top bar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-logo { max-height: 34px; }
.topbar-title { font-weight: 700; color: var(--navy); }
.topbar-subtitle { font-size: 0.8em; color: var(--grey); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-user { font-size: 0.9em; color: var(--grey); }

/* ---------------- Tabs ---------------- */
.tabs {
  display: flex;
  gap: 4px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  overflow-x: auto;
}
.tab-btn {
  background: none;
  border: none;
  padding: 12px 16px;
  font-size: 0.95em;
  cursor: pointer;
  color: var(--grey);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--navy); }
.tab-btn.active { color: var(--action); border-bottom-color: var(--action); font-weight: 600; }

/* ---------------- Content ---------------- */
.content { padding: 24px; max-width: 1100px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.banner {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 0.92em;
}
.banner-warning { background: var(--amber-bg); color: var(--amber); }
.banner-info { background: var(--blue-light); color: var(--navy); }

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.card h3 { margin-top: 0; color: var(--navy); }
.card h4 { color: var(--navy); margin: 18px 0 8px; }

.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}
.stat-card .stat-value { font-size: 1.7em; font-weight: 700; color: var(--navy); }
.stat-card .stat-label { font-size: 0.82em; color: var(--grey); margin-top: 4px; }

/* ---------------- Forms ---------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.88em;
  color: #333;
  font-weight: 600;
}
.form-grid input, .form-grid select, .form-grid textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.95em;
  font-weight: 400;
  font-family: inherit;
}
.form-grid .full-width { grid-column: 1 / -1; }
.field-hint { font-size: 0.82em; font-weight: 400; color: var(--grey); }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }

/* ---------------- Tables ---------------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92em;
}
.data-table th {
  text-align: left;
  background: var(--grey-light);
  padding: 8px 10px;
  color: #444;
  font-weight: 600;
}
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table select, .data-table input[type="text"] { border: 1px solid var(--border); border-radius: 6px; padding: 5px 7px; font-size: 0.95em; font-family: inherit; }

/* Briefly flashes a row that was jumped to via a deep link (e.g. the
   "View task" button in the Owner Task Notifications email) — see
   flashRow() in app.js. */
.row-highlight { animation: row-highlight-flash 2.5s ease-out; }
@keyframes row-highlight-flash {
  0%, 15% { background-color: #fff3cd; }
  100% { background-color: transparent; }
}

/* ---------------- Status badges ---------------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.8em;
  font-weight: 600;
}
.badge-pending { background: var(--amber-bg); color: var(--amber); }
.badge-approved { background: var(--green-bg); color: var(--green); }
.badge-rejected { background: var(--red-bg); color: var(--red); }
.badge-cancelled { background: var(--grey-light); color: var(--grey); }

/* ---------------- Milestone progress bar ---------------- */
.progress-track {
  display: inline-block;
  width: 100px;
  height: 8px;
  background: var(--grey-light);
  border-radius: 999px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 8px;
}
.progress-fill { height: 100%; background: var(--navy); }
.progress-label { display: inline-block; font-size: 0.85em; color: var(--grey); vertical-align: middle; }

/* ---------------- Expanded milestone panel ---------------- */
.expanded-row td { background: var(--grey-light); }
.expanded-panel { padding: 8px 4px; }
.invite-preview {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 0.88em;
  line-height: 1.5;
  margin-bottom: 10px;
  white-space: pre-wrap;
}

/* ---------------- Dashboard wallchart ---------------- */
.wallchart-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}
.wallchart-month-label { font-weight: 700; color: var(--navy); min-width: 160px; text-align: center; }

.wallchart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 14px;
  font-size: 0.85em;
  color: var(--grey);
}
.wallchart-legend-item { display: inline-flex; align-items: center; gap: 6px; }

.wallchart-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
.wallchart-dot-hire { background: var(--navy); }
.wallchart-dot-subcontractor { background: var(--amber); }
.wallchart-dot-cis-operative { background: var(--teal); }

.wallchart-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  font-size: 0.8em;
  font-weight: 600;
  color: var(--grey);
  text-align: center;
  margin-bottom: 4px;
}

.wallchart-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.wallchart-day {
  min-height: 84px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  background: #fff;
  overflow-y: auto;
}
.wallchart-day-empty { background: var(--grey-light); border-color: transparent; }
.wallchart-day-today { border-color: var(--navy); border-width: 2px; }
.wallchart-day-number { font-size: 0.82em; font-weight: 600; color: var(--grey); margin-bottom: 4px; }

.wallchart-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78em;
  padding: 2px 6px;
  border-radius: 999px;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wallchart-pill-hire { background: var(--blue-light); color: var(--navy); }
.wallchart-pill-subcontractor { background: var(--amber-bg); color: var(--amber); }
.wallchart-pill-cis-operative { background: var(--teal-bg); color: var(--teal); }

@media (max-width: 640px) {
  .wallchart-day { min-height: 60px; font-size: 0.85em; }
}

/* ---------------- Toast / loading ---------------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--navy-dark);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 0.92em;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  max-width: 320px;
  z-index: 50;
}
.toast.toast-error { background: var(--red); }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}
.spinner {
  width: 34px; height: 34px;
  border: 4px solid var(--blue-light);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .content { padding: 14px; }
  .topbar { padding: 10px 14px; }
}

/* ---- Engagement ---------------------------------------------------
   The block at the top of an expanded subcontractor row: where their
   engagement has got to, what happened so far, and what can be done
   next. Set apart from the onboarding checklist underneath it because
   it is a different question — whether we are working with this firm
   at all, rather than how far through setting them up we are. */
.engagement-block {
  border-left: 3px solid var(--navy, #1f3864);
  padding: 2px 0 10px 14px;
  margin-bottom: 18px;
}
.engagement-block h4 { margin: 0 0 6px; }
.engagement-block p { margin: 0 0 10px; }

/* The dated facts. Not a table: it is a handful of lines read in order,
   and a table of two columns would be heavier than what it carries. */
.engagement-trail {
  margin: 0 0 12px;
  padding-left: 18px;
  font-size: 13px;
  color: var(--grey, #6b7280);
}
.engagement-trail li { margin-bottom: 3px; }
.engagement-doc { margin-right: 8px; }

.engagement-note {
  display: block;
  width: 100%;
  max-width: 520px;
  margin-bottom: 10px;
}
.engagement-file {
  display: block;
  font-size: 13px;
  margin-bottom: 10px;
}
.engagement-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Sits above the table it filters, which is also the count of where
   every firm stands. */
.stage-filter {
  display: inline-block;
  font-size: 13px;
  margin-bottom: 12px;
}
.stage-filter select { margin-left: 6px; }

/* ---- The approval queue -------------------------------------------
   One entry per thing waiting on a decision, of any kind, on the tab
   everybody has. Not a table: each entry carries a summary, a trail and
   its own buttons, which is a card's worth of content per row. */
.queue-entry {
  border: 1px solid var(--border, #e2e5ea);
  border-radius: 10px;
  padding: 14px 16px 10px;
  margin-bottom: 14px;
}
.queue-entry:last-child { margin-bottom: 0; }
.queue-entry > h4 { margin: 0 0 4px; }
.queue-entry > p { margin: 0 0 10px; }
/* Which of the three this is. A name on its own does not say whether
   you are approving a groundworks firm or a new starter in accounts. */
.queue-type {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--grey-light, #eef1f5);
  color: var(--grey, #6b7280);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
}
/* The facts the decision turns on — insurance dates, CIS status, the
   role and the start date. Without these the queue is a list of names
   and Approve is a rubber stamp. */
.engagement-summary {
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  font-size: 13px;
}
.engagement-summary b {
  color: var(--grey, #6b7280);
  font-weight: 600;
  margin-right: 5px;
}
