/* =========================================================
   styles.css — Global styles for TSDCI QA/QC Punchlist
   ========================================================= */

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

:root {
  --bg: #f5f4f0;
  --surface: #fff;
  --surface2: #eeede9;
  --border: rgba(0,0,0,.10);
  --border2: rgba(0,0,0,.18);
  --text: #1a1917;
  --text2: #6b6860;
  --accent: #1d4ed8;
  --red: #b91c1c;
  --green: #166534;
  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1c1c1a;
    --surface2: #252523;
    --border: rgba(255,255,255,.08);
    --text: #f0efe9;
    --text2: #a09e99;
    --accent: #60a5fa;
    --red: #fca5a5;
    --green: #86efac;
  }
}

body {
  font-family: -apple-system, "SF Pro Text", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  font-size: 15px;
}
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; }
.safety-copy { color:var(--text2); font-size:13px; line-height:1.5; margin:0 0 16px; }
.danger-btn { background:var(--red); }

/* ── Gate / Login ── */
#gate {
  display: flex;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate-box {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 28px;
  padding: 28px 24px;
  box-shadow: 0 8px 20px rgba(0,0,0,.1);
}
.gate-logo { font-size: 48px; text-align: center; margin-bottom: 8px; }
.gate-title { font-size: 22px; font-weight: 700; text-align: center; }
.gate-sub { font-size: 13px; color: var(--text2); margin-bottom: 24px; text-align: center; }
.gate-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 13px;
  font-size: 16px;
  margin-bottom: 12px;
}
.gate-btn {
  width: 100%;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.gate-offline-btn {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border2);
  margin-top: 12px;
}
.divider {
  text-align: center;
  font-size: 12px;
  color: var(--text2);
  margin: 16px 0 12px;
  position: relative;
}
.divider::before, .divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border2);
}
.divider::before { left: 0; }
.divider::after  { right: 0; }

/* ── Top Bar ── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top, 0) 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 52px;
  gap: 8px;
}
.app-title { font-size: 18px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: #9ca3af; }
.sync-dot.online  { background: #22c55e; box-shadow: 0 0 4px #22c55e; }
.sync-dot.syncing { background: #f59e0b; animation: pulse 1s infinite; }
.sync-dot.error   { background: #ef4444; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
.topbar-btns { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 18px;
}

/* ── Stats row ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(62px, 1fr));
  gap: 8px;
  padding: 12px 16px;
}
.stat {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  border: 1px solid var(--border);
}
.stat-num { font-size: 22px; font-weight: 700; }
.stat-lbl { font-size: 10px; color: var(--text2); }
.stat-verification {
  border-color: #d97706;
  background: #fffbeb;
}
.stat-verification .stat-num { color: #92400e; }

@media (prefers-color-scheme: dark) {
  .stat-verification { background: #2b2112; border-color: #b45309; }
  .stat-verification .stat-num { color: #fbbf24; }
}

/* ── Filters ── */
.filters {
  padding: 8px 16px 10px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  align-items: center;
  position: sticky;
  top: calc(53px + env(safe-area-inset-top, 0px));
  z-index: 90;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.filter-chip {
  white-space: nowrap;
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--text2);
  cursor: pointer;
}
.filter-chip.active { background: var(--text); color: var(--bg); }
.select-actions { display: flex; gap: 8px; margin-left: auto; }
.select-btn {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}

/* ── List / Items ── */
.list { padding: 0 16px 80px; }
.item {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 10px;
  padding: 14px;
}
.item-row  { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.item-check { width: 24px; flex-shrink: 0; margin-top: 2px; }
.item-details { flex: 1; min-width: 0; }
.item-desc { font-weight: 600; word-break: break-word; }
.item-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-size: 12px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; }
.badge-gray     { background: var(--surface2); color: var(--text2); }
.badge-critical { background: #fef2f2; color: #b91c1c; }
.badge-high     { background: #fff7ed; color: #c2410c; }
.badge-medium   { background: #fffbeb; color: #92400e; }
.badge-low      { background: #f0fdf4; color: #166534; }
.badge-open     { background: #eff6ff; color: #1d4ed8; }
.badge-progress { background: #fffbeb; color: #92400e; }
.badge-closed   { background: #f0fdf4; color: #166534; }
.badge-void     { background: #eeede9; color: #6b6860; }
.date-info { font-size: 10px; color: var(--text2); margin-left: auto; }
.photo-thumb {
  width: 70px; height: 70px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border2);
  cursor: pointer;
}
.photo-strip { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.status-pri-select { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
select.small-select {
  padding: 4px 8px;
  border-radius: 16px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  font-size: 12px;
}
.upload-btn-small {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
}

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: 20px; right: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  border: none;
  font-size: 28px;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  cursor: pointer;
  z-index: 200;
}

/* ── Bottom Sheets ── */
.sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 300;
  opacity: 0;
  transition: opacity .25s;
}
.sheet-backdrop.open { display: block; opacity: 1; }
.sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 0 16px 24px;
  z-index: 400;
  transform: translateY(100%);
  transition: transform .3s;
  max-height: 92dvh;
  overflow-y: auto;
}
.sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--border2);
  border-radius: 2px;
  margin: 12px auto 16px;
}
.sheet-title { font-size: 18px; font-weight: 600; margin-bottom: 16px; }
.field { margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 500; color: var(--text2); display: block; margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 15px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.submit-btn {
  width: 100%;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-weight: 600;
  cursor: pointer;
}
.export-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  gap: 8px;
  justify-content: center;
}
.upload-progress { font-size: 12px; color: var(--text2); margin-top: 6px; display: none; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #166534;
  color: #fff;
  padding: 10px 20px;
  border-radius: 40px;
  font-size: 14px;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

/* ── PDF Preview Modal ── */
#preview-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 900;
  flex-direction: column;
}
#preview-modal.open { display: flex; }
.preview-header { background: var(--surface); padding: 16px; display: flex; justify-content: space-between; }
.preview-body { flex: 1; overflow: auto; padding: 20px; background: #525659; }
#pdf-content { background: #fff; width: 100%; max-width: 297mm; margin: 0 auto; }

/* ── PDF Page Styles ── */
.pdf-page {
  background: #fff;
  color: #000;
  padding: 6mm 12mm 8mm;
  font-family: Arial, sans-serif;
  page-break-after: always;
}
.pdf-header-logo { text-align: left; margin-bottom: 8px; border-bottom: 2px solid #333; padding-bottom: 6px; }
.pdf-logo-img { height: 50px; width: auto; }
.pdf-title { text-align: center; font-weight: bold; background: #eef2ff; padding: 4px; margin: 6px 0; font-size: 13px; }
.pdf-info-grid { display: flex; justify-content: space-between; font-size: 8.5px; border: 1px solid #ccc; padding: 5px; margin-bottom: 8px; }
.pdf-legend-table { width: 100%; border-collapse: collapse; font-size: 7.5px; margin: 6px 0; }
.pdf-legend-table td { padding: 3px; border: 1px solid #000; text-align: center; font-weight: bold; }
.pdf-table { width: 100%; border-collapse: collapse; font-size: 7.5px; table-layout: fixed; }
.pdf-table th, .pdf-table td { border: 1px solid #000; padding: 4px; vertical-align: top; }
.pdf-table th { background: #e5e7eb; }
.pdf-img { width: 100%; height: auto; max-height: 70px; object-fit: contain; }
.pdf-footer { text-align: center; font-size: 6.5px; border-top: 1px solid #ccc; padding-top: 5px; margin-top: 12px; }

/* ── Empty state ── */
.empty { text-align: center; padding: 40px; color: var(--text2); }
