:root {
  --bg: #0b0d12;
  --panel: #12161f;
  --panel-2: #171c27;
  --border: #232a39;
  --text: #e6ebf3;
  --muted: #8a93a6;
  --accent: #5b8cff;
  --accent-2: #8a6bff;
  --ok: #3ddc97;
  --warn: #ffc857;
  --err: #ff6b6b;
  --master: #ff7eb6;
  --manager: #5b8cff;
  --worker: #3ddc97;
  --inactive: #4a5160;
}

* { box-sizing: border-box; }
.hidden { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 80% -10%, #1a1f33 0%, var(--bg) 60%);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Pretendard", "Inter", "Segoe UI", sans-serif;
}

/* ── Topbar ─────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 24px;
  padding: 12px 22px;
  background: rgba(11, 13, 18, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
/* ── Brand (Intelligence Pet) ───────────────────────── */
.brand {
  display: inline-flex; align-items: center; gap: 12px;
  text-decoration: none; color: inherit;
}
.brand:hover .brand-mark-glow { opacity: 0.95; }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 12px; }

.brand-mark {
  position: relative;
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.brand-mark-glow {
  position: absolute; inset: -14%;
  border-radius: 14px;
  background: radial-gradient(60% 60% at 50% 50%,
    rgba(91,211,255,0.45) 0%,
    rgba(91,140,255,0.32) 45%,
    rgba(138,107,255,0.4) 100%);
  filter: blur(8px);
  opacity: 0.7;
  transition: opacity 160ms ease;
  pointer-events: none;
}
.brand-mark-tile {
  position: absolute; inset: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #5BD3FF 0%, var(--accent) 55%, var(--accent-2) 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.28);
}
.brand-mark-paw {
  position: relative;
  width: 22px; height: 22px;
  color: #ffffff;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}
.brand-mark-sparkle {
  position: absolute;
  width: 11px; height: 11px;
  bottom: 6px; left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.95);
  filter: drop-shadow(0 1px 1.5px rgba(0,0,0,0.45));
}

.brand-text {
  display: inline-flex; flex-direction: column; line-height: 1.15; min-width: 0;
}
.brand-title {
  display: inline-flex; align-items: baseline; gap: 8px;
  font-weight: 700; letter-spacing: 0.2px; font-size: 15px;
}
.brand-en {
  background: linear-gradient(135deg, #5BD3FF, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-ko { color: var(--text); font-weight: 600; font-size: 13px; }
.brand-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }

@media (max-width: 720px) {
  .brand-text { display: none; }
  .tabs { margin-left: 8px; }
}

.tabs { display: flex; gap: 4px; margin-left: 20px; }
.tabs button {
  background: transparent; border: 0; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.tabs button:hover { color: var(--text); background: var(--panel); }
.tabs button.active {
  color: var(--text);
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.18), rgba(138, 107, 255, 0.18));
  border: 1px solid rgba(91, 140, 255, 0.35);
}

.status {
  margin-left: auto; padding: 6px 10px; border-radius: 999px;
  background: var(--panel); color: var(--muted); font-size: 12px;
  border: 1px solid var(--border);
}
.status.ok { color: var(--ok); border-color: rgba(61, 220, 151, 0.3); }
.status.err { color: var(--err); border-color: rgba(255, 107, 107, 0.3); }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.topbar-actions .status {
  margin-left: 0;
}
.user-chip {
  font-size: 12px;
  color: var(--muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Login gate ─────────────────────────────────────── */
.login-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(900px 500px at 70% 0%, #1a1f33 0%, var(--bg) 55%);
}
.login-card {
  width: min(420px, 100%);
  padding: 28px 26px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
}
.login-brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}
.login-brand .brand-en {
  font-weight: 700;
  font-size: 18px;
  background: linear-gradient(135deg, #5bd3ff, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-brand .brand-ko {
  font-size: 13px;
  color: var(--muted);
}
.login-lead {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}
.login-lead code {
  font-size: 12px;
  padding: 2px 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, Menlo, monospace;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}
.login-label {
  font-size: 12px;
  color: var(--muted);
}
.login-error {
  margin: 0;
  font-size: 12px;
  color: var(--err);
}
.login-submit {
  margin-top: 4px;
  width: 100%;
}
.login-foot {
  margin: 16px 0 0;
  font-size: 11px;
  text-align: center;
}
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.app-shell > .topbar {
  flex-shrink: 0;
}
.app-shell > #view {
  flex: 1;
  min-height: 0;
}

/* ── Page ──────────────────────────────────────────── */
main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}
.page { display: flex; flex-direction: column; gap: 18px; }
.page-dashboard {
  flex: 1;
  min-height: 0;
}
.page-dashboard .kpis {
  flex-shrink: 0;
}
.page-dashboard .card--org {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.page-dashboard .card--org .card-h,
.page-dashboard .card--org .org-unassigned {
  flex-shrink: 0;
}
.page-dashboard .card--org .org-chart {
  flex: 1;
  min-height: 0;
}
.page-h { display: flex; align-items: center; justify-content: space-between; }
.page-h h2 { margin: 0; font-size: 18px; }
.actions { display: flex; gap: 8px; align-items: center; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.card-h {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-h h2 { margin: 0; font-size: 15px; }
.legend { display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 12px; }

/* ── KPIs ──────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi {
  padding: 16px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--border);
}
.kpi .lbl { color: var(--muted); font-size: 12px; }
.kpi .val { font-size: 28px; font-weight: 700; margin-top: 6px; }
.kpi .val.ok { color: var(--ok); }
.kpi .val.warn { color: var(--warn); }

/* ── Buttons / inputs ──────────────────────────────── */
.btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 13px; font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0; color: white;
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: rgba(255,107,107,0.4); }
.btn.sm { padding: 4px 9px; font-size: 12px; }

input, select, textarea {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
}
input[type="search"] { width: 220px; }

/* ── Table ─────────────────────────────────────────── */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td {
  text-align: left; padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
table.data th {
  color: var(--muted); font-weight: 500; font-size: 12px;
  background: var(--panel-2);
}
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: rgba(91, 140, 255, 0.04); }
table.data tr.row-instance { cursor: pointer; }
table.data tr.row-instance:hover td { background: rgba(91, 140, 255, 0.08); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; border: 1px solid var(--border); color: var(--muted);
}
.badge.master   { color: var(--master);   border-color: rgba(255,126,182,0.4); }
.badge.manager  { color: var(--manager);  border-color: rgba(91,140,255,0.4); }
.badge.worker   { color: var(--worker);   border-color: rgba(61,220,151,0.4); }
.badge.ok       { color: var(--ok);       border-color: rgba(61,220,151,0.4); }
.badge.warn     { color: var(--warn);     border-color: rgba(255,200,87,0.4); }
.badge.err      { color: var(--err);      border-color: rgba(255,107,107,0.4); }

/* ── Org chart ─────────────────────────────────────── */
.org-chart {
  overflow: hidden;
  min-height: 280px;
  position: relative;
  cursor: grab;
  touch-action: none;
}
.org-chart.org-chart-panning { cursor: grabbing; }
.org-chart .org-chart-pan-inner {
  padding: 30px;
  display: inline-block;
  vertical-align: top;
  box-sizing: border-box;
  will-change: transform;
  transform-origin: 0 0;
}
.org-chart-zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 4;
  display: flex;
  gap: 6px;
  align-items: center;
}
.org-chart-zoom .btn {
  min-width: 36px;
  padding: 8px 10px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
}
.org-chart-zoom .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.tree { display: flex; gap: 30px; }
.tree ul {
  list-style: none; padding: 0; margin: 0;
  display: flex; gap: 24px; position: relative;
}
.tree li {
  position: relative; padding-top: 24px;
  display: flex; flex-direction: column; align-items: center;
}
.tree li::before {
  content: ""; position: absolute; top: 0; left: 50%;
  width: 1px; height: 24px; background: var(--border);
}
.tree li:first-child::after, .tree li:last-child::after {
  content: ""; position: absolute; top: 0;
  width: 50%; height: 1px; background: var(--border);
}
.tree li:first-child::after { left: 50%; }
.tree li:last-child::after { right: 50%; }
.tree li:not(:first-child):not(:last-child)::after {
  content: ""; position: absolute; top: 0; left: 0;
  width: 100%; height: 1px; background: var(--border);
}
.tree > .root::before, .tree > .root::after { display: none; }

.node {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px; min-width: 170px;
  text-align: center; color: var(--text);
  position: relative;
}
.node .nm { font-weight: 600; }
.node .pos { font-size: 11px; color: var(--muted); }
.node .ip { font-size: 11px; color: var(--muted); margin-top: 4px; font-family: ui-monospace, Menlo, monospace; }
.node.master  { border-color: rgba(255,126,182,0.5); box-shadow: 0 0 0 1px rgba(255,126,182,0.2); }
.node.manager { border-color: rgba(91,140,255,0.5); }
.node.worker  { border-color: rgba(61,220,151,0.4); }
.node.inactive { opacity: 0.55; border-style: dashed; }

/* ── Org chart DnD ─────────────────────────────────── */
.node[draggable="true"] { cursor: grab; -webkit-user-select: none; user-select: none; transition: transform 80ms ease, box-shadow 120ms ease, border-color 120ms ease; }
.node[draggable="true"]:active { cursor: grabbing; }
.node .node-grip {
  position: absolute; top: 4px; right: 6px;
  font-size: 12px; line-height: 1; color: var(--muted); opacity: 0.55;
  pointer-events: none;
}
.node.dragging { opacity: 0.45; transform: scale(0.97); }
.node.drop-hover {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px rgba(91,140,255,0.45), 0 6px 18px rgba(91,140,255,0.18);
}
.node.drop-forbid {
  border-color: var(--err) !important;
  box-shadow: 0 0 0 2px rgba(255,107,107,0.4);
}

.org-unassigned {
  margin: 14px 18px 0;
  padding: 12px 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: rgba(91, 140, 255, 0.04);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}
.org-unassigned.drop-hover {
  border-color: var(--accent);
  background: rgba(91, 140, 255, 0.12);
  color: var(--text);
}

.legend-sep { color: var(--border); padding: 0 4px; }
.legend-hint { color: var(--muted); font-size: 12px; }

.dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--inactive); margin-right: 6px; vertical-align: middle;
}
.dot.master   { background: var(--master); }
.dot.manager  { background: var(--manager); }
.dot.worker   { background: var(--worker); }
.dot.inactive { background: var(--inactive); }

/* ── Modal ─────────────────────────────────────────── */
.modal-bg {
  position: fixed; inset: 0; background: rgba(5,7,12,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; width: min(720px, 92vw); max-height: 90vh;
  display: flex; flex-direction: column;
}
.modal .h {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal .h h3 { margin: 0; font-size: 16px; }
.modal .b { padding: 18px; overflow-y: auto; }
.modal .f {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.modal .x { background: transparent; color: var(--muted); border: 0; font-size: 20px; cursor: pointer; }

.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid label {
  display: flex; flex-direction: column; gap: 4px;
  color: var(--muted); font-size: 12px;
}
.form-grid label .req::after { content: " *"; color: var(--err); }

pre.code {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px; overflow-x: auto;
  font-family: ui-monospace, Menlo, monospace; font-size: 12px;
  color: #cbd5e1;
}
pre.code.code-sm { padding: 10px; font-size: 11px; max-height: 200px; margin: 0; }

.detail-sheet {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
}
.detail-row {
  display: grid;
  grid-template-columns: minmax(120px, 160px) 1fr;
  gap: 6px 16px;
  align-items: start;
}
.detail-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}
.detail-lbl {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}
.detail-val {
  min-width: 0;
  word-break: break-word;
}

.modal.modal-detail {
  width: min(920px, 94vw);
}

.detail-lead {
  margin: 0 0 16px;
  font-size: 12px;
  line-height: 1.5;
}

.detail-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 14px 16px;
  margin-bottom: 18px;
  background: linear-gradient(
    135deg,
    rgba(91, 140, 255, 0.1),
    rgba(138, 107, 255, 0.07)
  );
  border: 1px solid var(--border);
  border-radius: 12px;
}

.detail-hero-id {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.detail-hero-domain {
  font-size: 13px;
  color: var(--text);
}

.detail-hero-sep {
  flex: 1 1 12px;
  min-width: 12px;
  height: 1px;
  background: var(--border);
  opacity: 0.9;
}

@media (max-width: 560px) {
  .detail-hero-sep {
    display: none;
  }
}

.detail-section {
  margin: 0;
}

.detail-section-h {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.detail-section-b .detail-sheet.tight {
  gap: 8px;
}

.detail-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 22px;
  margin-bottom: 18px;
  align-items: start;
}

.detail-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

@media (max-width: 720px) {
  .detail-cols {
    grid-template-columns: 1fr;
  }
}

.secret-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.secret-box {
  background: var(--bg);
  border: 1px solid rgba(255, 200, 87, 0.28);
  border-radius: 10px;
  padding: 10px 12px;
}

.secret-box-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.secret-box-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--warn);
  font-family: ui-monospace, Menlo, monospace;
}

.secret-pre {
  max-height: 140px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.secret-empty {
  margin: 0;
  font-size: 13px;
}

.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Menlo, monospace; }
.empty {
  padding: 60px; text-align: center; color: var(--muted);
}
