/* ============================================================
   DRAIN VISION LTD — H&S APP STYLES
   Mobile-first, touch-friendly
   ============================================================ */

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

:root {
  --blue:       #1a3a5c;
  --blue-light: #2563a8;
  --orange:     #f59e0b;
  --orange-dark:#d97706;
  --green:      #16a34a;
  --red:        #dc2626;
  --amber:      #ca8a04;
  --bg:         #f1f5f9;
  --card:       #ffffff;
  --text:       #1e293b;
  --muted:      #64748b;
  --border:     #e2e8f0;
  --pass:       #dcfce7;
  --fail:       #fee2e2;
  --na:         #f1f5f9;
  --radius:     12px;
  --shadow:     0 2px 8px rgba(0,0,0,0.08);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 80px;
}

/* ---- HEADER ---- */
.app-header {
  background: var(--blue);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.app-header .logo { font-size: 22px; }
.app-header h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.app-header .subtitle { font-size: 12px; opacity: 0.7; margin-top: 1px; }
.back-btn {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px 4px 0;
  display: none;
  line-height: 1;
}
.back-btn.visible { display: block; }

/* ---- VIEWS ---- */
.view { display: none; padding: 20px; max-width: 600px; margin: 0 auto; }
.view.active { display: block; }

/* ---- HOME ---- */
.home-welcome {
  background: var(--blue);
  color: white;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.home-welcome h2 { font-size: 20px; margin-bottom: 4px; }
.home-welcome p  { font-size: 14px; opacity: 0.8; }

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}
.action-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  border: 2px solid transparent;
  box-shadow: var(--shadow);
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.action-card:active { transform: scale(0.97); }
.action-card.primary { border-color: var(--blue); }
.action-card.secondary { border-color: var(--orange); }
.action-card .icon { font-size: 36px; margin-bottom: 8px; }
.action-card h3 { font-size: 15px; font-weight: 700; color: var(--blue); margin-bottom: 4px; }
.action-card p  { font-size: 12px; color: var(--muted); }
.action-card-full {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 20px;
  cursor: pointer;
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s ease;
}
.action-card-full:active { transform: scale(0.98); }
.action-card-full .icon { font-size: 28px; }
.action-card-full h3 { font-size: 15px; font-weight: 700; color: var(--blue); }
.action-card-full p  { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- CARDS ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 15px; font-weight: 700; color: var(--blue); margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }

/* ---- FORM ELEMENTS ---- */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-group label .required { color: var(--red); margin-left: 3px; }

input[type="text"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 16px; /* prevents zoom on iOS */
  color: var(--text);
  background: white;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue-light);
}
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 fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}
textarea { resize: vertical; min-height: 80px; }

/* ---- STEP INDICATOR ---- */
.step-indicator {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  align-items: center;
}
.step-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.2s;
}
.step-dot.active  { background: var(--blue); }
.step-dot.done    { background: var(--green); }
.step-label {
  font-size: 13px;
  color: var(--muted);
  margin-left: 4px;
}

/* ---- TASK CHECKBOXES ---- */
.task-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.task-chip {
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.task-chip.selected {
  border-color: var(--blue);
  background: #eff6ff;
  color: var(--blue);
  font-weight: 700;
}

/* ---- HAZARD ITEMS ---- */
.hazard-item {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fafafa;
}
.hazard-item.selected { border-color: var(--orange); background: #fffbeb; }
.hazard-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}
.hazard-check { width: 22px; height: 22px; flex-shrink: 0; margin-top: 1px; }
.hazard-title { font-size: 14px; font-weight: 600; }
.hazard-detail { font-size: 12px; color: var(--muted); margin-top: 3px; }
.hazard-who { font-size: 12px; color: var(--blue-light); margin-top: 2px; }

/* ---- RISK ASSESSMENT ---- */
.risk-block {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.risk-block h4 { font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.risk-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.risk-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  color: white;
  margin-top: 6px;
}
.controls-list { margin-top: 8px; }
.control-chip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border: 2px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 13px;
  -webkit-tap-highlight-color: transparent;
}
.control-chip.selected { border-color: var(--green); background: #f0fdf4; }
.control-chip input[type="checkbox"] { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }

/* ---- PRESTART CHECKLIST ---- */
.checklist-section { margin-bottom: 16px; }
.checklist-section h4 {
  font-size: 14px;
  font-weight: 700;
  color: var(--blue);
  padding: 8px 12px;
  background: #eff6ff;
  border-radius: 6px;
  margin-bottom: 8px;
}
.checklist-item {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: white;
}
.checklist-item:last-child { border-bottom: none; border-radius: 0 0 8px 8px; }
.checklist-item:first-of-type { border-radius: 8px 8px 0 0; }
.checklist-item-label { flex: 1; font-size: 13px; padding-right: 8px; line-height: 1.4; }
.checklist-btns { display: flex; gap: 4px; flex-shrink: 0; }
.check-btn {
  width: 42px; height: 36px;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  background: white;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.check-btn.pass.active  { background: var(--pass);  border-color: var(--green); color: var(--green); }
.check-btn.fail.active  { background: var(--fail);  border-color: var(--red);   color: var(--red); }
.check-btn.na.active    { background: var(--na);    border-color: var(--muted); color: var(--muted); }
.item-comment { display: none; width: 100%; margin-top: 8px; }
.item-comment.visible { display: block; }
.checklist-item-wrap { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 6px; }
.item-comment-row { padding: 0 12px 10px; background: white; }

/* ---- SIGNATURE PAD ---- */
.sig-wrap {
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: white;
  position: relative;
}
.sig-canvas { display: block; width: 100%; touch-action: none; }
.sig-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--border);
  font-size: 14px;
  pointer-events: none;
  transition: opacity 0.2s;
}
.sig-label.hidden { opacity: 0; }
.sig-clear {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 0;
  text-decoration: underline;
}

/* ---- BUTTONS ---- */
.btn {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn-primary   { background: var(--blue);   color: white; }
.btn-secondary { background: var(--orange); color: white; }
.btn-outline   { background: white; color: var(--blue); border: 2px solid var(--blue); }
.btn-danger    { background: var(--red);    color: white; }
.btn-sm {
  display: inline-block;
  width: auto;
  padding: 8px 16px;
  font-size: 14px;
}
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row .btn { flex: 1; }

/* ---- QR CODES PAGE ---- */
.qr-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.qr-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.qr-card canvas { max-width: 100%; }
.qr-card h4 { font-size: 14px; font-weight: 700; margin-top: 8px; color: var(--blue); }
.qr-card p  { font-size: 12px; color: var(--muted); }

/* ---- TOOLBOX TALK ---- */
.toolbox-header {
  background: var(--blue);
  color: white;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.toolbox-header h2 { font-size: 18px; }
.toolbox-header p  { font-size: 13px; opacity: 0.8; margin-top: 4px; }
.topic-section {
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 14px;
}
.topic-header {
  background: #f8fafc;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 14px;
  color: var(--blue);
  border-bottom: 2px solid var(--border);
}
.topic-content { padding: 14px 16px; background: white; }
.topic-point {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.5;
}
.topic-point:last-child { border-bottom: none; }
.topic-point .bullet { color: var(--orange); font-weight: 700; flex-shrink: 0; }
.attendance-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.attendance-row:last-child { border-bottom: none; }
.attendance-name { flex: 1; font-size: 14px; font-weight: 600; }
.attend-check {
  width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: white;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.attend-check.checked { background: var(--green); border-color: var(--green); color: white; }
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.week-nav button {
  background: none;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 18px;
  cursor: pointer;
  color: var(--blue);
}
.week-label { font-size: 15px; font-weight: 700; color: var(--blue); }

/* ---- STATUS MESSAGES ---- */
.status-msg {
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  display: none;
}
.status-msg.success { background: #dcfce7; color: #15803d; display: block; }
.status-msg.error   { background: #fee2e2; color: #dc2626; display: block; }
.status-msg.info    { background: #dbeafe; color: #1d4ed8; display: block; }

/* ---- OFFLINE BADGE ---- */
.offline-badge {
  background: var(--amber);
  color: white;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  margin-left: auto;
  display: none;
}
.offline-badge.visible { display: block; }

/* ---- SETTINGS / ADMIN ---- */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.settings-row:last-child { border-bottom: none; }
.settings-row label { font-weight: 600; }
.settings-row input {
  width: 200px;
  padding: 8px 10px;
  font-size: 14px;
}

/* ---- MISC ---- */
.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.text-muted { color: var(--muted); font-size: 13px; }
.add-custom-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--blue-light);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 10px 0;
  background: none;
  border: none;
  -webkit-tap-highlight-color: transparent;
}
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 380px) {
  .action-grid { grid-template-columns: 1fr; }
  .qr-grid { grid-template-columns: 1fr; }
  .task-grid { grid-template-columns: 1fr; }
}

@media print {
  .app-header, .btn, .back-btn { display: none !important; }
  body { padding: 0; background: white; }
  .qr-grid { grid-template-columns: repeat(3, 1fr); }
}
