/* Cleaning Duties — the sheet follows the "new Cleaning tasks" workbook.
 * Every sheet colour below is the workbook's own (cell fills, fonts and the
 * conditional formats on the ☐/☑/☒ and Reason columns); the toolbar around
 * it uses the portal palette. */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --accent: #2563eb;
  --red: #dc2626;
  --green: #16a34a;

  /* workbook */
  --xl-grid: #d4d4d4;          /* Excel gridline */
  --xl-line: #000000;          /* thin cell border */
  --xl-week: #4472c4;          /* "Week 1" heading font */
  --xl-section-bg: #d9d9d9;    /* section row fill */
  --xl-section-fg: #00b050;    /* section row font */
  --xl-done-bg: #e2efda;       /* ☑ box */
  --xl-done-fg: #00b050;
  --xl-missed-bg: #fce4e4;     /* ☒ box */
  --xl-missed-fg: #c00000;
  --xl-need-done: #99e699;     /* Reason empty after ☑ */
  --xl-need-missed: #ff9999;   /* Reason empty after ☒ — must be filled */
  --xl-font: Calibri, Carlito, "Segoe UI", Arial, sans-serif;
  --xl-symbol: "Segoe UI Symbol", "Segoe UI", "DejaVu Sans", "Noto Sans Symbols 2", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: Inter, system-ui, sans-serif; }

.auth-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
}

/* ── Toolbar ───────────────────────────────────────────────────────────── */
.page { padding: 16px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
  color: #fff; font-weight: 800; background: linear-gradient(135deg, #15803d, #22c55e);
}
.brand-title { font-weight: 700; }
.brand-sub { font-size: .75rem; color: var(--text-muted); }
.week-nav { display: flex; align-items: center; gap: 6px; }
.week-nav select {
  font: inherit; font-size: .9rem; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 6px; background: #fff; min-width: 0; max-width: 62vw;
}
.who { display: flex; align-items: center; gap: 8px; }
.who-name { font-size: .85rem; font-weight: 600; color: var(--text-muted); }
.btn {
  font: inherit; font-size: .85rem; font-weight: 600; padding: 6px 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text);
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.legend { margin: 0 0 10px; font-size: .82rem; color: var(--text-muted); }
.g-done { color: var(--xl-done-fg); font-family: var(--xl-symbol); }
.g-missed { color: var(--xl-missed-fg); font-family: var(--xl-symbol); }

/* ── The sheet ─────────────────────────────────────────────────────────── */
.sheet-wrap { overflow: auto; background: #fff; border: 1px solid var(--xl-grid); max-height: calc(100vh - 150px); }
.sheet-wrap.is-loading { opacity: .55; }
/* Separate borders, right + bottom per cell: collapsed borders detach from
 * sticky cells while scrolling, which is what kept dropping grid lines. */
.sheet {
  border-collapse: separate; border-spacing: 0; table-layout: fixed; width: max-content;
  border-top: 1px solid var(--xl-line); border-left: 1px solid var(--xl-line);
  font-family: var(--xl-font); font-size: 11pt; color: #000;
}
.sheet th, .sheet td {
  border: 0; border-right: 1px solid var(--xl-grid); border-bottom: 1px solid var(--xl-grid);
  padding: 0 4px; height: 29px; vertical-align: middle;
}

.sheet thead th {
  position: sticky; z-index: 2; background: #fff; font-weight: 700;
  border-right-color: var(--xl-line); border-bottom-color: var(--xl-line);
}
.sheet thead .r1 th { top: 0; height: 20px; }
.sheet thead .r2 th { top: 21px; height: 40px; white-space: normal; line-height: 1.15; }
.sheet thead .r1 th[rowspan] { height: 61px; }
.sheet .week-title { color: var(--xl-week); font-size: 12pt; padding: 0; }
.day-date { display: block; font-weight: 400; font-size: 9pt; color: #595959; }

.c-sno { text-align: center; }
.c-duty { text-align: left; white-space: normal; line-height: 1.2; }
.c-name { text-align: center; }
.sheet thead .c-duty { text-align: left; }
tbody .c-sno, tbody .c-duty, tbody .c-name { border-right-color: var(--xl-line); }
tbody .c-sno, tbody .c-duty, tbody .second td { border-bottom-color: var(--xl-line); }
.sheet .day-end { border-right-color: var(--xl-line); }

.section td {
  background: var(--xl-section-bg); color: var(--xl-section-fg); font-size: 14pt; font-weight: 700;
  text-align: center; height: 35px; padding: 0;
  border-right-color: var(--xl-line); border-bottom-color: var(--xl-line);
}
/* Centred like the merged A:R row, but on the part of the sheet in view. */
.section-title, .week-label { position: sticky; left: 0; display: block; width: min(100%, calc(100vw - 34px)); }

/* ☐ / ☑ / ☒ box — a list cell, as in the workbook */
.mark { padding: 0; text-align: center; color: #000; }
.mark select {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent; cursor: pointer;
  width: 100%; height: 100%; min-height: 28px; text-align: center; text-align-last: center;
  font-family: var(--xl-symbol); font-size: 14pt; color: inherit;
}
.mark select:disabled { cursor: default; color: inherit; opacity: 1; }
.mark-done { background: var(--xl-done-bg); }
.mark-done { color: var(--xl-done-fg); }
.mark-missed { background: var(--xl-missed-bg); }
.mark-missed { color: var(--xl-missed-fg); }
.mark.future { color: #bfbfbf; }
.mark.future select { cursor: not-allowed; }
.mark select:focus-visible, .reason textarea:focus-visible { outline: 2px solid var(--xl-week); outline-offset: -2px; }

/* Reason for ☒ */
.reason { padding: 0; }
.reason.need-done { background: var(--xl-need-done); }
.reason.need-missed { background: var(--xl-need-missed); }
.reason textarea {
  display: block; width: 100%; height: 100%; min-height: 28px; resize: none; border: 0; background: transparent;
  font: inherit; font-size: 10pt; padding: 5px 4px; color: #000; overflow: hidden;
}
.reason textarea:disabled { color: #000; }

/* Sign box */
.sign { padding: 2px 4px; text-align: center; }
.sign-btn {
  font-family: Inter, system-ui, sans-serif; font-size: .74rem; font-weight: 600; cursor: pointer;
  padding: 3px 14px; border-radius: 5px; border: 1px solid var(--accent); background: #fff; color: var(--accent);
}
.sign-btn:hover:not(:disabled) { background: var(--accent); color: #fff; }
.sign-btn:disabled { border-color: #d0d0d0; color: #a6a6a6; cursor: not-allowed; }
.signed { position: relative; display: flex; flex-direction: column; line-height: 1.1; padding-right: 12px; }
.signed-name { font-weight: 700; font-size: 9.5pt; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signed-at { font-size: 8pt; color: #595959; white-space: nowrap; }
.unsign {
  position: absolute; top: -1px; right: -2px; border: 0; background: none; cursor: pointer;
  color: #a6a6a6; font-size: 14px; line-height: 1; padding: 0 2px;
}
.unsign:hover { color: var(--xl-missed-fg); }

/* Keep Sno / duty / name in view while scrolling across the days, where there's room. */
@media (min-width: 900px) {
  .sheet .c-sno, .sheet .c-duty, .sheet .c-name { position: sticky; z-index: 1; background: #fff; }
  .sheet .c-sno { left: 0; }
  .sheet .c-duty { left: 43px; }
  .sheet .c-name { left: 355px; }
  .sheet thead .c-sno, .sheet thead .c-duty, .sheet thead .c-name { z-index: 3; }
  .week-label { left: 494px; width: min(100%, calc(100vw - 528px)); }
}

@media (max-width: 640px) {
  .page { padding: 10px; }
  .who-name { display: none; }
  .sheet-wrap { max-height: none; }
}

/* ── Toasts ────────────────────────────────────────────────────────────── */
#toastContainer { position: fixed; bottom: 20px; right: 20px; left: auto; display: flex; flex-direction: column; gap: 10px; z-index: 10000; }
.toast {
  padding: 12px 16px; border-radius: 8px; background: #fff; border: 1px solid var(--border);
  max-width: min(380px, calc(100vw - 32px)); font-size: .88rem; box-shadow: 0 10px 30px rgba(15, 23, 42, .12);
}
.toast-success { border-left: 4px solid var(--green); }
.toast-error { border-left: 4px solid var(--red); }

/* ── Print: the sheet only, landscape, colours kept ────────────────────── */
@media print {
  @page { size: landscape; margin: 8mm; }
  body { background: #fff; }
  .page { padding: 0; }
  .no-print, #toastContainer { display: none !important; }
  .sheet-wrap { overflow: visible; max-height: none; border: 0; }
  .sheet { zoom: .5; }
  .sheet th, .sheet td { position: static !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
