:root {
  /* Warm neutral greys after the Claude desktop app (docs/layout/: measured 2026-10-19). Depth comes from lightness:
     sidebar → main → raised surfaces get lighter in dark mode; text has three levels. Accent and status are our own. */
  --side-bg: #fafaf9;
  --bg: #fcfcfb;
  --surface: #ffffff;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #6b6964;
  --muted: var(--text-2);
  --line: rgb(0 0 0 / 10%);
  --neutral-bg: #f1f0ed;
  --accent: #1f5fd6;
  --accent-text: #ffffff;
  --ok: #197a35;
  --ok-bg: #dafbe1;
  --warn: #8f6000;
  --warn-bg: #fff4d4;
  --info: #0969da;
  --info-bg: #ddf4ff;
  --danger: #cf222e;
  --danger-text: #ffffff;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Every text colour above reaches 4.5:1 on the backgrounds it sits on, in both modes (test/contrast.test.ts) */
  /* a dense type scale; hierarchy mostly from --text / --text-2 / --text-3 */
  --fs-1: 11px;
  --fs-2: 12px;
  --fs-3: 13px;
  --fs-4: 14px;
  --fs-5: 15px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --side-bg: #111111;
    --bg: #151515;
    --surface: #20201f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #97958f;
    --line: rgb(255 255 255 / 10%);
    --neutral-bg: #2a2a28;
    --accent: #5292ff;
    --accent-text: #0b0b0b;
    --ok: #56d364;
    --ok-bg: #12261a;
    --warn: #e3b341;
    --warn-bg: #2a2110;
    --info: #79c0ff;
    --info-bg: #10233a;
    --danger: #ff7b72;
    --danger-text: #0b0b0b;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-4)/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

.check { display: flex; gap: 4px; align-items: center; color: var(--muted); white-space: nowrap; }

button, .btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 13px; text-decoration: none; cursor: pointer; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.status { margin: 10px 16px 0; color: var(--muted); font-size: 12px; }
.status.error { color: var(--danger); }

main { padding: 8px 16px 40px; max-width: 1100px; margin: 0 auto; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

.row {
  display: grid; grid-template-columns: 76px 1fr auto; gap: 4px 14px; align-items: center;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.row.system { opacity: .7; }
.port { font: 600 18px var(--mono); }
.main { min-width: 0; }
.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.badge { padding: 1px 7px; border-radius: 999px; font-size: 11px; background: var(--neutral-bg); color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--info); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.more { grid-column: 1 / -1; }
.more summary { color: var(--muted); font-size: 12px; cursor: pointer; width: max-content; }
.more dl { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; margin: 8px 0 0; font-size: 12px; }
.more dt { color: var(--muted); }
.more dd { margin: 0; font-family: var(--mono); word-break: break-all; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 13px; box-shadow: 0 6px 24px rgb(0 0 0 / .2);
}
.toast.error { background: var(--danger); color: var(--danger-text); }

@media (max-width: 640px) {
  .row { grid-template-columns: 60px 1fr; }
  .port { font-size: 16px; }
  .actions { grid-column: 1 / -1; justify-content: flex-start; }
}
.toast a { color: inherit; font-weight: 600; }

/* pin + name */
.name-line { display: flex; align-items: center; gap: 4px; min-width: 0; }
.pin {
  flex: none; padding: 0 2px; border: 0; background: none;
  color: var(--muted); font-size: 15px; line-height: 1; opacity: .55;
}
.pin:hover { opacity: 1; border: 0; }
.pin.on { color: #d4a72c; opacity: 1; }

/* ⋯ menu */
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer;
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  font-size: 13px; line-height: 1.2;
}
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 3;
  display: grid; min-width: 150px; padding: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .08);
}
.menu-panel button { border: 0; justify-content: flex-start; width: 100%; }
.menu-panel button:hover { background: var(--neutral-bg); }
.menu-panel button.danger { color: var(--danger); }

/* logs dialog */
.logs {
  width: min(960px, calc(100vw - 24px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
.logs::backdrop { background: rgb(0 0 0 / .4); }
.logs[open] { display: flex; flex-direction: column; }
.logs header {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.logs-source { color: var(--muted); font: 12px var(--mono); }
.logs-controls { display: flex; gap: 6px; align-items: center; }
.logs-controls select {
  padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
}
.logs pre {
  flex: 1; margin: 0; padding: 12px 14px; overflow: auto; min-height: 200px;
  font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-all;
}

/* devices strip */
.devices {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; margin-bottom: 4px;
  scrollbar-width: thin;
}
.device {
  flex: none; min-width: 170px; max-width: 250px; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; cursor: default;
}
.device.self { border-color: var(--accent); }
.device-head { display: flex; align-items: center; gap: 6px; min-width: 0; }
.device-head strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-os { color: var(--muted); font-size: 11px; margin-left: auto; white-space: nowrap; }
.device-line {
  color: var(--muted); font-size: 12px; margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.device.ok .dot { background: var(--ok); }
.device.warn .dot { background: var(--warn); }
.device.bad .dot { background: var(--danger); }
.device.off { opacity: .65; }

/* 사용 중: who is using this port right now */
.users { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 5px; }
.user-chip {
  padding: 1px 8px; border-radius: 999px; font-size: 12px; text-decoration: none;
  border: 1px solid var(--line); color: var(--text); background: var(--surface);
}
.user-chip::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: var(--muted); vertical-align: 1px; }
.user-chip.u-tailnet::before, .user-chip.u-pool::before { background: var(--accent); }
.user-chip.u-lan::before, .user-chip.u-other::before { background: var(--warn); }
.user-chip.u-local { color: var(--muted); }
.user-chip.u-routed { border-style: dashed; color: var(--muted); }
.user-chip.u-routed::before { background: var(--accent); opacity: .5; }
.user-chip:hover { border-color: var(--muted); }
.count-pill { color: var(--muted); font-variant-numeric: tabular-nums; }

/* other machines' listening ports (hostports.js): 기기 cards and the 서비스 tab's host view */
.hports { list-style: none; margin: 6px 0 0; padding: 0; display: grid; }
.hports li { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 5px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--text); }
.hports li:first-child { border-top: 0; }
.hp-name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; min-width: 0; }
.hp-port { font: 600 13px var(--mono); min-width: 3.6em; }
.hp-proc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22ch; }
.hp-proc.unknown { color: var(--muted); font-size: 12px; }
.hp-open { flex: none; color: var(--accent); font-size: 13px; text-decoration: none; }
.hp-open:hover { text-decoration: underline; }
.hp-more { color: var(--muted); font-size: 12px; }
.hports .tag { padding: 0 6px; border-radius: 999px; font-size: 11px; background: var(--neutral-bg); color: var(--muted); }
.hports .tag.info { color: var(--info); background: var(--info-bg); }
.hports .tag.warn { color: var(--warn); background: var(--warn-bg); }
.remote { margin-top: 4px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.remote-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 4px; }
.remote-head strong { font-size: 15px; }
.remote-head span { color: var(--muted); font-size: 13px; }
.remote .hports li { padding: 8px 0; font-size: 14px; }
.remote-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.list[hidden], .remote[hidden] { display: none; }
#hostSel {
  flex: none; max-width: 15em; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
}
.check:has(input:disabled) { opacity: .5; }
/* grouped ports: one card per compose project / unit / process, a sub-row per port */
.group { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding-top: 10px; }
.group.system { opacity: .7; }
.group .row.system { opacity: 1; }
.group-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 0 14px 6px; min-width: 0; }
.group-name { font-weight: 650; }
.group-meta { color: var(--muted); font-size: 12px; }
.sub { list-style: none; margin: 0; padding: 0; }
.row.sub { border: 0; border-top: 1px solid var(--line); border-radius: 0; background: transparent; padding: 10px 14px; }
.row.sub .port { font-size: 15px; color: var(--muted); }
.last-used { color: var(--muted); font-size: 12px; margin-top: 4px; }
.last-used::before { content: '◷ '; }

/* down alerts (alerts.js) */
.bell { padding: 0 3px; border: 0; background: none; font-size: 13px; line-height: 1; opacity: .28; filter: grayscale(1); }
.bell:hover { opacity: .8; border: 0; }
.bell.on { opacity: 1; filter: none; }
.name-line .bell { order: 3; }
.alerts-btn { padding: 4px 9px; }
.alerts-btn.alarm { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
.alerts-btn.none { opacity: .6; }
.badge.bad { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }
.row.missing { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.row.missing .port { color: var(--danger); }
.alerts-dlg {
  width: min(560px, calc(100vw - 24px)); max-height: 85vh; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
.alerts-dlg::backdrop { background: rgb(0 0 0 / .4); }
.alerts-dlg header { display: flex; justify-content: space-between; align-items: center; }
.alerts-dlg header strong { font-size: 15px; }
.alerts-dlg h4 { margin: 14px 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.alerts-channel { margin: 10px 0 0; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.alerts-channel.ok { background: var(--ok-bg); }
.alerts-channel.ok strong { color: var(--ok); }
.alerts-channel.bad { background: var(--warn-bg); }
.alerts-channel.bad strong { color: var(--warn); }
.alerts-list, .alerts-recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.alerts-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; flex-wrap: wrap; }
.alerts-item .dot.ok { background: var(--ok); }
.alerts-item .dot.warn { background: var(--warn); }
.alerts-item .dot.bad { background: var(--danger); }
.alerts-port { font: 600 12px var(--mono); color: var(--muted); min-width: 36px; }
.alerts-state { font-size: 12px; color: var(--muted); }
.alerts-state.bad { color: var(--danger); }
.alerts-state.warn { color: var(--warn); }
.alerts-off { margin-left: auto; padding: 2px 8px; font-size: 12px; }
.alerts-recent { color: var(--muted); font-size: 12px; }
.alerts-recent time { font-family: var(--mono); font-size: 11px; }
.alerts-recent .failed { color: var(--danger); }
.alerts-help { color: var(--muted); font-size: 12px; margin: 14px 0 0; }
.alerts-dlg footer { display: flex; justify-content: flex-end; margin-top: 12px; }
.muted { color: var(--muted); }

/* service detail link + uptime bars (uptime.js) */
a.name { color: inherit; text-decoration: none; }
a.name:hover { text-decoration: underline; text-underline-offset: 2px; }
.uptime-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.uptime-pct { font-variant-numeric: tabular-nums; }
.ubar { display: inline-flex; gap: 2px; align-items: stretch; height: 14px; }
.ubar i { width: 4px; border-radius: 2px; background: var(--line); }
.ubar i.up { background: var(--ok); }
.ubar i.down { background: var(--danger); }
.ubar i.quiet { background: var(--warn); }

/* self-watch chip and dialog (selfwatch.js) */
.sw-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.sw-chip[hidden] { display: none; }
.sw-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.sw-chip.warn { color: var(--warn); }
.sw-chip.warn .sw-dot { background: var(--warn); }
.sw-chip.alarm { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
.sw-chip.alarm .sw-dot { background: var(--danger); }
.sw-dlg .alerts-item .dot.muted { background: var(--line); }
.sw-dlg .alerts-state.muted { color: var(--muted); }
@media (max-width: 640px) {
  .sw-chip:not(.alarm):not(.warn) .sw-text { display: none; }
}
/* preview instance badge (profile.js) */
.profile-badge { flex: none; padding: 1px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); font-size: 12px; font-weight: 600; white-space: nowrap; }

/* owners and cleanup (owners.js) */
.owners-banner { margin: 0 0 12px; padding: 10px 14px; border: 1px solid var(--warn); border-radius: 10px; background: var(--warn-bg); }
.owners-banner[hidden] { display: none; }
.owners-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.owners-actions { display: flex; align-items: center; gap: 6px; }
.owners-ended { margin: 6px 0 0; font-size: 13px; }
.owners-banner .menu-panel { min-width: 240px; }
.owners-banner .menu-panel .muted { padding: 4px 8px; }
.owners-list { margin: 8px 0 4px; padding-left: 18px; font-size: 13px; }
.owners-list .muted, .owners-banner .muted { color: var(--muted); font-size: 12px; }
.owner-badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 설정 체크리스트 chip (onboarding.js), a link to the 설정 tab */
.ob-chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; font-size: 12px; white-space: nowrap; color: var(--accent, var(--text)); }
.ob-chip[hidden] { display: none; }
.ob-chip.warn { color: var(--warn); }
.ob-icon { font-size: 13px; line-height: 1; }
.sw-runbook { flex-basis: 100%; padding-left: 16px; font-size: 12px; }
/* Smart defaults (features/suggestions.js): 🔔 알림 켜기? on a 서비스 row, 추천 이름 on a 기기 card */
.sg-chip, .sg-name { display: inline-flex; align-items: center; gap: 4px; }
.sg-chip { background: var(--info-bg); color: var(--info); padding-right: 3px; }
.sg-name { margin-top: 6px; font-size: 13px; color: var(--info); flex-wrap: wrap; }
.sg-chip button, .sg-name button { padding: 0 7px; font-size: 11px; line-height: 18px; border-radius: 999px; }
.sg-chip .sg-yes, .sg-name .sg-yes { color: var(--info); border-color: color-mix(in srgb, var(--info) 45%, var(--line)); }
.sg-chip .sg-no, .sg-name .sg-no { color: var(--muted); }
.sg-chip.sg-idle { background: var(--neutral-bg); color: var(--muted); }
/* 읽기 전용 (lib/access.js, #29): not the owner — write controls look disabled and a line under the header says why */
.readonly-note { margin: 8px auto 0; width: calc(100% - 32px); max-width: 1068px; box-sizing: border-box; padding: 7px 12px; border-radius: 8px; font-size: 13px; background: var(--warn-bg); color: var(--warn); }
html[data-readonly] [data-write] { opacity: .45; pointer-events: none; cursor: not-allowed; }
/* 기록 (lib/audit.js, #30): service.html's 기록 section and the dashboard's 최근 기록 */
.audit-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.audit-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; min-width: 0; }
.audit-list time { font: 12px var(--mono); color: var(--muted); min-width: 9em; }
.audit-list .audit-target { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.audit-list .badge { margin-left: auto; }
.audit-recent { margin: 18px 0 6px; font-size: 13px; }
.audit-recent summary { cursor: pointer; color: var(--muted); }
.audit-recent .audit-list { margin-top: 8px; }
.audit-recent p { margin: 6px 0 0; font-size: 12px; }
