/*
 * STYLE.CSS - design tokens & layout
 * ==================================
 * A ledger/payslip-inspired look: slab serif for headings, monospace for
 * all numeric figures, a paper-grid background, and a stamped "Gross"/
 * "Net" box pair. All colors are defined once below and referenced via
 * var(--name) everywhere else in this file.
 *
 * QUIRKS:
 * - .weekend-row and .ph-row can both apply to the same <tr> (a public
 *   holiday can fall on a Saturday/Sunday). .ph-row is declared AFTER
 *   .weekend-row below so it wins on equal specificity - this is a
 *   deliberate CSS-order dependency, not an accident. If you reorder these
 *   two rules, public-holiday-on-a-weekend shading will silently break.
 * - --ph-border is defined but not currently used anywhere - reserved in
 *   case a border treatment is wanted for public-holiday rows later.
 * - .field-error and .ph-row are toggled entirely from app.js via
 *   classList - there's no CSS-only trigger for either.
 */
:root {
  --paper: #F7F5F0;
  --paper-line: #DCD6C8;
  --ink: #20291F;
  --forest: #2F5233;
  --forest-dark: #1E3721;
  --amber: #C97A3D;
  --amber-light: #F1E1CD;
  --header-bg: #EAE6DA;
  --red-stamp: #A3392E;
  --ph-color: #E7D9F2;
  --ph-border: #8B5FBF;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --slab: 'Zilla Slab', Georgia, serif;
  --sans: 'Inter', -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    linear-gradient(var(--paper-line) 1px, transparent 1px) 0 0 / 100% 32px,
    var(--paper);
  min-height: 100vh;
}

.topbar {
  background: var(--forest);
  color: var(--paper);
  border-bottom: 4px solid var(--amber);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 22px;
}
.topbar h1 {
  font-family: var(--slab);
  font-weight: 700;
  font-size: 2.1rem;
  margin: 0;
  letter-spacing: 0.01em;
}
.topbar h1 .mark { color: var(--amber); }
.tagline {
  margin: 4px 0 0;
  font-size: 0.95rem;
  opacity: 0.85;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: #fff;
  border: 1px solid var(--paper-line);
  border-radius: 4px;
  box-shadow: 0 1px 0 rgba(32, 41, 31, 0.04);
  padding: 20px 22px;
}

.setup-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--forest-dark);
}
.field input {
  font-family: var(--mono);
  font-size: 0.95rem;
  padding: 8px 10px;
  border: 1px solid var(--paper-line);
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
}
.field input:focus, select:focus {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}
.field-status {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--forest-dark);
  align-self: end;
  padding-bottom: 9px;
}
.date-picker-button {
  font-family: var(--mono);
  font-size: 0.95rem;
  padding: 8px 10px;
  border: 1px solid var(--paper-line);
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.date-picker-button:hover, .date-picker-button:focus {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.toggle-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.toggle-input-row input[type="number"] {
  font-family: var(--mono);
  font-size: 0.95rem;
  padding: 8px 10px;
  border: 1px solid var(--paper-line);
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
  width: 100px;
}
.unit-label {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: #b7b1a0; /* inactive by default; app.js toggles this to var(--forest-dark) for whichever unit is active */
}
.unit-label.unit-active { color: var(--forest-dark); }

.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--paper-line);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s;
}
.switch-slider::before {
  content: '';
  position: absolute;
  height: 14px;
  width: 14px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}
.switch input:checked + .switch-slider { background: var(--forest); }
.switch input:checked + .switch-slider::before { transform: translateX(16px); }
.switch input:focus + .switch-slider { outline: 2px solid var(--amber); outline-offset: 2px; }

.footer-link {
  text-align: center;
  margin-top: 4px;
}
.footer-link a {
  font-size: 0.8rem;
  color: #8a8471;
  text-decoration: none;
}
.footer-link a:hover {
  color: var(--forest);
  text-decoration: underline;
}

.table-panel { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
thead th {
  background: var(--header-bg);
  text-align: left;
  padding: 10px 8px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--forest-dark);
  border-bottom: 2px solid var(--forest);
  white-space: nowrap;
}
tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--paper-line);
  vertical-align: middle;
}
tbody tr.weekend-row { background: var(--amber-light); }
/* Must stay AFTER .weekend-row above - see the file header note on cascade order. */
tbody tr.ph-row { background: var(--ph-color); }
.col-date { font-family: var(--mono); white-space: nowrap; }
.col-time input { font-family: var(--mono); width: 90px; padding: 4px; border: 1px solid var(--paper-line); border-radius: 3px; }
.col-time input.field-error {
  border: 2px solid var(--red-stamp);
  background: #FBEAE8;
}
.col-code select { padding: 4px; border: 1px solid var(--paper-line); border-radius: 3px; background: #fff; }
.col-hours { font-family: var(--mono); font-weight: 600; text-align: right; }
.col-type { font-size: 0.82rem; }
.col-type select { padding: 4px; border: 1px solid var(--paper-line); border-radius: 3px; background: #fff; color: var(--ink); }
.col-ph { text-align: center; }
.col-ot { text-align: center; }
#shiftTable:not(.is-fulltime) .col-ot { display: none; }
.col-details { text-align: center; }
.day-details-link {
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--forest);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
  padding: 2px 4px;
}
.day-details-link:disabled {
  color: #b7b1a0;
  text-decoration: none;
  cursor: default;
}

.summary-panel h2, .notes-panel h2 {
  font-family: var(--slab);
  font-size: 1.2rem;
  color: var(--forest-dark);
  margin: 0 0 14px;
}
.summary-panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.export-buttons { display: flex; gap: 8px; margin-bottom: 14px; }
.export-btn {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--forest-dark);
  background: var(--paper);
  border: 1px solid var(--paper-line);
  border-radius: 3px;
  padding: 6px 12px;
  cursor: pointer;
}
.export-btn:hover { background: var(--header-bg); border-color: var(--forest); }
.summary-grid { display: flex; flex-direction: column; }
.summary-row {
  display: grid;
  grid-template-columns: 1fr 90px 100px;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--paper-line);
  font-size: 0.9rem;
}
.summary-hours, .summary-pay { font-family: var(--mono); text-align: right; }
.summary-pay { font-weight: 600; }

.stamp {
  margin-top: 20px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 3px solid var(--red-stamp);
  color: var(--red-stamp);
  border-radius: 6px;
  padding: 10px 24px;
  transform: rotate(-1.5deg);
}
.stamp-label {
  font-family: var(--slab);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.stamp-amount {
  font-family: var(--mono);
  font-size: 1.6rem;
  font-weight: 700;
}

.tax-block {
  margin-top: 18px;
  padding-top: 4px;
  border-top: 1px dashed var(--paper-line);
}

.stamp-takehome {
  border-color: var(--forest);
  color: var(--forest-dark);
  transform: rotate(1.2deg);
}

.notes-panel ul {
  margin: 0;
  padding-left: 20px;
  font-size: 0.85rem;
  color: #4a4536;
  line-height: 1.6;
}

/* ---- Mobile layout (phones and narrow screens) ----
 * Below this width, the table stops being a table: each row becomes a
 * bordered card, each cell becomes a label+value line (label supplied by
 * the data-label attribute set in app.js's buildRow(), read here via
 * content: attr(data-label)), and Day/Date are pulled out as a plain
 * unlabeled header line at the top of the card instead of another
 * label+value row, since which day it is should be the first thing you
 * see, not something you read a label to find.
 */
@media (max-width: 700px) {
  .wrap { padding: 14px 12px 48px; gap: 14px; }
  .panel { padding: 14px 16px; }
  .topbar-inner { padding: 20px 16px 16px; }
  .topbar h1 { font-size: 1.6rem; }

  .setup-panel { gap: 14px; }

  .table-panel { overflow-x: visible; border: none; box-shadow: none; background: none; }
  table, thead, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }

  tbody tr {
    border: 1px solid var(--paper-line);
    border-radius: 6px;
    background: #fff;
    margin-bottom: 10px;
    padding: 10px 12px 4px;
  }
  tbody tr.weekend-row { background: var(--amber-light); }
  tbody tr.ph-row { background: var(--ph-color); }

  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 0;
    border-bottom: 1px dashed var(--paper-line);
    font-size: 0.85rem;
  }
  tbody td::before {
    content: attr(data-label);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #8a8471;
    font-weight: 600;
    margin-right: 12px;
    white-space: nowrap;
  }

  /* Day + Date form an unlabeled 2-line header block instead of label+value rows. */
  .col-day, .col-date {
    display: block;
    border-bottom: none;
    padding: 1px 0;
  }
  .col-day::before, .col-date::before { content: none; }
  .col-day { font-family: var(--slab); font-weight: 700; font-size: 1rem; color: var(--forest-dark); }
  .col-date {
    color: #6b6656;
    font-size: 0.85rem;
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--paper-line);
  }

  .col-time input { width: 110px; font-size: 0.9rem; }
  .col-code select, .col-type select { max-width: 190px; }
  .col-hours { font-size: 0.95rem; }
  .col-details { border-bottom: none; justify-content: flex-end; padding-top: 4px; }
  .day-details-link { font-size: 0.9rem; }

  .summary-row { grid-template-columns: 1fr 64px 82px; gap: 6px; font-size: 0.82rem; }
  .stamp { padding: 8px 18px; }
  .stamp-amount { font-size: 1.35rem; }

  .day-detail-panel, .calendar-panel { padding: 20px 16px; max-width: 100%; }
  .calendar-day { font-size: 0.78rem; }
}

.day-detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(32, 41, 31, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.day-detail-overlay.hidden { display: none; }
.day-detail-panel {
  position: relative;
  background: #fff;
  border-radius: 6px;
  padding: 26px 28px;
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
}
.day-detail-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--forest-dark);
  cursor: pointer;
  padding: 4px 8px;
}
.day-detail-panel h3 {
  font-family: var(--slab);
  font-size: 1.15rem;
  color: var(--forest-dark);
  margin: 0 0 4px;
  padding-right: 24px;
}
.day-detail-meta {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: #6b6656;
  margin: 0 0 16px;
}
.day-detail-note {
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 0 0 14px;
  padding: 8px 10px;
  border-left: 3px solid #c9a227;
  background: #fbf6e3;
}
.day-detail-body .summary-row {
  grid-template-columns: 1fr 80px 90px;
  font-size: 0.85rem;
}
.day-detail-total {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  padding-top: 10px;
  margin-top: 6px;
  border-top: 2px solid var(--forest);
  font-family: var(--mono);
}
.day-detail-empty {
  font-size: 0.9rem;
  color: #6b6656;
  padding: 10px 0;
}

.calendar-panel { max-width: 340px; }
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-right: 20px;
}
.calendar-nav button {
  background: none;
  border: 1px solid var(--paper-line);
  border-radius: 3px;
  color: var(--forest-dark);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 10px;
}
.calendar-nav button:hover { background: var(--header-bg); }
#calendarMonthLabel {
  font-family: var(--slab);
  font-weight: 600;
  color: var(--forest-dark);
}
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #8a8471;
  text-align: center;
  margin-bottom: 4px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.calendar-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.85rem;
  border-radius: 4px;
  border: 1px solid transparent;
  background: none;
  color: var(--ink);
}
.calendar-day.cal-outside { color: #c9c3b2; }
.calendar-day.cal-disabled { color: #c9c3b2; cursor: default; }
.calendar-day.cal-valid-monday {
  cursor: pointer;
  background: var(--amber-light);
  border-color: var(--amber);
  font-weight: 600;
}
.calendar-day.cal-valid-monday:hover { background: var(--amber); color: #fff; }
.calendar-day.cal-public-holiday {
  background: var(--ph-color);
  border-color: var(--ph-border);
}
/* A valid Monday that's ALSO a public holiday - keep the Monday styling
   (it's still clickable/selectable) but add a dot to flag the PH overlap,
   rather than trying to blend two background colors. */
.calendar-day.cal-valid-monday.cal-public-holiday::after {
  content: '';
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ph-border);
  margin-top: 16px;
}
.calendar-day { position: relative; }
.calendar-day.cal-selected {
  outline: 2px solid var(--forest);
  outline-offset: -2px;
}

/* ---- Print / Save-as-PDF view ----
 * #printArea is populated by app.js's buildPrintHtml() right before
 * window.print() is called. It's hidden on-screen and only appears in
 * print - everything else on the page is hidden while printing instead,
 * so the printout is just this clean payslip-style summary rather than
 * the interactive form controls (which don't print as read-only values).
 */
.print-area { display: none; }

@media print {
  @page {
    size: A4 landscape;
    margin: 12mm;
  }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; }
  body {
    background: #fff;
    color: #000;
    font-family: var(--sans);
  }
  .print-area h1 {
    font-family: var(--slab);
    font-size: 1.4rem;
    margin: 0 0 2px;
  }
  .print-area .print-meta {
    font-family: var(--mono);
    font-size: 0.85rem;
    color: #333;
    margin: 0 0 16px;
  }
  .print-area table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    margin-bottom: 20px;
  }
  .print-area tr { page-break-inside: avoid; }
  .print-area th, .print-area td {
    border: 1px solid #999;
    padding: 4px 6px;
    text-align: left;
  }
  .print-area th { background: #eee; }
  .print-area td.print-num { text-align: right; font-family: var(--mono); }
  .print-area .print-summary-table td:first-child { width: 60%; }
  .print-area .print-total-row td {
    font-weight: 700;
    border-top: 2px solid #000;
  }

  /* Page 2: day-by-day category matrix - 15 columns (1 label + 14 days)
   * on one landscape A4 page, so every column has to stay narrow. */
  .print-page-break { page-break-before: always; }
  .print-matrix-table {
    table-layout: fixed;
    font-size: 0.62rem;
  }
  .print-matrix-table th, .print-matrix-table td {
    padding: 2px 3px;
    text-align: center;
  }
  .print-matrix-table th:first-child,
  .print-matrix-table td:first-child {
    text-align: left;
    width: 13%;
  }
}
