/* ===== Bản đồ Hạ tầng – Quy hoạch phường Thanh Miếu ===== */
:root {
  --red: #b3261e; --red-d: #8c1d17; --gold: #d4a017; --ink: #1d2433; --mute: #5f6b7a;
  --line: #dfe3ea; --bg: #f4f6f9; --card: #fff; --ok: #1e7b45; --warn: #9a6700; --err: #b3261e;
  --top: 56px; --side: 300px; --radius: 8px;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--ink); background: var(--bg); font-size: 14px; }
a { color: var(--red); }
code, .mono { font-family: Consolas, "Courier New", monospace; font-size: 12.5px; }
.hidden { display: none !important; }
.muted { color: var(--mute); } .small { font-size: 12.5px; }
.ok { color: var(--ok); background: #e7f5ec; padding: 8px 12px; border-radius: 6px; }
.warn { color: var(--warn); background: #fff6dd; padding: 8px 12px; border-radius: 6px; }
.err { color: var(--err); background: #fdecea; padding: 8px 12px; border-radius: 6px; }
.err-t { color: var(--err); }
.req { color: var(--err); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: #eef1f5; color: var(--mute); vertical-align: middle; }

/* Nút */
.btn { display: inline-flex; align-items: center; gap: 4px; padding: 8px 14px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 6px; cursor: pointer; font: inherit; text-decoration: none; line-height: 1.2; }
.btn:hover { border-color: #b9c1cc; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-d); }
.btn.danger { color: var(--err); border-color: #f0c2bf; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { display: flex; width: 100%; justify-content: center; margin-top: 6px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--red); cursor: pointer; font: inherit; padding: 2px 4px; }
.link.danger { color: var(--err); }
.icon-btn { background: none; border: 0; font-size: 20px; cursor: pointer; color: inherit; padding: 4px 8px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* Biểu mẫu */
.form label { display: block; margin: 8px 0; font-weight: 500; }
.form input:not([type=checkbox]):not([type=color]), .form select, .form textarea, dialog input, dialog select, dialog textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: #fff; font-weight: 400; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid #f3b6b1; border-color: var(--red); }
.form label.chk, label.chk { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.form.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form.inline input, .form.inline select { width: auto; display: inline-block; margin: 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 14px; }
fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 6px 0; padding: 6px 10px; }
legend { font-weight: 600; font-size: 13px; }

/* Trang đơn (đăng nhập, cài đặt, tài khoản) */
.page { min-height: 100%; }
.card { background: var(--card); border-radius: 12px; box-shadow: 0 2px 14px rgba(20, 30, 50, .08); padding: 24px 28px; }
.card.narrow { max-width: 520px; margin: 40px auto; }
.card.wide { max-width: 1200px; margin: 0 auto; }
.card-in { border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-top: 16px; background: #fbfcfd; }
.login-page { min-height: 100vh; padding: 1px 0; background: linear-gradient(160deg, #7a1712 0%, #b3261e 45%, #d4a017 130%); }
.brand-block { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.brand-block h1 { font-size: 19px; margin: 2px 0 0; }
.emblem { width: 52px; height: 52px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #e14b3d, var(--red-d)); color: #ffe08a;
  display: grid; place-items: center; font-weight: 700; letter-spacing: .5px; border: 2px solid var(--gold); flex: none; }
.emblem.sm { width: 36px; height: 36px; font-size: 13px; border-width: 1.5px; }
.org { font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; opacity: .85; }
.qr { width: 220px; margin: 10px 0; } .qr svg { width: 100%; height: auto; }

/* ===== Ứng dụng bản đồ ===== */
.app { overflow: hidden; }
.topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--top); z-index: 1001; display: flex; align-items: center; gap: 12px; padding: 0 12px;
  background: linear-gradient(90deg, var(--red-d), var(--red)); color: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.topbar.static { position: sticky; }
.topbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar .title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .btn { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .35); color: #fff; }
.topbar .btn:hover { background: rgba(255, 255, 255, .22); }
.userbox { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.userbox .who { font-size: 13px; opacity: .9; max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { position: relative; flex: 1; max-width: 460px; margin-left: 12px; }
.search input { width: 100%; padding: 9px 12px; border-radius: 20px; border: 0; font: inherit; }
.dropdown { position: absolute; top: 42px; left: 0; right: 0; background: #fff; color: var(--ink); border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, .2); max-height: 60vh; overflow: auto; }
.dropdown button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 9px 12px; cursor: pointer; font: inherit; }
.dropdown button:hover { background: #fdf2f1; }
.dropdown button span { display: block; font-size: 12px; color: var(--mute); }
.dropdown p { padding: 10px 12px; margin: 0; }

#map { position: fixed; top: var(--top); left: 0; right: 0; bottom: 0; background: #dfe5ec; transition: left .2s; }
.side-open #map { left: var(--side); }
.sidebar { position: fixed; top: var(--top); bottom: 0; left: 0; width: var(--side); z-index: 1000; background: #fff; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; transform: translateX(-100%); transition: transform .2s; }
.side-open .sidebar { transform: none; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.basemaps { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { flex: 1; border: 1px solid var(--line); background: #fff; padding: 5px 6px; border-radius: 5px; cursor: pointer; font-size: 12px; }
.seg button.on { background: var(--red); color: #fff; border-color: var(--red); }
.layer-tree { flex: 1; overflow: auto; padding: 4px 6px 10px; }
.grp summary { font-weight: 600; padding: 8px 6px; cursor: pointer; color: var(--red-d); }
.lyr { display: flex; align-items: center; padding: 3px 6px 3px 14px; border-radius: 5px; }
.lyr:hover { background: #f6f7fa; }
.lyr label { flex: 1; display: flex; align-items: center; gap: 7px; cursor: pointer; min-width: 0; }
.lyr .ln { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lyr .cnt { font-size: 11px; color: var(--mute); background: #f0f2f5; border-radius: 9px; padding: 0 7px; margin-left: 4px; }
.lyr.dim .ln { color: #9aa3ae; }
.lyr.dim .ln::after { content: " (phóng to để xem)"; font-size: 11px; }
.lyr-menu { padding: 2px 0 6px 40px; display: flex; flex-wrap: wrap; gap: 2px 8px; font-size: 12.5px; }
.sw { display: inline-block; flex: none; }
.sw.pt { width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); }
.sw.line { width: 18px; height: 0; border-top: 3px solid; }
.sw.poly { width: 15px; height: 11px; border: 2px solid; border-radius: 2px; }
.edit-tools { border-top: 1px solid var(--line); padding: 10px 12px; background: #fffaf2; }
.side-foot { border-top: 1px solid var(--line); padding: 8px 12px; max-height: 110px; overflow: auto; }

.panel { position: fixed; top: calc(var(--top) + 10px); right: 10px; bottom: 34px; width: 380px; max-width: calc(100vw - 20px); z-index: 1002;
  background: #fff; border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); display: flex; flex-direction: column; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.panel-head b { font-size: 15px; }
.panel-body { overflow: auto; padding: 12px 16px 16px; }
.lyrname { display: flex; align-items: center; gap: 7px; color: var(--mute); margin-bottom: 8px; }
table.props { width: 100%; border-collapse: collapse; }
table.props th { text-align: left; font-weight: 500; color: var(--mute); width: 42%; vertical-align: top; padding: 6px 8px 6px 0; border-bottom: 1px solid #f0f2f5; }
table.props td { padding: 6px 0; border-bottom: 1px solid #f0f2f5; }
.atts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.att img { width: 100%; height: 110px; object-fit: cover; border-radius: 6px; display: block; }
ul.hist { padding-left: 18px; font-size: 13px; }
ul.errs { max-height: 180px; overflow: auto; color: var(--err); padding-left: 18px; }

.coordbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 999; font-size: 12px; padding: 4px 12px; background: rgba(255, 255, 255, .9); color: var(--ink); pointer-events: none; text-align: center; }
.side-open .coordbar { left: var(--side); }
.editbar { position: fixed; top: calc(var(--top) + 10px); left: 50%; transform: translateX(-50%); z-index: 1003; background: #1d2433; color: #fff;
  padding: 8px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, .3); max-width: 92vw; }
.editbar .btn { margin-left: 6px; }
.toast { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); z-index: 3000; background: #1d2433; color: #fff; padding: 10px 18px; border-radius: 8px; max-width: 90vw; box-shadow: 0 4px 18px rgba(0, 0, 0, .3); }
.toast.err { background: var(--err); }

.map-tools { display: flex; flex-direction: column; background: #fff; border-radius: 6px; box-shadow: 0 1px 6px rgba(0, 0, 0, .3); overflow: hidden; }
.map-tools button { width: 36px; height: 34px; border: 0; border-bottom: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 16px; }
.map-tools button:hover { background: #f4f4f4; }
.leaflet-tooltip.lbl { background: rgba(255, 255, 255, .92); border: 0; font-weight: 600; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
.leaflet-container { font: inherit; }

dialog { border: 0; border-radius: 12px; padding: 20px 22px; width: 520px; max-width: 94vw; box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(20, 25, 35, .45); }
dialog h3 { margin-top: 0; }
dialog label { display: block; margin: 10px 0; font-weight: 500; }

/* Nhúng vào trang khác */
.embed .topbar { height: 46px; } .embed { --top: 46px; }
.embed .userbox, .embed .brand .org { display: none; }

/* ===== Quản trị ===== */
.admin-main { padding: 16px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; max-width: 1200px; margin: 0 auto 12px; }
.tabs button { border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 6px; cursor: pointer; font: inherit; }
.tabs button.on { background: var(--red); border-color: var(--red); color: #fff; }
table.grid { width: 100%; border-collapse: collapse; margin: 10px 0; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
table.grid th { background: #f6f7fa; font-weight: 600; font-size: 13px; }
table.grid td.num { text-align: right; } table.grid td.c { text-align: center; }
table.grid.fields input, table.grid.fields select { margin: 0 !important; padding: 5px 7px !important; }
table.grid td.mono { max-width: 380px; word-break: break-all; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 10px 0 18px; }
.stats div { background: #fdf2f1; border-radius: 10px; padding: 14px; }
.stats b { display: block; font-size: 26px; color: var(--red); } .stats span { color: var(--mute); }

@media (max-width: 800px) {
  :root { --side: 86vw; }
  .side-open #map, .side-open .coordbar { left: 0; }
  .topbar .brand .org, .userbox .who { display: none; }
  .topbar .title { display: none; }
  .search { margin-left: 0; }
  .userbox .btn { padding: 5px 7px; font-size: 12px; }
  .panel { top: auto; bottom: 0; right: 0; left: 0; width: auto; max-width: none; height: 58vh; border-radius: 14px 14px 0 0; }
  .coordbar { display: none; }
}
@media print {
  .topbar, .sidebar, .panel, .coordbar, .editbar, .map-tools, .leaflet-control-zoom { display: none !important; }
  #map { position: absolute; inset: 0 !important; }
}

.warn-t { color: var(--warn); font-weight: 600; }
.sso-btn { margin: 4px 0 6px; padding: 12px 14px; font-size: 15px; }
details.local-login { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
details.local-login summary { cursor: pointer; color: var(--mute); font-size: 13px; }
