@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@400;600&display=swap');

:root {
  --bg-base:      #f0f4f8;
  --bg-surface:   #ffffff;
  --bg-panel:     #f8fafc;
  --bg-card:      #ffffff;
  --bg-hover:     #eef2f7;

  --border:       #d1dbe8;
  --border-dark:  #b0bfce;

  --accent:       #1a56db;
  --accent-light: #e8f0fe;
  --accent-hover: #1447b8;

  --danger:       #e02424;
  --danger-light: #fff0f0;
  --danger-border:#fca5a5;

  --success:      #057a55;
  --success-light:#f0fdf4;

  --warning:      #b45309;
  --warning-light:#fffbeb;

  --text-primary:   #111827;
  --text-secondary: #374151;
  --text-muted:     #6b7280;
  --text-light:     #9ca3af;

  --sidebar-width: 310px;
  --header-h: 56px;
  --font: 'Sarabun', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.14);
}

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

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.55;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 4px; }

/* ── Login ── */
.login-overlay {
  position: fixed; inset: 0;
  background: rgba(17,24,39,0.55);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}

.login-box {
  background: #fff;
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 44px 40px;
  width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-box h2 {
  font-size: 1.9rem; font-weight: 800;
  color: var(--accent); text-align: center;
  margin-bottom: 4px; letter-spacing: 0.02em;
}

.login-subtitle {
  text-align: center; color: var(--text-muted);
  font-size: 0.88rem; margin-bottom: 28px;
}

.login-box h3 {
  font-size: 0.82rem; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.08em; margin: 20px 0 12px;
}

.login-box hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* ── Inputs ── */
input[type="text"], input[type="password"], textarea {
  width: 100%;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 1rem;
  font-family: var(--font);
  margin-bottom: 10px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.12);
}
input::placeholder, textarea::placeholder { color: var(--text-light); }

/* ── Buttons ── */
.btn-primary {
  width: 100%; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius); padding: 12px 16px;
  font-size: 1rem; font-weight: 700; font-family: var(--font);
  cursor: pointer; transition: all 0.2s; letter-spacing: 0.02em;
  box-shadow: 0 2px 8px rgba(26,86,219,0.25);
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(26,86,219,0.35); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: #fff; color: var(--text-secondary);
  border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; font-size: 0.92rem; font-family: var(--font);
  cursor: pointer; width: 100%; transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

.btn-danger {
  width: 100%; background: var(--danger); color: #fff;
  border: none; border-radius: var(--radius); padding: 12px 16px;
  font-size: 1rem; font-weight: 700; font-family: var(--font);
  cursor: pointer; transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(224,36,36,0.25);
}
.btn-danger:hover { background: #c81e1e; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(224,36,36,0.35); }

/* ── Layout ── */
.container { display: flex; height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden; flex-shrink: 0;
  box-shadow: 2px 0 8px rgba(0,0,0,0.04);
}
.sidebar-right {
  border-right: none;
  border-left: 1px solid var(--border);
  box-shadow: -2px 0 8px rgba(0,0,0,0.04);
}

.sidebar-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 18px; height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.sidebar-header h2 {
  font-size: 1.05rem; font-weight: 800;
  color: var(--text-primary); display: flex; align-items: center; gap: 8px;
}

.sidebar-body { flex: 1; overflow-y: auto; padding: 16px; }

.card {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  margin-bottom: 12px; box-shadow: var(--shadow);
}

/* ── Main Content ── */
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ── Map Topbar ── */
.map-topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 0 16px; height: var(--header-h);
  display: flex; gap: 10px; align-items: center;
  flex-shrink: 0; position: relative;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.map-title {
  font-size: 0.88rem; font-weight: 700;
  color: var(--text-muted); white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
}
.map-title::before {
  content: '●'; color: var(--success); font-size: 0.6rem;
  animation: blink 2s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.2} }

/* ── Clock ── */
.topbar-clock {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-family: var(--font-mono); font-size: 1.1rem; font-weight: 600;
  color: var(--accent); letter-spacing: 0.06em;
  white-space: nowrap; pointer-events: none;
}

.map-topbar input {
  flex: 1; margin: 0; padding: 8px 12px;
  font-size: 0.92rem; height: 38px; border-radius: var(--radius);
}
.map-topbar .btn-secondary {
  width: auto; padding: 8px 16px; height: 38px;
  font-size: 0.88rem; white-space: nowrap;
}
.search-container { display: contents; }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 120px; right: 100px;
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); z-index: 1000;
  box-shadow: var(--shadow-lg); max-height: 220px; overflow-y: auto;
}
.search-results div {
  padding: 10px 14px; cursor: pointer; font-size: 0.88rem;
  border-bottom: 1px solid var(--border); color: var(--text-secondary);
  transition: background 0.15s;
}
.search-results div:hover { background: var(--accent-light); color: var(--accent); }
.search-results div:last-child { border-bottom: none; }

#map { flex: 1; width: 100%; }

/* ── Stats Bar ── */
.stats-bar-top {
  display: flex; background: #fff;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0; padding: 12px 0; justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}
.stat-block { flex: none; padding: 0 40px; text-align: center; }
.stat-value {
  font-family: var(--font-mono); font-size: 1.8rem; font-weight: 700;
  color: var(--text-primary); line-height: 1.1; transition: all 0.3s;
}
.stat-block.danger .stat-value { color: var(--danger); }
.stat-block.accent  .stat-value { color: var(--accent); }
.stat-block.muted   .stat-value { color: var(--text-muted); }
.stat-label {
  font-size: 0.72rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.07em; margin-top: 3px;
}
.stat-divider { width: 1px; background: var(--border); margin: 4px 0; flex-shrink: 0; align-self: stretch; }

/* ── Form ── */
.note { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 10px; }

.location-display {
  background: var(--accent-light);
  border: 1.5px solid #bfdbfe;
  border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 9px 12px;
  font-size: 0.88rem; color: var(--accent);
  margin-bottom: 12px; font-family: var(--font-mono);
  font-weight: 600;
}

textarea#caseDetails { height: 90px; resize: vertical; }

.field-label {
  font-size: 0.8rem; font-weight: 700; color: var(--text-secondary);
  margin: 12px 0 6px; text-transform: uppercase; letter-spacing: 0.06em;
}

.officer-row { display: flex; gap: 6px; margin-bottom: 6px; }
.officer-input { flex: 1; margin: 0 !important; }

.btn-remove-officer {
  background: var(--danger-light); color: var(--danger);
  border: 1.5px solid var(--danger-border); border-radius: var(--radius);
  width: 34px; height: 34px; cursor: pointer;
  font-size: 0.85rem; font-weight: 700; flex-shrink: 0; transition: all 0.2s;
}
.btn-remove-officer:hover { background: var(--danger); color: #fff; }

.btn-add-officer {
  background: #fff; color: var(--text-muted);
  border: 1.5px dashed var(--border-dark); border-radius: var(--radius);
  padding: 9px 12px; font-size: 0.9rem; cursor: pointer;
  width: 100%; text-align: left; transition: all 0.2s;
  margin-bottom: 12px; font-family: var(--font);
}
.btn-add-officer:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

.btn-open-case {
  width: 100%; background: var(--danger); color: #fff;
  border: none; border-radius: var(--radius); padding: 14px;
  font-size: 1.05rem; font-weight: 800; cursor: pointer;
  transition: all 0.2s; font-family: var(--font);
  box-shadow: 0 3px 10px rgba(224,36,36,0.3);
}
.btn-open-case:hover { background: #c81e1e; transform: translateY(-1px); box-shadow: 0 5px 18px rgba(224,36,36,0.4); }

/* ── Profile ── */
.user-profile-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  background: var(--bg-panel); flex-shrink: 0;
}
.profile-avatar {
  width: 42px; height: 42px; border-radius: var(--radius);
  object-fit: cover; border: 2px solid var(--accent); flex-shrink: 0;
}
.profile-info { flex: 1; min-width: 0; }
.profile-username { font-weight: 700; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-primary); }
.profile-login { font-size: 0.75rem; color: var(--text-muted); font-family: var(--font-mono); margin-top: 1px; }
.btn-profile-edit {
  background: #fff; border: 1.5px solid var(--border);
  border-radius: var(--radius); color: var(--text-muted);
  padding: 5px 10px; font-size: 0.78rem; cursor: pointer;
  white-space: nowrap; transition: all 0.2s; font-family: var(--font);
}
.btn-profile-edit:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* ── Tabs ── */
.tab-buttons { display: flex; border-bottom: 1px solid var(--border); background: #fff; flex-shrink: 0; }
.tab-btn {
  flex: 1; background: transparent; border: none;
  border-bottom: 3px solid transparent; color: var(--text-muted);
  padding: 12px 8px; font-size: 0.85rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s; font-family: var(--font);
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--accent-light); }
.tab-btn:hover:not(.active) { color: var(--text-secondary); background: var(--bg-hover); }

.tab-content { display: none; flex: 1; overflow-y: auto; padding: 14px; }
.tab-content.active { display: block; }

.section-title {
  font-size: 0.78rem; font-weight: 800; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}
.section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Case Items ── */
.case-item {
  background: #fff; border: 1.5px solid var(--border);
  border-radius: var(--radius); margin-bottom: 8px;
  overflow: hidden; transition: all 0.2s;
  box-shadow: var(--shadow);
}
.case-item:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

/* OPEN — แถบแดง + พื้นหลัง warm */
.case-item.open {
  border-left: 5px solid var(--danger);
  background: linear-gradient(135deg, #fff8f8 0%, #fff 60%);
}

/* CLOSED — จาง + เส้นเขียว */
.case-item.closed {
  border-left: 5px solid #9ca3af;
  background: #fafafa;
  opacity: 0.72;
}

.case-header {
  display: flex; align-items: center; padding: 11px 14px;
  cursor: pointer; gap: 8px; transition: background 0.15s;
}
.case-header:hover { background: var(--bg-hover); }

.case-item.open .case-header::before {
  content: '●'; color: var(--danger); font-size: 0.6rem;
  animation: blink 1.5s infinite; flex-shrink: 0;
}
.case-item.closed .case-header::before {
  content: '●'; color: #9ca3af; font-size: 0.6rem; flex-shrink: 0;
}

.case-item > div:last-child {
  padding: 0 14px 12px; font-size: 0.88rem;
  color: var(--text-secondary); line-height: 1.65;
}

/* ── Filter Bar ── */
.filter-bar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.filter-group { display: flex; gap: 5px; }
.filter-btn {
  flex: 1; background: #fff; border: 1.5px solid var(--border);
  border-radius: var(--radius); color: var(--text-muted);
  padding: 7px; font-size: 0.82rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s; font-family: var(--font);
}
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter-btn[data-filter="open"].active   { background: var(--danger); border-color: var(--danger); }
.filter-btn[data-filter="closed"].active { background: #6b7280; border-color: #6b7280; }
.filter-btn:hover:not(.active) { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.filter-search { margin: 0 !important; padding: 9px 12px !important; font-size: 0.9rem !important; height: 38px; }

/* ── Activity Feed ── */
.activity-feed { display: flex; flex-direction: column; gap: 7px; }
.activity-item {
  display: flex; gap: 10px; padding: 10px 12px;
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); border-left: 4px solid var(--border);
  box-shadow: var(--shadow); animation: fadeUp 0.25s ease forwards;
}
.activity-item.type-created { border-left-color: var(--danger); }
.activity-item.type-closed  { border-left-color: #9ca3af; }
.activity-item.type-updated { border-left-color: var(--warning); }
@keyframes fadeUp { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }
.activity-icon { font-size: 1rem; flex-shrink: 0; }
.activity-body { flex: 1; min-width: 0; }
.activity-text { font-size: 0.85rem; color: var(--text-primary); line-height: 1.4; }
.activity-time { font-size: 0.72rem; color: var(--text-muted); font-family: var(--font-mono); margin-top: 3px; }

/* ── Modal ── */
.modal { display: none; position: fixed; inset: 0; background: rgba(17,24,39,0.6); backdrop-filter: blur(4px); z-index: 5000; align-items: center; justify-content: center; }
.modal[style*="block"] { display: flex !important; }
.modal-content {
  background: #fff; border: 1px solid var(--border);
  border-top: 4px solid var(--accent); border-radius: var(--radius-lg);
  width: 90%; max-width: 700px; max-height: 88vh; overflow-y: auto;
  padding: 30px 32px; position: relative; box-shadow: var(--shadow-lg);
}
.close-btn {
  position: absolute; top: 16px; right: 16px;
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-muted);
  font-size: 0.9rem; cursor: pointer; transition: all 0.2s;
}
.close-btn:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger-border); }
.modal-content h2 { font-size: 1.25rem !important; font-weight: 800 !important; margin-bottom: 18px !important; color: var(--text-primary); }
.modal-cameras { display: grid; grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); gap: 10px; margin-top: 16px; }
.modal-camera-box { background: var(--bg-base); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.camera-title { padding: 8px 12px; font-size: 0.82rem; color: var(--text-muted); border-bottom: 1px solid var(--border); font-weight: 600; }

/* ── Settings ── */
.settings-label { display: block; font-size: 0.8rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.06em; margin: 14px 0 6px; }
input[type="file"] { background: var(--bg-panel); border: 1.5px dashed var(--border-dark); border-radius: var(--radius); color: var(--text-secondary); padding: 9px 12px; font-size: 0.9rem; width: 100%; cursor: pointer; margin-bottom: 10px; }
#imagePreview { text-align: center; margin: 12px 0; }
#previewImg { width: 66px; height: 66px; border-radius: var(--radius); object-fit: cover; border: 2px solid var(--accent); }

/* ── Logout ── */
#logoutBtn {
  background: var(--danger-light); color: var(--danger);
  border: 1.5px solid var(--danger-border); border-radius: var(--radius);
  padding: 7px 14px; font-size: 0.82rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s; font-family: var(--font);
}
#logoutBtn:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ── Toast ── */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 9000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  background: #fff; border: 1px solid var(--border);
  border-left: 5px solid var(--accent); border-radius: var(--radius);
  padding: 14px 16px; min-width: 290px; max-width: 360px;
  box-shadow: var(--shadow-lg); pointer-events: all;
  animation: toastIn 0.3s ease forwards;
  display: flex; gap: 12px; align-items: flex-start;
}
.toast.toast-danger  { border-left-color: var(--danger); }
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-out { animation: toastOut 0.3s ease forwards; }
.toast-icon { font-size: 1.2rem; flex-shrink: 0; margin-top: 1px; }
.toast-body { flex: 1; }
.toast-title { font-size: 0.9rem; font-weight: 700; color: var(--text-primary); margin-bottom: 3px; }
.toast-msg   { font-size: 0.8rem; color: var(--text-muted); line-height: 1.45; }
@keyframes toastIn  { from{opacity:0;transform:translateX(16px)} to{opacity:1;transform:translateX(0)} }
@keyframes toastOut { from{opacity:1;transform:translateX(0)} to{opacity:0;transform:translateX(16px)} }

/* ── Map ── */
.leaflet-container { background: #e8edf3 !important; }
.leaflet-tile { filter: saturate(0.85) brightness(1.02); }
.leaflet-popup-content-wrapper { background: #fff !important; border: 1px solid var(--border) !important; border-radius: var(--radius) !important; color: var(--text-primary) !important; font-family: var(--font) !important; font-size: 0.9rem !important; box-shadow: var(--shadow-lg) !important; }
.leaflet-popup-tip { background: #fff !important; }
.leaflet-control-zoom a { background: #fff !important; color: var(--text-secondary) !important; border-color: var(--border) !important; font-weight: 700; }
.leaflet-control-zoom a:hover { background: var(--accent-light) !important; color: var(--accent) !important; }
.leaflet-bar { border: 1px solid var(--border) !important; box-shadow: var(--shadow) !important; }

/* ── History Tab ── */
.history-container { padding: 4px 0; }
.history-filter {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    background: #f8f9fa; padding: 8px 10px;
    border-radius: 8px; border: 1px solid #e9ecef; margin-bottom: 10px;
}
.history-filter label { font-size: 0.78rem; font-weight: 700; white-space: nowrap; }
.history-filter input[type="date"] {
    flex: 1; padding: 5px 8px; border: 1px solid #ced4da;
    border-radius: 6px; font-size: 0.82rem; margin-bottom: 0; min-width: 0;
}
.history-stats {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff; border-radius: 8px; padding: 8px 12px;
    font-size: 0.82rem; margin-bottom: 12px; display: none;
}
.history-stats.visible { display: block; }
.history-stats strong { font-size: 1.2rem; }
.history-timeline { position: relative; }
.history-empty { text-align: center; color: #aaa; font-size: 0.85rem; padding: 24px 0; }
.timeline-date-label {
    font-size: 0.72rem; font-weight: 700; color: #667eea;
    padding: 3px 10px; background: #eef0ff; border-radius: 20px;
    display: inline-block; margin-bottom: 8px;
}
.timeline-item { display: flex; gap: 8px; margin-bottom: 8px; }
.timeline-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: #764ba2; margin-top: 5px; flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(118,75,162,0.15);
}
.timeline-card {
    flex: 1; background: #fff; border: 1px solid #e9ecef;
    border-radius: 8px; padding: 8px 10px; cursor: pointer;
    transition: box-shadow 0.2s, transform 0.2s;
}
.timeline-card:hover { box-shadow: 0 4px 12px rgba(102,126,234,0.15); transform: translateY(-1px); }
.timeline-card-id { font-size: 0.72rem; font-weight: 700; color: #667eea; margin-bottom: 2px; }
.timeline-card-details {
    font-size: 0.85rem; color: #333; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 3px;
}
.timeline-card-meta { font-size: 0.75rem; color: #888; }
.timeline-card-time { font-size: 0.72rem; color: #aaa; margin-top: 3px; }
.timeline-date-group { margin-bottom: 14px; }

/* ══════════════════════════════════════
   RESPONSIVE — MOBILE (≤ 768px)
   ══════════════════════════════════════ */
@media (max-width: 768px) {
  .container { flex-direction: column; height: 100vh; position: relative; }

  /* ซ่อน sidebar ทั้งคู่ตอนเริ่มต้น */
  .sidebar-left, .sidebar-right {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100% !important;
    z-index: 500;
    max-height: 100%;
    overflow-y: auto;
    border: none !important;
    display: none;
  }

  /* map เต็มจอ */
  .main-content {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    flex: none;
  }

  #map { height: 100%; width: 100%; }

  /* Navbar — ลอยบนแผนที่ รองรับ iPhone notch */
  .navbar {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 600;
    background: rgba(255,255,255,0.95);
    padding: 6px 10px;
    padding-top: max(env(safe-area-inset-top, 10px), 44px);
    flex-wrap: wrap;
    gap: 4px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
  .navbar-left { gap: 6px; }
  .navbar-center { order: 3; width: 100%; }
  .search-box { width: 100%; }

  /* PTT bar — ใต้ navbar */
  #pttBar {
    flex-shrink: 0;
  }

  /* Stats bar — อยู่ใน sidebar ไม่ต้อง absolute แล้ว */
  .stats-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 6px 0;
    scrollbar-width: none;
  }
  .stats-bar::-webkit-scrollbar { display: none; }
  .stat-block { padding: 0 10px; flex-shrink: 0; }
  .stat-value { font-size: 1.4rem; }
  .stat-divider { flex-shrink: 0; }

  /* map-topbar ซ่อนบน mobile */
  .map-topbar { display: none; }

  /* Modal */
  .modal-content {
    width: 96vw !important;
    max-width: 96vw !important;
    margin: 10px auto;
    max-height: 88vh;
    overflow-y: auto;
  }

  /* Tabs */
  .tab-btn { font-size: 0.78rem; padding: 6px 10px; }

  /* sidebar เมื่อเปิด ต้องหลีก safe area */
  .sidebar-left.active, .sidebar-right.active {
    padding-top: max(env(safe-area-inset-top, 10px), 44px);
    padding-bottom: max(env(safe-area-inset-bottom, 16px), 80px);
  }
}

/* ปุ่ม toggle มือถือ */
#mobileToggle {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 16px;
  z-index: 700;
  gap: 8px;
}
@media (max-width: 768px) {
  #mobileToggle { display: flex; flex-direction: row; gap: 6px; }
  #mobileToggle {
    bottom: max(env(safe-area-inset-bottom, 16px), 20px);
    left: 8px;
    right: 8px;
  }
  #mobileToggle button {
    flex: 1;
    padding: 14px 6px;
    border: none;
    border-radius: 28px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 3px 16px rgba(0,0,0,0.35);
    color: #fff;
  }
}

/* ── Announcement ── */
@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}

/* ── Mobile/Desktop visibility ── */
.hide-on-mobile { display: flex; }
.show-on-mobile { display: none !important; }

@media (max-width: 768px) {
  .hide-on-mobile { display: none !important; visibility: hidden !important; }
  .show-on-mobile { display: flex !important; }
  /* ซ่อน stats-bar-top บน mobile */
  .stats-bar-top { display: none !important; }
}

/* ── Mobile Stats Bar Center ── */
@media (max-width: 768px) {
  .show-on-mobile.stats-bar {
    justify-content: center !important;
    gap: 0;
  }
  .show-on-mobile .stat-block {
    flex: 1;
    text-align: center;
    padding: 6px 4px;
  }
  .show-on-mobile .stat-value {
    font-size: 1.6rem;
  }
  .show-on-mobile .stat-label {
    font-size: 0.65rem;
  }
}
