/* ------ Design tokens ------ */
:root {
  --brand-vpg: #1e3a8a;      /* deep blue */
  --brand-vpg-accent: #f59e0b;
  --brand-vdc: #b91c1c;      /* red */
  --brand-vdc-accent: #fbbf24;
  --brand-hwc: #0f766e;      /* teal */
  --brand-hwc-accent: #84cc16;

  --brand: var(--brand-vpg);
  --brand-accent: var(--brand-vpg-accent);

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --border: #e4e7ec;
  --border-strong: #cfd4dc;
  --text: #0f172a;
  --text-2: #475467;
  --muted: #98a2b3;
  --danger: #b42318;
  --success: #067647;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,0.06);
  --shadow: 0 4px 12px rgba(16,24,40,0.08);

  --tap: 44px;
}

body[data-brand="VDC"] { --brand: var(--brand-vdc); --brand-accent: var(--brand-vdc-accent); }
body[data-brand="HWC"] { --brand: var(--brand-hwc); --brand-accent: var(--brand-hwc-accent); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 20px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.hint { color: var(--text-2); font-size: 13px; margin: 0 0 12px; }
.eyebrow { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

/* ------ Header ------ */
.app-header {
  background: linear-gradient(180deg, var(--brand) 0%, color-mix(in srgb, var(--brand) 85%, black) 100%);
  color: white;
  padding: max(env(safe-area-inset-top), 12px) 16px 12px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.brand-switcher {
  display: flex; gap: 6px; margin-bottom: 10px;
}
.brand-btn {
  flex: 1;
  min-height: 36px;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.1);
  color: white;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.05em;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.brand-btn.active { background: white; color: var(--brand); border-color: white; }
.brand-btn:active { transform: scale(0.98); }
.header-title { display: flex; flex-direction: column; gap: 2px; }
.header-title .eyebrow { color: rgba(255,255,255,0.8); }
.sync-status {
  position: absolute; top: max(env(safe-area-inset-top), 12px); right: 16px;
  display: flex; align-items: center; gap: 6px; font-size: 11px; color: rgba(255,255,255,0.85);
}
.sync-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 0 2px rgba(52,211,153,0.25); }
.sync-status.offline .dot { background: #f59e0b; box-shadow: 0 0 0 2px rgba(245,158,11,0.25); }

/* ------ Main ------ */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

/* ------ Stepper ------ */
.stepper {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 2px 12px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.stepper::-webkit-scrollbar { display: none; }
.step {
  scroll-snap-align: start;
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.step span {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--border); color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px;
}
.step.active { background: var(--brand); color: white; border-color: var(--brand); }
.step.active span { background: rgba(255,255,255,0.25); color: white; }
.step.done { border-color: var(--brand); color: var(--brand); }
.step.done span { background: var(--brand); color: white; }

/* ------ Panels ------ */
.step-panel { display: none; }
.step-panel.active { display: block; animation: fade 0.15s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ------ Cards & fields ------ */
.card, fieldset.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
fieldset.card { margin-top: 0; }
fieldset.card legend {
  padding: 0 6px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--text-2);
}
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field:last-child { margin-bottom: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field input, .field select, .field textarea,
.mat-line input, .mat-grid input, .mat-grid select,
.labor-head input, .labor-head select,
.day-grid input, .rate-grid input {
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 16px; /* iOS zoom fix */
  font-family: inherit;
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus,
.mat-grid input:focus, .mat-grid select:focus,
.day-grid input:focus, .rate-grid input:focus,
.labor-head input:focus, .labor-head select:focus,
.mat-line input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent);
  background: white;
}
.field textarea { min-height: 120px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* ------ Chips ------ */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 36px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip.active { background: var(--brand); color: white; border-color: var(--brand); }
.chip:active { transform: scale(0.98); }

/* ------ Buttons ------ */
.btn {
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.05s, background 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--brand); color: white; box-shadow: var(--shadow-sm); }
.btn.primary:hover { box-shadow: var(--shadow); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.ghost { background: transparent; color: var(--text-2); border-color: transparent; }
.btn.tiny { min-height: 32px; padding: 4px 10px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: var(--border); background: var(--surface); }
.btn.full { width: 100%; }
.btn.big { min-height: 52px; font-size: 16px; }
.step-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }
.step-nav.submit-row { margin-top: 20px; }
.step-nav .btn { flex: 1; }
.step-nav .btn.ghost { flex: 0 0 auto; }

/* ------ Labor rows ------ */
.labor-row { padding: 12px; }
.labor-head {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto auto;
  gap: 6px; margin-bottom: 10px;
  align-items: center;
}
.pw-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  cursor: pointer;
  background: var(--surface-2);
  height: 44px;
  white-space: nowrap;
}
.pw-toggle input {
  width: 16px; height: 16px; accent-color: var(--brand);
}
.day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.day-grid label { display: flex; flex-direction: column; gap: 2px; }
.day-grid label > span { font-size: 10px; font-weight: 700; text-align: center; color: var(--muted); text-transform: uppercase; }
.day-grid input { text-align: center; padding: 8px 4px; font-size: 15px; }

.rate-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.rate-grid label { display: flex; flex-direction: column; gap: 2px; }
.rate-grid label > span { font-size: 10px; font-weight: 700; text-align: center; color: var(--muted); text-transform: uppercase; }
.rate-grid input { text-align: center; padding: 8px 4px; font-size: 15px; }
.rate-grid .row-total output {
  min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-weight: 700;
  color: var(--brand);
}

/* ------ Materials ------ */
.material-row { padding: 12px; }
.mat-line { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 10px; align-items: center; }
.mat-grid { display: grid; grid-template-columns: 1fr 1fr 1fr 1.2fr; gap: 6px; }
.mat-grid label { display: flex; flex-direction: column; gap: 2px; }
.mat-grid label > span { font-size: 10px; font-weight: 700; text-align: center; color: var(--muted); text-transform: uppercase; }
.mat-grid input, .mat-grid select { text-align: center; padding: 8px 4px; font-size: 15px; }
.mat-grid .row-total output {
  min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-weight: 700;
  color: var(--brand);
}

/* ------ Totals ------ */
.totals { padding: 14px; }
.totals-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0;
  font-size: 14px;
  color: var(--text-2);
  border-bottom: 1px dashed var(--border);
}
.totals-row:last-child { border-bottom: none; }
.totals-row strong { color: var(--text); font-size: 16px; }
.totals-row.grand { font-size: 15px; font-weight: 700; color: var(--text); padding-top: 12px; }
.totals-row.grand strong { color: var(--brand); font-size: 20px; }

/* ------ Photos ------ */
.photo-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.photo-slot {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
}
.photo-slot label {
  display: block;
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 6px;
}
.photo-slot input[type="file"] {
  font-size: 12px;
  width: 100%;
}
.photo-preview, .photo-grid img {
  margin-top: 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.photo-preview img, .photo-grid img { width: 100%; height: auto; display: block; border-radius: var(--radius-sm); }
.photo-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 6px;
}

/* ------ Signatures ------ */
.sig-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.sig-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sig-header label { font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-2); }
.sig-pad {
  width: 100%;
  height: 180px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  touch-action: none;
  display: block;
  margin-bottom: 10px;
}
.check-inline { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 14px; }
.check-inline input { width: 20px; height: 20px; }

/* ------ Modal ------ */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, 0.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 720px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  margin: 20px auto;
}
.modal-header, .modal-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-footer {
  border-bottom: none; border-top: 1px solid var(--border);
  gap: 8px;
}
.modal-footer .btn { flex: 1; }
.modal-header h2 { margin: 0; }
.preview-body {
  padding: 16px;
  max-height: 60vh;
  overflow-y: auto;
  font-size: 14px;
  color: var(--text);
}
.preview-body h3 { margin: 16px 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--brand); }
.preview-body h3:first-child { margin-top: 0; }
.preview-body table { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 12px; }
.preview-body th, .preview-body td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.preview-body th { background: var(--surface-2); font-weight: 700; }

/* ------ Toast ------ */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #0f172a; color: white;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ------ Narrow phones ------ */
@media (max-width: 480px) {
  h1 { font-size: 18px; }
  .app { padding: 12px; }
  .card, fieldset.card { padding: 12px; }
  .day-grid input, .rate-grid input, .mat-grid input, .mat-grid select { font-size: 14px; padding: 8px 2px; }
  .day-grid label > span, .rate-grid label > span, .mat-grid label > span { font-size: 9px; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-3 .field:last-child { grid-column: span 2; }
  .photo-group { grid-template-columns: 1fr; }
  .labor-head {
    grid-template-columns: 1fr 1fr auto;
    grid-template-areas:
      "name name name"
      "class pw remove";
    gap: 6px;
  }
  .labor-head .emp-name { grid-area: name; }
  .labor-head .emp-class { grid-area: class; }
  .labor-head .pw-toggle { grid-area: pw; }
  .labor-head .remove-row { grid-area: remove; }
}

/* ---- Legal footer ---- */
.legal-footer {
  margin-top: 32px;
  padding: 20px 16px 28px;
  background: #f5f6f8;
  border-top: 1px solid #e4e7ec;
  color: #667085;
  font-size: 11px;
  line-height: 1.6;
  text-align: center;
}
.legal-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  justify-content: center;
  align-items: center;
}
.legal-footer .sep {
  color: #cfd4dc;
}
.legal-footer .legal-link {
  color: #475467;
  text-decoration: underline;
  text-decoration-color: #cfd4dc;
  text-underline-offset: 3px;
}
.legal-footer .legal-link:hover {
  color: #1e3a8a;
}
.legal-footer .brand-line {
  font-weight: 500;
  color: #475467;
}
@media (max-width: 480px) {
  .legal-footer .brand-line {
    width: 100%;
    margin-top: 4px;
  }
  .legal-footer .sep:last-of-type {
    display: none;
  }
}

/* ---- New-version update banner ---- */
.update-banner {
  position: sticky;
  top: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: #0b2a5b;
  color: #ffffff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  animation: banner-slide 0.3s ease-out;
}
.update-banner .update-text {
  flex: 1;
  min-width: 0;
}
.update-banner .update-btn {
  flex-shrink: 0;
  background: #f59e0b;
  color: #0b2a5b;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  min-height: 32px;
}
.update-banner .update-btn:hover,
.update-banner .update-btn:active {
  background: #d97706;
  color: #ffffff;
}
@keyframes banner-slide {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}

/* ---- Version tag in header ---- */
.version-tag {
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 10px;
  font-weight: 500;
  color: rgba(255,255,255,0.55);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
  pointer-events: none;
  user-select: none;
}
.app-header { position: relative; }
