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

body {
  font-family: 'Inter', Arial, sans-serif;
  background: #d0d0d0;
  color: #111;
  min-height: 100vh;
}

/* ═══ SETUP SCREEN ════════════════════════════════════════ */
#setup-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: #e4e4e4;
}

.setup-card {
  background: #fff;
  border: 1px solid #bbb;
  box-shadow: 0 4px 20px rgba(0,0,0,0.13);
  max-width: 620px;
  width: 100%;
  padding: 2.8rem 3rem;
}

.setup-header {
  text-align: center;
  margin-bottom: 2rem;
  padding-bottom: 1.2rem;
  border-bottom: 2px solid #111;
}
.setup-header .eyebrow { font-size: 0.63rem; letter-spacing: 0.2em; text-transform: uppercase; color: #888; margin-bottom: 0.4rem; }
.setup-header h1       { font-size: 1.65rem; font-weight: 700; }
.setup-header .tagline { font-size: 0.83rem; color: #666; margin-top: 0.25rem; }

/* Form layout */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem 1.6rem; }

.form-field { display: flex; flex-direction: column; gap: 0.3rem; }
.form-field.full { grid-column: 1 / -1; }

.form-field label {
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #666;
  font-weight: 600;
}
.form-field input,
.form-field select {
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  color: #111;
  background: #f6f6f6;
  border: 1px solid #ccc;
  border-radius: 2px;
  padding: 0.48rem 0.65rem;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  width: 100%;
}
.form-field input:focus,
.form-field select:focus { border-color: #333; background: #fff; }

.time-range-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 0.5rem; }
.time-range-separator { font-size: 1rem; color: #888; padding-bottom: 0.48rem; text-align: center; }

/* ═══ TOLERANCE TOGGLE ════════════════════════════════════ */
.tolerance-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
  padding: 0.55rem 0.8rem;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.tolerance-toggle-row:hover { background: #e8e8e8; }
.tolerance-toggle-row.active { background: #e8f4e8; border-color: #5a9e5a; }

.tolerance-label-group { display: flex; flex-direction: column; gap: 0.15rem; }
.tolerance-label-group .label-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #333;
}
.tolerance-label-group .label-description { font-size: 0.67rem; color: #777; }
.tolerance-toggle-row.active .label-title       { color: #2d6a2d; }
.tolerance-toggle-row.active .label-description { color: #4a8a4a; }

/* Toggle switch widget */
.toggle-switch { position: relative; width: 38px; height: 21px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 21px;
  transition: background 0.2s;
  cursor: pointer;
}
.toggle-track::before {
  content: '';
  position: absolute;
  width: 15px;
  height: 15px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-track               { background: #4a8a4a; }
.toggle-switch input:checked + .toggle-track::before       { transform: translateX(17px); }

/* Auto-fill option section */
.autofill-section {
  margin: 1.6rem 0 0;
  padding: 0.9rem 1.1rem;
  background: #f4f4f4;
  border-left: 3px solid #555;
}
.autofill-section p { font-size: 0.86rem; color: #444; margin-bottom: 0.6rem; }
.radio-group { display: flex; gap: 2rem; flex-wrap: wrap; }
.radio-group label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; cursor: pointer; color: #333; }
.radio-group input[type="radio"] { accent-color: #333; width: 14px; height: 14px; }

/* Generate button */
.btn-generate {
  width: 100%;
  margin-top: 1.8rem;
  padding: 0.82rem 2rem;
  background: #111;
  color: #fff;
  border: none;
  font-family: 'Inter', sans-serif;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-generate:hover    { background: #333; }
.btn-generate:disabled { background: #888; cursor: wait; }

/* Loading indicator */
#loading-indicator {
  display: none;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: #555;
  justify-content: center;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #ccc;
  border-top-color: #333;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* API status badge */
.api-badge {
  display: none;
  font-size: 0.63rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.2rem 0.55rem;
  border-radius: 2px;
  margin-top: 0.6rem;
  font-weight: 600;
}
.api-badge.online  { background: #d4edda; color: #155724; display: block; }
.api-badge.offline { background: #fff3cd; color: #856404; display: block; }
.api-badge.center  { text-align: center; }

/* ═══ SHEET SCREEN — TOOLBAR ══════════════════════════════ */
#sheet-screen { display: none; }

.toolbar {
  background: #1a1a1a;
  color: #fff;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}
.toolbar-title { font-size: 0.68rem; letter-spacing: 0.15em; text-transform: uppercase; opacity: 0.45; margin-right: auto; }

.btn-toolbar {
  font-family: 'Inter', sans-serif;
  font-size: 0.67rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.42rem 1rem;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.25);
  background: transparent;
  color: #fff;
  transition: all 0.15s;
}
.btn-toolbar:hover          { background: rgba(255,255,255,0.1); }
.btn-toolbar.primary        { background: #fff; color: #111; border-color: #fff; }
.btn-toolbar.primary:hover  { background: #ddd; }

.btn-back {
  font-size: 0.67rem;
  font-weight: 500;
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
  padding: 0.4rem 0;
  font-family: 'Inter', sans-serif;
}
.btn-back:hover { color: #fff; }

/* ═══ DOCUMENT AREA ═══════════════════════════════════════ */
.document-area {
  padding: 2.5rem 1.5rem 4rem;
  background: #d0d0d0;
  min-height: calc(100vh - 46px);
  display: flex;
  justify-content: center;
}

.document-sheet {
  background: #fff;
  width: 210mm;
  min-height: 297mm;
  padding: 14mm 15mm 18mm;
  box-shadow: 0 2px 14px rgba(0,0,0,0.28);
  font-family: Arial, sans-serif;
  font-size: 11pt;
  color: #000;
}

/* ═══ DOCUMENT HEADER ═════════════════════════════════════ */
.doc-header { border: 1.5px solid #000; margin-bottom: 0; }

.doc-header-row-top { display: flex; border-bottom: 1px solid #000; }
.doc-header-month   { flex: 1; padding: 4px 8px; border-right: 1px solid #000; font-size: 10.5pt; white-space: nowrap; }
.doc-header-hours   { flex: 1.6; padding: 4px 8px; font-size: 10.5pt; }

.doc-header-row-department { padding: 4px 8px; border-bottom: 1px solid #000; font-size: 10.5pt; min-height: 26px; }
.doc-header-row-name       { padding: 4px 8px; font-size: 10.5pt; min-height: 26px; }

.field-label { font-weight: 700; }
.field-value { font-weight: 400; }

/* ═══ TIMESHEET TABLE ═════════════════════════════════════ */
.timesheet-table {
  width: 100%;
  border-collapse: collapse;
  border: 1.5px solid #000;
  border-top: none;
  font-family: Arial, sans-serif;
  font-size: 10pt;
}
.timesheet-table thead th {
  font-weight: 700;
  font-size: 10pt;
  padding: 4px 4px;
  border: 1px solid #000;
  border-top: 1.5px solid #000;
  text-align: center;
  background: #fff;
}
.col-day     { width: 56px; }
.col-time    { width: 80px; }
.col-sig     { }
.col-absence { width: 115px; }

.timesheet-table tbody td {
  padding: 0;
  border-right: 1px solid #000;
  vertical-align: middle;
  height: 23px; 
}
.timesheet-table tbody td:last-child { border-right: none; }
.timesheet-table tbody tr            { border-bottom: 1px solid #000; }
.timesheet-table tbody tr:last-child { border-bottom: 1.5px solid #000; }

/* Day cell */
.day-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 22px;
  padding: 0 3px;
}
.day-num     { font-size: 10pt; font-weight: 700; min-width: 18px; text-align: center; }
.day-abbr    { font-size: 7.5pt; color: #555; text-transform: uppercase; }
.holiday-info { font-size: 6.5pt; font-style: italic; color: #555; margin-left: 1px; }

/* Row state — weekend / holiday */
tr.weekend { background: #e8e8e8; }
tr.holiday { background: #e8e8e8; }
tr.weekend .day-abbr,
tr.holiday .day-abbr { color: #444; }

/* Time inputs */
.time-input {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 9pt;
  color: #000;
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
  text-align: center;
  padding: 0 3px;
  height: 22px;
  cursor: text;
}

tr.weekend .time-input,
tr.holiday .time-input { cursor: default; color: #666; }

/* Hide the dashes (--:--) when the time field is empty*/
.time-input:invalid::-webkit-datetime-edit {
  color: transparent;
}

.time-input:invalid::-webkit-calendar-picker-indicator {
  visibility: hidden;
}

.time-input:focus::-webkit-datetime-edit {
  color: #000;
}

.time-input:focus::-webkit-calendar-picker-indicator {
  visibility: visible;
}

.time-input::-webkit-datetime-edit {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

@media print {
  .time-input::-webkit-calendar-picker-indicator {
    display: none !important;
  }
}

/* Signature cell */
.sig-td { text-align: center; vertical-align: middle; height: 22px; }

/* Row state — absent */
.absence-label { display: none; font-size: 8pt; font-weight: 700; letter-spacing: 0.04em; }
tr.absent .absence-label   { display: inline; }
tr.absent .time-input      { opacity: 0.25; pointer-events: none; }
tr.absent                  { background: #e8e8e8; }

/* Absence reason dropdown */
.absence-select {
  width: 96%;
  margin: 0 2%;
  font-family: 'Inter', Arial, sans-serif;
  font-size: 7.5pt;
  padding: 1px 2px;
  border: 1px solid #999;
  border-radius: 2px;
  background: #fff;
  outline: none;
  cursor: pointer;
  background: no-repeat; 
  background-position: 100%;
}

/* Totals row */
.totals-row { background: #efefef !important; }
.totals-row td {
  font-size: 8pt;
  font-family: Arial, sans-serif;
  padding: 5px 8px !important;
  height: auto !important;
  border-top: 1.5px solid #000;
  font-weight: 600;
}

/* ═══ DOCUMENT FOOTER ═════════════════════════════════════ */
.doc-footer { 
  margin-top: 25px; 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
} 
.signature-block { 
  width: 260px; 
  text-align: center; 
  margin-top: 70px; 
}
.signature-line  { border: none; border-bottom: 1.5px solid #000; margin-bottom: 6px; }
.signature-role  { font-size: 8.5pt; color: #444; text-transform: uppercase; letter-spacing: 0.1em; }
.generated-date  { font-size: 7pt; color: #999; margin-top: 16px; }

/* ═══ PRINT RULES ═════════════════════════════════════════ */

@page {
  size: A4;
  margin: 15mm 12mm 8mm 12mm; 
}

@media print {
  body { background: #fff !important; }
  .toolbar          { display: none !important; }
  #setup-screen     { display: none !important; }
  #sheet-screen     { display: block !important; }
  
  .document-area    { 
    padding: 0 !important; 
    margin: 0 !important;
    background: #fff !important; 
    display: block !important; 
    min-height: auto !important;
  }
  
  .document-sheet   { 
    box-shadow: none !important; 
    width: 100% !important; 
    padding: 0 !important; 
    margin: 0 !important;
    min-height: auto !important;
    transform: none !important; 
  }

  .col-absence,
  .timesheet-table thead th.col-absence { display: none !important; }
  .absence-select                       { display: none !important; }

  tr.weekend, tr.holiday, tr.absent, .totals-row {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/*Completely hides the schedule fields on weekends and on days off/holidays.*/
tr.weekend .time-input,
tr.absent .time-input {
  display: none;
}

/* ═══ RESPONSIVE — MOBILE ════════════════════════════════ */

@media screen and (max-width: 680px) {
  body {
    background: #fff;
  }

  /* — Setup screen — */
  #setup-screen {
    padding: 0;
    align-items: flex-start;
  }

  .setup-card {
    padding: 1.5rem 1.1rem 2rem;
    border: none;
    box-shadow: none;
    min-height: 100vh;
    border-radius: 0;
  }

  .setup-header h1   { font-size: 1.35rem; }
  .setup-header .tagline { font-size: 0.78rem; }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 0.9rem;
  }
  .form-field.full { grid-column: 1; }

  /* Month and Year side-by-side on mobile (they're short) */
  .form-grid > .form-field:nth-child(1),
  .form-grid > .form-field:nth-child(2) {
    display: inline-flex;
    width: calc(50% - 0.45rem);
  }
  .form-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.9rem;
  }
  .form-grid > .form-field { flex: 1 1 calc(50% - 0.45rem); }
  .form-grid > .form-field.full { flex: 1 1 100%; }

  .form-field input,
  .form-field select {
    font-size: 1rem;      /* prevents iOS auto-zoom on focus */
    padding: 0.6rem 0.7rem;
  }

  .time-range-row {
    grid-template-columns: 1fr auto 1fr;
    gap: 0.4rem;
  }

  .radio-group {
    flex-direction: column;
    gap: 0.65rem;
  }
  .radio-group label { font-size: 0.85rem; }

  .btn-generate {
    padding: 0.95rem 2rem;
    font-size: 0.8rem;
    /* tap-friendly height */
    min-height: 48px;
  }

  .autofill-section { padding: 0.8rem 0.9rem; }
  .autofill-section p { font-size: 0.82rem; }

  /* — Toolbar — */
  .toolbar {
    padding: 0.55rem 0.9rem;
    gap: 0.5rem;
  }

  .toolbar-title { display: none; }   /* hide verbose label on small screens */

  #toolbar-source-badge { display: none; }

  .btn-back  { font-size: 0.72rem; white-space: nowrap; }

  .btn-toolbar {
    font-size: 0.62rem;
    padding: 0.45rem 0.7rem;
    letter-spacing: 0.06em;
    white-space: nowrap;
  }

  /* — Document area — */
  .document-area {
    padding: 0.5rem 0 2rem; 
    overflow-x: hidden;
    display: flex;
    justify-content: center;
    -webkit-overflow-scrolling: touch;
    background: #fff;
  }

  .document-sheet {
    width: 740px; 
    min-height: auto;
    padding: 15px 4px 20px; 
    transform-origin: top center;
    transform: scale(calc(100vw / 740px)); 
    margin-bottom: -120%;   
    box-shadow: none;
  }

  .signature-block { 
    margin-top: 35px; 
  }
}

/* ═══ VERY SMALL SCREENS (< 380px) ══════════════════════ */
@media screen and (max-width: 380px) {
  .setup-card { padding: 1.2rem 0.9rem 1.8rem; }
  .setup-header h1 { font-size: 1.2rem; }
}
