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

:root {
  --blue:     #1a56a0;
  --blue-dk:  #133f7a;
  --blue-lt:  #e8f0fa;
  --green:    #1a7a45;
  --green-lt: #e6f5ed;
  --red:      #b91c1c;
  --red-lt:   #fef2f2;
  --yellow:   #92400e;
  --yellow-lt:#fffbeb;
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --radius:   12px;
  --shadow:   0 2px 12px rgba(0,0,0,0.09);
  --font:     -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ───────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--blue);
  color: #fff;
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.header-inner {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.header-icon { font-size: 1.5rem; line-height: 1; }

.header-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.header-subtitle {
  font-size: 0.7rem;
  opacity: 0.8;
}

.header-nav {
  display: flex;
  gap: 0.25rem;
}

.nav-link {
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  transition: background 0.15s;
}

.nav-link:hover { background: rgba(255,255,255,0.15); }
.nav-logout { color: rgba(255,220,220,0.9); }

/* ─── Main content ─────────────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem;
}

.app-footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--gray-400);
  border-top: 1px solid var(--gray-200);
}

/* ─── Flash messages ───────────────────────────────────────────────────────── */
.flash-container { margin-bottom: 0.75rem; }

.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  font-weight: 500;
  border-left: 4px solid transparent;
}

.flash-success { background: var(--green-lt); color: var(--green); border-color: var(--green); }
.flash-danger  { background: var(--red-lt);   color: var(--red);   border-color: var(--red); }
.flash-warning { background: var(--yellow-lt); color: var(--yellow); border-color: #f59e0b; }
.flash-info    { background: var(--blue-lt);   color: var(--blue);   border-color: var(--blue); }

.flash-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0.6;
  padding: 0 0.25rem;
  line-height: 1;
}

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.75rem 1.25rem;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: 2px solid transparent;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
  -webkit-appearance: none;
}

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

.btn-primary  { background: var(--blue);  color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dk); border-color: var(--blue-dk); }

.btn-success  { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover { background: #155a33; }

.btn-danger   { background: var(--red);   color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #991b1b; }

.btn-outline  { background: transparent; color: var(--blue); border-color: var(--blue); }
.btn-outline:hover { background: var(--blue-lt); }

.btn-full { width: 100%; }
.btn-lg   { padding: 1rem 1.5rem; font-size: 1.05rem; }
.btn-sm   { padding: 0.45rem 0.8rem; font-size: 0.82rem; }
.btn-xs   { padding: 0.3rem 0.6rem; font-size: 0.75rem; }

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ─── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.5rem;
}

.page-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gray-800);
}

/* ─── Login ────────────────────────────────────────────────────────────────── */
.login-body {
  background: linear-gradient(135deg, var(--blue) 0%, #2563eb 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-wrapper {
  width: 100%;
  max-width: 400px;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 2.5rem 2rem;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
}

.login-logo {
  font-size: 3rem;
  text-align: center;
  margin-bottom: 0.75rem;
}

.login-app-name {
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
  color: var(--blue);
  margin-bottom: 0.25rem;
}

.login-tagline {
  text-align: center;
  color: var(--gray-600);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
}

.login-form { display: flex; flex-direction: column; gap: 0.75rem; }

.login-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 1.25rem;
}

/* ─── Field / Form ─────────────────────────────────────────────────────────── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.field-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gray-600);
}

.required { color: var(--red); margin-left: 2px; }

.field-input {
  font-family: var(--font);
  font-size: 1rem;
  padding: 0.75rem 1rem;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  width: 100%;
  background: #fff;
  color: var(--gray-800);
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.field-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,86,160,0.12);
}

.field-textarea { resize: vertical; min-height: 80px; }

.form-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.form-actions { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.25rem; }

/* ─── School card list ─────────────────────────────────────────────────────── */
.card-list { display: flex; flex-direction: column; gap: 0.75rem; }

.school-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.school-name { font-size: 1.05rem; font-weight: 700; color: var(--gray-800); }
.school-address { font-size: 0.85rem; color: var(--gray-600); }

.school-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ─── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-600);
}

.empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-text { font-size: 1rem; margin-bottom: 1.25rem; }

/* ─── School banner ────────────────────────────────────────────────────────── */
.school-banner {
  background: linear-gradient(120deg, var(--blue) 0%, #2563eb 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.school-banner-name { font-size: 1.1rem; font-weight: 700; }
.school-banner-address { font-size: 0.82rem; opacity: 0.85; margin-top: 0.2rem; }

/* ─── Step cards (inspection) ──────────────────────────────────────────────── */
.step-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 0.85rem;
  border-left: 4px solid var(--gray-200);
}

.step-card.step-done { border-left-color: var(--green); }

.step-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--gray-200);
  color: var(--gray-600);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.step-num-done { background: var(--green); color: #fff; }

.step-label {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
  color: var(--gray-800);
}

.step-badge {
  background: var(--green-lt);
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  white-space: nowrap;
}

.step-blocked {
  background: var(--yellow-lt);
  color: var(--yellow);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

/* ─── GPS ──────────────────────────────────────────────────────────────────── */
.gps-result {
  background: var(--green-lt);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.gps-coords { font-size: 0.9rem; font-weight: 700; color: var(--green); }

.gps-status {
  margin-top: 0.6rem;
  font-size: 0.88rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-weight: 500;
}

.gps-status:empty { display: none; }
.gps-loading { background: var(--blue-lt); color: var(--blue); }
.gps-ok      { background: var(--green-lt); color: var(--green); }
.gps-error   { background: var(--red-lt);   color: var(--red); }

/* ─── Photos ───────────────────────────────────────────────────────────────── */
.photo-preview {
  margin-bottom: 0.75rem;
  text-align: center;
}

.photo-thumb {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid var(--gray-200);
}

.photo-hint {
  font-size: 0.78rem;
  color: var(--gray-400);
  margin-top: 0.3rem;
}

.photo-preview-inline {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 0.6rem;
  border: 2px solid var(--gray-200);
}

.hidden { display: none !important; }

/* ─── Infra list ───────────────────────────────────────────────────────────── */
.infra-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 0.75rem; }

.infra-item {
  display: flex;
  gap: 0.75rem;
  background: var(--gray-50);
  border-radius: 10px;
  padding: 0.75rem;
  align-items: flex-start;
  border: 1px solid var(--gray-200);
}

.infra-thumb {
  width: 80px;
  height: 70px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}

.infra-desc { flex: 1; display: flex; flex-direction: column; gap: 0.4rem; }

.infra-desc-text {
  font-size: 0.88rem;
  color: var(--gray-800);
  line-height: 1.4;
}

/* ─── Add infra details ────────────────────────────────────────────────────── */
.add-infra-details { margin-top: 0.25rem; }

.add-infra-details summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.add-infra-details summary::-webkit-details-marker { display: none; }
.add-infra-details[open] summary { margin-bottom: 0.75rem; }

.add-infra-form {
  background: var(--gray-50);
  border-radius: 10px;
  padding: 1rem;
  border: 1px solid var(--gray-200);
}

/* ─── Finalize card ────────────────────────────────────────────────────────── */
.finalize-card { border-left-color: var(--blue-dk); }

.finalize-hint {
  font-size: 0.88rem;
  color: var(--gray-600);
  margin-bottom: 0.75rem;
}

/* ─── Reports ──────────────────────────────────────────────────────────────── */
.report-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.report-date     { font-size: 1rem; font-weight: 700; color: var(--gray-800); }
.report-inspector{ font-size: 0.88rem; color: var(--gray-600); }
.report-gps      { font-size: 0.85rem; color: var(--gray-600); }
.report-photos-count { font-size: 0.85rem; color: var(--gray-600); }
.link-maps { color: var(--blue); text-decoration: none; }
.link-maps:hover { text-decoration: underline; }

/* ─── Settings ─────────────────────────────────────────────────────────────── */
.settings-section {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.settings-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 0.75rem;
}

.settings-info { display: flex; flex-direction: column; gap: 0.25rem; }

.info-row {
  display: flex;
  gap: 0.75rem;
  font-size: 0.9rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--gray-100);
}

.info-label { font-weight: 600; color: var(--gray-600); min-width: 80px; }
.info-value { color: var(--gray-800); }

.settings-hint {
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-top: 0.5rem;
}

.settings-hint code {
  background: var(--gray-100);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.78rem;
}

.settings-form { margin-top: 0.75rem; }

.logo-preview {
  text-align: center;
  margin-bottom: 0.75rem;
}

.logo-img {
  max-height: 80px;
  max-width: 200px;
  object-fit: contain;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 0.25rem;
  background: var(--gray-50);
}

/* ─── Report viewer ────────────────────────────────────────────────────────── */
.rview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.rview-actions-bottom {
  margin-top: 1rem;
  justify-content: center;
}

.rview-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.rview-header { border-top: 4px solid var(--blue); }

.rview-logo-wrap {
  text-align: center;
  margin-bottom: 0.75rem;
}

.rview-logo {
  max-height: 72px;
  max-width: 180px;
  object-fit: contain;
}

.rview-title-block {
  text-align: center;
  margin-bottom: 0.75rem;
}

.rview-app-name {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--blue);
}

.rview-app-sub {
  font-size: 0.82rem;
  color: var(--gray-600);
  margin-top: 0.15rem;
}

.rview-divider {
  height: 1px;
  background: var(--gray-200);
  margin: 0.85rem 0;
}

.rview-section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.75rem;
}

.rview-info-table {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--gray-200);
}

.rview-info-row {
  display: flex;
  gap: 0;
  font-size: 0.9rem;
}

.rview-info-row:nth-child(odd)  { background: var(--gray-50); }
.rview-info-row:nth-child(even) { background: #fff; }

.rview-info-label {
  font-weight: 700;
  color: var(--gray-600);
  padding: 0.55rem 0.85rem;
  min-width: 110px;
  border-right: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.rview-info-value {
  color: var(--gray-800);
  padding: 0.55rem 0.85rem;
  flex: 1;
  word-break: break-word;
}

.rview-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
}
.rview-link:hover { text-decoration: underline; }

.rview-photo-wrap { text-align: center; }

.rview-photo {
  width: 100%;
  max-height: 340px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid var(--gray-200);
}

.rview-photo-caption {
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-top: 0.4rem;
}

.rview-infra-count {
  font-size: 0.85rem;
  color: var(--gray-600);
  margin-bottom: 0.85rem;
}

.rview-infra-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.rview-infra-item {
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  overflow: hidden;
  background: var(--gray-50);
}

.rview-infra-photo {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  display: block;
}

.rview-infra-caption {
  padding: 0.65rem 0.85rem;
  font-size: 0.9rem;
  color: var(--gray-800);
  line-height: 1.45;
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
}

.rview-infra-num {
  background: var(--blue);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.rview-footer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--gray-400);
  padding: 1rem;
  line-height: 1.6;
  border-top: 1px solid var(--gray-200);
  margin-top: 0.5rem;
}

.report-btns {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ─── Lightbox ─────────────────────────────────────────────────────────────── */
.lightbox-trigger {
  cursor: zoom-in;
  transition: opacity 0.15s, transform 0.15s;
}
.lightbox-trigger:hover { opacity: 0.88; transform: scale(1.015); }

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.lightbox.open { display: flex; }

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  animation: lb-fade-in 0.2s ease;
}

@keyframes lb-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.lightbox-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 3rem 1rem 1rem;
}

.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  animation: lb-zoom-in 0.22s ease;
  cursor: zoom-out;
}

@keyframes lb-zoom-in {
  from { opacity: 0; transform: scale(0.88); }
  to   { opacity: 1; transform: scale(1); }
}

.lightbox-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.3);
  color: #fff;
  font-size: 1.1rem;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  line-height: 1;
}
.lightbox-close:hover { background: rgba(255,255,255,0.3); }

/* ─── Responsive fine-tuning ───────────────────────────────────────────────── */
@media (max-width: 400px) {
  .school-actions { flex-direction: column; }
  .school-actions .btn { width: 100%; }
  .gps-result { flex-direction: column; }
}

@media (min-width: 680px) {
  .app-main { padding: 1.5rem; }
  .school-card { flex-direction: row; align-items: center; justify-content: space-between; }
  .school-actions { flex-wrap: nowrap; }
}
