:root {
  --orange: #fe571b;
  --orange-dark: #dd3c14;
  --orange-light: #fff1ec;
  --navy: #37474f;
  --navy-dark: #263238;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --bg: #f8fafc;
  --foreman: #f59e0b;
  --journeyman: #3b82f6;
  --apprentice: #10b981;
  --helper: #94a3b8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topnav {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  /* viewport-fit=cover draws content under the notch/status bar/Dynamic
     Island - push the nav down below it instead of letting the clock or
     camera cutout overlap the brand/links. */
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  padding-left: calc(24px + env(safe-area-inset-left, 0px));
  padding-right: calc(24px + env(safe-area-inset-right, 0px));
  background: white;
  border-bottom: 3px solid var(--navy);
}

.topnav .brand {
  font-weight: 700;
  color: var(--navy);
  margin-right: 16px;
}
.topnav .brand::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orange);
  margin-left: 4px;
}

.topnav a {
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.topnav a:hover { color: var(--orange); }

.topnav a.active {
  color: var(--orange);
  font-weight: 700;
  position: relative;
}
.topnav a.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -17px;
  height: 3px;
  background: var(--orange);
}

main {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 24px;
}

h1 { font-size: 22px; margin-bottom: 16px; }

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

.btn {
  display: inline-block;
  padding: 8px 14px;
  background: var(--orange);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--orange-dark); }

.btn.secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.secondary:hover { background: #f8fafc; }

.btn.danger {
  background: #fee2e2;
  color: #b91c1c;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

th { background: #f1f5f9; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; }

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

a.rowlink { color: var(--orange-dark); text-decoration: none; font-weight: 500; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.rank-Owner { background: #ede9fe; color: #5b21b6; }
.rank-Co-Owner { background: #ede9fe; color: #6d28d9; }
.rank-Foreman { background: #fef3c7; color: #92400e; }
.rank-Journeyman { background: #dbeafe; color: #1e40af; }
.rank-Apprentice { background: #d1fae5; color: #065f46; }
.rank-Helper { background: #f1f5f9; color: #475569; }

.status-Quoted { background: #f1f5f9; color: #475569; }
.status-Scheduled { background: #dbeafe; color: #1e40af; }
.status-InProgress { background: #fef3c7; color: #92400e; }
.status-Completed { background: #d1fae5; color: #065f46; }
.status-Cancelled { background: #fee2e2; color: #b91c1c; }

form.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  max-width: 560px;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.field textarea { min-height: 70px; resize: vertical; }

.form-actions { display: flex; gap: 8px; margin-top: 20px; }

/* Calendar */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.cal-nav { display: flex; gap: 8px; align-items: center; }

.cal-grid {
  display: grid;
  grid-template-columns: 160px repeat(7, 1fr);
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.cal-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px;
  min-height: 70px;
  vertical-align: top;
}

.cal-cell.head {
  background: #f1f5f9;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 10px;
  min-height: auto;
  text-align: center;
}

.cal-cell.emp {
  background: #fcfcfd;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 10px;
  min-height: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cal-cell.today { background: var(--orange-light); }

.hours-grid { grid-template-columns: 160px repeat(7, 1fr) 100px; }
.hours-cell {
  min-height: auto;
  padding: 10px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.hours-row-total { font-weight: 700; background: #f8fafc; }

.assignment-chip {
  display: block;
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 4px;
  margin-bottom: 3px;
  background: var(--orange-light);
  color: var(--navy-dark);
  text-decoration: none;
  border-left: 3px solid var(--orange);
}

.add-slot {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-decoration: none;
  text-align: center;
  padding: 2px;
}
.add-slot:hover { color: var(--orange); }

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

/* Time Clock */
.time-clock-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 80px 20px;
  text-align: center;
}

.tc-status { font-size: 20px; font-weight: 600; margin: 0; }
.tc-detail { color: var(--muted); font-size: 14px; margin: 0 0 8px; line-height: 1.5; }

.tc-button {
  display: inline-block;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  border: none;
  font-size: 26px;
  font-weight: 700;
  color: white;
  cursor: pointer;
  text-decoration: none;
  line-height: 260px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  transition: transform 0.1s ease;
}
.tc-button:active { transform: scale(0.97); }
.tc-start { background: linear-gradient(180deg, #22c55e, #16a34a); }
.tc-stop { background: linear-gradient(180deg, #ef4444, #b91c1c); }

.tc-secondary-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.nearby-banner {
  background: var(--orange-light);
  border: 1px solid var(--orange);
  border-radius: 10px;
  padding: 14px 18px;
  max-width: 320px;
  margin-bottom: 20px;
  text-align: center;
}

/* Scrollable wrapper for wide tables/grids on narrow screens */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
}

/* KPI stat cards */
.kpi-row { display: flex; gap: 16px; margin: 20px 0; flex-wrap: wrap; }
.kpi-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
}
.kpi-value { font-size: 28px; font-weight: 700; color: var(--navy); }
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; }

/* Date range filter form */
.date-range-form {
  max-width: none;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  padding: 16px 20px;
  flex-wrap: wrap;
}
.date-range-form .field { margin: 0; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .topnav {
    flex-wrap: wrap;
    gap: 12px 16px;
    padding: 12px 16px;
    /* this reset was wiping out the safe-area padding-top set above, right
       where it actually matters - guarantee real empty space below the
       notch/status bar/Dynamic Island even if env() misbehaves on some
       devices, rather than relying on it alone. */
    padding-top: max(50px, calc(12px + env(safe-area-inset-top, 0px)));
  }
  .topnav .brand { margin-right: 0; width: 100%; }
  .topnav form { margin-left: 0; order: 99; width: 100%; }
  .topnav a.active::after { bottom: -12px; }

  main { padding: 0 14px; margin: 16px auto; }

  .page-header, .cal-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .cal-nav {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }
  .cal-nav strong {
    width: 100%;
    order: -1;
    font-size: 15px;
  }

  .cal-grid { min-width: 640px; }
  .hours-grid { min-width: 720px; }

  form.card { max-width: none; padding: 16px; }
  .date-range-form { flex-direction: column; align-items: stretch; }
  .date-range-form button { width: 100%; }

  .tc-button {
    width: min(220px, 70vw);
    height: min(220px, 70vw);
    line-height: min(220px, 70vw);
    font-size: 22px;
  }
}
