/* Professional business design system for attendance & payroll.
   Zero external dependencies, system fonts only. Slate text on a light
grey canvas, one deep-navy brand colour, colour only where it means
something. Tabular numerals everywhere. */

:root {
  /* Canvas & Surface */
  --bg-canvas: #f5f6f8;
  --bg-surface: #ffffff;
  --bg-surface-subtle: #f1f5f9;
  --bg-surface-hover: #f8fafc;
  --bg-surface-active: #e2e8f0;

  /* Text Hierarchy */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-on-dark: #ffffff;

  /* Borders & Outlines */
  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;
  --border-focus: var(--primary);

  /* Brand / Primary Accent (deep navy) */
  --primary: #1f3a5f;
  --primary-hover: #18304f;
  --primary-active: #12253d;
  --primary-subtle: #eef3f8;
  --primary-border: #c6d4e4;
  --primary-ring: rgba(31, 58, 95, 0.22);

  /* Semantic Status Colors (quiet: light backgrounds, dark text) */
  --success: #047857;
  --success-bg: #f2faf6;
  --success-border: #cfe8dc;
  --success-text: #065f46;

  --warning: #b45309;
  --warning-bg: #fdf9f1;
  --warning-border: #f0e2c4;
  --warning-text: #7c4a06;

  --danger: #b91c1c;
  --danger-bg: #fdf4f4;
  --danger-border: #f0d3d3;
  --danger-text: #8c1c1c;

  --info: #1d4ed8;
  --info-bg: #f2f6fd;
  --info-border: #d2ddf6;
  --info-text: #1c3d94;

  /* Shadows: popovers, dialogs and toasts only. Cards and tables use a border. */
  --shadow-xs: none;
  --shadow-sm: none;
  --shadow-md: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 24px rgba(15, 23, 42, 0.14), 0 2px 6px rgba(15, 23, 42, 0.08);

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-full: 9999px;

  /* Backwards compatibility variables */
  --ink: var(--text-primary);
  --dim: var(--text-muted);
  --line: var(--border-subtle);
  --flag: var(--warning-bg);
  --flagline: var(--warning-border);
  --over: var(--success-bg);
  --ok: var(--success);
  --bad: var(--danger);
  --paper: var(--bg-surface);
}

/* Base Reset & Typography */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text-primary);
  background: var(--bg-canvas);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Inline SVG icon, sized by its width/height attributes. */
.icon {
  display: inline-block;
  vertical-align: -0.125em;
  flex: none;
}

/* `hidden` must beat the display rules on .pill, button etc. */
[hidden] { display: none !important; }

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

/* Tabular Numerals */
.num, .money, .sec-input, .cal-hours, table.list td:nth-child(n+3), table.grid td:nth-child(n+3) {
  font-variant-numeric: tabular-nums;
}

/* The worker key-in page keeps its own full-width header (no sidebar). */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}

/* Worker name / passport block on the key-in page header. */
.header-title {
  display: flex;
  flex-direction: column;
}

.header-title h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--text-primary);
  line-height: 1.2;
}

/* -- App shell: sidebar nav and the page-header row ---------------------- */

.shell {
  display: flex;
  min-height: 100vh;
}

.shell-sidebar {
  width: 224px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 12px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 60;
}

.shell-brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 8px 12px;
}

/* Keep the original logo on narrow screens; the desktop wordmark is trimmed. */
.shell-logo {
  width: 184px;
  max-width: 100%;
  height: auto;
}

.shell-wordmark,
.shell-mark {
  display: none;
}

/* The sidebar's top block keeps the logo at full inner width. */
.shell-side-head {
  display: flex;
  flex-direction: column;
}

.shell-collapse-btn {
  display: none;
  position: relative;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius-sm);
  box-shadow: none;
  background: transparent;
  text-align: left;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  flex: none;
}

.shell-collapse-btn:hover {
  background: var(--bg-surface-subtle);
  color: var(--text-primary);
}

.shell-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shell-group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 14px 8px 4px;
}

.shell-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  transition: background-color 0.12s ease, color 0.12s ease;
}

.shell-nav-item:hover {
  background: var(--bg-surface-subtle);
  color: var(--text-primary);
}

.shell-nav-item.active {
  background: var(--primary-subtle);
  color: var(--primary);
  font-weight: 600;
}

.shell-nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 2px;
  border-radius: 2px;
  background: var(--primary);
}

.shell-nav-item .icon {
  color: currentColor;
  opacity: 0.9;
}

.shell-spacer {
  flex: 1;
}

.shell-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.shell-topbar {
  display: none;
}

.shell-content {
  padding: 20px 24px 40px;
  min-width: 0;
}

/* The page's own wrapper carries no margin inside the shell. */
.shell-content .list-wrap,
.shell-content .page {
  max-width: none;
  margin: 0;
  padding: 0;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--text-primary);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.shell-backdrop {
  display: none;
}

/* Wide screens: the sidebar button folds the sidebar into a 64px icon rail.
   The state lives on <html> so the script in index.html can apply it before
   the first paint. */
@media (min-width: 900px) {
  .shell-collapse-btn {
    display: inline-flex;
  }
  .shell-sidebar .shell-logo {
    display: none;
  }
  .shell-sidebar .shell-wordmark {
    display: block;
    width: 184px;
    max-width: 100%;
    height: auto;
  }
  html.shell-collapsed .shell-sidebar {
    width: 64px;
    padding: 16px 8px;
    overflow: visible;
  }
  html.shell-collapsed .shell-sidebar .shell-wordmark {
    display: none;
  }
  html.shell-collapsed .shell-brand {
    align-items: center;
    padding: 4px 0 12px;
  }
  html.shell-collapsed .shell-mark {
    display: block;
  }
  html.shell-collapsed .shell-group-label {
    height: 1px;
    width: 24px;
    margin: 8px auto;
    padding: 0;
    background: var(--border-subtle);
    font-size: 0;
  }
  html.shell-collapsed .shell-group-label:first-child {
    display: none;
  }
  html.shell-collapsed .shell-nav-item,
  html.shell-collapsed .shell-collapse-btn,
  html.shell-collapsed .shell-sidebar .header-session button {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    width: 40px;
    height: 40px;
    gap: 0;
    padding: 0;
  }
  html.shell-collapsed .shell-nav-item.active {
    border-radius: var(--radius-md);
    box-shadow: inset 0 0 0 1px var(--primary-border);
  }
  html.shell-collapsed .shell-nav-item.active .icon {
    color: var(--primary);
    opacity: 1;
  }
  html.shell-collapsed .shell-nav-item.active::before {
    display: none;
  }
  html.shell-collapsed .shell-sidebar .icon {
    width: 18px;
    height: 18px;
  }
  html.shell-collapsed .shell-sidebar :is(.shell-nav-item, .shell-collapse-btn, .header-logout):is(:hover, :focus-visible)::after {
    content: attr(aria-label);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    padding: 5px 8px;
    background: var(--text-primary);
    color: white;
    font-size: 12px;
    font-weight: 400;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
    pointer-events: none;
    z-index: 70;
  }
  html.shell-collapsed .shell-collapse-label,
  html.shell-collapsed .shell-nav-label,
  html.shell-collapsed .shell-sidebar .header-session-email,
  html.shell-collapsed .header-logout-label {
    display: none;
  }
  html.shell-collapsed .shell-sidebar .header-session {
    align-items: center;
    padding: 12px 0 4px;
  }
  html.shell-collapsed .header-logout .icon {
    display: inline-block;
  }
}

@media (max-width: 899px) {
  .shell-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    height: auto;
    width: 248px;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.18s ease, visibility 0.18s ease;
    box-shadow: var(--shadow-lg);
  }
  .shell-nav-open .shell-sidebar {
    transform: translateX(0);
    visibility: visible;
  }
  .shell-nav-open .shell-backdrop {
    display: block;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(15, 23, 42, 0.38);
    z-index: 55;
  }
  .shell-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 40;
  }
  .shell-topbar .shell-brand {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 0;
  }
  .shell-topbar .shell-logo {
    width: auto;
    height: 32px;
  }
  .shell-content {
    padding: 16px 16px 32px;
  }
}

.shell-menu-btn {
  padding: 6px;
}

.spacer {
  flex: 1;
}

.header-session {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.header-session-email {
  font-size: 11px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* In the sidebar the session block sits at the bottom, full width. */
.shell-sidebar .header-session {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--border-subtle);
}

.shell-sidebar .header-session button {
  width: 100%;
}

/* When the sidebar is an icon rail the button shows the icon alone. */
.header-logout .icon {
  display: none;
}

/* Period Switcher Toolbar */
.period-control {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 2px 6px;
  box-shadow: var(--shadow-xs);
}

.period-control select {
  border: none;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  background: transparent;
  padding: 4px 8px 4px 4px;
  cursor: pointer;
  outline: none;
}

.period-control:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.period-stepper-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-weight: bold;
  line-height: 1;
}

.period-stepper-btn:hover {
  background: var(--bg-surface-subtle);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

/* Buttons */
button {
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1.3;
}

button:hover {
  background: var(--bg-surface-hover);
  border-color: var(--text-muted);
}

button:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

button.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}

button.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

button.secondary {
  background: var(--bg-surface);
  color: var(--text-secondary);
}

button.secondary:hover {
  color: var(--text-primary);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

button.ghost:hover {
  background: var(--bg-surface-subtle);
  border-color: transparent;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.all-workers-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
  font-size: 12px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  box-shadow: var(--shadow-xs);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.all-workers-link:hover {
  color: var(--text-primary);
  background: var(--bg-surface-subtle);
  border-color: var(--text-muted);
}

/* Status Pills & Badges */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-subtle);
  color: var(--text-secondary);
  line-height: 1.4;
}

.pill.review, .pill.open, .pill[data-status="open"] {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning-text);
}

.pill.reviewed, .pill.done, .pill[data-status="done"] {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

.pill.not-started, .pill[data-status="not-started"] {
  background: var(--bg-surface-subtle);
  border-color: var(--border-subtle);
  color: var(--text-muted);
}

.pill.norate {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

.tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-text);
  margin-right: 3px;
}

.tag.over-tag {
  border-color: var(--success-border);
  background: var(--success-bg);
  color: var(--success-text);
}

/* A day's remark in the Notes column: two lines at most, and a long unbroken word breaks. */
.remark {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-size: 11px;
  line-height: 1.3;
  color: var(--text-secondary);
}

.tag + .remark {
  margin-top: 2px;
}

.badge.ph {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  color: var(--info-text);
  margin-left: 4px;
}

/* -- List Page (Worker List & Overview) ---------------------------------- */

.list-wrap {
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

/* KPI Summary Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.kpi-icon {
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.kpi-bar-wrap {
  height: 5px;
  background: var(--bg-surface-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 4px;
}

.kpi-bar {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

/* Toolbar & Filters */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1;
}

.search-input-wrap {
  position: relative;
  min-width: 240px;
  max-width: 340px;
  flex: 1;
}

.search-input {
  width: 100%;
  font: inherit;
  font-size: 12px;
  padding: 7px 12px 7px 30px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.site-filter {
  font: inherit;
  font-size: 12px;
  max-width: 220px;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.site-filter:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  color: var(--text-muted);
  pointer-events: none;
}

.filter-pills {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 3px;
}

.filter-pill-btn {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  box-shadow: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-pill-btn:hover {
  background: var(--bg-surface-subtle);
  color: var(--text-primary);
}

.filter-pill-btn.active {
  background: var(--primary-subtle);
  color: var(--primary);
  font-weight: 600;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Workers Table */
.table-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

/* The Workers Registry table has 11 columns; on a narrow window the card scrolls sideways. */
.table-card.scroll-x {
  overflow-x: auto;
}

table.list {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-surface);
}

table.list th, table.list td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
  vertical-align: middle;
}

table.list th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  background: var(--bg-surface-subtle);
  border-bottom: 1px solid var(--border-strong);
  user-select: none;
}

table.list th.num, table.list td.num {
  text-align: right;
}

table.list tr.worker-row {
  cursor: pointer;
  transition: background-color 0.1s ease;
}

table.list tr.worker-row:hover {
  background: var(--primary-subtle);
}

table.list tr:last-child td {
  border-bottom: none;
}

table.list tr.unresolved-row {
  color: var(--text-muted);
}

/* Worker Identity in Table */
.worker-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.worker-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

.worker-name-block {
  display: flex;
  flex-direction: column;
}

.worker-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 13px;
}

.worker-passport {
  font-size: 11px;
  color: var(--text-muted);
  font-family: ui-monospace, Menlo, monospace;
}

.warn-text {
  color: var(--danger);
  font-weight: 600;
}

.empty-state {
  padding: 48px 16px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  color: var(--text-muted);
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}

/* -- Worker Entry Page (Two-Column Layout) ------------------------------ */

main {
  display: grid;
  grid-template-columns: minmax(0, 2.35fr) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 54px);
  box-sizing: border-box;
}

/* The entry header can wrap to two lines, so size main from what is left. */
#app:has(> main) { display: flex; flex-direction: column; height: 100vh; }
#app:has(> main) > main { flex: 1; min-height: 0; height: auto; }

/* In a window too narrow for the grid and the payslip side by side, the payslip
   goes under the grid; each pane still scrolls on its own. 1290px is the first
   10px step at or above 1287, the narrowest window where the left pane (2.35fr
   of the window less 36px padding and gap, less its border and a 17px scrollbar)
   still fits the grid's 858px minimum width below; the payslip already fits by
   about 1230. */
@media (max-width: 1290px) {
  main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 2fr) minmax(0, 1fr);
  }
}

section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: auto;
  display: flex;
  flex-direction: column;
}

section h2 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Sticky Worker Sub-Header in Left Pane */
.worker-header-card {
  padding: 12px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 15;
}

.worker-nav-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.worker-title-block {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.worker-title-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.worker-site-tag {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-surface-subtle);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.key-hint {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  padding: 0 4px;
  margin-left: 3px;
  background: var(--bg-surface-subtle);
}

/* 31-Day Timesheet Grid */
section.grid-section { overflow: hidden; }

.grid-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

table.grid {
  width: 100%;
  /* Never narrower than its columns: the In - Out column takes what is left, and
     a narrower pane scrolls sideways instead of squeezing the time boxes out.
     858 = 573 for the other columns + 285 for one time cell at its smallest
     (four boxes, gaps, the echo's 10ch, cell padding), measured in Chrome. */
  min-width: 858px;
  border-collapse: collapse;
  table-layout: fixed;
}

table.grid th, table.grid td {
  padding: 3px 5px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  vertical-align: middle;
}

table.grid th:first-child, table.grid td:first-child,
table.grid th:nth-child(2), table.grid td:nth-child(2),
table.grid th:nth-child(8), table.grid td:nth-child(8),
table.grid th:nth-child(9), table.grid td:nth-child(9) {
  text-align: left;
}

table.grid th:nth-child(1), table.grid td:nth-child(1) { width: 122px; }
table.grid th:nth-child(2), table.grid td:nth-child(2) { width: auto; white-space: nowrap; overflow: hidden; }
table.grid th:nth-child(3), table.grid td:nth-child(3),
table.grid th:nth-child(5), table.grid td:nth-child(5) { width: 42px; }
table.grid th:nth-child(4), table.grid td:nth-child(4) { width: 66px; }
table.grid th:nth-child(6), table.grid td:nth-child(6) { width: 52px; }
table.grid th:nth-child(7), table.grid td:nth-child(7) { width: 100px; }
table.grid th:nth-child(8), table.grid td:nth-child(8) { width: 44px; }
table.grid th:nth-child(9), table.grid td:nth-child(9) { width: 105px; white-space: normal; }

table.grid th {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  background: var(--bg-surface-subtle);
  border-bottom: 1px solid var(--border-strong);
  z-index: 8;
  padding: 6px 6px;
}

table.grid tr.dim td {
  color: var(--text-muted);
}

/* A date paid in a later payslip: its hours stay on the row but are not paid here. */
table.grid tr.paid-later td {
  color: var(--text-muted);
  background: var(--bg-surface-subtle);
}

.tag.paid-later-tag {
  border-color: var(--info-border);
  background: var(--info-bg);
  color: var(--info-text);
}

/* Dates of earlier payslips paid in this one: read-only, above the grid. */
.carried-in {
  flex: none;
  margin-bottom: 8px;
  border: 1px solid var(--info-border);
  border-radius: var(--radius-md);
  background: var(--info-bg);
}

.carried-in h3 {
  margin: 6px 8px;
  font-size: 12px;
  color: var(--info-text);
}

.carried-scroll {
  max-height: 30vh;
  overflow: auto;
}

table.grid tr.warn td {
  background: var(--warning-bg);
}

/* Focused Row Highlighting */
table.grid tr.cur td {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

table.grid tr.over td {
  background: var(--success-bg);
}

table.grid tr.sun td:first-child {
  color: var(--danger);
  font-weight: 600;
}

table.grid tr:focus {
  outline: none;
}

table.grid button {
  padding: 1px 6px;
  font-size: 11px;
  line-height: 16px;
}

table.grid tr.row-edit-tr td {
  text-align: left;
  white-space: normal;
  overflow: visible;
  padding: 0;
}

/* Input Section & Monospace Boxes */
.sec {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.sec-input {
  flex: none;
  width: calc(5ch + 10px);
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 18px;
  height: 24px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0 4px;
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: all 0.15s ease;
}

.sec-input::placeholder {
  color: #cbd5e1;
}

.sec-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-ring);
  background: #ffffff;
}

.sec-input[data-col="2"] {
  margin-left: 8px;
  border-left-color: var(--border-strong);
}

.echo {
  flex: 1;
  min-width: 10ch;
  margin-left: 6px;
  font-size: 10px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, Menlo, monospace;
}

.echo.bad {
  color: var(--danger);
  font-weight: 500;
}

/* Multiplier Segmented Control */
.mult {
  display: inline-flex;
  gap: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

.mult button {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  line-height: 18px;
  height: 20px;
  border: none;
  border-right: 1px solid var(--border-strong);
  border-radius: 0;
  background: var(--bg-surface);
  color: var(--text-secondary);
  box-shadow: none;
}

.mult button:last-child {
  border-right: none;
}

.mult button:hover {
  background: var(--bg-surface-subtle);
  color: var(--text-primary);
}

.mult button[aria-pressed="true"] {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

/* Inline Row Override Form */
.row-edit {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-surface-subtle);
  border: 1px dashed var(--primary-border);
  border-radius: var(--radius-sm);
  margin: 4px 6px;
  font-size: 12px;
}

.row-edit input[type=number] {
  width: 65px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-family: ui-monospace, Menlo, monospace;
}

.row-edit input[type=text] {
  width: 240px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
}

.row-edit input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-ring);
}

/* Hint / Keyboard Bar */
.hint {
  flex: none;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 6px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface-subtle);
  white-space: nowrap;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 12px;
}

/* -- Payslip Preview (Right Column) ------------------------------------- */

.slip {
  padding: 16px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.slip .readback {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--primary-subtle);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  line-height: 1.4;
}

.slip .who {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
}

.slip .sub {
  color: var(--text-secondary);
  font-size: 11px;
}

.slip-statement-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

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

.slip table td {
  padding: 5px 8px;
  text-align: right;
  border-bottom: 1px solid var(--border-subtle);
}

.slip table td:first-child {
  text-align: left;
  color: var(--text-secondary);
}

.slip table tr:hover td {
  background: var(--bg-surface-subtle);
}

.slip .tot td {
  font-weight: 600;
  color: var(--text-primary);
  border-top: 2px solid var(--border-strong);
  border-bottom: 2px solid var(--border-strong);
  background: var(--bg-surface-subtle);
}

/* Highlighted Net Pay Callout Box */
.slip .net td {
  font-weight: 700;
  font-size: 14px;
  color: var(--primary);
  background: var(--primary-subtle);
  border-top: 2px solid var(--primary-border);
  border-bottom: 2px solid var(--primary-border);
}

.slip .money {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 600;
}

.slip .money.norate {
  color: var(--danger);
  font-family: inherit;
}

.slip input {
  width: 88px;
  text-align: right;
  font: inherit;
  font-family: ui-monospace, Menlo, monospace;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  background: var(--bg-surface);
  transition: all 0.15s ease;
}

.slip input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-ring);
}

.slip .note-row input {
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.slip tr.employer td {
  color: var(--text-muted);
  font-size: 11px;
}

.slip tr.employer.header td {
  font-weight: 600;
  padding-top: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-band {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: normal;
  margin-top: 1px;
}

.stat-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  margin-right: 4px;
  vertical-align: middle;
}

.stat-tag.auto {
  color: var(--text-muted);
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
}

.stat-tag.edited {
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid var(--success-border);
}

/* -- Period Mini-Calendar (Under Payslip) ------------------------------- */

.cal {
  margin-top: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  box-shadow: var(--shadow-xs);
}

.cal h3 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin: 0 0 10px;
}

.cal-month {
  margin-bottom: 12px;
}

.cal-month h4 {
  font-size: 11px;
  font-weight: 600;
  margin: 0 0 6px;
  color: var(--text-primary);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 3px;
}

.cal-head {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  padding: 2px 0;
}

.cal-cell {
  min-height: 36px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px 4px;
  font-size: 11px;
  line-height: 1.2;
  cursor: pointer;
  background: var(--bg-surface);
  transition: all 0.1s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.cal-cell:hover:not(.out):not(.blank) {
  border-color: var(--primary);
  background: var(--primary-subtle);
}

.cal-cell.blank, .cal-cell.out {
  border-color: transparent;
  background: transparent;
  cursor: default;
}

.cal-cell.out {
  color: #cbd5e1;
}

.cal-cell.off {
  color: var(--text-muted);
  background: var(--bg-surface-subtle);
}

.cal-cell.sun .cal-day {
  color: var(--danger);
}

.cal-cell.warn {
  background: var(--warning-bg);
  border-color: var(--warning-border);
}

.cal-cell .cal-day {
  display: block;
  font-weight: 600;
  font-size: 10px;
}

.cal-cell .cal-hours {
  display: block;
  font-family: ui-monospace, Menlo, monospace;
  text-align: right;
  font-size: 10px;
  color: var(--text-secondary);
}

.cal-cell .ph-mark {
  font-size: 9px;
  color: var(--info);
  margin-left: 2px;
}

/* Night marker in the period calendar: a small dot, not a character. */
.cal-cell .night-dot {
  color: var(--success);
}

.cal-cell .night-dot::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 3px;
  border-radius: 50%;
  background: currentColor;
  vertical-align: middle;
}

.cal-cell.over .cal-hours {
  color: var(--success);
  font-weight: 600;
}

.cal-cell.out .cal-day, .cal-cell.out .ph-mark, .cal-cell.out .cal-hours {
  color: #cbd5e1;
}

.cal-cell:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* -- Toast Messages ----------------------------------------------------- */

#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #ffffff;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 500;
  z-index: 100;
  display: none;
  max-width: 80vw;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: toastFadeIn 0.2s ease;
}

@keyframes toastFadeIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

#toast.bad {
  background: var(--danger);
}

#toast.show {
  display: block;
}

.err-page {
  padding: 48px;
  color: var(--text-secondary);
  text-align: center;
}

/* -- Modals & Dialogs --------------------------------------------------- */

dialog {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  background: var(--bg-surface);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  outline: none;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.worker-dialog {
  width: 640px;
  max-width: 95vw;
}

.worker-dialog h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  gap: 4px;
}

.form-grid input[type=text], .form-grid input[type=number], .form-grid select {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  color: var(--text-primary);
  background: var(--bg-surface);
  outline: none;
  transition: all 0.15s ease;
}

.form-grid input:focus, .form-grid select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.form-grid label.check-field {
  flex-direction: row;
  align-items: center;
  align-self: end;
  gap: 8px;
  padding-bottom: 7px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
}

.dialog-actions .spacer { flex: 1; }

button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-bg); border-color: var(--danger-border); }

.form-note {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 11px;
}

.form-note.type-note {
  grid-column: auto;
  align-self: end;
  margin: 0;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

.add-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin: 16px 0;
}

.page-note {
  color: var(--text-secondary);
  font-size: 12px;
}

/* Clients and dated placements */
.clients-from-sites { margin-bottom: 20px; padding: 12px 16px; }
.clients-from-sites button { width: auto; align-self: flex-start; }
.client-site-choice { display: flex; align-items: center; gap: 8px; margin: 8px 0; overflow-wrap: anywhere; }
.client-inactive { color: var(--text-muted); }
.client-name { min-width: 160px; max-width: 320px; overflow-wrap: anywhere; }
.client-name .tag { display: block; width: fit-content; margin-top: 4px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.worker-clients { grid-column: 1 / -1; min-width: 0; }
.worker-clients h3 { margin: 0 0 8px; }
.placement-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: end; margin-bottom: 10px; }
.placement-row select, .placement-row input { min-width: 0; width: 100%; }
.placement-row input { font: inherit; padding: 6px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); }
@media (max-width: 480px) {
  .worker-edit-dialog .form-grid, .client-dialog .form-grid { grid-template-columns: minmax(0, 1fr); }
  .client-dialog input { min-width: 0; }
  .placement-row { grid-template-columns: minmax(0, 1fr); }
  .placement-row button { justify-self: start; }
}

/* Add worker picker (month list) */
.add-worker-dialog .search-input-wrap {
  max-width: none;
  margin-bottom: 12px;
}

.add-worker-list {
  max-height: 50vh;
  overflow-y: auto;
}

.add-worker-line {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border-subtle);
}

.add-worker-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.add-worker-line button {
  flex-shrink: 0;
}

.add-worker-list .page-note {
  margin: 16px 4px;
}

/* Import Dialog */
.import-dialog {
  width: 920px;
}

.import-dialog h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 8px;
}

.import-dialog h3 {
  font-size: 13px;
  font-weight: 600;
  margin: 16px 0 6px;
  color: var(--text-secondary);
}

.import-text {
  width: 100%;
  font: 12px/1.4 ui-monospace, Menlo, Monaco, Consolas, monospace;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 10px;
  resize: vertical;
  white-space: pre;
  background: var(--bg-surface);
  outline: none;
}

.import-text:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.import-preview {
  margin-top: 10px;
  max-height: 50vh;
  overflow: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px;
}

.import-summary {
  font-weight: 600;
  margin: 6px 0;
}

.import-errors {
  color: var(--danger);
  margin: 6px 0;
  padding-left: 18px;
}

.import-scroll {
  overflow-x: auto;
}

table.list.import-table th, table.list.import-table td {
  padding: 6px 10px;
  white-space: nowrap;
}

.import-change {
  margin: 6px 0;
}

.import-change ul {
  margin: 4px 0 8px;
  padding-left: 20px;
}

.change-from {
  color: var(--text-muted);
  text-decoration: line-through;
}

.change-to {
  font-weight: 600;
  color: var(--primary);
}

.page {
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 20px;
}

/* Sign-in page (login.html) */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
}

.login-logo {
  width: 100%;
  max-width: 320px;
  height: auto;
}

.login-card {
  /* Undo the worker page's grid layout on <main>. */
  display: block;
  height: auto;
  width: 100%;
  max-width: 384px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.login-card h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.login-form input {
  font: inherit;
  font-size: 14px;
  height: 40px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
}

.login-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.login-form input:disabled {
  background: var(--bg-surface-subtle);
  color: var(--text-secondary);
}

.login-form button {
  width: 100%;
  height: 40px;
  font-size: 14px;
  padding: 8px 12px;
}

.login-hint,
.login-error {
  margin: 12px 0 0;
  font-size: 12px;
}

.login-hint { color: var(--text-secondary); }
.login-error { color: var(--danger-text); font-weight: 600; }

/* Pay rules page (#/rules): read-only cards. */
.rules-head h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

.rules-head p {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.rules-page {
  display: grid;
  gap: 16px;
}

.rules-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  min-width: 0;
}

.rules-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

.rules-card p {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.rules-card a {
  color: var(--primary);
  text-decoration: underline;
}

.rules-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 16px;
}

.rules-list li {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr);
  gap: 8px;
}

.rules-list .rules-no {
  font-weight: 700;
  color: var(--primary);
}

.rules-list p {
  margin-top: 2px;
}

.rules-scroll {
  margin-top: 12px;
  overflow-x: auto;
}

.rules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.rules-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  padding: 8px 16px 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.rules-table td {
  padding: 8px 16px 8px 0;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
  min-width: 140px;
  font-variant-numeric: tabular-nums;
}

.rules-table tr:last-child td {
  border-bottom: none;
}

/* -- Month lock -------------------------------------------------------- */

.month-lock-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.month-heading {
  font-size: 14px;
  font-weight: 600;
  margin: 0 4px 0 0;
}

.pill.locked {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning-text);
  overflow-wrap: anywhere;
}

.lock-note {
  color: var(--text-secondary);
  font-size: 12px;
}

.lock-banner {
  margin: 12px 12px 0;
  padding: 8px 12px;
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-sm);
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.lock-banner .icon {
  margin-right: 6px;
}

/* Calendar billing list and worker view; tables scroll within their cards. */
.billing-page { min-width: 0; }
.billing-page .toolbar-left { min-width: 0; }
.billing-page .filter-pills { flex-wrap: wrap; }
.billing-page table { min-width: 640px; }
.billing-page tbody tr { cursor: pointer; }
.billing-page td { overflow-wrap: anywhere; }
.billing-page td:nth-child(2), .billing-page td:nth-child(3) { min-width: 140px; }
.billing-page td:last-child { min-width: 180px; max-width: 320px; }
.billing-page .num { white-space: nowrap; }
.billing-header h1 { font-size: 15px; margin: 0; overflow-wrap: anywhere; }
.billing-header .worker-site-tag { white-space: normal; overflow-wrap: anywhere; }
.billing-title { display: flex; align-items: center; flex-wrap: wrap; gap: 5px 8px; min-width: 0; }
.billing-header .worker-passport { background: var(--bg-surface-subtle); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border-subtle); }
.billing-period { color: var(--text-muted); font-size: 11px; }
.billing-summary { color: var(--text-secondary); font-size: 12px; }
.billing-month > section { min-width: 0; min-height: 0; }
.billing-month .hint { white-space: normal; }
.billing-tick { display: inline-flex; align-items: center; gap: 3px; margin-left: 4px; font-size: 10px; white-space: nowrap; }
.billing-tick input { margin: 0; }
/* Billing has eight read-only columns, not the timesheet's nine input columns. */
table.billing-grid { min-width: 770px; }
table.billing-grid th:nth-child(1), table.billing-grid td:nth-child(1) { width: 145px; }
table.billing-grid th:nth-child(2), table.billing-grid td:nth-child(2) { width: auto; }
table.billing-grid th:nth-child(3), table.billing-grid td:nth-child(3) { width: 42px; }
table.billing-grid th:nth-child(4), table.billing-grid td:nth-child(4) { width: 66px; }
table.billing-grid th:nth-child(5), table.billing-grid td:nth-child(5) { width: 42px; }
table.billing-grid th:nth-child(6), table.billing-grid td:nth-child(6) { width: 112px; }
table.billing-grid th:nth-child(7), table.billing-grid td:nth-child(7) { width: 100px; }
table.billing-grid th:nth-child(8), table.billing-grid td:nth-child(8) { width: 100px; }
.billing-grid .echo { margin-left: 0; }
.billing-grid .tag { margin-left: 3px; }
.billing-grid .row-edit { flex-wrap: wrap; }
.billing-grid .row-edit label { white-space: nowrap; }
.billing-date:hover { text-decoration: underline; text-underline-offset: 3px; }
.billing-lock { margin-left: 4px; }
.billing-split { background: var(--primary-subtle); color: var(--text-secondary); font-size: 11px; }
.billing-total { font-weight: 700; background: var(--bg-surface-subtle); }
.billing-preview td:first-child { white-space: normal; overflow-wrap: anywhere; }
.billing-preview .money { white-space: nowrap; }
.billing-preview td:nth-child(2) { white-space: nowrap; }
.billing-issues { color: var(--warning-text); }
ul.billing-issues { margin: 0; padding-left: 20px; }
.billing-adjustment { display: flex; flex-direction: column; gap: 8px; }
.billing-adjustment button { align-self: flex-end; }
.billing-preview .note-row td:last-child { width: 65%; }
.billing-preview .readback, .billing-preview .who, .billing-preview .sub { overflow-wrap: anywhere; }
