:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --accent: #1f2937; --accent-ink: #fff; --warn: #b45309; --warn-bg: #fef3c7; --danger: #b91c1c;
  --unused: #f1f2f4; --active: #dfe3ea; --hover: #e4e7ec; --sidebar: #eceef2; --head: #fafafb; --focus: #fff; --toolbar: rgba(245, 246, 248, .94);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
button { font: inherit; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); cursor: pointer; }
button:hover { border-color: #c7cbd2; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.icon { padding: 2px 8px; border: none; background: none; font-size: 18px; line-height: 1; color: var(--muted); }
button.icon.danger:hover { color: var(--danger); }
button.add { margin-top: 8px; border-style: dashed; color: var(--muted); background: none; }
input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: var(--warn); }
.badge { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); font-size: 12px; font-weight: 600; }

/* 첫 화면 */
.home { max-width: 760px; margin: 48px auto; padding: 0 20px; }
.home-head { display: flex; gap: 14px; align-items: center; }
.home-head h1 { margin: 0; font-size: 28px; }
.home-head p { margin: 2px 0 0; }
.logo { width: 52px; height: 52px; }
.actions { display: flex; gap: 8px; margin: 24px 0 8px; }
.empty { margin-top: 24px; padding: 32px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; }
.show-list { list-style: none; padding: 0; margin: 20px 0; display: grid; gap: 8px; }
.show-list li { display: flex; align-items: center; gap: 6px; }
.show-item { flex: 1; display: grid; gap: 3px; text-align: left; padding: 12px 14px; background: var(--panel); }
.show-item strong { font-size: 16px; }

/* 온라인 프로젝트 */
.online { margin: 28px 0 8px; padding: 16px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.online h2 { margin: 0 0 10px; font-size: 18px; }
.online-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.online-head h2 { margin: 0; }
.login-row { display: flex; gap: 8px; }
.login-row input { flex: 1; min-width: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.group-bar { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; flex-wrap: wrap; }
.group-bar select, .stack select, .stack input { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.online .show-list { margin: 10px 0 0; }
.local-title { margin: 28px 0 0; font-size: 18px; }
.cloud-tag { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 999px; background: var(--active); font-size: 12px; }
button.link { border: none; background: none; padding: 2px 4px; color: var(--muted); text-decoration: underline; }
.danger-text { color: var(--danger) !important; }
.dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 18px 20px; width: min(520px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .35); }
.dialog h3 { margin: 0 0 12px; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.stack { display: grid; gap: 8px; }
.stack label { display: flex; align-items: center; gap: 8px; }
.stack label input, .stack label select { flex: 1; }
.rev-list, .member-list, .conflict-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 50vh; overflow: auto; }
.rev-list li, .member-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.conflict-list li { display: grid; gap: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.invite { font-size: 13px; }

/* 개요: 맥 앱의 묶음 폼 */
.card-section { margin-bottom: 26px; }
.card-section h3 { margin: 0 0 8px 12px; font-size: 14px; }
.card { background: var(--panel); border-radius: 10px; border: 1px solid var(--line); }
.card > * + * { border-top: 1px solid var(--line); }
.card-row { display: flex; align-items: center; gap: 16px; min-height: 46px; padding: 6px 14px; }
.card-label { flex: none; max-width: 50%; }
.card-value { flex: 1; display: flex; justify-content: flex-end; align-items: center; gap: 10px; min-width: 0; }
.card-value input:not([type="checkbox"]), .card-value textarea { width: 100%; border: none; background: none; text-align: right; padding: 4px 2px; outline: none; resize: none; }
.card-value input[type="date"], .card-value input[type="time"] { width: auto; text-align: left; border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; }
.card-foot { margin: 6px 12px 0; font-size: 12px; color: var(--muted); }
.moment { display: inline-flex; align-items: center; gap: 2px; }
button.clear { border: none; background: none; color: var(--muted); padding: 0 4px; font-size: 15px; }
.switch { appearance: none; width: 38px; height: 22px; border-radius: 11px; background: var(--line); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: left .15s; }
.switch:checked { background: #0a84ff; }
.switch:checked::after { left: 18px; }
.contact-row { display: grid; grid-template-columns: 1.3fr 1fr 1.1fr 1.1fr 1.4fr 28px; gap: 8px; align-items: center; padding: 6px 14px; min-height: 46px; }
.contact-row input { width: 100%; min-width: 0; border: none; background: none; padding: 4px 2px; outline: none; }
.contact-row input:focus, .card-value input:focus, .card-value textarea:focus { background: var(--focus); border-radius: 5px; }
.contact-row .icon { visibility: hidden; }
.contact-row:hover .icon { visibility: visible; }
button.row-add { display: block; width: 100%; text-align: left; border: none; border-radius: 0 0 10px 10px; background: none; color: var(--muted); padding: 12px 14px; }

/* 편집 화면 */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { display: flex; flex-direction: column; gap: 6px; padding: 14px 10px; background: var(--sidebar); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; }
.back { align-self: flex-start; border: none; background: none; color: var(--muted); padding: 4px 6px; }
.show-title { font-weight: 700; padding: 4px 8px 10px; }
.sidebar nav { display: grid; gap: 2px; }
.nav-row { display: flex; align-items: center; gap: 9px; padding: 7px 8px 7px 10px; border-radius: 8px; cursor: pointer; user-select: none; }
.nav-row:hover { background: var(--hover); }
.nav-row.active { background: var(--active); }
.nav-icon { display: inline-flex; width: 18px; height: 18px; color: var(--muted); }
.nav-icon svg { width: 18px; height: 18px; }
.nav-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pdf-check { width: 16px; height: 16px; margin: 0; accent-color: #0a84ff; cursor: pointer; }
.sidebar-foot { margin-top: auto; padding: 8px; display: grid; gap: 4px; }
main { min-width: 0; }
.toolbar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 10px 20px; background: var(--toolbar); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.spacer { flex: 1; }
#save-status { font-size: 13px; color: #047857; }
#save-status[data-kind="pending"] { color: var(--muted); }
#save-status[data-kind="error"] { color: var(--danger); font-weight: 700; }
.content { padding: 20px; }

.form { max-width: 980px; margin: 0 auto; }
.form h3 { margin: 24px 0 8px; font-size: 15px; }
.form h3:first-child { margin-top: 0; }
.form-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; margin: 6px 0; }
.form-row > div { display: flex; gap: 8px; }
.form-row input, textarea { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.form-row input[type="date"], .form-row input[type="time"] { width: auto; }
textarea { resize: vertical; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 7px 8px; background: var(--head); border-bottom: 1px solid var(--line); }
td { padding: 1px 2px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: none; }
td input:not([type="checkbox"]), td select { width: 100%; min-width: 60px; padding: 6px 6px; border: 1px solid transparent; border-radius: 5px; background: transparent; font-weight: 600; }
td input:focus, td select:focus { outline: none; border-color: #9ca3af; background: var(--focus); }
td.narrow { width: 76px; }
td.narrow input { min-width: 0; }
td.wide { width: 40%; }
td.center { text-align: center; }
td:last-child { width: 32px; }
tr.unused td { background: var(--unused); }
tr.unused input { font-weight: 400; color: var(--muted); }

.group { margin-bottom: 22px; }
.group-head input, .rack-head input.rack-name { font-size: 17px; font-weight: 700; border: none; background: none; padding: 4px 2px; }
.subgroup { margin: 10px 0 0 14px; }
.subgroup-head input { font-weight: 700; border: none; background: none; padding: 4px 2px; }
.rack { margin-bottom: 26px; }
.rack-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.rack-head input:not(.rack-name) { flex: 1; border: none; background: none; color: var(--muted); padding: 4px; }

.print-all { display: none; }

/* 다크 모드 (맥 앱처럼 시스템 설정을 따른다) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1f21; --panel: #2a2b2e; --ink: #ececec; --muted: #9a9ca1; --line: #3a3b3f;
    --accent: #0a84ff; --accent-ink: #fff; --warn: #fbbf24; --warn-bg: #3d3214; --danger: #f87171;
    --unused: #242528; --active: #3a3b3f; --hover: #303135; --sidebar: #252629; --head: #2f3033; --focus: #34353a;
    --toolbar: rgba(30, 31, 33, .94);
    color-scheme: dark;
  }
  #save-status { color: #34d399; }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { grid-template-columns: repeat(4, auto); }
  .content { padding: 12px; overflow-x: auto; }
}

@media print {
  .sidebar, .toolbar, .content, button { display: none !important; }
  .shell { display: block; }
  .print-all { display: block; }
  .print-all section { break-inside: avoid-page; margin-bottom: 18px; }
  .print-all h1 { margin: 0 0 2px; }
  .print-all h2 { font-size: 16px; border-bottom: 2px solid #000; padding-bottom: 3px; }
  table { border-radius: 0; }
  td input, td select { font-size: 11px; padding: 2px 4px; }
  textarea { border: none; }
}

/* 자동 완성 목록 */
.suggest { position: fixed; z-index: 20; margin: 0; padding: 4px; list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: 320px; }
.suggest li { padding: 5px 10px; border-radius: 5px; cursor: pointer; white-space: nowrap; }
.suggest li:hover, .suggest li.on { background: #0a84ff; color: #fff; }

/* 장비 이름 옆 I/O 사용 횟수 */
.name-cell { display: flex; align-items: center; gap: 6px; }
.name-cell input { flex: 1; }
.io-badge { flex: none; font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); background: rgba(127,127,127,.14); padding: 1px 6px; border-radius: 999px; }
.io-badge.short { color: #f59e0b; background: rgba(245,158,11,.14); }
