/* ============================================================
   FLHA TOOL — STYLES
   Mobile-first. Tap targets min 48px. No horizontal scroll.
   ============================================================ */

/* --- Reset & Base ----------------------------------------- */

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

:root {
  --orange:       #FF6B00;
  --orange-dark:  #D95800;
  --orange-light: #FFF3E8;
  --navy:         #1A1A2E;
  --gray-100:     #F5F5F7;
  --gray-200:     #E8E8EC;
  --gray-400:     #ABABBA;
  --gray-600:     #6B6B80;
  --gray-900:     #1C1C28;
  --white:        #FFFFFF;
  --success:      #1A9E55;
  --success-bg:   #E8F7EF;
  --error:        #CC2020;
  --error-bg:     #FDECEA;
  --warn:         #D97706;
  --warn-bg:      #FFFBEB;
  --risk-low:     #1A9E55;
  --risk-medium:  #D97706;
  --risk-high:    #CC2020;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg:    0 4px 24px rgba(0,0,0,0.12);
  --transition:   0.18s ease;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
}

/* --- Screens ---------------------------------------------- */

.screen {
  min-height: 100vh;
}

.screen.hidden { display: none; }
.screen.active { display: block; }

/* --- Passcode Screen -------------------------------------- */

#passcode-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  padding: 24px 16px;
}

.passcode-card {
  background: var(--white);
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.brand-mark {
  margin-bottom: 32px;
}

.brand-icon {
  width: 56px;
  height: 56px;
  margin-bottom: 12px;
}

.brand-name {
  font-size: 2rem;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -0.5px;
}

.brand-sub {
  font-size: 0.85rem;
  color: var(--gray-600);
  margin-top: 4px;
  letter-spacing: 0.3px;
}

.passcode-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.passcode-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-900);
  text-align: left;
}

.passcode-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  text-align: center;
  letter-spacing: 0.05em;
  outline: none;
  transition: border-color var(--transition);
}

.passcode-input:focus {
  border-color: var(--orange);
}

/* --- Buttons ---------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  min-height: 48px;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--orange);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--orange-dark);
}

.btn-sending,
.btn-sending:hover {
  background: var(--gray-400);
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--white);
  color: var(--orange);
  border: 2px solid var(--orange);
}

.btn-secondary:hover {
  background: var(--orange-light);
}

.btn-ghost {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--gray-200);
  font-size: 0.85rem;
  padding: 8px 12px;
  min-height: 36px;
}

.btn-ghost:hover {
  background: var(--error-bg);
  border-color: var(--error);
}

.btn-full {
  width: 100%;
}

.btn-large {
  padding: 18px 24px;
  font-size: 1.05rem;
  min-height: 56px;
}

.btn-add {
  margin-top: 12px;
  font-size: 0.9rem;
  padding: 10px 16px;
  min-height: 44px;
}

/* --- App Header ------------------------------------------- */

.app-header {
  background: var(--navy);
  color: var(--white);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.5px;
  color: var(--orange);
}

.header-company {
  font-size: 0.8rem;
  color: var(--gray-400);
  text-align: right;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Queue Banner ----------------------------------------- */

.queue-banner {
  background: #FFFBEB;
  border-bottom: 2px solid var(--warn);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--warn);
}

.queue-retry-btn {
  background: var(--warn);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  min-height: 32px;
}

.queue-retry-btn:hover {
  opacity: 0.9;
}

/* --- Form Main -------------------------------------------- */

.form-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-900);
}

/* --- Cards ------------------------------------------------ */

.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--orange-light);
}

/* --- Field Groups ----------------------------------------- */

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 480px) {
  .field-grid {
    grid-template-columns: 1fr;
  }
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-group.full-width {
  grid-column: 1 / -1;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-600);
  letter-spacing: 0.2px;
}

.req {
  color: var(--error);
}

.optional {
  color: var(--gray-400);
  font-weight: 400;
  font-size: 0.8rem;
}

input[type="text"],
input[type="date"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  color: var(--gray-900);
  background: var(--white);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
  min-height: 48px;
}

input[type="text"]:focus,
input[type="date"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255, 107, 0, 0.12);
}

input.has-error,
select.has-error,
textarea.has-error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(204, 32, 32, 0.08);
}

textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B6B80' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  cursor: pointer;
}

.field-error {
  font-size: 0.8rem;
  color: var(--error);
  min-height: 1em;
  display: block;
}

.section-note {
  font-size: 0.85rem;
  color: var(--gray-600);
  margin-bottom: 16px;
  line-height: 1.6;
}

/* --- PPE Checklist ---------------------------------------- */

.ppe-group-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 10px;
}

.ppe-group-label--additional {
  margin-top: 18px;
}

.ppe-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ppe-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: 24px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-600);
  background: var(--white);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  min-height: 40px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.ppe-chip:hover {
  border-color: var(--orange);
  color: var(--orange);
}

.ppe-chip.checked {
  background: var(--orange);
  border-color: var(--orange);
  color: var(--white);
  font-weight: 600;
}

.ppe-chip.checked:hover {
  background: var(--orange-dark);
  border-color: var(--orange-dark);
  color: var(--white);
}

/* --- Task Rows -------------------------------------------- */

.task-row {
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
  background: var(--gray-100);
  position: relative;
}

.task-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
}

.task-row-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--orange);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.task-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.risk-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.risk-badge.Low    { background: #E8F7EF; color: var(--risk-low); }
.risk-badge.Medium { background: #FFFBEB; color: var(--risk-medium); }
.risk-badge.High   { background: #FDECEA; color: var(--risk-high); }

select.risk-select.Low    { border-color: var(--risk-low);    color: var(--risk-low);    font-weight: 600; }
select.risk-select.Medium { border-color: var(--risk-medium); color: var(--risk-medium); font-weight: 600; }
select.risk-select.High   { border-color: var(--risk-high);   color: var(--risk-high);   font-weight: 600; }

/* --- Worker Rows ------------------------------------------ */

.worker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.worker-row input {
  flex: 1;
}

.worker-num {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gray-400);
  min-width: 24px;
  text-align: right;
}

/* --- Error & Status ---------------------------------------- */

.error-inline {
  color: var(--error);
  font-size: 0.85rem;
  padding: 10px 14px;
  background: var(--error-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--error);
}

.error-banner {
  padding: 14px 16px;
  background: var(--error-bg);
  border: 1px solid var(--error);
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.hidden { display: none !important; }

/* --- Submit Area ------------------------------------------ */

.submit-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 4px;
}

/* --- Success Screen --------------------------------------- */

#success-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  padding: 24px 16px;
}

.success-card {
  background: var(--white);
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.success-icon {
  width: 72px;
  height: 72px;
  background: var(--success-bg);
  color: var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  margin: 0 auto;
}

.success-card h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gray-900);
}

.success-msg {
  color: var(--gray-600);
  font-size: 0.95rem;
}

.success-detail {
  font-size: 0.8rem;
  color: var(--gray-400);
  font-style: italic;
}

/* --- Loading Overlay -------------------------------------- */

#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(3px);
}

.loading-box {
  background: var(--white);
  border-radius: var(--radius);
  padding: 36px 40px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-lg);
}

.loading-box p {
  color: var(--gray-600);
  font-size: 0.9rem;
  font-weight: 500;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Utility ---------------------------------------------- */

@media (min-width: 600px) {
  .form-main {
    padding: 32px 24px 64px;
  }
  .card {
    padding: 28px 28px;
  }
}
