:root {
  --border: #111;
  --border-soft: #444;
  --year-bg: #0a0a0a;
  --week-bg: #cfdbf0;
  --section-bg: #8a8a8a;
  --count-bg: #b7b7b7;
  --four-tracks: #f3c242;
  --four-tracks-soft: #fbe4a3;
  --on-leave: #e03c2b;
  --off: #8ed88c;
  --late-added: #c084fc;
  --row-hover: #f0f6ff;
  --white: #fff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: #111;
  background: #fafafa;
}

button {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid #bbb;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
}
button:hover { background: #f3f3f3; }
button.primary { background: #2563eb; color: #fff; border-color: #2563eb; }
button.primary:hover { background: #1d4ed8; }
button.danger { background: #e03c2b; color: #fff; border-color: #e03c2b; }
button.danger:hover { background: #c5301f; }
button.send-btn { background: #16a34a; color: #fff; border-color: #16a34a; font-weight: 600; }
button.send-btn:hover { background: #15803d; }
button.copy-btn { background: #7c3aed; color: #fff; border-color: #7c3aed; font-weight: 600; }
button.copy-btn:hover { background: #6d28d9; }
button.clear-btn { background: #dc2626; color: #fff; border-color: #dc2626; font-weight: 600; }
button.clear-btn:hover { background: #b91c1c; }

/* ===================== Top bar ===================== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: #111;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left, .topbar-center, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar strong { font-size: 16px; letter-spacing: 0.4px; }
.brand-logo {
  height: 36px;
  width: auto;
  display: block;
  background: #fff;
  padding: 2px 6px;
  border-radius: 4px;
}
.brand-title {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #fff;
  border-left: 2px solid #d32f2f;
  padding-left: 10px;
  margin-left: 2px;
}
.user-badge {
  background: #444;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}
.topbar button { background: #1f1f1f; color: #fff; border-color: #333; }
.topbar button:hover { background: #2b2b2b; }
.topbar button.send-btn { background: #16a34a; color: #fff; border-color: #16a34a; }
.topbar button.copy-btn { background: #7c3aed; color: #fff; border-color: #7c3aed; }
.topbar button.copy-btn:hover { background: #6d28d9; }
.topbar button.clear-btn { background: #dc2626; color: #fff; border-color: #dc2626; }
.topbar button.clear-btn:hover { background: #b91c1c; }

main { padding: 12px; overflow-x: auto; }

/* ===================== Grid ===================== */

.grid-container {
  display: grid;
  grid-template-columns: 110px repeat(14, minmax(100px, 1fr));
  border: 1px solid var(--border);
  background: var(--white);
  font-size: 12px;
  min-width: 1600px;
}

/* Header cells */
.gc { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px 6px; background: #fff; }
.gc:last-child { border-right: none; }

.year-cell {
  grid-column: 1;
  grid-row: 1 / span 3;
  background: var(--year-bg);
  color: #fff;
  font-weight: 700;
  font-size: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.week-header {
  background: var(--week-bg);
  text-align: center;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 6px 0;
}

.day-name {
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 6px 0;
}

.day-date {
  text-align: center;
  padding: 6px 0;
  font-weight: 500;
}

.black-bar {
  grid-column: 1 / -1;
  height: 6px;
  background: #000;
}

.section-label, .count-cell {
  background: var(--section-bg);
  color: #fff;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  padding: 4px 0;
  letter-spacing: 0.5px;
}
.count-cell { background: var(--count-bg); font-weight: 600; }

/* Driver rows */
.row-label {
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  padding: 6px 4px;
  background: #fff;
  cursor: pointer;
  user-select: none;
}
.row-label:hover { background: var(--row-hover); }

.row-label.placeholder {
  background: var(--four-tracks);
  color: #111;
}

/* Cells */
.cell {
  text-align: center;
  padding: 4px 2px;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1px;
  min-height: 36px;
}
.cell:hover { background: var(--row-hover); }

.cell .assigned-name {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #1e3a8a;
  text-transform: uppercase;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.cell .time-line { font-size: 12px; }

.cell.empty { background: #fff; }
.cell.empty::before { content: "-"; color: #555; }

.cell.work { background: #fff; }
.cell.work .time { display: inline-block; }

.cell.on-leave {
  background: var(--on-leave);
  color: #fff;
  font-weight: 700;
}
.cell.on-leave::before { content: "On Leave"; }

.cell.off {
  background: var(--off);
  color: #111;
  font-weight: 700;
}
.cell.off::before { content: "OFF"; }

/* Placeholder (4 TRACKS) row cells get yellow tint when work */
.row.placeholder .cell.work { background: var(--four-tracks); }
.row.placeholder .cell.empty { background: var(--four-tracks-soft); }

/* Planner added a cell after its 2-week period had already started */
.cell.late-added { color: #fff; font-weight: 700; }
.cell.late-added .assigned-name { color: #fff; }
.cell.late-added.empty::before { content: "Late"; color: #fff; }

/* "row" is a virtual concept — use attribute on row-label and cells via data attributes */

/* Add-row buttons */
.add-row-bar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  padding: 4px;
  background: #f3f3f3;
  border-bottom: 1px solid var(--border);
}
.add-row-bar button {
  font-size: 11px;
  padding: 3px 10px;
}

/* ===================== Login ===================== */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b, #0f172a);
}
.login-card {
  background: #fff;
  padding: 28px 32px;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-logo {
  width: 100%;
  max-width: 240px;
  height: auto;
  margin: 0 auto 4px;
  display: block;
}
.login-card h1 {
  margin: 0 0 8px 0;
  font-size: 20px;
  text-align: center;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-top: 2px solid #d32f2f;
  padding-top: 10px;
}
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.login-card input {
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 14px;
}
.login-card button {
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 10px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}
.error { color: #b91c1c; margin: 0; font-size: 13px; }

/* ===================== Modals ===================== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  background: #fff;
  padding: 20px 22px;
  border-radius: 6px;
  min-width: 340px;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card.wide { min-width: 640px; max-width: 80vw; }
.modal-card h3 { margin: 0; }
.modal-section { display: flex; flex-direction: column; gap: 6px; }
.modal-section label { font-size: 12px; color: #555; }
.quick-options { display: flex; flex-wrap: wrap; gap: 6px; }
.quick-options button { font-size: 12px; }
.assign-row { display: flex; align-items: center; gap: 8px; }
.assign-label {
  font-size: 13px;
  flex: 1;
  padding: 4px 8px;
  background: #f1f5f9;
  border-radius: 4px;
  min-height: 22px;
}
.assign-label.has-driver { background: #dbeafe; color: #1e3a8a; font-weight: 600; }
button.danger-outline {
  color: #dc2626;
  border-color: #fecaca;
  background: #fff;
}
button.danger-outline:hover { background: #fee2e2; }
.time-row { flex-direction: row; gap: 14px; }
.time-row label { flex-direction: row; align-items: center; gap: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.driver-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
}
.driver-item {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
}
.driver-item:last-child { border-bottom: none; }
.driver-item:hover { background: var(--row-hover); }
.driver-item .id { color: #94a3b8; font-size: 11px; }

#row-name-input, #driver-search {
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 14px;
}

/* Send result list */
#send-results {
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px;
}
.send-card {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px 12px;
  background: #f9fafb;
}
.send-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  margin-bottom: 6px;
}
.send-name { font-weight: 700; }
.send-phone { color: #475569; font-variant-numeric: tabular-nums; }
.send-status { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.status-sent    { background: #dcfce7; color: #166534; }
.status-preview { background: #dbeafe; color: #1e3a8a; }
.status-error   { background: #fee2e2; color: #991b1b; }
.status-skipped { background: #e5e7eb; color: #374151; }
.send-detail { font-size: 12px; color: #64748b; margin-bottom: 6px; }
.send-message {
  background: #111;
  color: #e5e7eb;
  padding: 10px 12px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  margin: 0;
}
