:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --green: #16a34a;
  --sidebar: #1e293b;
  --sidebar-text: #cbd5e1;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14.5px; }

/* ---------- layout ---------- */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 238px; min-width: 238px; background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow: hidden; }
.sidebar .logo { display: flex; align-items: center; gap: 10px; padding: 18px 18px 16px; font-size: 19px; font-weight: 700; color: #fff; border-bottom: 1px solid rgba(148, 163, 184, .15); }
.sidebar .logo .logo-ic { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #6366f1, #8b5cf6); border-radius: 9px; font-size: 17px; }
.sidebar .logo > span:last-child { color: #fff; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 12px 10px 16px; scrollbar-width: thin; scrollbar-color: #475569 transparent; }
.sidebar .nav-sec { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: #64748b; padding: 14px 12px 5px; }
.sidebar .nav-sec:first-child { padding-top: 4px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: var(--sidebar-text); text-decoration: none; margin-bottom: 2px; font-weight: 500; font-size: 14px; border-left: 3px solid transparent; }
.sidebar nav a .ic { width: 20px; text-align: center; font-size: 15px; }
.sidebar nav a:hover { background: #334155; color: #fff; }
.sidebar nav a.active { background: linear-gradient(90deg, rgba(99, 102, 241, .25), rgba(99, 102, 241, .08)); color: #fff; border-left-color: #818cf8; }
.sidebar .me { padding: 12px 14px 14px; border-top: 1px solid rgba(148, 163, 184, .15); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.sidebar .me .avatar { width: 38px; height: 38px; min-width: 38px; border-radius: 50%; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; }
.sidebar .me .me-info { flex: 1; min-width: 0; }
.sidebar .me .name { color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .me .role { color: #94a3b8; margin-top: 2px; font-size: 12px; }
.sidebar .me .qvs { color: #818cf8; margin-top: 2px; font-size: 11.5px; width: 100%; }
.sidebar .me button { margin-top: 8px; width: 100%; background: #334155; border: 0; color: #e2e8f0; padding: 8px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.sidebar .me button:hover { background: #475569; }
.sidebar .me .logout { background: transparent; border: 1px solid #475569; }
.sidebar .me .logout:hover { background: rgba(220, 38, 38, .18); border-color: rgba(220, 38, 38, .5); color: #fecaca; }
.sidebar .me .install-btn { background: transparent; border: 1px solid #6366f1; color: #a5b4fc; }
.sidebar .me .install-btn:hover { background: rgba(99, 102, 241, .15); }
.sidebar .me .install-btn.ready { background: var(--primary); border-color: var(--primary); color: #fff; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, .5); } 50% { box-shadow: 0 0 0 6px rgba(99, 102, 241, 0); } }

.main { flex: 1; padding: 22px 26px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; }

/* ---------- cards & grids ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.card .num { font-size: 26px; font-weight: 700; color: var(--primary); }
.card .lbl { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } .cards { grid-template-columns: repeat(2, 1fr); } }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel h3 { font-size: 15px; margin-bottom: 10px; color: var(--text); }
.zona-head { font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }

/* ---------- filters & buttons ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input,
.filters select,
.filters .btn {
  width: auto; min-width: 0; flex: 0 0 auto;
  height: 38px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13.5px; background: #fff; color: var(--text);
  box-sizing: border-box; vertical-align: middle;
}
.filters input[type=text], .filters input[type=search] { flex: 1 1 180px; min-width: 150px; max-width: 260px; }
.filters input[type=date], .filters input[type=month] { min-width: 150px; }
.filters .btn { display: inline-flex; align-items: center; justify-content: center; }
.btn { display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--text); text-decoration: none; }
.btn:hover { background: #f8fafc; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-sm { padding: 4px 9px; font-size: 12.5px; border-radius: 6px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; background: #f8fafc; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #eef2ff; }
td .sub { color: var(--muted); font-size: 12px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-gray { background: #e2e8f0; color: #475569; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-indigo { background: #e0e7ff; color: #4338ca; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 22px; text-align: center; }

/* ---------- modals ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: flex; align-items: flex-start; justify-content: center; padding: 40px 14px; z-index: 2000; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 560px; max-width: 100%; padding: 20px 22px; }
.modal.wide { width: 720px; }
.modal h2 { font-size: 17px; margin-bottom: 14px; }
.modal-top { display: flex; margin-bottom: 8px; }
.modal-back { background: #e2e8f0; border: 1px solid var(--border); border-radius: 8px; padding: 6px 14px; font-weight: 700; font-size: 14px; cursor: pointer; color: var(--text); }
.modal .close-x { float: right; margin-top: -38px; background: #dc2626; border: 0; width: 34px; height: 34px; border-radius: 50%; font-size: 20px; font-weight: 800; cursor: pointer; color: #fff; line-height: 34px; text-align: center; padding: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; }
textarea { resize: vertical; min-height: 70px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.checkbox-list { display: flex; flex-wrap: wrap; gap: 6px; }
.checkbox-list label { display: flex; align-items: center; gap: 5px; border: 1px solid var(--border); padding: 5px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--text); }
.checkbox-list input { width: auto; }

/* ---------- contact detail ---------- */
.detail-top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.detail-top h2 { font-size: 18px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 14px; margin-bottom: 14px; font-size: 13.5px; }
.info-grid div { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.info-grid .k { color: var(--muted); font-size: 11.5px; display: block; }
.timeline-item { border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 8px; padding: 9px 12px; margin-bottom: 8px; font-size: 13.5px; }
.timeline-item .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }

/* ---------- mobile ---------- */
.menu-btn { display: none; position: fixed; top: 10px; left: 10px; z-index: 45; background: var(--primary); color: #fff; border: 0; border-radius: 9px; width: 40px; height: 40px; font-size: 18px; cursor: pointer; box-shadow: 0 3px 10px rgba(0,0,0,.25); }
.backdrop { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 55; }
.backdrop.show { display: block; }

@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 60; height: 100vh; transform: translateX(-105%); transition: transform .22s ease; box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 30px rgba(0,0,0,.4); }
  .menu-btn { display: block; }
  .main { padding: 58px 12px 20px; }
  .page-head { gap: 8px; }
  .page-head h1 { font-size: 18px; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .card { padding: 11px 12px; }
  .card .num { font-size: 21px; }
  .grid2 { grid-template-columns: 1fr; gap: 10px; }
  .panel { padding: 12px; margin-bottom: 10px; overflow-x: auto; }
  table { min-width: 560px; font-size: 13px; }
  th, td { padding: 8px 8px; }
  .filters { gap: 6px; }
  .filters input, .filters select, .filters .btn { height: 42px; }
  .filters input[type=search], .filters input[type=text] { min-width: 100%; flex: 1 1 100%; max-width: none; }
  .filters select, .filters input[type=date], .filters input[type=month] { flex: 1 1 45%; min-width: 0; }
  .overlay { padding: 12px 8px; align-items: flex-start; }
  .modal, .modal.wide { width: 100%; border-radius: 16px 16px 0 0; padding: 16px; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  .form-grid { grid-template-columns: 1fr; }
  .btn { padding: 9px 13px; font-size: 13.5px; }
  .search-bar { flex-direction: column; }
  .search-bar .btn { display: flex; align-items: center; justify-content: center; width: 100%; height: 54px; padding: 0; font-size: 17.5px; font-weight: 800; border-radius: 12px; letter-spacing: .3px; }
  .detail-actions .btn { flex: 1 1 45%; }
  .info-grid { grid-template-columns: repeat(2, 1fr); }
  #toast-root { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: 100%; }
}

@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .info-grid { grid-template-columns: 1fr; }
}

/* ---------- toast ---------- */
#toast-root { position: fixed; bottom: 18px; right: 18px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; }

/* Leaflet map panes have z-index 400-1000: isolate every map container so they
   can NEVER bleed above modals (z-index 2000). */
#mon-map, #loc-map, #trail-map-el, #qv-zone-map, #u-zone-map, #mon-user-map { position: relative; z-index: 0; }
.toast { background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 13.5px; box-shadow: 0 6px 18px rgba(0,0,0,.25); max-width: 360px; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--green); }

/* ---------- login ---------- */
.login-wrap { width: 100%; min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e293b, #312e81); }
.login-box { background: #fff; border-radius: 14px; padding: 30px 34px; width: 370px; max-width: 92vw; }
.login-box h1 { font-size: 21px; margin-bottom: 4px; }
.login-box .sub { color: var(--muted); margin-bottom: 20px; font-size: 13.5px; }
.login-box label { margin-top: 12px; }
.login-box .btn { margin-top: 18px; width: 100%; }

/* ---------- my panel ---------- */
.me-card { display: flex; align-items: center; gap: 14px; }
.me-card .avatar.big { width: 54px; height: 54px; min-width: 54px; border-radius: 50%; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 22px; }
.me-card .name-big { font-size: 17px; font-weight: 700; }
.me-card .sub { margin-top: 3px; }

/* ---------- search page ---------- */
.search-hero { max-width: 900px; margin: 0 auto; }
.search-bar { display: flex; gap: 10px; margin-bottom: 8px; }
.search-bar input { flex: 1; padding: 14px 16px; font-size: 16.5px; border-radius: 10px; }
.search-bar .btn { padding: 0 22px; font-size: 15px; border-radius: 10px; }
.search-hero > .sub { display: block; margin-bottom: 14px; }
.notfound { text-align: center; padding: 32px 10px; color: var(--muted); font-size: 15px; }
.notfound .btn { margin-top: 14px; }

/* ---------- activity ---------- */
.act-item { display: flex; gap: 8px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid #f1f5f9; font-size: 13.5px; }
.act-item .when { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }
