/* ===== Design tokens ===== */
:root {
  --paper: #f5f7f2;
  --surface: #ffffff;
  --surface-soft: #eef4f0;
  --ink: #18201c;
  --muted: #65736b;
  --line: #d9e2dc;
  --line-strong: #c4d1c8;

  --teal: #006b5d;
  --teal-soft: #d9eee8;
  --teal-strong: #005a4f;
  --coral: #d95d45;
  --coral-soft: #f8ded7;
  --gold: #bd8b17;
  --gold-soft: #f5e8c9;

  --shadow-sm: 0 2px 8px rgba(24, 32, 28, 0.04);
  --shadow: 0 8px 24px rgba(24, 32, 28, 0.06);
  --shadow-lg: 0 16px 40px rgba(24, 32, 28, 0.08);

  --radius-sm: 7px;
  --radius: 10px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --paper: #0d1311;
  --surface: #18221e;
  --surface-soft: #1e2a25;
  --ink: #e8eee9;
  --muted: #8a988f;
  --line: #2c3833;
  --line-strong: #3a4943;

  --teal: #38c2ad;
  --teal-soft: #163a32;
  --teal-strong: #4cd1bc;
  --coral: #f17a64;
  --coral-soft: #3a201b;
  --gold: #e3b04b;
  --gold-soft: #3d2f10;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .table-wrap table.data th { background: #131c19; }
[data-theme="dark"] table.data tr:hover td { background: #1d2722; }
[data-theme="dark"] .ledger-detail { background: #131c19; }
[data-theme="dark"] .ledger-clickable:hover td { background: #1d2722; }
[data-theme="dark"] .form-grid input, [data-theme="dark"] .form-grid select,
[data-theme="dark"] .toolbar input, [data-theme="dark"] .toolbar select,
[data-theme="dark"] .login-card input, [data-theme="dark"] .login-card select {
  background: #131c19;
  color: var(--ink);
}
[data-theme="dark"] .landing-hero { background: linear-gradient(135deg, var(--teal-soft) 0%, var(--paper) 100%); }
[data-theme="dark"] .hero-stats .item { background: rgba(0,0,0,0.25); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { font-size: 16px; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

a { color: inherit; }

/* ===== Topbar ===== */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1300px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}
.brand {
  font-weight: 900;
  font-size: 15px;
  flex-shrink: 0;
  color: var(--ink);
}
.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 18px;
  cursor: pointer;
  color: var(--ink);
  line-height: 1;
  border-radius: 8px;
  min-height: 38px;
  font-weight: 900;
}
.nav-toggle.open { color: var(--teal); border-color: var(--teal); background: var(--teal-soft); }

.nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  flex-wrap: wrap;
}
.nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  padding: 8px 12px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.nav a:hover { background: var(--surface-soft); color: var(--ink); }
.nav a.active { background: var(--teal-soft); color: var(--teal); }
.nav-ico { font-size: 15px; line-height: 1; flex-shrink: 0; }

.user-area {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  flex-shrink: 0;
}
.user-area .who { color: var(--muted); font-weight: 800; }
.btn-text {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  padding: 8px 12px;
  border-radius: 7px;
  cursor: pointer;
  min-height: 38px;
}
.btn-text:hover { background: var(--surface-soft); }

/* mobile nav */
@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .nav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
    box-shadow: var(--shadow);
    flex: 0;
  }
  .nav.open { display: flex; }
  .nav a { padding: 12px 14px; font-size: 15px; border-radius: 10px; }
  .user-area .who { display: none; }
}
@media (max-width: 860px) {
  .brand { font-size: 14px; }
  .nav-toggle { margin-left: auto; }
  .user-area { margin-left: 0; }
}

/* ===== Shell ===== */
.shell {
  max-width: 1300px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}
h1 { margin: 0 0 16px; font-size: 22px; line-height: 1.25; }
h2 { margin: 0 0 12px; font-size: 17px; }
h3 { margin: 0 0 10px; font-size: 15px; }
@media (min-width: 768px) {
  .shell { padding: 28px 24px 60px; }
  h1 { font-size: 28px; }
  h2 { font-size: 19px; }
}

/* ===== Login card ===== */
body.login-page {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
@media (min-width: 480px) {
  .login-card { padding: 36px 32px; }
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .brand { margin: 0 0 24px; color: var(--muted); font-size: 13px; font-weight: 700; }

.error {
  background: var(--coral-soft);
  color: #833020;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
  border-left: 3px solid var(--coral);
}

.login-card form { display: grid; gap: 12px; }
.login-card label { display: grid; gap: 6px; font-size: 12px; font-weight: 800; color: var(--muted); }
.login-card input, .login-card select {
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
}
.login-card input:focus, .login-card select:focus {
  outline: 2px solid var(--teal-soft);
  border-color: var(--teal);
}
.login-card button {
  height: 48px;
  margin-top: 4px;
  background: var(--teal);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.login-card button:hover { background: var(--teal-strong); }
.login-card button:active { transform: translateY(1px); }
.login-links {
  margin-top: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.login-links a { color: var(--teal); font-weight: 700; text-decoration: none; }
.login-links a:hover { text-decoration: underline; }
.login-links .sep { color: var(--border); }

/* ===== Metrics ===== */
.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
@media (min-width: 640px) {
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .metrics { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 92px;
  box-shadow: var(--shadow-sm);
}
.metric .k { color: var(--muted); font-size: 12px; font-weight: 800; }
.metric .v { margin-top: 6px; font-size: 20px; font-weight: 950; line-height: 1.2; }
.metric .s { margin-top: 4px; color: var(--muted); font-size: 11px; }
@media (min-width: 768px) {
  .metric { padding: 16px; min-height: 108px; }
  .metric .v { font-size: 22px; margin-top: 8px; }
}

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
@media (min-width: 768px) { .card { padding: 20px; } }
.card h2 { margin-top: 0; }

.todo { margin: 0; padding-left: 16px; }
.todo li { margin: 6px 0; font-size: 14px; }
.todo a { color: var(--teal); text-decoration: none; font-weight: 700; }

/* ===== Table ===== */
.table-wrap {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th, table.data td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
table.data th {
  background: #f8faf7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
table.data td.num, table.data th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
table.data tr:hover td { background: #f8faf7; }
table.data a { color: var(--teal); text-decoration: none; font-weight: 700; }
@media (max-width: 640px) {
  table.data { font-size: 12px; }
  table.data th, table.data td { padding: 9px 10px; }
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar input[type=search], .toolbar input[type=text], .toolbar input[type=date], .toolbar input[type=number], .toolbar select {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  background: #fff;
}
.toolbar input:focus, .toolbar select:focus { outline: 2px solid var(--teal-soft); border-color: var(--teal); }
@media (max-width: 640px) {
  .toolbar { gap: 6px; }
  .toolbar input[type=text], .toolbar input[type=search] { flex: 1 1 100%; min-width: 0; }
  .toolbar select { flex: 1 1 auto; min-width: 0; }
}

.btn {
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
.btn:hover { background: var(--teal-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn-secondary:hover { background: var(--surface-soft); }

.pager {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}
.tag.teal { color: var(--teal); background: var(--teal-soft); }
.tag.coral { color: #9d321f; background: var(--coral-soft); }
.tag.gold { color: #785500; background: var(--gold-soft); }
.tag.muted { color: var(--muted); background: var(--surface-soft); }

/* ===== Form ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  max-width: 720px;
}
@media (min-width: 640px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}
.form-grid input, .form-grid select {
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
}
.form-grid input:focus, .form-grid select:focus {
  outline: 2px solid var(--teal-soft);
  border-color: var(--teal);
}
.form-actions {
  margin-top: 18px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ===== KV list ===== */
.kv {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 8px 16px;
  font-size: 13px;
}
@media (min-width: 768px) { .kv { grid-template-columns: 160px 1fr; } }
.kv .k { color: var(--muted); font-weight: 800; }

/* ===== Ledger detail row ===== */
.ledger-detail { background: #f8faf7; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.ledger-detail pre { margin: 0; font-family: "SF Mono", Consolas, monospace; font-size: 11px; color: var(--ink); white-space: pre-wrap; word-break: break-all; }
.ledger-clickable { cursor: pointer; }
.ledger-clickable:hover td { background: #f0f5f1; }

/* ===== Summary bar ===== */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
@media (min-width: 640px) { .summary-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .summary-bar { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.summary-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow-sm);
}
.summary-item .k { color: var(--muted); font-size: 11px; font-weight: 800; }
.summary-item .v { margin-top: 4px; font-size: 16px; font-weight: 900; word-break: break-all; }
.summary-item .s { margin-top: 2px; color: var(--muted); font-size: 11px; }

/* ===== Landing ===== */
.landing-hero {
  min-height: 56vh;
  display: flex;
  align-items: center;
  padding: 56px 16px 40px;
  background: linear-gradient(135deg, var(--teal-soft) 0%, var(--paper) 100%);
}
.landing-inner { max-width: 880px; margin: 0 auto; width: 100%; }
.landing-eyebrow {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--teal);
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 16px;
}
.landing-inner h1 {
  font-size: 30px;
  line-height: 1.2;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}
@media (min-width: 768px) {
  .landing-inner h1 { font-size: 42px; }
  .landing-hero { padding: 80px 24px 64px; }
}
.landing-inner p {
  color: var(--muted);
  font-size: 16px;
  margin: 0 0 24px;
  max-width: 600px;
}
.landing-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.landing-actions .btn { padding: 0 22px; height: 48px; font-size: 15px; }

.landing-info { max-width: 880px; margin: 40px auto; padding: 0 16px; }
.landing-features {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 640px) {
  .landing-features { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.landing-feature {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.landing-feature h3 { margin: 0 0 8px; font-size: 15px; }
.landing-feature p { margin: 0; color: var(--muted); font-size: 13px; }

/* ===== Hero stats (landing) ===== */
.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 24px;
  max-width: 560px;
}
@media (min-width: 640px) {
  .hero-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.hero-stats .item {
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
}
.hero-stats .item .k { color: var(--muted); font-size: 11px; font-weight: 800; }
.hero-stats .item .v { margin-top: 2px; font-size: 16px; font-weight: 950; color: var(--ink); }

/* ===== Footer ===== */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 24px 16px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* ===== Org chart (조직도 다이어그램) ===== */
.org-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.org-zoom { margin-left: auto; display: flex; gap: 4px; }
.org-zoom button {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 7px; padding: 5px 9px; font: inherit; font-size: 12px; font-weight: 800; cursor: pointer;
}
.org-zoom button.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.org-viewport {
  overflow: auto; border: 1px solid var(--line); border-radius: 12px;
  background:
    radial-gradient(circle, var(--line) 1px, transparent 1px) 0 0 / 22px 22px,
    var(--surface-soft);
  padding: 24px; min-height: 420px;
}
.org-canvas { transform-origin: top center; transition: transform .15s ease; width: max-content; margin: 0 auto; }

.org-tree, .org-tree ul { list-style: none; margin: 0; padding: 0; }
.org-tree ul { display: flex; justify-content: center; padding-top: 16px; position: relative; }
.org-tree li { position: relative; padding: 16px 4px 0; text-align: center; }
/* connectors */
.org-tree li::before, .org-tree li::after {
  content: ''; position: absolute; top: 0; right: 50%; width: 50%; height: 16px; border-top: 2px solid var(--border);
}
.org-tree li::after { right: auto; left: 50%; border-left: 2px solid var(--border); }
.org-tree li:only-child::before, .org-tree li:only-child::after { display: none; }
.org-tree li:only-child { padding-top: 16px; }
.org-tree li:first-child::before, .org-tree li:last-child::after { border: 0; }
.org-tree li:last-child::before { border-right: 2px solid var(--border); border-radius: 0 6px 0 0; }
.org-tree li:first-child::after { border-radius: 6px 0 0 0; }
.org-tree ul ul::before {
  content: ''; position: absolute; top: 0; left: 50%; width: 0; height: 16px; border-left: 2px solid var(--border);
}
.org-tree > li { padding-top: 0; }
.org-tree > li::before, .org-tree > li::after { display: none; }

.org-node {
  display: inline-flex; flex-direction: column; gap: 4px; align-items: stretch;
  min-width: 200px; max-width: 240px; padding: 8px 10px 6px; border-radius: 8px; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--line); box-shadow: 0 1px 3px rgba(0,0,0,.06);
  transition: transform .1s, box-shadow .1s, border-color .1s;
}
/* 이름·이메일·코드 3줄 표시 — 각 행은 "라벨 : 값" 형태 */
.org-node .org-fields {
  display: flex; flex-direction: column; gap: 2px; width: 100%; padding-top: 2px;
}
.org-node .org-row {
  display: flex; align-items: baseline; gap: 6px; font-size: 11px; line-height: 1.3;
  text-align: left;
}
.org-node .org-row-k {
  flex-shrink: 0; min-width: 36px; color: var(--muted); font-size: 10px; font-weight: 600;
}
.org-node .org-row-v {
  flex: 1; min-width: 0; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.org-node .org-row-email {
  font-family: Consolas, Menlo, monospace; font-size: 10px; color: var(--muted);
}
.org-node .org-row-code {
  font-family: Consolas, Menlo, monospace; font-weight: 800; letter-spacing: 0.5px;
}
.org-node.is-root .org-row-k,
.org-node.is-root .org-row-v,
.org-node.is-root .org-row-email { color: #fff; }
.org-node.is-root .org-row-k { color: #b8c5d4; }
.org-node:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.12); border-color: var(--teal); }
.org-node.is-root { background: linear-gradient(135deg, #1f2a44, #11203a); border-color: #11203a; }
.org-node.is-root .org-code, .org-node.is-root .org-name { color: #fff; }
/* 옛 코드/이름 셀(레거시 페이지 호환) 은 숨김 처리 — 새 .org-fields 사용 */
.org-node .org-code:not(.org-row-code), .org-node .org-name { display: none; }
.org-node.is-svip { border-color: var(--gold, #c8961e); }
.org-node.is-match { outline: 3px solid var(--gold, #c8961e); outline-offset: 2px; }
.org-node .org-code { font-size: 11px; font-weight: 900; color: var(--ink); font-family: Consolas, monospace; line-height: 1.2; }
.org-node .org-name { font-size: 11px; color: var(--muted); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100px; }
.org-node .org-badges { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; }
.org-node .org-badges .tag { font-size: 9px; padding: 0 4px; line-height: 1.4; }
/* 토글 버튼 — 클릭 가능함을 명확히. 펼치기/접기 상태별 색상 구분. */
.org-node .org-toggle {
  margin-top: 4px; font-size: 10px; font-weight: 800;
  padding: 2px 8px; border-radius: 10px;
  background: var(--teal); color: #fff;
  display: inline-flex; align-items: center; gap: 3px;
  user-select: none; line-height: 1.3;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.org-node .org-toggle:hover { filter: brightness(1.1); }
.org-node.collapsed .org-toggle { background: var(--gold, #c8961e); color: #fff; }
.org-node.collapsed + ul { display: none; }

/* 대수 배지 — 본인 기준 몇 대인지 */
.org-node .org-depth {
  display: inline-block; font-size: 9px; font-weight: 900;
  padding: 1px 6px; border-radius: 6px; margin-bottom: 1px; letter-spacing: .02em;
}
/* 10대 단위 색상 구분 (tier 0=본인, 1=1~10대, 2=11~20대, 3=21~30대) */
.org-node[data-tier="0"] .org-depth { background: #11203a; color: #fff; }
.org-node[data-tier="1"] .org-depth { background: #d7efe6; color: #1f8a70; }
.org-node[data-tier="2"] .org-depth { background: #f6eccf; color: #b9831a; }
.org-node[data-tier="3"] .org-depth { background: #e7e0f7; color: #6b4ea8; }
.org-node[data-tier="4"] .org-depth { background: #fde2e2; color: #b23a48; }
/* tier 좌측 컬러바로 10대 그룹 한눈에 */
.org-node[data-tier="1"] { border-left: 4px solid #1f8a70; }
.org-node[data-tier="2"] { border-left: 4px solid #c8961e; }
.org-node[data-tier="3"] { border-left: 4px solid #6b4ea8; }
.org-node[data-tier="4"] { border-left: 4px solid #b23a48; }

/* 펼치기 클릭한 노드 강조 + 그 하위 묶음 구분 */
.org-node.active { outline: 3px solid var(--teal); outline-offset: 3px; box-shadow: 0 8px 22px rgba(31,138,112,.28); z-index: 3; }
.org-node.active + ul { background: var(--teal-soft); border-radius: 14px; padding-bottom: 10px; }

/* 항상: 직속 하부 묶음을 은은하게 구분 (클릭/hover 없이도) */
.org-tree li > ul { background: rgba(31,138,112,.045); border-radius: 14px; }
/* 마우스 올린 노드의 하부 라인 강조 */
.org-tree li.hover-branch > .org-node { border-color: var(--teal); box-shadow: 0 6px 18px rgba(31,138,112,.22); }
.org-tree li.hover-branch > ul { background: var(--teal-soft); outline: 2px dashed var(--teal); outline-offset: 2px; }
.org-tree li.hover-branch > ul .org-node { border-color: rgba(31,138,112,.45); }

/* ===== Desktop 좌측 사이드바 (≥1024px) — 로그인 화면 제외 ===== */
@media (min-width: 1024px) {
  body:not(.login-page) .topbar {
    position: fixed; inset: 0 auto 0 0;
    width: 252px; height: 100vh; overflow-y: auto;
    border-right: 1px solid var(--line); border-bottom: 0;
    box-shadow: 2px 0 12px rgba(0,0,0,.03);
  }
  body:not(.login-page) .topbar-inner {
    flex-direction: column; align-items: stretch;
    max-width: none; height: 100%; padding: 22px 14px; gap: 4px;
  }
  body:not(.login-page) .brand {
    font-size: 16px; padding: 4px 10px 16px; margin-bottom: 8px;
    border-bottom: 1px solid var(--line);
  }
  body:not(.login-page) .nav {
    flex-direction: column; align-items: stretch; flex: 0 1 auto; gap: 3px; flex-wrap: nowrap;
  }
  body:not(.login-page) .nav a { padding: 11px 12px; font-size: 14px; }
  body:not(.login-page) .user-area {
    margin-left: 0; margin-top: auto; flex-direction: column; align-items: stretch;
    gap: 6px; padding-top: 14px; border-top: 1px solid var(--line);
  }
  body:not(.login-page) .user-area .who { display: block; padding: 2px 10px; font-size: 12px; }
  body:not(.login-page) .shell { margin-left: 252px; max-width: none; padding: 30px 40px 64px; }
  body:not(.login-page) .shell > h1:first-child { margin-top: 0; }
}

/* ===== Segmented filter (수당원장 전체/회원지급만/낙전만 토글) ===== */
.seg-filter { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg-filter button {
  border: 0; border-right: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font: inherit; font-size: 13px; font-weight: 800;
  padding: 8px 14px; cursor: pointer; min-height: 38px;
}
.seg-filter button:last-child { border-right: 0; }
.seg-filter button:hover { background: var(--surface-soft); color: var(--ink); }
.seg-filter button.active { background: var(--teal); color: #fff; }

/* ===== 줌 슬라이더 (조직도) ===== */
.org-zoom-slider { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.org-zoom-slider input[type=range] { width: 130px; accent-color: var(--teal); cursor: pointer; }
.org-zoom-slider .zval { font-size: 12px; font-weight: 800; color: var(--muted); min-width: 44px; text-align: right; }
.org-viewport { touch-action: none; }  /* 모바일 핀치줌을 직접 처리하기 위해 */

/* ===== 모달 (회원 상세/관리) ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal-overlay.open { display: flex; }
.modal-card { background: var(--surface); border-radius: 16px; max-width: 460px; width: 100%; max-height: 86vh; overflow-y: auto; box-shadow: 0 24px 64px rgba(0,0,0,.35); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* 회원 상세 — 관리 작업 카드 */
.mgr-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.mgr-block { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--surface-soft); }
.mgr-block h3 { margin: 0 0 6px; font-size: 14px; }
.mgr-block .hint { color: var(--muted); font-size: 12px; margin: 0 0 10px; line-height: 1.5; }
.mgr-block .result { margin-top: 10px; padding: 10px 12px; border-radius: 8px; font-size: 13px; background: #fff; border: 1px solid var(--line); }
.mgr-block .result.ok { background: #e8f7f1; border-color: #1f8a70; color: #145a48; }
.mgr-block .result.err { background: #fde2e2; border-color: #b23a48; color: #6b1a25; }
.mgr-block .result code { font-family: Consolas, monospace; font-size: 14px; font-weight: 800; padding: 2px 6px; background: rgba(0,0,0,.06); border-radius: 4px; letter-spacing: .04em; }

/* 회원 목록 — 직급별 요약 카드 (클릭으로 필터) */
.rank-card { transition: transform .1s, border-color .1s, background .1s; cursor: pointer; }
.rank-card:hover { transform: translateY(-1px); border-color: var(--teal); background: var(--teal-soft); }
.rank-card.active { border-color: var(--teal); background: var(--teal-soft); box-shadow: 0 2px 6px rgba(31,138,112,.2); }
.rank-card.active .v { color: var(--teal); }

/* 수당 발생이유 모달 — 공식 박스 + kv 테이블 */
.formula-box {
  background: linear-gradient(135deg, #f0f9f5, #e6f5ee);
  border: 1.5px solid var(--teal);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--teal);
  margin: 6px 0 12px;
  text-align: center;
}
.kv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 4px 0 10px;
}
.kv-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
}
.kv-table td:first-child {
  width: 110px;
  color: var(--muted);
  font-weight: 700;
}
.kv-table td:last-child {
  color: var(--ink);
}

/* ============================================================
 * 토스트 알림 (성공/오류/정보) — 화면 상단 중앙, 자동 사라짐
 * ============================================================ */
#toastHost {
  position: fixed;
  top: 88px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast {
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 14px 20px;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .2);
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity .25s, transform .25s;
  min-width: 280px;
  max-width: 520px;
  text-align: center;
  pointer-events: auto;
  cursor: pointer;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-success { background: #1f8a70; color: #fff; border-color: #1f8a70; }
.toast.toast-error { background: #b23a48; color: #fff; border-color: #b23a48; }
.toast.toast-info { background: #11203a; color: #fff; border-color: #11203a; }
.toast.toast-warn { background: #c8961e; color: #fff; border-color: #c8961e; }
.toast .toast-sub { font-weight: 400; font-size: 12px; opacity: .9; margin-top: 4px; }

/* 중앙 모달 (자동 사라지지 않는 중요 알림용) */
.feedback-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: none; align-items: center; justify-content: center; z-index: 10000;
}
.feedback-modal-overlay.open { display: flex; }
.feedback-modal {
  background: #fff; border-radius: 14px; padding: 28px 32px;
  max-width: 480px; min-width: 320px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  text-align: center;
}
.feedback-modal .icon { font-size: 48px; line-height: 1; margin-bottom: 12px; }
.feedback-modal .title { font-size: 18px; font-weight: 900; margin-bottom: 8px; }
.feedback-modal .body { color: var(--muted); font-size: 14px; line-height: 1.6; margin-bottom: 20px; }
.feedback-modal .btn { min-width: 100px; }
