:root {
  --brand: #0b5394;
  --brand-2: #1c7ed6;
  --ink: #1f2933;
  --muted: #66727f;
  --line: #dde3ea;
  --bg: #ffffff;
  --soft: #f3f6f9;
  --ok: #2b8a3e;
  --warn: #e67700;
  --bad: #c92a2a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --shadow: 0 4px 18px rgba(0, 0, 0, .18);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #dfe7ee; color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
#map { position: fixed; inset: 0; z-index: 1; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; } /* đè giữ không bật menu chép chữ của iPhone */
#ui { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }

/* ---------- Thanh trên ---------- */
.topbar { position: absolute; left: 10px; right: 10px; top: calc(10px + var(--safe-t)); display: flex; gap: 8px; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 26px; height: 48px;
  padding: 0 8px 0 16px; box-shadow: var(--shadow); }
.search input { flex: 1; border: 0; outline: 0; background: none; min-width: 0; font-size: 16px; }
.search .ic { color: var(--muted); }
.round { width: 48px; height: 48px; border-radius: 50%; background: var(--bg); box-shadow: var(--shadow);
  display: grid; place-items: center; font-size: 20px; flex: none; }
.round.sm { width: 44px; height: 44px; font-size: 18px; }
.round.on { background: var(--brand); color: #fff; }

.sync { position: absolute; left: 50%; transform: translateX(-50%); top: calc(66px + var(--safe-t)); background: rgba(255,255,255,.95);
  border-radius: 14px; padding: 3px 10px; font-size: 13px; box-shadow: var(--shadow); white-space: nowrap; }
.sync.wait { color: var(--warn); } .sync.off { color: var(--bad); } .sync.ok { color: var(--ok); }

.mapfilter { position: absolute; left: 50%; transform: translateX(-50%); top: calc(96px + var(--safe-t)); background: var(--ink); color: #fff;
  border-radius: 18px; padding: 7px 14px; font-size: 14px; box-shadow: var(--shadow); white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis; }
.mapfilter .x { margin-left: 6px; opacity: .8; }
.xa-select { flex: 1; min-width: 0; height: 42px; border: 1.5px solid var(--line); border-radius: 12px; padding: 0 10px; background: #fff; font-size: 15px; }
.side { position: absolute; right: 10px; bottom: calc(96px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; }
.gpsacc { position: absolute; left: 10px; bottom: calc(96px + var(--safe-b)); background: rgba(255,255,255,.95); border-radius: 12px;
  padding: 4px 10px; font-size: 13px; box-shadow: var(--shadow); }

/* ---------- Nút thêm ---------- */
.addbar { position: absolute; left: 10px; right: 10px; bottom: calc(14px + var(--safe-b)); display: flex; gap: 10px; }
.btn-big { flex: 1; height: 62px; border-radius: 16px; color: #fff; font-weight: 700; font-size: 19px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-big.cong { background: #e8590c; }
.btn-big.kenh { background: var(--brand-2); }
.btn-big .plus { font-size: 26px; line-height: 1; font-weight: 400; }

/* ---------- Bảng trượt dưới ---------- */
.sheet-wrap { position: absolute; inset: 0; background: rgba(0,0,0,.25); display: flex; align-items: flex-end; }
.sheet-wrap.clear { background: none; pointer-events: none; }
.sheet-wrap.clear .sheet { pointer-events: auto; }
.sheet { width: 100%; max-height: 88vh; overflow: auto; background: var(--bg); border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  padding: 8px 16px calc(16px + var(--safe-b)); animation: up .18s ease-out; }
@media (min-width: 700px) { .sheet-wrap { justify-content: center; } .sheet { max-width: 520px; border-radius: 18px; margin-bottom: 16px; } }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-wrap.clear .sheet { position: relative; transition: transform .2s ease, max-height .25s ease; max-height: 62vh; }
.sheet-wrap.clear .grip { width: 60px; height: 6px; margin: 2px auto 12px; cursor: pointer; }
.sheet.mini { max-height: calc(98px + var(--safe-b)) !important; overflow: hidden; }
.sheet-x { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 50%; background: var(--soft); color: var(--muted);
  font-size: 16px; z-index: 2; }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 10px; }
.sheet h2 { margin: 0 0 4px; font-size: 21px; }
.sheet h3 { margin: 16px 0 6px; font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.sub { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea, .field select { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px; background: #fff;
  font-size: 17px; outline: 0; }
.field input:focus, .field textarea:focus { border-color: var(--brand-2); }
.field textarea { min-height: 70px; resize: vertical; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1.5px solid var(--line); border-radius: 20px; padding: 8px 14px; background: #fff; font-size: 15px; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

.btn { height: 50px; border-radius: 12px; padding: 0 18px; font-weight: 600; font-size: 16px; background: var(--soft); display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; }
.actions { display: flex; gap: 8px; margin-top: 14px; }
.actions .btn { flex: 1; }

.posbox { display: flex; align-items: center; gap: 10px; background: var(--soft); border-radius: 12px; padding: 10px 12px; margin: 8px 0; font-size: 15px; }
.posbox b { font-weight: 600; }
.posbox .btn { height: 38px; padding: 0 12px; font-size: 14px; background: #fff; }

.photos { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; }
.photos .ph { position: relative; flex: none; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; background: var(--soft); }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .ph .x { position: absolute; top: 2px; right: 2px; width: 26px; height: 26px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; }
.photos .add { flex: none; width: 84px; height: 84px; border-radius: 10px; border: 2px dashed var(--line); display: grid; place-items: center;
  color: var(--muted); font-size: 13px; text-align: center; }
.detail-photos { display: flex; gap: 8px; overflow-x: auto; margin: 8px 0; }
.detail-photos img { height: 150px; border-radius: 10px; display: block; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; margin: 8px 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 13px; font-weight: 600; color: #fff; }

/* ---------- Danh sách ---------- */
.panel { position: absolute; inset: 0; background: var(--bg); display: flex; flex-direction: column; padding-top: var(--safe-t); }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px; border-bottom: 1px solid var(--line); }
.panel-head .search { box-shadow: none; background: var(--soft); }
.panel-head h2 { margin: 0; font-size: 19px; flex: 1; }
.panel-body { flex: 1; overflow: auto; padding: 4px 0 calc(16px + var(--safe-b)); }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 10px; border-bottom: 1px solid var(--line); }
.filters .chip { flex: none; padding: 6px 12px; font-size: 14px; }
.item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--soft); }
.item .ico { width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-size: 16px; font-weight: 700; }
.item .t { font-weight: 600; } .item .s { font-size: 14px; color: var(--muted); }
.item .d { margin-left: auto; font-size: 14px; color: var(--muted); white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Menu ---------- */
.menu .item { font-size: 17px; }
.menu .item .ico { background: var(--soft); color: var(--ink); font-size: 19px; }

/* ---------- Đang vẽ kênh ---------- */
.drawbar { position: absolute; left: 10px; right: 10px; top: calc(10px + var(--safe-t)); background: var(--bg); border-radius: 16px; box-shadow: var(--shadow);
  padding: 12px 14px; }
.drawbar .big { font-size: 28px; font-weight: 700; }
.drawbar .rec { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--bad); margin-right: 6px; animation: blink 1s infinite; }
.drawbar .rec.paused { animation: none; background: var(--muted); }
@keyframes blink { 50% { opacity: .2; } }
.drawctl { position: absolute; left: 10px; right: 10px; bottom: calc(14px + var(--safe-b)); display: flex; gap: 8px; }
.drawctl .btn { flex: 1; height: 58px; box-shadow: var(--shadow); background: var(--bg); }
.drawctl .btn.primary { background: var(--ok); color: #fff; }
.drawctl .btn.add { background: var(--brand-2); color: #fff; }
.arrow { width: 60px; height: 60px; flex: none; border-radius: 50%; background: var(--brand-2); color: #fff; display: grid; place-items: center;
  font-size: 34px; font-weight: 700; transition: transform .3s; }
.arrow.ok { background: var(--ok); }
.cross { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; pointer-events: none !important; }
.cross::before, .cross::after { content: ""; position: absolute; background: #ff1744; box-shadow: 0 0 0 1px #fff; }
.cross::before { left: 21px; top: 0; width: 2px; height: 44px; }
.cross::after { top: 21px; left: 0; height: 2px; width: 44px; }

/* ---------- Đăng nhập ---------- */
/* nền màn đăng nhập: ảnh xí nghiệp (anh-xi-nghiep.jpg), phủ lớp xanh cho chữ dễ đọc */
.auth { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; overflow: auto;
  background: linear-gradient(180deg, #0b5394, #08305a); padding-bottom: calc(24px + var(--safe-b)); }
/* ảnh xí nghiệp nằm trọn nửa trên, mờ dần xuống nền xanh */
.auth-hero { flex: none; width: 100%; height: 46vh; min-height: 260px; max-height: 520px;
  background: url(/anh-xi-nghiep.jpg) 40% 62% / cover no-repeat;
  -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent); mask-image: linear-gradient(180deg, #000 70%, transparent); }
.auth .card { position: relative; margin: -56px 16px 0; }
.auth .card { width: 100%; max-width: 400px; background: #fff; border-radius: 20px; padding: 22px; box-shadow: var(--shadow); }
.auth .logo { width: 64px; height: 64px; margin: 0 auto 8px; display: block; }
.auth h1 { text-align: center; margin: 0; font-size: 23px; }
.auth .sub { text-align: center; margin-bottom: 10px; }
.tabs { display: flex; background: var(--soft); border-radius: 12px; padding: 4px; margin: 12px 0 4px; }
.tabs button { flex: 1; height: 42px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.err { color: var(--bad); font-size: 15px; min-height: 20px; margin: 6px 0; }
.note { background: #fff4e6; color: #8a4b00; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }

/* ---------- Thông báo ---------- */
.toast { position: absolute; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); background: rgba(31,41,51,.94); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 15px; max-width: 90%; text-align: center; z-index: 50; animation: up .2s; }

/* ---------- Bản đồ ---------- */
.maplibregl-map { background: #cfd8dc; font: inherit; }
.maplibregl-ctrl-bottom-right { bottom: calc(80px + var(--safe-b)); right: 64px; }
.maplibregl-ctrl-attrib { font-size: 10px; }
.compass { position: relative; transition: transform .1s linear; }
.compass span { position: absolute; top: 5px; left: 0; right: 0; text-align: center; color: #e03131; font-size: 13px; line-height: 1; }
.compass i { font-style: normal; font-weight: 700; font-size: 13px; margin-top: 10px; }
.me { position: relative; width: 18px; height: 18px; }
/* tia hướng hình quạt giống Google Maps */
.me-cone { position: absolute; left: 50%; top: 50%; width: 76px; height: 64px; margin: -64px 0 0 -38px; transform-origin: 50% 100%;
  background: linear-gradient(to top, rgba(26,115,232,.62), rgba(26,115,232,0) 92%); clip-path: polygon(50% 100%, 6% 0, 94% 0);
  transition: transform .25s linear; pointer-events: none; }
.me .me-dot { position: relative; }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(26,115,232,.35), 0 1px 4px rgba(0,0,0,.4); }
.progress { height: 8px; background: var(--soft); border-radius: 4px; overflow: hidden; margin: 10px 0; }
.progress > div { height: 100%; background: var(--brand-2); width: 0; transition: width .2s; }
