/* ═══════════════════════════════════════════════════════════════════
   Gate Guard Interface — CSS v3.0  (Mobile-first, Modern)
   ═══════════════════════════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --g-navy:   #0f2744;
  --g-navy2:  #1a4a7a;
  --g-teal:   #0d9488;
  --g-teal2:  #0f766e;
  --g-green:  #16a34a;
  --g-red:    #dc2626;
  --g-amber:  #d97706;
  --g-bg:     #f1f5f9;
  --g-card:   #fff;
  --g-border: #e2e8f0;
  --g-radius: 12px;
  --g-shadow: 0 2px 12px rgba(0,0,0,.08);
}

.ssm-gate {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--g-bg); min-height: 100vh; color: #1f2937;
  -webkit-font-smoothing: antialiased;
}

/* ── Top bar ──────────────────────────────────────────────────────── */
.gate-topbar {
  background: linear-gradient(135deg, var(--g-navy) 0%, #1a4a7a 70%, #0d5c6e 100%);
  padding: 14px 20px;
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 100; gap: 12px; flex-wrap: wrap;
  box-shadow: 0 2px 12px rgba(15,39,68,.25);
}
.gate-topbar-left  { display: flex; align-items: center; gap: 12px; }
.gate-topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.gate-icon         { font-size: 1.8rem; filter: drop-shadow(0 2px 4px rgba(0,0,0,.3)); }
.gate-title        { font-size: 1rem; font-weight: 800; color: #fff; letter-spacing: -.01em; }
.gate-guard-name   { font-size: .76rem; color: rgba(255,255,255,.6); }
.gate-clock        { font-size: .84rem; color: rgba(255,255,255,.7); font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }
.gate-society-name { font-size: .78rem; color: rgba(255,255,255,.75); background: rgba(255,255,255,.12); padding: 3px 10px; border-radius: 9999px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Stats bar ────────────────────────────────────────────────────── */
.gate-stats-bar {
  display: flex; background: #fff;
  border-bottom: 1px solid var(--g-border); overflow-x: auto; -webkit-overflow-scrolling: touch;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.gate-stat { flex: 1; min-width: 80px; padding: 12px 8px; text-align: center; border-right: 1px solid var(--g-border); }
.gate-stat:last-child { border-right: none; }
.gate-stat-green { background: #f0fdf4; }
.gate-stat-amber { background: #fffbeb; }
.gate-stat-red   { background: #fef2f2; }
.gs-num { font-size: 1.6rem; font-weight: 800; color: var(--g-navy); line-height: 1; }
.gate-stat-green .gs-num { color: var(--g-green); }
.gate-stat-amber .gs-num { color: var(--g-amber); }
.gate-stat-red   .gs-num { color: var(--g-red);   }
.gs-lbl { font-size: .6rem; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; font-weight: 600; }

/* ── Tabs ─────────────────────────────────────────────────────────── */
.gate-tabs {
  display: flex; background: #fff;
  border-bottom: 2px solid var(--g-border);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.gate-tab {
  flex: 1; min-width: 100px; padding: 12px 10px;
  background: none; border: none; border-bottom: 3px solid transparent;
  font-size: .8rem; font-weight: 600; color: #6b7280; cursor: pointer;
  white-space: nowrap; transition: .18s; margin-bottom: -2px;
  font-family: 'Inter', sans-serif;
}
.gate-tab:hover { color: var(--g-navy); background: #f8fafc; }
.gate-tab.active { color: var(--g-teal); border-bottom-color: var(--g-teal); }

/* ── Panels ───────────────────────────────────────────────────────── */
.gate-panel { padding: 16px; }
.gate-card {
  background: var(--g-card); border-radius: var(--g-radius);
  padding: 20px; box-shadow: var(--g-shadow); margin-bottom: 16px;
  border: 1px solid var(--g-border);
}
.gate-card h3 { margin: 0 0 16px; font-size: 1rem; color: var(--g-navy); font-weight: 700; }

/* ── Form ─────────────────────────────────────────────────────────── */
.gate-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
@media(max-width: 500px) { .gate-row { grid-template-columns: 1fr; } }
.gate-field { display: flex; flex-direction: column; gap: 4px; }
.gate-field label { font-size: .78rem; font-weight: 600; color: #374151; }
.gate-req { color: var(--g-red); }
.gate-input {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--g-border);
  border-radius: 9px; font-size: .95rem; background: #fff; transition: .18s;
  box-sizing: border-box; font-family: 'Inter', sans-serif;
}
.gate-input:focus { outline: none; border-color: var(--g-teal); box-shadow: 0 0 0 3px rgba(13,148,136,.1); }
.gate-hint {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px;
  padding: 10px 14px; font-size: .82rem; color: #92400e; margin-bottom: 10px;
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.gate-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 20px; border-radius: 9px; border: none; font-size: .875rem;
  font-weight: 700; cursor: pointer; transition: .18s; text-decoration: none;
  white-space: nowrap; font-family: 'Inter', sans-serif;
}
.gate-btn-primary { background: var(--g-teal); color: #fff; }
.gate-btn-primary:hover { background: var(--g-teal2); color: #fff; }
.gate-btn-primary:disabled { background: #94a3b8; cursor: not-allowed; }
.gate-btn-outline { background: transparent; color: var(--g-navy); border: 1.5px solid var(--g-border); }
.gate-btn-outline:hover { border-color: var(--g-navy); background: #f8fafc; }
.gate-btn-danger { background: #fee2e2; color: var(--g-red); border: 1px solid #fecaca; }
.gate-btn-danger:hover { background: var(--g-red); color: #fff; }
.gate-btn-green  { background: #dcfce7; color: var(--g-green); border: 1px solid #bbf7d0; }
.gate-btn-green:hover { background: var(--g-green); color: #fff; }
.gate-btn-sm   { padding: 7px 14px; font-size: .8rem; }
.gate-btn-full { width: 100%; padding: 14px; }

/* ── Camera area ──────────────────────────────────────────────────── */
.gate-camera-area {
  background: #f8fafc; border: 2px dashed var(--g-border); border-radius: var(--g-radius);
  padding: 24px; text-align: center; min-height: 100px;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  gap: 8px; cursor: pointer; transition: .2s;
}
.gate-camera-area:hover { border-color: var(--g-teal); background: #f0fdf9; }
.camera-placeholder { color: #9ca3af; font-size: .875rem; }

/* ── Badges ───────────────────────────────────────────────────────── */
.gate-preapproved-badge {
  background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px;
  padding: 10px 14px; font-size: .875rem; color: #15803d;
  display: flex; align-items: center; gap: 8px;
}

/* ── Messages ─────────────────────────────────────────────────────── */
.gate-msg { padding: 11px 14px; border-radius: 9px; font-size: .875rem; margin-bottom: 12px; font-weight: 500; }
.gate-msg.success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.gate-msg.error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.gate-msg.info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.gate-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; border-radius: 9px; padding: 11px 14px; font-size: .875rem; margin-bottom: 12px; }

/* ── Result panel ─────────────────────────────────────────────────── */
.gate-result { background: #f8fafc; border: 1px solid var(--g-border); border-radius: var(--g-radius); padding: 24px; margin-top: 16px; }
.gate-result.approved { background: #f0fdf4; border-color: #bbf7d0; }
.gate-result.denied   { background: #fef2f2; border-color: #fecaca; }
.gate-result.pending  { background: #fffbeb; border-color: #fde68a; }

/* ── Vehicle check ────────────────────────────────────────────────── */
.vc-result-card { padding: 20px; border-radius: var(--g-radius); text-align: center; border: 2px solid var(--g-border); }
.vc-result-card.registered { border-color: var(--g-green); background: #f0fdf4; }
.vc-result-card.unknown    { border-color: var(--g-amber); background: #fffbeb; }
.vc-details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; text-align: left; }
.vc-detail-item  { background: #fff; border-radius: 7px; padding: 8px 10px; }
.vc-detail-label { font-size: .68rem; color: #6b7280; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.vc-detail-value { font-size: .875rem; font-weight: 700; color: var(--g-navy); }

/* ── Visitor log rows ─────────────────────────────────────────────── */
.gate-visitor-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid #f3f4f6; flex-wrap: wrap;
}
.gate-visitor-row:last-child { border-bottom: none; }
.gvr-photo {
  width: 42px; height: 42px; border-radius: 50%; object-fit: cover;
  background: #e5e7eb; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
  border: 2px solid var(--g-border);
}
.gvr-info { flex: 1; min-width: 0; }
.gvr-name { font-weight: 700; font-size: .9rem; color: var(--g-navy); }
.gvr-meta { font-size: .74rem; color: #6b7280; }
.gvr-status { padding: 3px 10px; border-radius: 9999px; font-size: .7rem; font-weight: 700; white-space: nowrap; }
.status-approved { background: #dcfce7; color: #15803d; }
.status-pending  { background: #fef3c7; color: #92400e; }
.status-denied   { background: #fee2e2; color: #b91c1c; }
.status-exited   { background: #f3f4f6; color: #374151; }
.gvr-exit-btn {
  padding: 5px 12px; border-radius: 7px; background: var(--g-navy); color: #fff;
  border: none; font-size: .74rem; cursor: pointer; font-family: 'Inter', sans-serif;
  font-weight: 600; transition: .15s;
}
.gvr-exit-btn:hover { background: var(--g-navy2); }

/* ── Pre-approved list ────────────────────────────────────────────── */
.preapproved-row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid #f3f4f6; }
.preapproved-row:last-child { border-bottom: none; }
.pr-info { flex: 1; }
.pr-name { font-weight: 700; font-size: .9rem; color: var(--g-navy); }
.pr-meta { font-size: .74rem; color: #6b7280; }
.pr-badge { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; padding: 2px 8px; border-radius: 9999px; font-size: .7rem; font-weight: 700; }

/* ── Gate login page ──────────────────────────────────────────────── */
.gate-login-wrap {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: linear-gradient(135deg, #064e3b 0%, #0d5c3a 40%, #0f766e 80%, #0d9488 100%);
  padding: 20px;
}
.gate-login-box {
  background: #fff; border-radius: 20px; padding: 40px 36px;
  width: 100%; max-width: 400px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.gate-login-icon { font-size: 3.5rem; margin-bottom: 12px; filter: drop-shadow(0 4px 8px rgba(0,0,0,.2)); }
.gate-login-box h2 { font-size: 1.4rem; color: var(--g-navy); margin: 0 0 4px; font-weight: 800; }
.gate-login-box p  { color: #6b7280; font-size: .875rem; margin: 0 0 24px; }
.gate-already-in { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 10px; padding: 20px; text-align: center; }
.gate-locked { background: #fef2f2; border: 1px solid #fecaca; border-radius: 10px; padding: 20px; text-align: center; color: #b91c1c; }

/* ── Shift button ─────────────────────────────────────────────────── */
.gate-shift-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  border-radius: 8px; font-size: .8rem; font-weight: 700; cursor: pointer;
  transition: .18s; border: none; font-family: 'Inter', sans-serif;
}
.gate-shift-btn.start { background: #dcfce7; color: var(--g-green); border: 1px solid #bbf7d0; }
.gate-shift-btn.start:hover { background: var(--g-green); color: #fff; }
.gate-shift-btn.end { background: #fee2e2; color: var(--g-red); border: 1px solid #fecaca; }
.gate-shift-btn.end:hover { background: var(--g-red); color: #fff; }

/* ── Logout btn in topbar ─────────────────────────────────────────── */
.gate-logout-btn {
  display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22);
  border-radius: 7px; color: rgba(255,255,255,.85); font-size: .78rem; font-weight: 600;
  cursor: pointer; transition: .18s; text-decoration: none; font-family: 'Inter', sans-serif;
}
.gate-logout-btn:hover { background: rgba(255,255,255,.22); color: #fff; }

/* ── Hide theme logout ────────────────────────────────────────────── */
body.ssm-gate-page .nav-menu a[href*="action=logout"],
body.ssm-gate-page .main-navigation a[href*="action=logout"],
body.ssm-gate-page header a[href*="action=logout"],
body.ssm-gate-page nav a[href*="action=logout"] { display: none !important; }
body.ssm-gate-page .nav-menu li:has(a[href*="action=logout"]),
body.ssm-gate-page .main-navigation li:has(a[href*="action=logout"]),
body.ssm-gate-page header li:has(a[href*="action=logout"]),
body.ssm-gate-page nav li:has(a[href*="action=logout"]) { display: none !important; }

/* ── Gate page: remove theme padding so gate fills full viewport ──── */
body.ssm-gate-page .entry-content,
body.ssm-gate-page .site-content,
body.ssm-gate-page .content-area,
body.ssm-gate-page article,
body.ssm-gate-page .post-content,
body.ssm-gate-page .page-content,
body.ssm-gate-page .wp-block-post-content { padding:0 !important; margin:0 !important; }
body.ssm-gate-page .ssm-lw--split { margin:0 !important; }

/* ── Gate dashboard full-bleed inside page wrapper ───────────────── */
.ssm-gate { max-width:100% !important; }
.ssm-gate .gate-topbar { position:sticky; top:32px; } /* below WP admin bar */
body.admin-bar .ssm-gate .gate-topbar { top:32px; }
@media(max-width:782px){
  body.admin-bar .ssm-gate .gate-topbar { top:46px; }
}

/* ── Login page: remove theme padding/max-width ───────────────────── */
body.ssm-gate-page .ssm-lw,
body.ssm-gate-page .ssm-lw--split,
body.ssm-gate-page .ssm-lw--center {
  margin-left: calc(-50vw + 50%) !important;
  margin-right: calc(-50vw + 50%) !important;
  width: 100vw !important;
  max-width: 100vw !important;
}

/* ── QR Patrol Panel ─────────────────────────────────────────────── */
#panel-patrol .gate-card { padding: 18px; }

#patrol-scanner-wrap video {
  border-radius: 12px;
  border: 3px solid #059669;
  background: #000;
  display: block;
  width: 100%;
}

#patrol-scan-msg {
  animation: ssm-patrol-fadein .25s ease;
  border-radius: 10px;
  font-weight: 600;
  font-size: .9rem;
  text-align: center;
  padding: 12px 16px;
}

@keyframes ssm-patrol-fadein { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Print styles — when admin prints QR code only show the modal content */
@media print {
  body > *:not(#patrol-qr-modal) { display: none !important; }
  #patrol-qr-modal {
    display: flex !important;
    position: static !important;
    background: #fff !important;
    inset: auto !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
   COMPREHENSIVE MOBILE RESPONSIVE STYLES
   Tested for iPhone Safari, Chrome Android, Samsung Browser
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

  /* ── Gate wrapper ── */
  .ssm-gate { width: 100vw !important; overflow-x: hidden; }

  /* ── Top bar ── */
  .gate-topbar { padding: 10px 12px; gap: 8px; }
  .gate-topbar-left { gap: 8px; flex: 1; min-width: 0; }
  .gate-topbar-right { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  .gate-guard-name { font-size: .85rem; }
  .gate-society-name { max-width: 120px; font-size: .72rem; }
  .gate-clock { font-size: .78rem; min-width: 56px; }
  .gate-btn { padding: 7px 12px; font-size: .82rem; }
  .gate-btn-primary, .gate-btn-danger { padding: 8px 14px; }

  /* ── Stats bar ── */
  .gate-stats-bar { gap: 0; }
  .gate-stat { padding: 8px 4px; min-width: 0; }
  .gs-num { font-size: 1.3rem; }
  .gs-lbl { font-size: .6rem; }

  /* ── Info bar ── */
  .gate-stats-bar + div[style*="background:#f0f9ff"] { font-size: .75rem !important; padding: 6px 10px !important; gap: 6px !important; }

  /* ── Tab bar ── */
  .gate-tabs { gap: 0; padding: 0; }
  .gate-tab { padding: 10px 8px; font-size: .72rem; min-width: 0; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* ── Cards ── */
  .gate-card { padding: 14px 12px; border-radius: 10px; margin: 8px; }
  h3.gate-card-title, .gate-card > h3 { font-size: 1rem; }

  /* ── Form rows: single column on mobile ── */
  .gate-row { grid-template-columns: 1fr !important; gap: 10px; }
  .gate-field label { font-size: .8rem; }
  .gate-input { padding: 10px 12px; font-size: 16px !important; } /* 16px prevents iOS zoom */

  /* ── Visitor log rows ── */
  .gvr-row { padding: 10px 12px; flex-direction: column; align-items: flex-start; gap: 8px; }
  .gvr-info { width: 100%; }
  .gvr-actions { width: 100%; display: flex; gap: 6px; flex-wrap: wrap; }
  .gvr-actions button { flex: 1; min-width: 80px; font-size: .75rem; }

  /* ── Vehicle check card ── */
  #vc-result-card { padding: 14px 12px; }

  /* ── Pre-approved list ── */
  .gate-card table { font-size: .78rem; }
  .gate-card table td, .gate-card table th { padding: 6px 8px; }

  /* ── Add visitor photo area ── */
  #photo-capture-area { padding: 20px; }

  /* ── Water tank ── */
  #panel-water-tank .gate-card { padding: 14px 12px; }
  #wt-status-card { padding: 20px 14px; }
  #wt-status-icon { font-size: 2rem; }
  #wt-status-text { font-size: .95rem; }
  #wt-pump-timer { font-size: 1.8rem; }
  #wt-btn-start, #wt-btn-stop, #wt-btn-done, #wt-btn-done2 { padding: 16px; font-size: .95rem; border-radius: 10px; }

  /* ── Patrol panel ── */
  #patrol-my-scans .gate-row { flex-direction: column; }
  #patrol-scanner-wrap { padding: 10px; }
  #patrol-scanner-wrap video { height: 240px; object-fit: cover; }

  /* ── Modals ── */
  .gate-modal-box { margin: 10px; padding: 16px; border-radius: 12px; max-height: 90vh; overflow-y: auto; }

  /* ── Shift timer ── */
  #shift-timer-wrap { font-size: .78rem; }
}

@media (max-width: 390px) {
  /* Extra small phones (iPhone SE, Galaxy A series) */
  .gate-tab { font-size: .65rem; padding: 8px 5px; }
  .gs-lbl { font-size: .55rem; }
  .gs-num { font-size: 1.1rem; }
  .gate-topbar { padding: 8px 10px; }
  .gate-btn { padding: 6px 10px; font-size: .78rem; }
}
