:root {
  --navy: #12264a; --navy2: #1d3866; --cream: #f6f1e6; --cream2: #fbf8f1; --gold: #e0a100;
  --ok: #2e7d32; --warn: #b07d00; --bad: #c62828; --line: #e2dccd; --text: #1c2333; --muted: #6b7280;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; color: var(--text); background: var(--cream2); }
a { color: var(--navy2); cursor: pointer; }
h2 { margin: 4px 0 12px; color: var(--navy); font-size: 22px; }
h4 { margin: 0 0 10px; color: var(--navy); font-size: 15px; }
h5 { margin: 16px 0 6px; color: var(--navy); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
code { background: #efe9da; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .pad { padding: 18px; }
.err { color: var(--bad); } .warnText { color: #7a5600; font-weight: 600; }
.grow { flex: 1; }

/* layout */
#app { height: 100%; display: flex; flex-direction: column; }
header#hdr { display: flex; align-items: center; gap: 14px; padding: 0 16px; height: 54px; background: var(--navy); color: var(--cream); flex: none; }
.brand { font-size: 17px; letter-spacing: .02em; } .brand b { color: var(--gold); }
.hsel { display: flex; align-items: center; gap: 6px; } .hsel span { opacity: .75; font-size: 12px; }
.hsel select { min-width: 220px; max-width: 320px; background: var(--navy2); color: var(--cream); border: 1px solid #3a5687; text-overflow: ellipsis; }
header .muted { color: #c8cfdc; }
.body { flex: 1; display: flex; min-height: 0; }
nav#nav { width: 230px; flex: none; background: #fff; border-right: 1px solid var(--line); overflow-y: auto; padding: 10px 0; }
nav#nav a { display: flex; align-items: center; gap: 10px; padding: 8px 18px; color: var(--text); text-decoration: none; border-left: 3px solid transparent; }
nav#nav a:hover { background: var(--cream); }
nav#nav a.on { background: var(--cream); border-left-color: var(--gold); font-weight: 600; color: var(--navy); }
nav#nav .ic { width: 20px; text-align: center; }
nav#nav .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); margin-left: auto; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }
.navhead { padding: 14px 18px 4px; font-size: 11px; letter-spacing: .1em; color: var(--muted); font-weight: 700; }
main#main { flex: 1; overflow: auto; padding: 18px 22px 60px; }
.center { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; min-height: 100%; }

/* cards + grids */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.card.wide { max-width: 720px; width: 100%; }
.card.warn { border-left: 4px solid var(--gold); background: #fffbef; }
.card.bad { border-left: 4px solid var(--bad); background: #fff5f5; }
.card.ok { border-left: 4px solid var(--ok); background: #f3faf3; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); gap: 14px; align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 14px; }
.grid2 > .card, .grid3 > .card { margin-bottom: 0; }
.grid2 + *, .grid3 + * { margin-top: 14px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.row.sticky { position: sticky; bottom: -1px; background: #fff; padding: 10px 0; border-top: 1px solid var(--line); margin-top: 14px; }

/* forms */
label { display: block; margin: 8px 0; font-size: 13px; color: #374151; }
label > input[type=text], label > input[type=number], label > input[type=search], label > select, label > textarea, label > .tgt, label > .row { display: flex; width: 100%; margin-top: 4px; }
label.chk { display: flex; align-items: center; gap: 6px; }
input[type=text], input[type=number], input[type=search], select, textarea { font: inherit; padding: 6px 9px; border: 1px solid #cfc7b4; border-radius: 6px; background: #fff; color: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9db4e0; outline-offset: 0; }
textarea { width: 100%; resize: vertical; }
.tgt { display: flex; gap: 6px; flex: 1; } .tgt select, .tgt input { flex: 1; min-width: 0; }
.chkgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0 14px; }
.btn { font: inherit; font-size: 13px; padding: 7px 14px; border-radius: 6px; border: 1px solid #c9c0aa; background: #fff; color: var(--navy); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.btn:hover { background: var(--cream); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; } .btn.primary:hover { background: var(--navy2); }
.btn.danger { color: var(--bad); border-color: #e9b4b4; } .btn.danger:hover { background: #fdecec; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
header .btn { background: transparent; color: var(--cream); border-color: #3a5687; } header .btn:hover { background: var(--navy2); }
.pill { padding: 3px 10px; border-radius: 99px; font-size: 12px; text-decoration: none; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill.ok { background: #244a2a; color: #d7f0d9; } .pill.warn { background: #6b4e00; color: #ffe9a8; }
.tag { padding: 1px 8px; border-radius: 99px; font-size: 11px; background: #eee; }
.tag.ok { background: #e3f3e4; color: #1b5e20; } .tag.warn { background: #fff4cc; color: #7a5600; } .tag.bad { background: #fde3e3; color: var(--bad); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; background: var(--cream); color: var(--navy); font-weight: 600; padding: 7px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.tbl td { padding: 6px 8px; border-bottom: 1px solid #f0ebe0; vertical-align: top; }
.tbl tbody tr:hover { background: #fbf7ee; }
.tbl.edit td { padding: 4px; } .tbl.edit input[type=text] { width: 100%; }
.tbl.files .fname { text-decoration: none; color: var(--text); }
.tbl .acts { white-space: nowrap; text-align: right; } .tbl .acts .btn { margin-left: 3px; }
th.sortable { cursor: pointer; user-select: none; }
.scrollx { overflow: auto; max-height: 70vh; }

/* run panel */
.runpanel .bar { height: 6px; background: #eee6d3; border-radius: 3px; overflow: hidden; margin: 8px 0; }
.runpanel .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--navy2), var(--gold)); transition: width .3s; }
.log { max-height: 180px; overflow: auto; background: #0f1b33; color: #cfe0ff; font: 12px/1.5 Consolas, monospace; padding: 8px 10px; border-radius: 6px; margin: 0; white-space: pre-wrap; }
.log:empty { display: none; }
.clientbar .cname { font-weight: 700; color: var(--navy); font-size: 15px; }

/* trees */
.tree.box { border: 1px solid var(--line); border-radius: 6px; max-height: 420px; overflow: auto; padding: 6px; background: var(--cream2); }
.tnode { display: flex; align-items: center; gap: 4px; padding: 2px 4px; border-radius: 4px; white-space: nowrap; cursor: default; }
.tnode label { margin: 0; display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }
.tnode.on { background: #e9e1cc; font-weight: 600; }
.tnode span { cursor: pointer; }
.tw { width: 14px; display: inline-block; color: var(--muted); }

/* explorer */
.xsplit { display: grid; grid-template-columns: 260px 1fr; gap: 14px; align-items: start; }
.xsplit .tree { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; max-height: 75vh; overflow: auto; }
.xright { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.crumbs { font-size: 14px; margin: 4px 0 8px; } .crumbs a { text-decoration: none; font-weight: 600; }

/* clients editor */
.clients { display: grid; grid-template-columns: 240px 1fr; gap: 16px; }
.clist { display: flex; flex-direction: column; gap: 6px; }
.citem { display: block; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--text); }
.citem.on { border-color: var(--navy); background: var(--cream); }
.cedit { min-width: 0; }
.usedby { margin-top: 14px; padding: 10px; background: var(--cream2); border-radius: 8px; }

/* viewer */
.vtitle { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 15px; flex-wrap: wrap; }
.vtitle .vname { overflow-wrap: anywhere; }
.vtabs { display: flex; gap: 2px; border-bottom: 2px solid var(--navy); margin-bottom: 8px; flex-wrap: wrap; }
.vtab { font: inherit; border: 1px solid var(--line); border-bottom: none; background: #fff; padding: 6px 14px; border-radius: 8px 8px 0 0; cursor: pointer; color: var(--navy); }
.vtab.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.vbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; } .vsearch { min-width: 260px; }
.vgrid { overflow: auto; max-height: calc(100vh - 260px); border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.vtable { border-collapse: collapse; table-layout: fixed; font-size: 12.5px; min-width: 100%; }
.vtable th, .vtable td { border: 1px solid #ece6d8; padding: 4px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: top; }
.vtable thead th { position: sticky; top: 0; background: var(--navy); color: #fff; z-index: 2; text-align: left; }
.vtable thead tr.filters th { top: 27px; background: var(--cream); padding: 2px; }
.vtable thead tr.filters input { width: 100%; padding: 2px 4px; font-size: 11px; border-radius: 3px; }
.vtable.summary td { white-space: pre-wrap; border-color: transparent; }
.vtable tr.lvl1 td:first-child { padding-left: 18px; } .vtable tr.lvl2 td:first-child { padding-left: 30px; } .vtable tr.lvl3 td:first-child { padding-left: 42px; }
.drop { border: 2px dashed #cdbf9d; border-radius: var(--radius); padding: 30px; text-align: center; color: var(--muted); background: #fff; margin-bottom: 12px; }
.drop.over { background: var(--cream); border-color: var(--navy); }

/* pickers + modals */
.picklist { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; margin-top: 8px; }
.picklist.short { max-height: 220px; }
.pickrow { display: flex; gap: 8px; align-items: flex-start; padding: 7px 10px; border-bottom: 1px solid #f1ece1; margin: 0; cursor: pointer; text-decoration: none; color: var(--text); }
.pickrow:hover { background: var(--cream); }
.modal-back { position: fixed; inset: 0; background: rgba(10, 20, 40, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: min(820px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--navy); }
.modal-head .x { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 14px 16px; overflow: auto; }
.modal-foot { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
pre.code { background: #0f1b33; color: #dbe7ff; padding: 10px; border-radius: 6px; font: 12px/1.45 Consolas, monospace; white-space: pre-wrap; word-break: break-all; max-height: 50vh; overflow: auto; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 99; max-width: 440px; }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.error { background: var(--bad); }

@media (max-width: 900px) {
  nav#nav { width: 64px; } nav#nav a { font-size: 0; padding: 10px; justify-content: center; } nav#nav .ic { font-size: 18px; } .navhead { display: none; }
  .xsplit, .clients { grid-template-columns: 1fr; } .hsel select { min-width: 140px; } header .muted, .pill { display: none; }
}

/* PC helper + Run on my PC */
.engsplit { display: grid; grid-template-columns: 260px 1fr; gap: 14px; align-items: start; }
.englist { display: flex; flex-direction: column; gap: 6px; max-height: 75vh; overflow: auto; }
.englist .navhead { padding: 8px 2px 2px; }
.engform { min-width: 0; }
.engform label > .row { margin-top: 4px; }
.modlist { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.card.engine { border-left: 4px solid var(--navy2); background: #f6f8fc; }
.sechead { margin: 18px 0 8px; }
details { margin: 8px 0; } summary { cursor: pointer; color: var(--navy); font-weight: 600; }
pre.desc { white-space: pre-wrap; font: inherit; color: var(--muted); margin: 6px 0; }
@media (max-width: 900px) { .engsplit { grid-template-columns: 1fr; } .englist { max-height: 260px; } }

/* phones: menu becomes a scrolling strip under the header */
@media (max-width: 640px) {
  header#hdr { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 6px 10px; }
  .brand { font-size: 15px; }
  .hsel { order: 5; width: 100%; } .hsel select { flex: 1; min-width: 0; }
  header .grow { display: none; }
  header .btn { margin-left: auto; }
  .body { flex-direction: column; }
  nav#nav { width: 100%; display: flex; overflow-x: auto; padding: 0; border-right: none; border-bottom: 1px solid var(--line); flex: none; -webkit-overflow-scrolling: touch; }
  nav#nav a { font-size: 11px; padding: 6px 10px 5px; flex-direction: column; gap: 1px; border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; justify-content: center; }
  nav#nav a.on { border-bottom-color: var(--gold); }
  nav#nav .ic { font-size: 16px; width: auto; }
  nav#nav .dot { position: absolute; margin: 0 0 0 26px; }
  main#main { padding: 12px 12px 60px; }
  h2 { font-size: 19px; }
  .card { padding: 12px; }
  .vsearch { min-width: 0; flex: 1; }
  .tbl { font-size: 12px; }
  .cedit > div { overflow-x: auto; }
  .tbl.edit { min-width: 540px; }
  .modal-back { padding: 8px; }
  .row.sticky { bottom: -12px; }
  .crumbs { font-size: 13px; }
  .vgrid { max-height: 65vh; }
}

/* review fixes */
label > input.inline, input.inline { display: inline-block !important; width: 6em !important; margin: 0 4px !important; }
.paircode { text-align: center; }
.paircode .code { font: 700 38px/1.2 Consolas, monospace; letter-spacing: .12em; color: var(--navy); background: var(--cream); border-radius: 10px; padding: 14px; margin: 10px auto; display: inline-block; }
.toast { cursor: pointer; }
:focus-visible { outline: 2px solid #4a74c9; outline-offset: 2px; }
@media (max-width: 640px) {
  .row.sticky { position: static; }
  .xright .scrollx { max-height: none; }
  .hsel select { max-width: none; }
}
