:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #f0f4f5;
  --ink: #102327;
  --muted: #5f7178;
  --line: #d9e1e4;
  --primary: #174c47;
  --accent: #d67244;
  --warning: #f3b84d;
  --shadow: 0 20px 48px rgba(16, 35, 39, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(214, 114, 68, 0.12), transparent 26%),
    linear-gradient(180deg, #fafcfc 0%, var(--bg) 100%);
  color: var(--ink);
}

a { color: inherit; text-decoration: none; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, #183d44 0%, #102327 100%);
  color: white;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.brand-card,
.panel,
.stat-card,
.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.brand-card {
  padding: 1.2rem;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: none;
}

.brand-card h1 {
  margin: 0.2rem 0;
  font-size: 1.35rem;
}

.content {
  padding: 2rem;
  width: min(100%, 1520px);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h2 {
  margin: 0.2rem 0;
  font-size: 2rem;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
}

.muted,
.lede {
  color: var(--muted);
}

.user-pill {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav-list {
  display: grid;
  gap: 0.35rem;
}

.nav-link,
.ghost-button {
  border-radius: 14px;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: white;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Current page: the one nav item you're actually standing on. Without this,
   a 10-item flat list gives zero sense of "where am I". */
.nav-link.active {
  background: var(--accent, #d67244);
  border-color: var(--accent, #d67244);
  font-weight: 600;
}

.nav-link:focus-visible,
.ghost-button:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

.ghost-button {
  width: 100%;
  cursor: pointer;
  text-align: left;
}

/* Groups the now-10-item nav into Operations / Money, so the list reads as
   two short lists instead of one long undifferentiated one. */
.nav-divider {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  margin: 0.5rem 0.25rem;
}

.stats-grid,
.panel-grid {
  display: grid;
  gap: 1rem;
}

.compliance-section {
  display: grid;
  gap: 0.9rem;
  margin-top: 1.5rem;
  width: 100%;
}

.section-heading h3 {
  margin: 0.15rem 0 0.35rem;
  font-size: 1.5rem;
}

.section-heading .muted {
  max-width: 72rem;
}

.tracker-filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.tracker-filter-bar button {
  align-self: end;
}

.tracker-list {
  display: grid;
  gap: 1rem;
}

.tracker-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  background: linear-gradient(180deg, #fff 0%, #f8fbfb 100%);
}

.tracker-card-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 0.85rem;
}

.tracker-card-header h4 {
  margin: 0 0 0.2rem;
  font-size: 1.1rem;
}

.tracker-card-header p {
  margin: 0.15rem 0;
}

.tracker-card-metrics {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tracker-assign-form {
  margin-top: 0.75rem;
  min-width: 220px;
}

.review-evidence {
  margin-top: 0.85rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fbfb;
}

.review-evidence h5 {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
}

.evidence-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}

.evidence-grid dt {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.evidence-grid dd {
  margin: 0;
  font-weight: 600;
  word-break: break-word;
}

.evidence-wide {
  grid-column: 1 / -1;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 1rem;
}

.panel-grid {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.stat-card,
.panel {
  padding: 1.2rem;
}

.panel-wide {
  width: 100%;
}

.stat-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.stat-card strong {
  font-size: 2rem;
}

.warning strong {
  color: #8e5b00;
}

.clean-list {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.6rem;
}

.form-grid {
  display: grid;
  gap: 1rem;
  /* Forms were stretching to full panel width, leaving huge dead space and
     pushing native input chrome (e.g. the date-picker icon) to the far edge. */
  max-width: 560px;
}

.compact-form {
  display: grid;
  gap: 0.65rem;
  min-width: 280px;
}

label {
  display: grid;
  gap: 0.4rem;
  font-weight: 600;
}

input,
textarea,
select,
button {
  width: 100%;
  min-width: 0;
  padding: 0.85rem 0.95rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  font: inherit;
}

/* Fixed-format values get a fixed-size field: a full-width date input separates
   the value (left) from the calendar icon (right) by the whole panel width. */
input[type="date"],
input[type="time"] {
  max-width: 15rem;
}

input:focus,
textarea:focus,
select:focus,
button:focus {
  outline: 2px solid rgba(214, 114, 68, 0.35);
  outline-offset: 2px;
}

/* Locked fields (e.g. approved-invoice header) must read as "not editable" —
   readonly inputs otherwise look identical to editable ones. */
input[readonly],
textarea[readonly],
select:disabled,
input:disabled,
textarea:disabled {
  background: var(--surface-soft, #f4f4f4);
  color: var(--muted);
  cursor: not-allowed;
}

button {
  background: linear-gradient(135deg, var(--primary), #256761);
  color: white;
  cursor: pointer;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.panel {
  overflow-x: auto;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.85rem 0.65rem;
  border-bottom: 1px solid var(--line);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.86rem;
  background: var(--surface-soft);
}

.status-compliant {
  color: #11613f;
  background: #e6f5ec;
}

.status-pending {
  color: #8d5f00;
  background: #fff4d8;
}

.status-pending_review,
.status-expiring_soon {
  color: #8d5f00;
  background: #fff4d8;
}

.status-valid,
.status-approved {
  color: #11613f;
  background: #e6f5ec;
}

.status-ready_for_review,
.status-paperless_matched {
  color: #11613f;
  background: #e6f5ec;
}

.status-auto_imported {
  color: #0f4f79;
  background: #e3f2fd;
}

.status-paperless_pending,
.status-pending_sync,
.status-queued {
  color: #8d5f00;
  background: #fff4d8;
}

.status-expired,
.status-rejected {
  color: #9e1d1d;
  background: #fde7e7;
}

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.auth-card {
  width: min(560px, 100%);
  padding: 1.75rem;
}

.auth-card h3 {
  margin: 0.2rem 0 1rem;
  font-size: 1.8rem;
}

.auth-card .form-grid {
  gap: 1rem;
}

.brand-preview {
  padding: 1.5rem;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--preview-primary), var(--preview-accent));
  color: white;
  display: grid;
  gap: 0.5rem;
}

.brand-logo {
  max-width: 160px;
  max-height: 72px;
  object-fit: contain;
  background: white;
  border-radius: 12px;
  padding: 0.5rem;
}

.error {
  color: #9e1d1d;
}

.success {
  color: #11613f;
}

/* ---------------------------------------------------------------------------
   Phase 03 — Reconciliation & Validation Gate (additive classes)
   All values from 03-UI-SPEC.md — no new hex beyond severity values enumerated
   in the spec. Severity rows use border + color for accessibility (AA compliant).
   --------------------------------------------------------------------------- */

/* Flag row severity — applied at <tr> level */
.flag-row--critical {
  background: #fde7e7;
  border-left: 3px solid #9e1d1d;
}

.flag-row--advisory {
  background: #fff4d8;
  border-left: 3px solid #f3b84d;
}

.flag-row--acknowledged {
  background: var(--surface-soft);
  opacity: 0.75;
}

/* Severity badge — extends .status-pill sizing */
.severity-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.86rem;
}

/* Validate Gate wrapper */
.validate-gate {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* Reason text beside disabled validate button */
.validate-gate__reason {
  color: #9e1d1d;
  font-size: 0.86rem;
  font-weight: 600;
}

/* Inline acknowledge form inside expanded flag row */
.acknowledge-form {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.5rem;
  padding: 0.85rem;
  background: var(--surface-soft);
  border-radius: 12px;
}

/* Bulk acknowledge: select-all checkboxes + one shared note + one button (UAT G4) */
.ack-bulk {
  margin-top: 1rem;
  max-width: 640px;
}
.ack-checkbox,
#ack-select-all {
  width: 1.1rem;
  height: 1.1rem;
  cursor: pointer;
}

/* Hour Snapshot 5-tile grid */
.hour-snapshot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem;
}

/* Flag metadata (rule_id + employee/client context) */
.flag-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* Acknowledgement trail note */
.ack-trail {
  font-size: 0.86rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 0.35rem;
}

/* Disabled validate button */
.button--disabled {
  background: var(--line);
  color: var(--muted);
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .content {
    width: 100%;
    padding: 1.25rem;
  }

  .page-header {
    flex-direction: column;
  }

  .user-pill {
    width: 100%;
  }

  .sidebar {
    border-bottom-left-radius: 24px;
    border-bottom-right-radius: 24px;
  }

  .content {
    padding: 1rem;
  }

  .page-header {
    flex-direction: column;
  }

  .tracker-card-header {
    flex-direction: column;
  }

  .tracker-card-metrics {
    justify-content: flex-start;
  }
}

/* ---------------------------------------------------------------------------
   Phase 04 — In-house Invoicing (additive classes)
   Status colours from 04-UI-SPEC.md Surface B B3 — invoice lifecycle pills.
   Do NOT modify existing classes above.
   --------------------------------------------------------------------------- */

/* Invoice DRAFT status pill: blue (UI-SPEC B3) */
.status-draft {
  color: #0f4f79;
  background: #e3f2fd;
}

/* Invoice VOID status pill: reuses .status-rejected destructive palette (UI-SPEC B3) */
.status-void {
  color: #9e1d1d;
  background: #fde7e7;
}

/* ------------------------------------------------------------------ */
/* Buttons + filter tabs — prod-grade polish (invoice list & detail)  */
/* .button is used on <a> AND <button>; the element rule above styles  */
/* only <button>, so anchor-buttons were unstyled. This class unifies  */
/* both and beats the element rule on specificity.                     */
/* ------------------------------------------------------------------ */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: auto;
  padding: 0.6rem 1.15rem;
  border: 1px solid transparent;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #256761);
  color: #fff;
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.1;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(23, 76, 71, 0.18);
  transition: transform 0.06s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.button:hover {
  filter: brightness(1.06);
  box-shadow: 0 8px 22px rgba(23, 76, 71, 0.26);
}
.button:active { transform: translateY(1px); }

.button-secondary,
.button.button-secondary {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--line);
  box-shadow: none;
}
.button-secondary:hover { background: var(--surface-soft); filter: none; }

.header-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

/* Segmented status filter (All / Draft / Approved / Paid / Void) */
.filter-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.25rem 0 1.5rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.filter-tabs a {
  padding: 0.5rem 1.05rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.filter-tabs a:hover { background: var(--surface-soft); color: var(--ink); }
.filter-tabs a.active {
  background: linear-gradient(135deg, var(--primary), #256761);
  color: #fff;
  box-shadow: 0 4px 12px rgba(23, 76, 71, 0.22);
}

/* Table readability: zebra + row hover */
.data-table tbody tr:hover { background: var(--surface-soft); }
.data-table tbody tr td { vertical-align: middle; }

/* Alert banners (error/success) — used across admin/payroll/invoice templates */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.alert-error { background: #fdeceb; border-color: #f3c6c1; color: #9c2b1f; }
.alert-success { background: #eaf6ee; border-color: #bfe3cb; color: #1f6b3a; }

.btn-small {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.btn-small:hover { background: var(--surface-soft); }
.btn-small-active { background: var(--primary); border-color: var(--primary); color: white; }
.btn-small-active:hover { background: var(--primary); }

/* Timesheet Approval calendar view — one column per day of the fortnight. */
.approve-calendar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
  overflow-x: auto;
}
.approve-cal-day {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem;
  min-height: 80px;
}
.approve-cal-day.is-today { border-color: var(--accent); border-width: 2px; }
.approve-cal-date { font-size: 0.75rem; font-weight: 700; margin-bottom: 0.4rem; }
.approve-cal-shift {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem;
  margin-bottom: 0.35rem;
  box-shadow: 0 1px 3px rgba(16, 35, 39, 0.06);
}
.approve-cal-shift.is-approved { opacity: 0.55; }

/* Roster grid — staff rows x day columns, whole fortnight at a glance
   (Deputy/When I Work/resource-timeline pattern) — Schedule page. */
.roster-grid-wrap { overflow-x: auto; }

.roster-grid { border-collapse: collapse; width: 100%; }
.roster-grid th, .roster-grid td { border: 1px solid var(--line); vertical-align: top; }

.roster-grid thead th {
  padding: 0.4rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  background: var(--surface-soft);
}
.roster-grid thead th.is-today { background: var(--accent); color: white; }
.roster-grid thead th.is-today .muted { color: rgba(255,255,255,0.85); }

.roster-grid .staff-col {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  min-width: 130px;
  padding: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}
.roster-grid thead .staff-col { background: var(--surface-soft); z-index: 2; }

.roster-cell {
  min-width: 170px;
  padding: 0.3rem;
  display: table-cell;
}
.roster-cell.drag-over { background: var(--surface-soft); outline: 2px dashed var(--accent); outline-offset: -2px; }

.shift-chip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  cursor: grab;
  box-shadow: 0 1px 3px rgba(16, 35, 39, 0.06);
  margin-bottom: 0.3rem;
}
.shift-chip:last-child { margin-bottom: 0; }
.shift-chip:active { cursor: grabbing; }

.chip-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  margin-bottom: 0.2rem;
}
.chip-time { font-weight: 600; }
.chip-client { font-size: 0.85rem; margin-bottom: 0.35rem; }

.ratio-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--primary);
  border: 1px solid var(--line);
  cursor: pointer;
  margin-bottom: 0.35rem;
}
.chip-ratio[open] .ratio-badge { background: var(--primary); color: white; border-color: var(--primary); }
.ratio-badge-empty { background: transparent; color: var(--muted); border-style: dashed; font-weight: 400; }
.ratio-badge-hint { background: transparent; border-style: dashed; color: var(--accent); }
.ratio-code { font-weight: 400; opacity: 0.85; }

/* Ratio hover breakdown (Schedule board) — the compact "1:1+1:3" chip badge
   has no room for per-block start/end times, so reveal them in a floating
   panel on hover instead, same pill look as the Timesheet Approval page. */
.ratio-hover-wrap { position: relative; display: inline-block; }
.ratio-hover-panel {
  display: none;
  position: absolute;
  z-index: 30;
  top: 100%;
  left: 0;
  margin-top: 4px;
  flex-direction: column;
  gap: 0.2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.4rem 0.5rem;
  min-width: 170px;
}
.ratio-hover-wrap:hover .ratio-hover-panel,
.ratio-hover-wrap:focus-within .ratio-hover-panel { display: flex; }
.ratio-hover-panel .ratio-badge { cursor: default; margin-bottom: 0; white-space: nowrap; }

/* Native <dialog> — Add-shift form. No JS framework needed: showModal()/close()
   are built into the platform, this just makes it look like the rest of the app. */
.add-shift-dialog {
  border: none;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 1.25rem;
  max-width: 420px;
  width: calc(100% - 2rem);
  background: var(--surface);
  color: var(--ink);
}
.add-shift-dialog::backdrop { background: rgba(16, 35, 39, 0.45); }

/* Stacked time-segmented ratio breakdown (Timesheet Approval worklist) —
   one pill per block instead of one collapsed "1:1+1:3" badge. */
.ratio-segments { display: flex; flex-direction: column; gap: 0.2rem; }
.ratio-segments .ratio-badge { cursor: default; margin-bottom: 0; white-space: nowrap; }
.ratio-desc { font-size: 0.72rem; margin: -0.1rem 0 0.15rem; display: block; }

.ratio-edit { margin: 0.4rem 0; padding: 0.4rem; background: var(--surface-soft); border-radius: 6px; }
.ratio-row { display: flex; gap: 0.3rem; margin-bottom: 0.3rem; }
.ratio-row input { min-width: 0; border: 1px solid var(--line); border-radius: 4px; padding: 0.2rem 0.3rem; font-size: 0.8rem; }

.assign-form select {
  width: 100%;
  font-size: 0.8rem;
  padding: 0.25rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.chip-care-note {
  font-size: 0.75rem;
  margin-bottom: 0.35rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.review-form { margin-bottom: 0.35rem; }
.review-toggle {
  font-size: 0.78125rem;
  font-weight: 650;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.review-toggle.is-reviewed { background: #e6f5ec; color: #11613f; border-color: transparent; }
