:root {
  color-scheme: light dark;
  --bg: #eef1f3; --panel: #e1e6ea; --card: #fff; --ink: #0f1418; --mute: #5b6670; --line: #c5cdd4;
  --accent: #0b6b6b; --accent-ink: #fff; --danger: #d32f2f; --warn: #b45309; --ok: #18794e; --hover: #f3f6f8;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14181b; --panel: #1d2226; --card: #21272c; --ink: #e9eef2; --mute: #9aa6b0; --line: #3a434a;
    --accent: #3bb3b3; --accent-ink: #0b1414; --danger: #ff6b6b; --warn: #f5a524; --ok: #4ade80; --hover: #2a3137; }
}
* { box-sizing: border-box; min-width: 0; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 19px; margin: 2px 0 0; overflow-wrap: anywhere; } h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--mute); margin: 0 0 8px; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
  background: var(--card); border-radius: 7px; cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; font-size: 14px; }
button:hover, .btn:hover { background: var(--hover); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
button.link { border: 0; background: none; color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input, select, textarea { min-height: 36px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); padding: 0 10px; width: 100%; }
textarea { padding: 8px 10px; resize: vertical; }
input[type=checkbox] { width: 17px; height: 17px; min-height: 0; accent-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled { background: var(--bg); color: var(--mute); }
.sp { flex: 1; }
.hint { color: var(--mute); font-size: 13px; margin: 6px 0; }
.warn { color: var(--warn); font-style: normal; font-size: 13px; }
.ok { color: var(--ok); font-size: 13.5px; margin: 6px 0; }
.empty { color: var(--mute); padding: 14px 4px; }
.sw { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; flex: none; }
.sw.sq { border-radius: 2px; height: 4px; width: 16px; vertical-align: 3px; }
.st { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; flex: none; }

/* top bar */
.top { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 20; }
.brand { font-weight: 800; font-size: 18px; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.crumbs { display: flex; gap: 8px; align-items: center; overflow: hidden; white-space: nowrap; }
.crumbs a { color: var(--ink); text-decoration: none; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.crumbs span { color: var(--mute); }
.umenu { position: relative; }
.udrop { position: absolute; right: 0; top: 42px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); min-width: 190px; padding: 4px; display: flex; flex-direction: column; }
.udrop[hidden] { display: none; }
.udrop button, .udrop a { border: 0; justify-content: flex-start; width: 100%; background: none; padding: 0 10px; min-height: 36px; display: flex; align-items: center; color: var(--ink); text-decoration: none; border-radius: 6px; font-size: 14px; }
.udrop button:hover, .udrop a:hover { background: var(--hover); }
.udrop a[hidden] { display: none; }

/* pages */
.page { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
.phead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin: 10px 0 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: var(--shadow); }
.pcard { color: var(--ink); text-decoration: none; display: block; } .pcard:hover { border-color: var(--accent); }
.pcard h3 { font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 0 0 4px; }
.pcard.arch { opacity: .7; }
.counts { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13.5px; margin: 8px 0; }
details summary { cursor: pointer; padding: 6px 0; }
.login { display: grid; place-items: center; min-height: calc(100vh - 52px); padding: 16px; }
.login form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 4px; }
.login button.primary { margin-top: 8px; }

/* forms */
.fld { display: flex; flex-direction: column; gap: 3px; margin: 0 0 9px; }
.fld > span { font-size: 12.5px; color: var(--mute); font-weight: 600; }
.chk { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.row select, .row input { flex: 1 1 140px; width: auto; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; margin: 4px 0; }
.kv dt { color: var(--mute); } .kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

/* project shell */
.proj { display: flex; flex-direction: column; height: calc(100vh - 52px); height: calc(100dvh - 52px); }
.ptabs { display: flex; align-items: flex-end; gap: 2px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; flex: none; }
.ptabs a, .ptabs .sync { flex: none; }
.ptabs a { padding: 10px 14px 9px; color: var(--mute); text-decoration: none; font-weight: 600; font-size: 14px; border-bottom: 3px solid transparent; white-space: nowrap; }
.ptabs a.on { color: var(--ink); border-bottom-color: var(--accent); }
.sync { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--mute); padding: 0 4px 11px; white-space: nowrap; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.sync.err .dot { background: var(--danger); }
.pbody { flex: 1; min-height: 0; overflow: auto; }
.pbody.tab-map { overflow: hidden; }

/* map */
.mapwrap { display: grid; grid-template-columns: minmax(0, 1fr) 360px; height: 100%; }
.maparea { display: flex; flex-direction: column; min-height: 0; }
.maptools { display: flex; gap: 6px; padding: 7px 10px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; flex: none; }
.maptools label { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 0 9px; min-height: 30px; white-space: nowrap; cursor: pointer; flex: none; }
.stage { position: relative; flex: 1; min-height: 0; background: #f7f8f9; overflow: hidden; }
svg.map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; cursor: grab; display: block; }
svg.map.crosshair { cursor: crosshair; }
svg.map .dev, svg.map .lnk polyline:first-child, svg.map .bend, svg.map .rot { cursor: pointer; }
svg.map text { font-family: system-ui, sans-serif; pointer-events: none; }
.zoombtns { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
.zoombtns button { min-width: 42px; padding: 0 8px; font-size: 17px; box-shadow: var(--shadow); }
.zoombtns button:last-child { font-size: 12.5px; }
.modebar { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; background: var(--ink); color: var(--bg);
  padding: 6px 6px 6px 14px; border-radius: 9px; font-size: 13.5px; max-width: calc(100% - 20px); box-shadow: var(--shadow); }
.modebar[hidden], .noplan[hidden], .legend[hidden] { display: none; }
.modebar span { overflow: hidden; text-overflow: ellipsis; }
.modebar button { min-height: 30px; }
.noplan { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: var(--card); border: 1px solid var(--line); padding: 12px 16px; border-radius: 9px; color: var(--mute); text-align: center; max-width: 80%; }
.legend { position: absolute; left: 10px; bottom: 10px; background: color-mix(in srgb, var(--card) 94%, transparent); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 13px; min-width: 170px; }
.legend div { display: flex; align-items: center; } .legend b { margin-left: auto; padding-left: 12px; }

/* side panel */
.side { background: var(--card); border-left: 1px solid var(--line); overflow-y: auto; }
.sec { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.sec.head { position: relative; padding-right: 44px; }
.sec.head .sub { font-size: 13px; color: var(--mute); }
.sec.head .x { position: absolute; right: 10px; top: 10px; min-height: 30px; width: 30px; padding: 0; font-size: 18px; }
.kindbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.kindbtns button { justify-content: flex-start; font-size: 13px; padding: 0 8px; }
.dlist { list-style: none; margin: 6px 0 0; padding: 0; }
.dlist li { display: flex; align-items: center; gap: 6px; padding: 6px 4px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px; }
.dlist li:hover { background: var(--hover); }
.dlist li.empty { cursor: default; }
.dlist b { white-space: nowrap; }
.dlist .ds { color: var(--mute); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ports { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; }
.port { flex-direction: column; min-height: 40px; padding: 2px; font-size: 13px; font-weight: 700; gap: 0; }
.port small { font-size: 9.5px; font-weight: 500; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.port.on { background: color-mix(in srgb, var(--accent) 18%, var(--card)); border-color: var(--accent); }

/* tables */
.tbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; left: 0; z-index: 3; }
.tbar input[type=search] { width: 220px; flex: 0 1 220px; }
.tbar select { width: auto; }
.cnt { color: var(--mute); font-size: 13px; }
.pad { padding: 0 14px; }
.tablewrap { overflow: auto; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13.5px; background: var(--card); }
table.grid th { position: sticky; top: 0; background: var(--panel); text-align: left; font-size: 12px; color: var(--mute); font-weight: 700; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: default; z-index: 1; }
table.grid th[data-sort] { cursor: pointer; } table.grid th[data-sort]:hover { color: var(--ink); }
table.grid td { padding: 2px 3px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid.ro td { padding: 7px 6px; }
table.grid td input, table.grid td select { min-height: 30px; border-color: transparent; background: transparent; padding: 0 6px; min-width: 70px; border-radius: 5px; }
table.grid td input[data-f=name] { min-width: 150px; font-weight: 600; }
table.grid td input[data-f=mount], table.grid td input[data-f=model] { min-width: 170px; }
table.grid td input[data-f=ip], table.grid td input[data-f=mac], table.grid td input[data-f=serial] { min-width: 125px; }
table.grid td input[data-f=ports], table.grid td input[data-f=vlan] { min-width: 60px; width: 70px; }
table.grid td select { min-width: 140px; }
table.grid td input:hover, table.grid td select:hover { border-color: var(--line); }
table.grid td input:focus, table.grid td select:focus { border-color: var(--accent); background: var(--card); }
table.grid td input:disabled { background: transparent; }
table.grid td.dup, table.grid td.dup input { color: var(--danger); font-weight: 700; }
table.grid td.num, table.grid th.num { text-align: right; padding-right: 10px; }
table.grid td.acts { text-align: right; } table.grid td.acts button { min-height: 28px; padding: 0 8px; font-size: 12.5px; }
table.grid tr.off td { opacity: .5; }
table.grid tr.tot td { font-weight: 700; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; padding: 16px; align-items: start; }
.card.wide { grid-column: 1 / -1; }
.bar { display: grid; grid-template-columns: 130px 1fr 40px; align-items: center; gap: 8px; margin: 6px 0; font-size: 13.5px; }
.bar i { display: block; height: 10px; border-radius: 5px; min-width: 2px; }
.bar b { text-align: right; }
.errs { font-size: 13px; max-height: 240px; overflow: auto; }

/* log */
.logwrap { max-width: 900px; margin: 0 auto; padding: 12px 16px; }
.log { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.log li { display: grid; grid-template-columns: 110px 140px 1fr; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.log li:last-child { border-bottom: 0; }
.log .tm { color: var(--mute); font-size: 13px; }
.log li span:last-child { overflow-wrap: anywhere; }
.log li.empty { display: block; }

/* modal & toast */
dialog.modal { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--card); color: var(--ink); width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog.modal::backdrop { background: rgba(0,0,0,.35); }
dialog.modal form { padding: 18px; }
dialog.modal h2 { margin: 0 0 12px; }
.mbody p { margin: 0 0 10px; }
.mact { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; transition: .2s; background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 9px; font-size: 14px; z-index: 100; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

@media (max-width: 900px) {
  .pbody.tab-map { overflow: auto; }
  .mapwrap { grid-template-columns: 1fr; height: auto; }
  .maparea { height: 68vh; min-height: 380px; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .log li { grid-template-columns: 1fr; gap: 2px; }
  .cards { grid-template-columns: 1fr; padding: 12px; }
}
@media (max-width: 560px) {
  .top { padding: 0 10px; gap: 6px; }
  .ubtn { max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
  .tbar input[type=search] { flex: 1 1 100%; width: 100%; }
  .two { grid-template-columns: 1fr; }
  .page { padding: 14px 12px 30px; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
