:root{
  --ink:#16202c;--muted:#64748b;--line:#e3e8ef;--bg:#f3f5f8;--card:#fff;
  --brand:#0f2a47;--accent:#1d5fd6;--accent-soft:#e8f0fe;
  --real:#1d5fd6;--test:#ea580c;--test-soft:#fff4e5;--ok:#15803d;--danger:#b42318;
  font-family:"Noto Sans Thai","Sarabun",Inter,system-ui,-apple-system,"Segoe UI",sans-serif;color:var(--ink);background:var(--bg)
}
*{box-sizing:border-box}html,body{height:100%}body{margin:0;display:flex;flex-direction:column}
.hidden{display:none!important}.muted{color:var(--muted)}.small{font-size:12.5px}
h2{font-size:18px;margin:0}h3{font-size:15px;margin:0 0 8px}

/* top bar */
.topbar{height:56px;flex:none;background:var(--brand);color:#fff;display:flex;align-items:center;justify-content:space-between;padding:0 18px}
.brand{font-weight:700;letter-spacing:.2px;display:flex;align-items:center;gap:10px;font-size:17px}
.logo{width:22px;height:22px;border-radius:50%;background:radial-gradient(circle at 50% 50%,#fff 0 3px,transparent 4px),conic-gradient(#38bdf8,#1d5fd6,#38bdf8);box-shadow:0 0 0 3px #ffffff22}
.topbar-right{display:flex;align-items:center;gap:12px}.who{font-size:13px;opacity:.85}

/* controls */
input,select{font:inherit;padding:9px 10px;border:1px solid #cfd7e2;border-radius:8px;width:100%;background:#fff;color:var(--ink)}
label{display:block;font-size:13px;color:#334155;margin:8px 0}label>input,label>select{margin-top:4px}
.btn{font:inherit;border:0;border-radius:8px;padding:9px 14px;cursor:pointer;font-weight:600;background:#e9eef5;color:var(--ink)}
.btn.primary{background:var(--accent);color:#fff}.btn.secondary{background:#e9eef5}.btn.block{width:100%}
.btn.ghost-light{background:#ffffff1a;color:#fff}.btn.icon{width:36px;height:36px;padding:0;font-size:18px;line-height:36px;text-align:center;background:transparent}
.btn.icon:hover,.btn.secondary:hover{background:#dde4ee}
.row{display:flex;gap:8px}.row>input{flex:1}
.alert{padding:9px 11px;border-radius:8px;background:var(--accent-soft);margin-top:8px;font-size:13px;white-space:pre-wrap}
.alert.err{background:#fde8e8;color:var(--danger)}

/* action buttons */
.actions{display:flex;gap:8px;margin-bottom:12px;flex-wrap:wrap}
.btn.action{display:inline-flex;align-items:center;gap:8px;padding:10px 14px;border-radius:10px;font-size:14px;box-shadow:0 1px 2px #0f172a14;transition:transform .05s,box-shadow .15s,background .15s}
.btn.action .ic{display:inline-flex;width:20px;height:20px;border-radius:6px;align-items:center;justify-content:center;font-size:15px;line-height:1;background:#ffffff33}
.btn.primary.action{flex:1;justify-content:center}
.btn.primary:hover{background:#174fb5;box-shadow:0 3px 10px #1d5fd640}
.btn.outline{background:#fff;color:#1e3a5f;border:1.5px solid #c5d3e6}
.btn.outline .ic{background:#eef3fb;color:#1d5fd6}
.btn.outline:hover{border-color:var(--accent);background:#f5f9ff}
.btn.action:active{transform:translateY(1px)}
.btn.danger{background:#fff;color:var(--danger);border:1.5px solid #f3c4c0}.btn.danger:hover{background:#fdf1f0}
.btn.sm{padding:5px 10px;font-size:12.5px;border-radius:7px}
.btn:disabled{opacity:.5;cursor:not-allowed}

/* modal */
.modal{border:0;border-radius:16px;padding:0;width:min(520px,calc(100vw - 24px));max-height:calc(100vh - 48px);box-shadow:0 24px 64px #0f172a40}
.modal::backdrop{background:#0f172a73}
.modal-head{display:flex;align-items:center;justify-content:space-between;padding:14px 16px 10px 20px;border-bottom:1px solid var(--line);position:sticky;top:0;background:#fff;margin:0}
.modal-head h3{margin:0;font-size:17px}
.modal-body{padding:16px 20px 20px}
.modal-foot{display:flex;gap:8px;justify-content:flex-end;margin-top:16px}
.hint{font-size:12.5px;color:var(--muted);margin:-2px 0 8px;line-height:1.45}
.field-row{display:flex;gap:8px;align-items:flex-end}.field-row>label{flex:1;margin-bottom:0}.field-row>.btn{margin-bottom:1px;white-space:nowrap}
.mlist{display:grid;gap:6px;margin:4px 0 14px}
.mitem{display:grid;grid-template-columns:1fr auto;gap:2px 10px;align-items:center;border:1px solid var(--line);border-radius:10px;padding:9px 12px}
.mitem .t{font-weight:600}.mitem .s{grid-column:1;font-size:12px;color:var(--muted)}
.mitem .b{grid-row:1/3;grid-column:2;display:flex;gap:6px}
.proto{font-size:11px;font-weight:700;border-radius:6px;padding:1px 6px}
.proto.findmy{background:#e8f0fe;color:#1d4ed8}.proto.ble{background:#ecfdf3;color:#15803d}
.sep{border:0;border-top:1px solid var(--line);margin:14px 0}

/* keys widget */
.keys-box{border:1px solid var(--line);border-radius:12px;padding:6px 14px 12px;margin:12px 0 4px}
.keys-box legend{font-weight:700;font-size:14px;padding:0 6px}
.keys-box.need{border-color:#f59e0b;background:#fffbeb}
textarea{font:13px/1.45 ui-monospace,SFMono-Regular,Consolas,monospace;width:100%;padding:9px 10px;border:1px solid #cfd7e2;border-radius:8px;margin-top:4px;resize:vertical}
textarea.secret{-webkit-text-security:disc}
.row.wrap{flex-wrap:wrap}
.file-btn{position:relative;overflow:hidden;display:inline-flex;align-items:center;gap:6px;margin:0}
.file-btn input{position:absolute;inset:0;opacity:0;cursor:pointer}
.kparsed{display:grid;gap:3px;margin-top:8px;font-size:12.5px}
.kp.ok{color:var(--ok)}.kp.bad{color:var(--danger)}
.idcard{border:1px solid var(--line);border-radius:10px;padding:10px 12px;margin:8px 0;font-size:12.5px}
.idcard .t{font-weight:700;font-size:13px;margin-bottom:4px}
.idcard code{font:12px ui-monospace,Consolas,monospace;background:#f1f5f9;border-radius:5px;padding:1px 5px;word-break:break-all}
.idgrid{display:grid;grid-template-columns:118px 1fr;gap:4px 8px;align-items:start}
.note{background:#f8fafc;border:1px solid var(--line);border-radius:10px;padding:10px 12px;font-size:12.5px;line-height:1.55;color:#334155}

/* detail tabs & manage menu */
.seg.seg3{grid-template-columns:1fr 1fr 1fr}
.seg.seg3 button{font-size:13px;white-space:nowrap;padding:8px 4px}
.detail-head{align-items:flex-start}
.detail-head .manage-btn{white-space:nowrap;display:inline-flex;align-items:center;gap:4px;width:auto;height:auto;line-height:1.2;margin-top:2px}
.detail-head .menu-pop{min-width:250px;padding:6px}
.detail-head .menu-pop button{display:flex;flex-direction:column;align-items:flex-start;gap:2px;padding:10px 12px}
.detail-head .menu-pop button b{font-size:14px;white-space:nowrap}
.detail-head .menu-pop button span{font-size:12px;color:var(--muted);font-weight:400}
.keys-existing .kitem{display:flex;align-items:center;gap:8px;padding:6px 0;border-bottom:1px dashed var(--line);font-size:13px}
.keys-existing .kitem:last-child{border-bottom:0}.keys-existing .kitem span.l{flex:1}

/* users / audit */
.modal.wide{width:min(1040px,calc(100vw - 24px))}
.who{background:none;border:0;color:#fff;font:inherit;font-size:13px;opacity:.9;cursor:pointer;text-decoration:underline dotted #ffffff80;text-underline-offset:3px}
.ro-badge{font-size:12px;font-weight:600;background:#f1f5f9;color:#475569;border-radius:999px;padding:3px 10px;margin-right:4px}
.table-wrap{overflow:auto;max-height:58vh;border:1px solid var(--line);border-radius:10px;margin:8px 0}
.tbl{width:100%;border-collapse:collapse;font-size:13.5px}
.tbl th{position:sticky;top:0;background:#f8fafc;text-align:left;font-size:12px;color:var(--muted);font-weight:600;padding:8px 10px;border-bottom:1px solid var(--line)}
.tbl td{padding:9px 10px;border-bottom:1px solid #eef2f6;vertical-align:top}
.tbl tr.off td{opacity:.55}.nowrap{white-space:nowrap}
.role{display:inline-block;font-size:11.5px;font-weight:700;border-radius:6px;padding:2px 7px;white-space:nowrap}
.role.admin{background:#fde8e8;color:#9b1c1c}.role.manager{background:#e8f0fe;color:#1d4ed8}.role.viewer{background:#f1f5f9;color:#475569}
.role-help{display:grid;gap:4px;font-size:12.5px;color:#334155;background:#f8fafc;border:1px solid var(--line);border-radius:10px;padding:10px 12px}
.ok-text{color:var(--ok);font-weight:600}
.group-checks{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:0 12px;padding-left:24px}
.group-checks .check{margin:4px 0}.dim{opacity:.4;pointer-events:none}
.audit-filters{display:grid;grid-template-columns:1.3fr 1.2fr .8fr 1.5fr;gap:8px;margin-bottom:6px}
.act{display:inline-block;font-size:12px;font-weight:600;border-radius:6px;padding:2px 8px;background:#eef2f7;white-space:nowrap}
.act.del{background:#fde8e8;color:#9b1c1c}.act.warn{background:#fff4e5;color:#9a3412}
.audit-d{color:#334155;margin-top:2px;line-height:1.5}.audit-d s{color:#94a3b8}
.topbar-right .btn{white-space:nowrap}
@media (max-width:1100px){.topbar-right .lbl{display:none}.topbar-right .admin-only{padding:7px 10px;font-size:15px}}
@media (max-width:900px){.audit-filters{grid-template-columns:1fr 1fr}.topbar-right{gap:6px}.brand{font-size:15px}}

/* apple accounts */
.cap{display:inline-block;width:70px;height:8px;background:#eef2f7;border-radius:99px;overflow:hidden;vertical-align:middle;margin-right:6px}
.cap-fill{height:100%;background:var(--ok)}.cap-fill.hi{background:#f59e0b}.cap-fill.full{background:var(--danger)}
.act.ok{background:#ecfdf3;color:#15803d}
.acct-sum{display:flex;gap:14px;align-items:center;flex-wrap:wrap;font-size:13px;margin:10px 0 4px}
.cmd{display:flex;gap:8px;align-items:center;background:#0f172a;color:#e2e8f0;border-radius:10px;padding:10px 12px;margin:8px 0}
.cmd code{flex:1;font:12.5px ui-monospace,Consolas,monospace;word-break:break-all;background:none;color:inherit}

/* archive */
.arch-banner{background:#f8fafc;border:1px dashed #94a3b8;border-radius:10px;padding:10px 12px;font-size:13px;margin-bottom:10px;display:flex;gap:10px;align-items:center}
.arch-banner span{flex:1}
.tag-card.archived{opacity:.7;background:#f8fafc}
.chip.arch{background:#e2e8f0}

/* login */
.booting{text-align:center;margin:80px auto;font-size:14px}
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:22px;box-shadow:0 2px 12px #0f172a0d}
.login-card{max-width:400px;width:calc(100% - 32px);margin:64px auto}

/* layout */
.layout{flex:1;display:grid;grid-template-columns:400px 1fr;min-height:0}
.side{background:var(--card);border-right:1px solid var(--line);overflow-y:auto;padding:14px 16px 28px}
.map-wrap{position:relative;min-height:0}#map{position:absolute;inset:0}
.side-head,.detail-head{display:flex;align-items:center;gap:8px;margin-bottom:10px}.side-head h2{flex:1}
.filters{display:grid;grid-template-columns:1fr 112px 112px;gap:8px}
.stats{display:flex;gap:8px;margin:10px 0;font-size:12.5px;color:var(--muted);flex-wrap:wrap}
.stats b{color:var(--ink)}

/* tag cards */
.tag-list{display:grid;gap:8px}
.tag-card{border:1px solid var(--line);border-radius:10px;padding:10px 12px;cursor:pointer;display:grid;grid-template-columns:12px 1fr auto;gap:4px 10px;align-items:start;background:#fff}
.tag-card:hover{border-color:#b9c7dc;background:#fafcff}
.tag-card .dot{margin-top:5px}
.tag-card .name{font-weight:600}.tag-card .when{font-size:12px;color:var(--muted);white-space:nowrap}
.tag-card .place{grid-column:2/4;font-size:13px;color:#334155}
.tag-card .sub{grid-column:2/4;font-size:12px;color:var(--muted)}
.dot{width:12px;height:12px;border-radius:50%;display:inline-block;background:var(--real)}
.dot.test{background:var(--test-soft);border:2px dashed var(--test)}.dot.none{background:#cbd5e1}
.chip{display:inline-block;font-size:11.5px;border-radius:6px;padding:1px 7px;background:#eef2f7;color:#334155;font-weight:600}
.badge-test{display:inline-block;font-size:11.5px;font-weight:700;border:1px dashed var(--test);background:var(--test-soft);color:#9a3412;border-radius:6px;padding:1px 6px}

/* folds */
.fold{border-top:1px solid var(--line);margin-top:14px;padding-top:10px}
.fold>summary{cursor:pointer;font-weight:600;font-size:14px;list-style:none;color:#1e3a5f}
.fold>summary::-webkit-details-marker{display:none}.fold-body{padding-top:6px}

/* detail */
.detail-title{flex:1;min-width:0}.detail-title h2{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.menu{position:relative}.menu>summary{list-style:none}.menu>summary::-webkit-details-marker{display:none}
.menu-pop{position:absolute;right:0;top:40px;background:#fff;border:1px solid var(--line);border-radius:10px;box-shadow:0 8px 24px #0f172a22;z-index:1000;min-width:150px;padding:4px}
.menu-pop button{display:block;width:100%;text-align:left;border:0;background:none;padding:9px 12px;font:inherit;border-radius:7px;cursor:pointer}
.menu-pop button:hover{background:#f1f5f9}.danger-text{color:var(--danger)}
.seg{display:grid;grid-template-columns:1fr 1fr;background:#eef2f7;border-radius:10px;padding:3px;margin:4px 0 14px}
.seg button{font:inherit;border:0;background:none;padding:8px;border-radius:8px;cursor:pointer;font-weight:600;color:#475569}
.seg button.active{background:#fff;color:var(--ink);box-shadow:0 1px 4px #0f172a1f}

/* place card */
.place-card{border:1px solid var(--line);border-radius:12px;padding:14px;margin-bottom:12px}
.place-head{display:flex;gap:10px;align-items:flex-start;margin-bottom:10px}
.place-title{font-size:16px;font-weight:700;line-height:1.35}
.admin{display:grid;grid-template-columns:120px 1fr;gap:6px 10px;font-size:13.5px;margin:0}
.admin dt{color:var(--muted)}.admin dd{margin:0;font-weight:500}
.kv{display:grid;grid-template-columns:120px 1fr;gap:6px 10px;font-size:13px;margin:10px 0 0;padding-top:10px;border-top:1px dashed var(--line)}
.kv dt{color:var(--muted)}.kv dd{margin:0;word-break:break-word}
.linkbtn{font:inherit;font-size:12.5px;background:none;border:0;color:var(--accent);cursor:pointer;padding:0;margin-left:6px}
.links{display:flex;gap:12px;margin-top:10px;font-size:13px}.links a{color:var(--accent);text-decoration:none}
.empty{border:1px dashed #cbd5e1;border-radius:12px;padding:18px;text-align:center;color:var(--muted);font-size:13.5px}

/* route */
.ranges{display:flex;flex-wrap:wrap;gap:6px}
.ranges button{font:inherit;font-size:13px;border:1px solid var(--line);background:#fff;border-radius:999px;padding:5px 11px;cursor:pointer}
.ranges button.active{background:var(--ink);border-color:var(--ink);color:#fff}
.custom-range{display:grid;grid-template-columns:1fr 1fr auto;gap:8px;align-items:end;margin-top:8px}.custom-range label{margin:0}
.check{display:flex;align-items:center;gap:8px;margin:10px 0}.check input{width:auto;margin:0}
.tiles{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;margin-bottom:12px}
.tile{background:#f7f9fc;border:1px solid var(--line);border-radius:10px;padding:8px 10px}
.tile b{display:block;font-size:16px}.tile span{font-size:11.5px;color:var(--muted)}
.timeline{position:relative}
.tl-item{display:grid;grid-template-columns:22px 1fr auto;gap:2px 10px;padding:10px 4px;cursor:pointer;border-radius:8px;position:relative}
.tl-item:hover,.tl-item.sel{background:#f3f7ff}
.tl-item::before{content:"";position:absolute;left:14px;top:30px;bottom:-10px;border-left:2px dotted #cbd5e1}
.tl-item:last-child::before{display:none}
.tl-num{width:22px;height:22px;border-radius:50%;background:var(--real);color:#fff;font-size:11px;font-weight:700;display:flex;align-items:center;justify-content:center;z-index:1}
.tl-num.test{background:var(--test-soft);color:#9a3412;border:2px dashed var(--test)}
.tl-num.now{background:#dc2626}
.tl-place{font-weight:600;font-size:13.5px}.tl-when{font-size:12px;color:var(--muted);text-align:right;white-space:nowrap}
.tl-sub{grid-column:2/4;font-size:12px;color:var(--muted)}
.tl-move{grid-column:2/4;font-size:12px;color:#475569;padding:2px 0}

/* map overlays */
.legend{position:absolute;left:12px;bottom:28px;z-index:500;background:#ffffffee;border:1px solid var(--line);border-radius:10px;padding:8px 10px;font-size:12px;display:grid;gap:4px}
.legend span{display:flex;align-items:center;gap:7px}
.lg{width:12px;height:12px;border-radius:50%;display:inline-block}
.lg-real{background:var(--real)}.lg-test{background:var(--test-soft);border:2px dashed var(--test)}.lg-stop{background:#fff;border:3px solid var(--ink)}
.map-btn{position:absolute;right:12px;top:12px;z-index:500;background:#fff;border:1px solid var(--line);box-shadow:0 1px 6px #0f172a1f;width:38px;height:38px;padding:0;font-size:18px}
.map-note{position:absolute;right:12px;bottom:22px;z-index:500;font-size:11.5px;background:#ffffffd9;padding:3px 8px;border-radius:6px;color:#475569}

/* leaflet custom icons */
.pin{width:30px;height:30px;border-radius:50% 50% 50% 0;transform:rotate(-45deg);background:var(--real);border:3px solid #fff;box-shadow:0 2px 6px #0003;display:flex;align-items:center;justify-content:center}
.pin span{transform:rotate(45deg);color:#fff;font-weight:700;font-size:12px}
.pin.test{background:var(--test-soft);border:2px dashed var(--test)}.pin.test span{color:#9a3412}
.stop-ic{width:24px;height:24px;border-radius:50%;background:#fff;border:3px solid var(--ink);color:var(--ink);font-size:11px;font-weight:800;display:flex;align-items:center;justify-content:center;box-shadow:0 1px 4px #0004}
.stop-ic.test{border:3px dashed var(--test);color:#9a3412;background:var(--test-soft)}
.stop-ic.now{background:#dc2626;border-color:#fff;color:#fff;width:28px;height:28px}
.stop-ic.start{background:var(--ok);border-color:#fff;color:#fff}
.arrow-ic{width:14px;height:14px;display:flex;align-items:center;justify-content:center}
.arrow-ic svg{width:14px;height:14px}
.leaflet-popup-content{font-family:inherit;font-size:13px;line-height:1.45}

@media (max-width:900px){
  .layout{grid-template-columns:1fr;grid-template-rows:45vh 1fr}
  .map-wrap{order:-1}.side{border-right:0;border-top:1px solid var(--line)}
  .tiles{grid-template-columns:repeat(2,1fr)}
  .who,.map-note{display:none}
  .btn.action{padding:9px 11px;font-size:13px}
  .topbar{padding:0 12px}.btn.ghost-light{padding:7px 10px;font-size:13px}
  .legend{left:8px;bottom:22px;padding:5px 8px;font-size:11px;gap:2px}
}
