/* Site Inspection App - base styles (mobile-first) */

:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* Top nav */
.topbar { background: #fff; border-bottom: 1px solid var(--gray-200); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--gray-800); }
.brand:hover { text-decoration: none; }
.nav-toggle { display: none; background: none; border: none; font-size: 1.4rem; cursor: pointer; margin-left: auto; }
#mainNav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-left: auto; }
#mainNav a { color: var(--gray-600); font-weight: 500; }
#mainNav a:hover { color: var(--blue); text-decoration: none; }
.nav-user { color: var(--gray-400); font-size: .9rem; }

@media (max-width: 720px) {
  .nav-toggle { display: block; }
  #mainNav { display: none; width: 100%; flex-direction: column; align-items: flex-start; gap: 10px; margin-top: 10px; }
  #mainNav.open { display: flex; }
}

/* Page structure */
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin: 8px 0 20px; }
.page-head h1 { margin: 0; font-size: 1.5rem; }
.page-head > div { display: flex; gap: 8px; flex-wrap: wrap; }

h2 { font-size: 1.15rem; margin-top: 28px; }
h3 { font-size: 1.05rem; }
.muted { color: var(--gray-400); }

/* Flash messages */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: .95rem; }
.flash-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* Buttons */
.btn {
  display: inline-block; padding: 9px 16px; border-radius: var(--radius);
  background: #fff; border: 1px solid var(--gray-200); color: var(--gray-800);
  cursor: pointer; font-size: .95rem; font-weight: 500; text-align: center;
}
.btn:hover { background: var(--gray-100); text-decoration: none; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-block { width: 100%; }

.link-btn { background: none; border: none; padding: 0; color: var(--blue); cursor: pointer; font: inherit; }
.link-btn:hover { text-decoration: underline; }
.link-danger { color: var(--red); }
.inline-form { display: inline; }

.action-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* Cards / forms */
.form-card, .login-card {
  background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 20px; max-width: 620px;
}
.form-card label, .login-card label {
  display: block; margin-bottom: 14px; font-weight: 600; font-size: .9rem; color: var(--gray-600);
}
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.checkbox-label input { width: auto; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=datetime-local], input[type=number], select, textarea {
  width: 100%; padding: 9px 10px; margin-top: 5px; border: 1px solid var(--gray-200);
  border-radius: var(--radius); font-size: 1rem; font-family: inherit; background: #fff;
}
textarea { resize: vertical; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > label { flex: 1 1 180px; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-num { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--gray-400); font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; }
.stat-warn .stat-num { color: var(--amber); }

/* Tables */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 560px; }
.data-table th, .data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--gray-100); white-space: nowrap; }
.data-table th { color: var(--gray-400); font-weight: 600; font-size: .8rem; text-transform: uppercase; }
.data-table tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 10px; }

.detail-table { border-collapse: collapse; margin-bottom: 20px; }
.detail-table th { text-align: left; padding: 6px 16px 6px 0; color: var(--gray-400); font-weight: 600; vertical-align: top; white-space: nowrap; }
.detail-table td { padding: 6px 0; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-pass { background: #ecfdf5; color: #047857; }
.badge-fail { background: #fef2f2; color: #b91c1c; }
.badge-followup { background: #fffbeb; color: #b45309; }
.badge-low { background: #f1f5f9; color: #475569; }
.badge-medium { background: #fffbeb; color: #b45309; }
.badge-high { background: #fff1f2; color: #be123c; }
.badge-critical { background: #450a0a; color: #fff; }

/* Filter bar */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.filter-bar select, .filter-bar input { padding: 8px 10px; border: 1px solid var(--gray-200); border-radius: var(--radius); font-size: .9rem; }

/* Photos */
.photo-block { margin: 18px 0; }
.block-label { display: block; font-weight: 600; font-size: .9rem; color: var(--gray-600); margin-bottom: 8px; }
.photo-actions { display: flex; gap: 10px; margin-bottom: 12px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; margin-bottom: 10px; }
.photo-thumb { position: relative; display: block; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--gray-200); aspect-ratio: 1; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-remove {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; border: none; font-size: 1rem; line-height: 1; cursor: pointer;
}
.gps-block { display: flex; align-items: center; gap: 12px; margin: 16px 0; flex-wrap: wrap; }

/* Photo lightbox (inspection_view.php) */
.lightbox-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.lightbox-overlay[hidden] { display: none; }
.lightbox-overlay img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox-close {
  position: absolute; top: 10px; right: 14px; background: none; border: none;
  color: #fff; font-size: 2.2rem; line-height: 1; cursor: pointer; padding: 6px 10px;
}
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.15);
  border: none; color: #fff; font-size: 1.8rem; width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
}
.lightbox-prev { left: 10px; }
.lightbox-next { right: 10px; }

/* Login */
.login-body { background: var(--gray-50); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin-bottom: 2px; }

/* Print */
@media print {
  .topbar, .no-print, .filter-bar, .action-row { display: none !important; }
  body { background: #fff; }
  .print-sheet { border: none; }
}
