/* =====================================================================
   P4 CCTV SURVEY — ธีมมืด น้ำเงินเข้ม + ทอง (โทนอาคารตำรวจ)
   แก้สีทั้งระบบได้ที่ :root ด้านล่างที่เดียว
   ===================================================================== */

:root {
  --bg:        #060d1a;
  --bg-2:      #0a1528;
  --surface:   rgba(14, 27, 49, .82);
  --surface-2: #10203a;
  --input:     #0a1730;
  --line:        rgba(96, 165, 250, .16);
  --line-strong: rgba(56, 189, 248, .45);
  --text:   #e6edf7;
  --muted:  #8ea2bf;
  --accent:   #38bdf8;
  --accent-2: #2563eb;
  --gold:   #f2c14e;
  --ok:     #34d399;
  --warn:   #fbbf24;
  --danger: #f87171;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --glow:   0 0 0 1px var(--line-strong), 0 0 24px rgba(56, 189, 248, .18);
  --font-head: "Kanit", "IBM Plex Sans Thai", Arial, sans-serif;
  --font-body: "IBM Plex Sans Thai", "Noto Sans Thai", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 0% -10%, rgba(37, 99, 235, .28), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgba(56, 189, 248, .12), transparent 60%),
    linear-gradient(rgba(56, 189, 248, .035) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(90deg, rgba(56, 189, 248, .035) 1px, transparent 1px) 0 0 / 44px 44px,
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; color: #f1f5fb; letter-spacing: .2px; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: 14px; line-height: 1.7; }
.hint  { color: var(--muted); font-size: 12px; line-height: 1.7; margin: 6px 0 0; }
::selection { background: rgba(56, 189, 248, .35); }

/* ---------- Layout ---------- */

.container { max-width: 1080px; margin: 0 auto; padding: 18px 14px 60px; }

.center-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.card.narrow { width: 100%; max-width: 460px; }
.center { text-align: center; }

/* การ์ดหน้า Login: ขอบเรืองแสง */
.card.hero-card { padding: 34px 26px; border-color: var(--line-strong); box-shadow: var(--shadow), 0 0 60px rgba(37, 99, 235, .25); }
.card.hero-card::before {
  content: ""; position: absolute; inset: -1px; border-radius: inherit; padding: 1px; pointer-events: none;
  background: linear-gradient(135deg, var(--gold), transparent 30%, transparent 70%, var(--accent));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
.brand-title { margin: 6px 0 4px; font-size: 30px; letter-spacing: 1.5px; }
.brand-title span { color: var(--gold); }
.brand-sub { margin: 0 0 4px; color: var(--muted); font-size: 14px; }
.chip-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 16px 0 4px; }
.chip { padding: 5px 11px; border: 1px solid var(--line); border-radius: 20px; font-size: 12px; color: var(--muted); background: rgba(10, 23, 48, .6); }

.logo-big {
  width: 128px; height: 128px; object-fit: contain; display: block; margin: 0 auto 10px;
  filter: drop-shadow(0 0 18px rgba(242, 193, 78, .35));
}
.symbol { font-size: 46px; margin: 10px 0; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap;
  padding: 10px 18px;
  background: rgba(6, 13, 26, .82);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), var(--accent), transparent);
  opacity: .7;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; }
.brand img { width: 40px; height: 40px; object-fit: contain; filter: drop-shadow(0 0 8px rgba(242, 193, 78, .4)); }
.brand-text strong { display: block; font-family: var(--font-head); font-size: 17px; letter-spacing: 1px; }
.brand-text strong span { color: var(--gold); }
.brand-text small { display: block; color: var(--muted); font-size: 11px; letter-spacing: .5px; }

.who { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.who-name { text-align: right; line-height: 1.35; }
.who-name small { display: block; color: var(--muted); font-size: 11px; }
.tier-chip {
  padding: 4px 10px; border-radius: 8px; font: 600 12px var(--font-head); letter-spacing: 1px;
  color: #0b1220; background: linear-gradient(135deg, var(--gold), #e0a82e);
}

/* ---------- Page head ---------- */

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 16px 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  border-left: 3px solid var(--gold);
}
.page-head h2 { margin: 0; font-size: 21px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 15px;
  border: 1px solid var(--line); border-radius: 11px;
  background: rgba(16, 32, 58, .9); color: var(--text);
  font: 600 14px var(--font-body);
  text-decoration: none; cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .1s, background .15s;
}
.btn:hover:not(:disabled) { border-color: var(--line-strong); box-shadow: 0 0 16px rgba(56, 189, 248, .18); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary {
  border-color: transparent; color: #fff;
  background: linear-gradient(135deg, var(--accent-2), #0ea5e9);
  box-shadow: 0 6px 18px rgba(37, 99, 235, .35);
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 6px 24px rgba(56, 189, 248, .45); }
.btn.soft   { background: rgba(56, 189, 248, .1); border-color: rgba(56, 189, 248, .3); color: #bae6fd; }
.btn.line   { background: #06c755; border-color: #06c755; color: #fff; font-size: 17px; padding: 16px; box-shadow: 0 8px 24px rgba(6, 199, 85, .3); }
.btn.danger { color: #fecaca; border-color: rgba(248, 113, 113, .4); background: rgba(127, 29, 29, .25); }
.btn.small  { padding: 6px 10px; font-size: 12px; border-radius: 9px; }
.btn.block  { display: flex; width: 100%; padding: 15px; font-size: 16px; margin-top: 18px; }
.icon-btn { padding: 8px 10px; }

/* ---------- Forms ---------- */

label { display: block; font-weight: 600; font-size: 14px; margin: 16px 0 0; color: #cfdaea; }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 7px; }
input, select, textarea {
  padding: 12px 13px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--input); color: var(--text);
  font: 15px var(--font-body);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: #5f7393; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 189, 248, .18); }
select:disabled, input:disabled { opacity: .7; }
select option { background: var(--surface-2); color: var(--text); }
input[type="file"] { padding: 9px; }
input[type="file"]::file-selector-button {
  margin-right: 12px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: rgba(56, 189, 248, .12); color: #bae6fd; font: 600 13px var(--font-body); cursor: pointer;
}

fieldset.box {
  margin: 20px 0 0; padding: 4px 15px 15px;
  border: 1px solid var(--line); border-radius: 12px; background: rgba(10, 23, 48, .55);
}
fieldset.box legend { padding: 0 6px; font-weight: 600; color: var(--gold); font-size: 14px; font-family: var(--font-head); }

.preview { display: block; max-width: 100%; max-height: 280px; object-fit: contain; margin-top: 12px; border-radius: 12px; background: #050b16; border: 1px solid var(--line); }

/* ---------- Status ---------- */

.status, .info {
  margin-top: 14px; padding: 12px 14px; border-radius: 11px;
  font-size: 14px; line-height: 1.7; overflow-wrap: anywhere;
  border: 1px solid transparent; border-left-width: 3px;
}
.status { white-space: pre-line; }
.info, .status.info { background: rgba(56, 189, 248, .08); border-color: rgba(56, 189, 248, .25); color: #bae6fd; }
.status.ok    { background: rgba(52, 211, 153, .1);  border-color: rgba(52, 211, 153, .35); color: #a7f3d0; }
.status.warn  { background: rgba(251, 191, 36, .1);  border-color: rgba(251, 191, 36, .35); color: #fde68a; }
.status.error { background: rgba(248, 113, 113, .1); border-color: rgba(248, 113, 113, .4); color: #fecaca; }

.badge { display: inline-block; padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.badge.ok   { background: rgba(52, 211, 153, .12); border-color: rgba(52, 211, 153, .35); color: #6ee7b7; }
.badge.wait { background: rgba(251, 191, 36, .12); border-color: rgba(251, 191, 36, .35); color: #fcd34d; }

/* ---------- Home dashboard ---------- */

.welcome {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 20px 22px; margin-bottom: 16px;
  background:
    linear-gradient(120deg, rgba(37, 99, 235, .35), rgba(14, 27, 49, .85) 55%),
    var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.welcome h2 { margin: 6px 0 4px; font-size: 22px; }
.welcome p { margin: 0; color: #c3d2e8; font-size: 14px; }
.welcome .eyebrow { color: var(--gold); font: 600 12px var(--font-head); letter-spacing: 2px; text-transform: uppercase; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  padding: 14px 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line);
}
.stat b { display: block; font: 600 26px var(--font-head); color: #fff; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 12px; }
.stat.gold b { color: var(--gold); }
.stat.cyan b { color: var(--accent); }
.stat.warn b { color: var(--warn); }

.section-title { display: flex; align-items: center; gap: 10px; margin: 26px 0 12px; font-size: 18px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--line-strong), transparent); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.menu-card {
  position: relative; display: block; padding: 18px 18px 18px 18px; min-height: 132px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: inherit; text-decoration: none;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  overflow: hidden;
}
.menu-card::after {
  content: "→"; position: absolute; right: 16px; top: 16px; color: var(--muted);
  font-size: 18px; transition: transform .15s, color .15s;
}
.menu-card:hover { transform: translateY(-3px); border-color: var(--line-strong); box-shadow: var(--glow); }
.menu-card:hover::after { color: var(--accent); transform: translateX(3px); }
.menu-card .icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; margin-bottom: 12px; border-radius: 12px; font-size: 22px;
  background: linear-gradient(135deg, rgba(37, 99, 235, .35), rgba(56, 189, 248, .12));
  border: 1px solid var(--line-strong);
}
.menu-card h3 { margin: 0 0 6px; font-size: 16px; }
.menu-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }

/* ---------- Lists ---------- */

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 6px 0 14px; }
.item {
  padding: 16px; margin-top: 12px;
  border: 1px solid var(--line); border-radius: 14px; background: rgba(10, 23, 48, .65);
  transition: border-color .15s;
}
.item:hover { border-color: rgba(56, 189, 248, .3); }
.item-title { font: 600 16px var(--font-head); color: #f1f5fb; margin-bottom: 6px; }
.item-detail { color: var(--muted); font-size: 14px; line-height: 1.8; white-space: pre-line; overflow-wrap: anywhere; }
.item-actions { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.item-actions select { flex: 1 1 180px; }
.item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }

/* ---------- Surveys ---------- */

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button {
  padding: 8px 13px; border: 1px solid var(--line); border-radius: 20px;
  background: rgba(10, 23, 48, .7); color: var(--muted); font: 600 13px var(--font-body); cursor: pointer;
}
.tabs button:hover { color: var(--text); border-color: var(--line-strong); }
.tabs button.active { background: linear-gradient(135deg, var(--accent-2), #0ea5e9); border-color: transparent; color: #fff; }
.tabs .count { display: inline-block; min-width: 20px; padding: 1px 6px; margin-left: 4px; border-radius: 10px; background: rgba(148, 163, 184, .18); font-size: 12px; }
.tabs button.active .count { background: rgba(255, 255, 255, .25); }

.badge.st-draft     { background: rgba(148, 163, 184, .12); border-color: rgba(148, 163, 184, .3); color: #cbd5e1; }
.badge.st-submitted { background: rgba(56, 189, 248, .12);  border-color: rgba(56, 189, 248, .4);  color: #7dd3fc; }
.badge.st-returned  { background: rgba(251, 146, 60, .12);  border-color: rgba(251, 146, 60, .4);  color: #fdba74; }
.badge.st-approved  { background: rgba(52, 211, 153, .12);  border-color: rgba(52, 211, 153, .4);  color: #6ee7b7; }

.cams { margin-top: 10px; border-top: 1px dashed var(--line); }
.cam-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); font-size: 14px; flex-wrap: wrap; }
.cam-row .muted { font-size: 13px; }
.cam-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.cam-thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #050b16; cursor: pointer; }
.cam-main { display: flex; gap: 12px; align-items: center; flex: 1 1 260px; min-width: 0; }
.focus-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ---------- Maps ---------- */

.map { width: 100%; height: 400px; border-radius: 14px; overflow: hidden; background: #0b1424; border: 1px solid var(--line); z-index: 0; }
.map.tall { height: min(60vh, 600px); min-height: 340px; }
.map-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.map-tools input { flex: 1; min-width: 170px; }

/* แผนที่โหมดมืด (สลับได้ด้วยปุ่ม 🌗 บนแผนที่) */
.map.dark .leaflet-tile-pane { filter: invert(100%) hue-rotate(185deg) brightness(.92) contrast(.88) saturate(.55); }

.map-hero { position: relative; margin-bottom: 16px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.map-hero.fullscreen {
  position: fixed; inset: 0; z-index: 5000; margin: 0; border-radius: 0;
  display: flex; flex-direction: column; background: var(--bg);
}
.map-hero.fullscreen .map { flex: 1; height: auto !important; min-height: 0; }
body.noscroll { overflow: hidden; }

.map.leaflet-container { font-family: var(--font-body); background: #0b1424; }
.map .leaflet-bar { border: 1px solid var(--line-strong) !important; box-shadow: var(--shadow) !important; }
.map .leaflet-bar a, .map .leaflet-bar a:hover { background: var(--surface-2); color: var(--text); border-bottom-color: var(--line); }
.map .leaflet-bar a:hover { background: #17305a; }
.map .leaflet-control-attribution { background: rgba(6, 13, 26, .75) !important; color: var(--muted) !important; }
.map .leaflet-control-attribution a { color: var(--accent) !important; }
.map .leaflet-popup-content-wrapper, .map .leaflet-popup-tip { background: var(--surface-2); color: var(--text); border: 1px solid var(--line-strong); box-shadow: var(--shadow); }
.map .leaflet-popup-content-wrapper { border-radius: 14px; }
.map a.leaflet-popup-close-button { color: var(--muted); }
.map-theme-btn { font-size: 16px; line-height: 30px; text-align: center; cursor: pointer; }

.pin-wrap { background: transparent !important; border: 0 !important; }
.pin {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border: 3px solid #fff; border-radius: 50% 50% 50% 8px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, .55), 0 0 12px rgba(56, 189, 248, .35);
  transform: rotate(-45deg);
}
.pin-inner {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: #fff; overflow: hidden;
  transform: rotate(45deg); font-size: 16px;
}
.pin-inner img { width: 100%; height: 100%; object-fit: contain; }
.pin-count {
  position: absolute; top: -6px; right: -6px;
  min-width: 18px; padding: 1px 5px; border-radius: 10px;
  background: #ef4444; color: #fff; font: bold 11px Arial, sans-serif; text-align: center;
  box-shadow: 0 0 8px rgba(239, 68, 68, .6);
}
.pin-selected .pin { outline: 3px solid var(--gold); }

.popup { width: 230px; }
.popup h4 { margin: 0 0 6px; font-size: 15px; }
.popup p { margin: 4px 0; font-size: 13px; color: #c3d2e8; }
.popup-photo { margin-top: 8px; min-height: 90px; background: #050b16; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.popup-photo img { display: block; width: 100%; max-height: 190px; object-fit: contain; }
.popup-photo .muted { padding: 24px 8px; font-size: 12px; }
.popup-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.popup-nav button { padding: 5px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--input); color: var(--text); cursor: pointer; }
.popup-link { display: block; margin-top: 10px; padding: 8px; border-radius: 9px; text-align: center; font-size: 13px; font-weight: 600; text-decoration: none; color: #bae6fd !important; background: rgba(56, 189, 248, .12); border: 1px solid rgba(56, 189, 248, .3); }

.legend { margin-top: 14px; padding: 12px 14px; background: var(--surface); border-radius: 14px; border: 1px solid var(--line); }
.legend summary { cursor: pointer; font-weight: 600; color: var(--text); }
.legend-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin-top: 12px; max-height: 220px; overflow-y: auto; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #c3d2e8; }
.dot { flex: 0 0 14px; width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 6px rgba(255, 255, 255, .25); }

/* ---------- Logos ---------- */

.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 18px; }
.logo-box { padding: 12px; border: 1px solid var(--line); border-radius: 14px; text-align: center; background: rgba(10, 23, 48, .55); }
.logo-box h4 { margin: 0 0 10px; font-size: 14px; }
.logo-preview {
  display: flex; align-items: center; justify-content: center;
  min-height: 200px; padding: 12px;
  border: 2px dashed var(--line-strong); border-radius: 12px; background: #050b16;
}
.logo-preview img { width: 170px; height: 170px; max-width: 100%; object-fit: contain; }

/* ---------- Scrollbar ---------- */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #1e3558; border-radius: 10px; border: 2px solid var(--bg); }

/* ---------- Mobile ---------- */

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .card { padding: 16px; }
  .two { grid-template-columns: 1fr; }
  .map { height: 330px; }
  .map.tall { height: 52vh; min-height: 300px; }
  .topbar { padding: 8px 12px; }
  .brand img { width: 34px; height: 34px; }
  .brand-text strong { font-size: 15px; }
  .who-name { display: none; }
  .welcome h2 { font-size: 19px; }
  .stat b { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
