:root {
  color-scheme: light;
  --blue: #1e40af;
  --blue-dark: #1e3a8a;
  --blue-light: #eff6ff;
  --green: #166534;
  --green-bg: #bbf7d0;
  --amber: #92400e;
  --amber-bg: #fffbeb;
  --red: #991b1b;
  --grey-50: #f9fafb;
  --grey-100: #f3f4f6;
  --grey-200: #e5e7eb;
  --grey-400: #9ca3af;
  --grey-600: #4b5563;
  --grey-900: #111827;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #eef2f7;
  color: var(--grey-900);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Modal ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

#modal-overlay.hidden { display: none !important; }

#modal {
  background: white;
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.2);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

#modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--grey-100);
}

#modal-date {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--grey-900);
}

#modal-day {
  font-size: 0.85rem;
  color: var(--grey-600);
  margin-top: 0.1rem;
}

#modal-close {
  background: var(--grey-100);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--grey-600);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.85rem;
  background: var(--grey-50);
  border-radius: 10px;
}

.modal-row-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--grey-600);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.modal-row-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--grey-900);
}

.modal-badge {
  display: inline-block;
  padding: 0.35rem 0.85rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
}

.modal-badge.rest          { background: var(--green-bg);  color: var(--green); }
.modal-badge.annual-leave  { background: #fed7aa; color: #c2410c; }
.modal-badge.toa           { background: var(--blue-light); color: #4338ca; }
.modal-badge.work          { background: var(--blue-light); color: var(--blue-dark); }

/* ── PIN screen ── */
#pin-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

#pin-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}

#pin-card .pin-icon {
  font-size: 2.5rem;
  margin-bottom: 0.25rem;
}

#pin-card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--blue-dark);
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
}

#pin-card p {
  font-size: 0.88rem;
  color: var(--grey-600);
  margin-bottom: 0.25rem;
}

#username-input {
  width: 100%;
  text-align: center;
  font-size: 1rem;
  padding: 0.65rem 1rem;
  border: 2px solid var(--grey-200);
  border-radius: 10px;
  background: var(--grey-50);
  color: var(--grey-900);
  font-family: inherit;
}

#username-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(30,64,175,0.12);
}

#pin-input {
  width: 100%;
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: 0.5rem;
  padding: 0.65rem 1rem;
  border: 2px solid var(--grey-200);
  border-radius: 10px;
  font-family: monospace;
  background: var(--grey-50);
  color: var(--grey-900);
}

#pin-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(30,64,175,0.12);
}

#pin-btn {
  width: 100%;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 9px;
  padding: 0.7rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 0.25rem;
}

#pin-btn:hover { background: var(--blue-dark); }

/* ── View toggle ── */
.view-toggle {
  margin-left: auto;
  display: flex;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}

.toggle-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.75);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  padding: 0.3rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.toggle-btn.active {
  background: white;
  color: var(--blue-dark);
}

.admin-btn {
  margin-left: 0.5rem;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 0.3rem 0.6rem;
  text-decoration: none;
  font-size: 1rem;
  transition: background 0.15s;
}

.admin-btn:hover { background: rgba(255,255,255,0.25); }

/* ── Month controls ── */
.month-nav {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

#month-label {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--grey-900);
  min-width: 140px;
  text-align: center;
}

/* ── Month grid view ── */
.month-grid-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.month-grid-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr) 60px;
  background: var(--blue-dark);
  color: white;
}

.month-grid-head-cell {
  padding: 0.5rem 0.25rem;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.month-grid-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr) 60px;
  border-bottom: 1px solid var(--grey-200);
}

.month-grid-row:last-of-type {
  border-bottom: none;
}

.month-cell {
  padding: 0.4rem 0.3rem;
  border-right: 1px solid var(--grey-100);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-height: 72px;
}

.month-cell.rest         { background: var(--green-bg); }
.month-cell.toa          { background: var(--blue-light); }
.month-cell.weekend-work { background: #fef08a; }
.month-cell.today        { background: var(--amber-bg); outline: 2px solid #f59e0b; outline-offset: -2px; }
.month-cell.out-of-month { opacity: 0.25; }

.month-cell-date {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--grey-600);
  align-self: flex-start;
}

.month-cell.today .month-cell-date {
  color: var(--amber);
}

.month-cell-duty {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--grey-900);
  text-align: center;
  line-height: 1.2;
}

.month-cell-time {
  font-size: 0.7rem;
  color: var(--blue);
  font-weight: 600;
}

.month-cell-rest {
  font-size: 0.7rem;
  color: var(--green);
  font-weight: 600;
  margin-top: auto;
  margin-bottom: auto;
}

.month-cell-al {
  font-size: 0.7rem;
  color: #c2410c;
  font-weight: 700;
  margin-top: auto;
  margin-bottom: auto;
}

.month-cell-toa {
  font-size: 0.7rem;
  color: #6366f1;
  font-weight: 600;
  margin-top: auto;
  margin-bottom: auto;
}

.month-grid-week-total {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--blue-dark);
  background: var(--blue-light);
  padding: 0.25rem;
  text-align: center;
}

.month-footer {
  padding: 0.75rem 1.25rem;
  background: var(--blue-dark);
  color: white;
  font-weight: 700;
  font-size: 0.9rem;
  text-align: right;
}

/* ── Header ── */
header {
  background: var(--blue-dark);
  color: white;
  padding: 0.75rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  max-width: 100%;
}

header .bus-icon {
  font-size: 1.3rem;
}

header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* ── Layout ── */
main {
  max-width: 680px;
  margin: 0 auto;
  padding: 1.1rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Card ── */
.card {
  background: white;
  border-radius: var(--radius);
  padding: 1.35rem;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 1.1rem;
  color: var(--blue-dark);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* ── Form ── */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.form-row.inline {
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0;
}

.form-row.inline label {
  flex: 0 0 auto;
}

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--grey-600);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

input[type="text"],
input[type="date"],
select {
  appearance: none;
  -webkit-appearance: none;
  border: 1.5px solid var(--grey-200);
  border-radius: 9px;
  padding: 0.6rem 0.85rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--grey-900);
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.25rem;
  cursor: pointer;
}

input[type="text"]:focus,
input[type="date"]:focus,
select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(30,64,175,0.12);
}

input[type="date"] {
  width: 160px;
}

/* ── Buttons ── */
.btn-primary {
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 9px;
  padding: 0.7rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  width: 100%;
  margin-top: 0.35rem;
  letter-spacing: 0.2px;
}

.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: var(--grey-100);
  color: var(--blue-dark);
  border: 1.5px solid var(--grey-200);
  border-radius: 9px;
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-secondary:hover { background: var(--grey-200); }

.btn-link {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}

/* ── Driver summary bar ── */
.driver-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--grey-100);
}

.driver-summary span {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--grey-900);
}

/* ── Errors / loading ── */
.error {
  color: var(--red);
  font-size: 0.83rem;
  margin-top: 0.4rem;
}

.hidden { display: none !important; }

.loading {
  text-align: center;
  color: var(--grey-400);
  padding: 2.5rem 1rem;
  font-size: 0.95rem;
}

/* ── Week cards ── */
.week-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.week-header {
  background: var(--blue-dark);
  color: white;
  padding: 0.9rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.week-header .week-range {
  font-weight: 700;
  font-size: 0.9rem;
}

.week-header .week-total {
  font-size: 0.82rem;
  background: rgba(255,255,255,0.15);
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-weight: 600;
}

.week-header.current-week {
  background: #15803d;
}

/* ── Day rows ── */
.day-row {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  align-items: center;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--grey-100);
  gap: 0.75rem;
  min-height: 56px;
}

.day-row:last-child { border-bottom: none; }

.day-row.weekend-work  { background: #fef08a; }
.day-row.annual-leave  { background: #fed7aa; }

.month-cell.annual-leave { background: #fed7aa; }

.annual-leave-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #c2410c;
}

.day-row.today {
  background: var(--amber-bg);
  border-left: 3px solid #f59e0b;
}

.day-row.today .day-name { color: var(--amber); }

.day-row.rest { background: var(--green-bg); }

.day-row.toa { background: var(--blue-light); }

.day-row.unknown { background: #fff7ed; }

.day-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--grey-600);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.day-name.today-label::after {
  content: ' ▸';
  color: #f59e0b;
}

/* ── Duty info ── */
.duty-info {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}

.duty-code {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--grey-900);
}

.duty-location {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--blue);
  text-transform: capitalize;
}

.duty-times {
  font-size: 0.8rem;
  color: var(--grey-600);
}

.duty-break {
  font-size: 0.75rem;
  color: var(--grey-400);
}

.duty-hours {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--blue-dark);
  text-align: right;
  white-space: nowrap;
  background: var(--blue-light);
  padding: 0.25rem 0.55rem;
  border-radius: 20px;
}

.rest-label {
  font-size: 0.83rem;
  color: var(--grey-400);
}

.toa-label {
  font-size: 0.83rem;
  color: #6366f1;
  font-weight: 600;
}

/* ── A/L header button ── */
.al-header-btn {
  margin-left: 0.4rem;
  background: #fed7aa;
  color: #9a3412;
  border: none;
  border-radius: 8px;
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  letter-spacing: 0.2px;
}
.al-header-btn:hover { background: #fdba74; }

/* ── A/L modal overlay ── */
#al-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#al-overlay.hidden { display: none !important; }

#al-modal {
  background: white;
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.2);
  animation: slideUp 0.2s ease;
}

.al-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--grey-100);
}

.al-modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--grey-900);
}

.al-modal-subtitle {
  font-size: 0.82rem;
  color: var(--grey-600);
  margin-top: 0.15rem;
}

#al-close {
  background: var(--grey-100);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--grey-600);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── A/L list ── */
.al-list {
  padding: 1rem 1.25rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.al-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff7ed;
  border: 1.5px solid #fed7aa;
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
}

.al-item-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.al-item-dates {
  font-weight: 700;
  font-size: 0.88rem;
  color: #7c2d12;
}

.al-item-arrow {
  font-size: 0.78rem;
  color: #9a3412;
  font-weight: 600;
}

.al-delete-btn {
  background: none;
  border: 1.5px solid #fca5a5;
  color: #991b1b;
  border-radius: 8px;
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.al-delete-btn:hover { background: #fee2e2; }

/* ── A/L add section ── */
.al-add-section {
  padding: 1rem 1.25rem 1.5rem;
  margin-top: 0.75rem;
  border-top: 1px solid var(--grey-100);
}

.al-add-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--grey-600);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 0.6rem;
}

.al-add-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.al-date-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.al-date-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--grey-600);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.al-date-input {
  width: 148px;
  border: 1.5px solid var(--grey-200);
  border-radius: 9px;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--grey-900);
}

.al-add-btn {
  background: #c2410c;
  color: white;
  border: none;
  border-radius: 9px;
  padding: 0.58rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.al-add-btn:hover { background: #9a3412; }

.al-error {
  color: var(--red);
  font-size: 0.82rem;
  margin-top: 0.5rem;
}

/* ── Annual leave underlying info ── */
.al-underlying {
  font-size: 0.75rem;
  color: #9a3412;
  font-style: italic;
}

.month-cell-al-sub {
  font-size: 0.62rem;
  color: #9a3412;
  font-style: italic;
  text-align: center;
}
