/* FacilityLog — same base theme as ChurchDirectory */

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #1a5276;
  --primary-dark:  #154360;
  --primary-light: #d6eaf8;
  --accent:        #2980b9;
  --text:          #1a1a2e;
  --text-sub:      #5d6d7e;
  --bg:            #f4f6f9;
  --surface:       #ffffff;
  --border:        #dce3ea;
  --red:           #c0392b;
  --red-light:     #fadbd8;
  --green:         #27ae60;
  --green-light:   #d5f5e3;
  --orange:        #e67e22;
  --orange-light:  #fdebd0;
  --header-height: 56px;
  --nav-height:    60px;
}

/* ── Dark Theme ───────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --primary:       #2e86c1;
  --primary-dark:  #1a5276;
  --primary-light: #1a2a3a;
  --accent:        #5dade2;
  --text:          #e8eaf0;
  --text-sub:      #8fa3b1;
  --bg:            #0f1923;
  --surface:       #1a2530;
  --border:        #2c3e50;
  --red:           #e74c3c;
  --red-light:     #2c1a1a;
  --green:         #2ecc71;
  --green-light:   #1a2c1a;
  --orange:        #e67e22;
  --orange-light:  #2c1f0f;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── App Shell ────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: 0 0 20px rgba(0,0,0,0.08);
  padding-top: env(safe-area-inset-top);
}

#app.hidden { display: none; }
.hidden { display: none !important; }

/* ── Header ───────────────────────────────────────────────────────────────── */
#app-header {
  height: var(--header-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--primary);
  color: white;
}

.header-title {
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.header-link {
  background: none;
  border: none;
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ── Main Content ─────────────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* ── Bottom Nav ───────────────────────────────────────────────────────────── */
#bottom-nav {
  flex-shrink: 0;
  display: flex;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-sub);
  font-size: 11px;
  font-weight: 500;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.nav-item.active { color: var(--primary); }

.nav-icon { font-size: 20px; line-height: 1; }
.nav-label { font-size: 10px; font-weight: 600; }

.nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 20px);
  background: var(--red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── Section Header ───────────────────────────────────────────────────────── */
.section-header {
  padding: 20px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.add-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.add-btn:active { opacity: 0.8; }

/* ── Checklist Template Cards ─────────────────────────────────────────────── */
.template-list { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; }

.template-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.template-card:active { background: var(--primary-light); border-color: var(--primary); }

.template-info { flex: 1; }

.template-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}

.template-type {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-sub);
}

.template-arrow {
  font-size: 20px;
  color: var(--text-sub);
  margin-left: 8px;
}

/* ── Active Run ───────────────────────────────────────────────────────────── */
.run-header {
  background: var(--primary);
  color: white;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.back-btn:active { background: rgba(255,255,255,0.35); }

.run-title { flex: 1; }
.run-name { font-size: 16px; font-weight: 700; }
.run-progress { font-size: 13px; opacity: 0.85; margin-top: 2px; }

.run-items { padding: 8px 0 100px; }

.checklist-category-heading {
  padding: 12px 16px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-sub);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.run-item {
  display: flex;
  align-items: center;
  min-height: 64px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 14px;
  -webkit-tap-highlight-color: transparent;
}

.run-item.checked { background: var(--green-light); }
.run-item.flagged-item { background: var(--orange-light); }

.check-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  background: white;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.check-btn.checked {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.run-item-label {
  flex: 1;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
}

.run-item.checked .run-item-label {
  color: var(--text-sub);
  text-decoration: line-through;
}

.flag-indicator {
  font-size: 12px;
  font-weight: 600;
  color: var(--orange);
  background: var(--orange-light);
  border: 1px solid var(--orange);
  border-radius: 6px;
  padding: 2px 6px;
  white-space: nowrap;
}

.flag-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: white;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

.flag-btn.flagged {
  background: var(--orange-light);
  border-color: var(--orange);
}

.run-complete-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.complete-btn {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

.complete-btn:disabled { opacity: 0.45; }
.complete-btn:active:not(:disabled) { opacity: 0.8; }

/* ── Issue List ───────────────────────────────────────────────────────────── */
.issue-list { padding: 0 0 16px; }

.issue-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.issue-item:active { background: var(--bg); }

.issue-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.issue-desc {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  line-height: 1.3;
}

.issue-status {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.status-open     { background: var(--red-light);    color: var(--red); }
.status-resolved { background: var(--green-light);  color: var(--green); }

.issue-meta {
  font-size: 12px;
  color: var(--text-sub);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.issue-asset-tag {
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 4px;
  padding: 1px 6px;
  font-weight: 600;
}

/* ── Asset List ───────────────────────────────────────────────────────────── */
.asset-list { padding: 0 0 16px; }

.asset-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
}

.asset-item:active { background: var(--bg); }

.asset-name { font-size: 16px; font-weight: 600; color: var(--text); }
.asset-meta { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.asset-arrow { font-size: 18px; color: var(--border); }

/* ── Detail View ─────────────────────────────────────────────────────────── */
.detail-header {
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.detail-title { flex: 1; font-size: 17px; font-weight: 700; }

.detail-body { padding: 16px 16px 120px; }

.detail-section { margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.detail-section:last-child { border-bottom: none; }

.detail-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-sub);
  margin-bottom: 6px;
}

.detail-value { font-size: 15px; color: var(--text); line-height: 1.5; }

.contact-card {
  background: var(--bg);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.contact-company { font-size: 15px; font-weight: 600; color: var(--text); }
.contact-tech    { font-size: 13px; color: var(--text-sub); margin-top: 2px; }
.contact-links   { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.contact-link    { font-size: 13px; font-weight: 600; color: var(--accent); text-decoration: none; }

.action-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.action-btn {
  flex: 1;
  padding: 12px 4px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.action-btn:active { opacity: 0.75; }
.action-primary  { background: var(--primary); color: white; }
.action-danger   { background: var(--red);     color: white; }
.action-success  { background: var(--green);   color: white; }

/* ── Settings ─────────────────────────────────────────────────────────────── */
.settings-section { padding: 0 16px 20px; }
.settings-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-sub);
  padding: 16px 0 8px;
}

.contact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.contact-info .contact-name  { font-size: 15px; font-weight: 600; }
.contact-info .contact-email { font-size: 13px; color: var(--text-sub); }
.contact-role-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--primary-light);
  color: var(--primary);
  padding: 3px 8px;
  border-radius: 6px;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.edit-field { margin-bottom: 14px; }

.edit-field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-sub);
  margin-bottom: 4px;
}

.edit-field input,
.edit-field select,
.edit-field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
}

.edit-field input:focus,
.edit-field select:focus,
.edit-field textarea:focus { border-color: var(--primary); }

.save-btn {
  width: 100%;
  padding: 13px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}

.save-btn:disabled { opacity: 0.5; }

.save-status { font-size: 13px; margin-top: 8px; text-align: center; }
.save-status.success { color: var(--green); }
.save-status.error   { color: var(--red); }

/* ── Bottom Sheets ────────────────────────────────────────────────────────── */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.sheet-content {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  background: white;
  border-radius: 20px 20px 0 0;
  padding: 12px 20px 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.sheet-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.sheet-subtitle {
  font-size: 14px;
  color: var(--text-sub);
  margin-bottom: 16px;
}

.flag-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  resize: none;
  -webkit-appearance: none;
}

.flag-textarea:focus { border-color: var(--primary); }

.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }

.sheet-btn {
  flex: 1;
  padding: 13px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sheet-btn-cancel  { background: var(--bg); color: var(--text-sub); }
.sheet-btn-confirm { background: var(--orange); color: white; }

/* ── Empty States ─────────────────────────────────────────────────────────── */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-sub);
  font-size: 15px;
  line-height: 1.6;
}

/* ── Login Screen ─────────────────────────────────────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}

#login-screen.hidden { display: none; }

.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 28px 36px;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 4px 32px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.login-title    { font-size: 26px; font-weight: 700; color: var(--primary); }
.login-subtitle { font-size: 14px; color: var(--text-sub); margin: 0 0 12px; }

.login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 13px 16px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── Scan Modal ────────────────────────────────────────────────────────────── */
.scan-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.88);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.scan-modal {
  width: 100%;
  max-width: 440px;
  padding-top: 8px;
}

.scan-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  color: #fff;
  font-weight: 700;
  font-size: 17px;
}

.scan-close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.scan-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
}

.scan-viewport video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-indicator {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 20px;
  white-space: nowrap;
  pointer-events: none;
}

.scan-result {
  background: #1a1a2e;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  color: #fff;
}

.scan-result.hidden { display: none; }

.scan-result-label {
  font-size: 11px;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}

.scan-result-value {
  font-size: 16px;
  font-weight: 700;
  word-break: break-all;
}

.scan-field-label {
  display: block;
  font-size: 11px;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
}

.scan-field-input {
  width: 100%;
  background: #2d2d40;
  border: 1px solid #444;
  border-radius: 7px;
  padding: 8px 10px;
  color: #fff;
  font-size: 14px;
}

.scan-apply-btn {
  width: 100%;
  background: #2f9e44;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.scan-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scan-ai-btn {
  background: #1971c2;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.scan-ai-btn:disabled { opacity: .6; }

.scan-cancel-btn {
  background: rgba(255,255,255,.1);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  cursor: pointer;
}

/* ── Asset Photos ──────────────────────────────────────────────────────────── */
.asset-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 4px;
}

.asset-photo-thumb {
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
  cursor: pointer;
  position: relative;
}

.asset-photo-thumb img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.asset-photo-label {
  font-size: 10px;
  color: var(--text-sub);
  padding: 3px 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--surface);
}

/* ── Asset Category Browse ─────────────────────────────────────────────────── */
.asset-view-toggle {
  display: flex;
  background: var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.asset-view-btn {
  background: none;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  cursor: pointer;
  white-space: nowrap;
}

.asset-view-btn.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

.category-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--primary);
  background: var(--primary-light);
  border-bottom: 1px solid var(--border);
  margin-top: 4px;
}

.category-heading:first-child { margin-top: 0; }

.category-count {
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}
