:root {
  --bg: #1a1d21;
  --panel: #222529;
  --text: #eef1f4;
  --muted: #a6afb8;
  --line: #353b43;
  --accent: #2ea043;
  --accent-soft: #1d3527;
  --danger: #f85149;
  --warn: #d29922;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top right, #2b3138, var(--bg) 40%);
  color: var(--text); min-height: 100vh;
}
html { overflow-y: scroll; }
* { scrollbar-width: thin; scrollbar-color: #9aa8b4 transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #3b434d; border-radius: 3px; }
*::-webkit-scrollbar-thumb:hover { background: #4e5a66; }

/* nav */
.top-nav { position: sticky; top: 0; z-index: 100; backdrop-filter: blur(6px); background: rgba(17,20,24,0.9); border-bottom: 1px solid var(--line); }
.top-nav-inner { max-width: 1400px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { font-size: 14px; font-weight: 800; color: #d9e2ea; letter-spacing: 0.02em; cursor: pointer; }
.nav-links { display: flex; align-items: center; gap: 8px; }
.nav-link { text-decoration: none; border: 1px solid #495463; color: #a6afb8; border-radius: 999px; padding: 7px 12px; font-size: 12px; font-weight: 700; background: #22272d; cursor: pointer; }
.nav-link:hover, .nav-link.active { color: #c3ebce; border-color: #2f6f42; background: #1d3527; }

/* layout */
.wrap { max-width: 1400px; margin: 0 auto; padding: 24px 20px 40px; }
.view { display: none; }
.view.active { display: block; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
h1 { font-size: 24px; font-weight: 800; color: var(--text); display: flex; align-items: center; gap: 10px; }
h1::before { content: '⬡'; font-size: 20px; color: var(--accent); }

/* grid & card */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.card h2 { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; }

/* drop zone */
#drop-zone { border: 2px dashed var(--line); border-radius: 10px; padding: 40px 20px; text-align: center; cursor: pointer; transition: all 0.2s; background: #171a1f; }
#drop-zone:hover, #drop-zone.dragover { border-color: var(--accent); background: var(--accent-soft); }
#drop-zone .icon { font-size: 36px; margin-bottom: 10px; }
#drop-zone p { color: var(--muted); font-size: 13px; line-height: 1.6; }
#drop-zone input { display: none; }
#file-list { margin-top: 12px; max-height: 120px; overflow-y: auto; }
#file-list .file-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px; font-size: 12px; background: #171a1f; border: 1px solid var(--line); margin-bottom: 4px; color: var(--text); }
#upload-btn { margin-top: 14px; width: 100%; padding: 10px; background: var(--accent); color: #fff; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 700; transition: background 0.2s; font-family: inherit; }
#upload-btn:hover:not(:disabled) { background: #249237; }
#upload-btn:disabled { background: #2a2e33; color: #484f58; cursor: not-allowed; }

/* log */
#log-box { background: #171a1f; border-radius: 8px; border: 1px solid var(--line); padding: 14px; height: 320px; overflow-y: auto; font-family: 'SFMono-Regular','Menlo','Courier New',monospace; font-size: 12px; line-height: 1.6; }
.log-info { color: #3fb950; }
.log-warn { color: var(--warn); }
.log-fail { color: var(--danger); }
.log-summary { color: #bc8cff; font-weight: bold; }
.log-default { color: var(--muted); }

/* csv file list */
#csv-file-list { height: 280px; overflow-y: auto; }
.csv-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 6px; font-size: 12px; background: #171a1f; border: 1px solid var(--line); margin-bottom: 6px; }
.csv-item .name { color: var(--text); }
.csv-item .size { color: var(--muted); font-size: 11px; }
.csv-item .delete-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; padding: 0 4px; }
.csv-item .delete-btn:hover { color: #ff7b72; }

/* dashboard history table */
.dash-history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dash-history-table thead { background: #171a1f; border-bottom: 1px solid var(--line); }
.dash-history-table thead th { text-align: left; padding: 10px 14px; color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.dash-history-table tbody tr { border-bottom: 1px solid #2a2e33; }
.dash-history-table tbody tr:hover { background: #25292e; }
.dash-history-table tbody td { padding: 11px 14px; }

/* btn group */
.btn-group { display: flex; gap: 6px; }
.icon-btn { background: #171a1f; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 3px 10px; font-size: 11px; cursor: pointer; font-family: inherit; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.icon-btn.pulse { border-color: var(--danger); color: var(--danger); animation: pulse-red 1.5s infinite; }
@keyframes pulse-red { 0%,100% { box-shadow: 0 0 0 0 rgba(248,81,73,0.5); } 50% { box-shadow: 0 0 0 5px rgba(248,81,73,0); } }
.empty-msg { color: #484f58; font-size: 13px; text-align: center; margin-top: 40px; }

/* history */
#view-history .card { padding: 24px; }
#view-history .card h2 { margin-bottom: 20px; }
#view-history table { width: 100%; border-collapse: collapse; font-size: 13px; }
#view-history thead { background: #171a1f; border-bottom: 1px solid var(--line); }
#view-history thead th { text-align: left; padding: 10px 14px; color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
#view-history tbody tr { border-bottom: 1px solid #2a2e33; }
#view-history tbody tr:hover { background: #25292e; }
#view-history tbody td { padding: 11px 14px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.badge.success { background: #1d3527; color: #99d8ac; border: 1px solid #2f6f42; }
.badge.fail { background: #3a1a1a; color: #f85149; border: 1px solid #da3633; }
tbody tr.main-row { cursor: pointer; }
tbody tr.detail-row { display: none; background: #171a1f; }
tbody tr.detail-row.open { display: table-row; }
.detail-cell { padding: 0 !important; }
.detail-inner { padding: 12px 20px 12px 40px; border-bottom: 1px solid #2a2e33; }
.detail-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.detail-table th { text-align: left; padding: 6px 10px; color: var(--muted); font-weight: 700; border-bottom: 1px solid #2a2e33; text-transform: uppercase; font-size: 11px; letter-spacing: 0.04em; }
.detail-table td { padding: 7px 10px; color: var(--text); border-bottom: 1px solid var(--panel); }
.detail-table tr:last-child td { border-bottom: none; }
.chevron { display: inline-block; transition: transform 0.2s; margin-right: 6px; color: var(--muted); }
.chevron.open { transform: rotate(90deg); }
.pagination { display: flex; justify-content: center; align-items: center; gap: 6px; margin-top: 20px; }
.page-btn { background: #22272d; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 5px 12px; font-size: 12px; cursor: pointer; font-family: inherit; }
.page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.empty-row { color: #484f58; font-size: 13px; text-align: center; padding: 40px; }

/* toast */
#toast-container { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); z-index: 9999; display: flex; flex-direction: column; align-items: center; gap: 10px; pointer-events: none; }
.toast { pointer-events: auto; min-width: 280px; max-width: 400px; padding: 20px 24px 16px; border-radius: 12px; font-size: 13px; line-height: 1.6; box-shadow: 0 8px 32px rgba(0,0,0,0.6); animation: fadeIn 0.2s ease; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; background: var(--panel); border: 1px solid var(--line); color: var(--text); }
.toast.confirm { border-color: var(--warn); }
.toast-icon { font-size: 32px; line-height: 1; }
.toast-icon.summary { color: #3fb950; } .toast-icon.error { color: var(--danger); } .toast-icon.confirm { color: var(--warn); }
.toast-title { font-size: 14px; font-weight: 700; }
.toast-title.summary { color: #3fb950; } .toast-title.error { color: var(--danger); } .toast-title.confirm { color: var(--warn); }
.toast-body { color: var(--muted); font-size: 12px; word-break: break-all; }
.toast-btn-row { display: flex; gap: 10px; margin-top: 4px; }
.toast-btn { padding: 5px 20px; border-radius: 6px; font-size: 12px; cursor: pointer; border: 1px solid var(--line); font-family: inherit; }
.toast-btn.ok { background: #b08800; border-color: var(--warn); color: #fff; } .toast-btn.ok:hover { background: var(--warn); }
.toast-btn.cancel { background: #2a2e33; color: var(--text); } .toast-btn.cancel:hover { background: var(--line); }
.toast-close { margin-top: 4px; background: #2a2e33; border: 1px solid var(--line); color: var(--text); cursor: pointer; font-size: 12px; padding: 4px 16px; border-radius: 6px; font-family: inherit; }
.toast-close:hover { background: var(--line); }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* node */
.node-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 12px; }
.node-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.node-company-code { background: var(--accent-soft); border: 1px solid #2f6f42; color: #99d8ac; border-radius: 6px; padding: 3px 10px; font-size: 12px; font-weight: 700; font-family: 'SFMono-Regular',monospace; }
.node-company-name { font-size: 16px; font-weight: 700; color: var(--text); }
.node-name-tag { margin-left: auto; font-size: 12px; color: var(--text); background: #1c2333; border: 1px solid #30363d; border-radius: 6px; padding: 3px 10px; }
.node-info-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(180px,1fr)); gap: 12px; }
.node-info-item { display: flex; flex-direction: column; gap: 4px; }
.node-info-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.node-info-value { font-size: 14px; color: var(--text); font-weight: 600; }
.node-info-value.muted { color: var(--muted); font-weight: 400; }
.node-ha-badge { display: inline-flex; align-items: center; gap: 6px; background: #2d1f3d; border: 1px solid #6e40c9; color: #bc8cff; border-radius: 6px; padding: 3px 10px; font-size: 12px; font-weight: 700; }
.node-empty { color: var(--muted); text-align: center; padding: 40px; font-size: 14px; }
#node-input:focus, #company-input:focus { outline: none; border-color: var(--accent); }

/* search */
.search-row { display: flex; gap: 10px; align-items: center; }
.search-input { flex: 1; background: #171a1f; border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 10px 14px; font-size: 14px; font-family: inherit; }
.search-btn { padding: 10px 20px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit; }
.search-btn:hover { background: #249237; }

/* company */
.company-summary { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 16px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.company-summary-info { flex: 1; }
.company-summary-name { font-size: 20px; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.company-summary-code { font-size: 13px; color: var(--muted); }
.company-node-count { text-align: center; background: var(--accent-soft); border: 1px solid #2f6f42; border-radius: 10px; padding: 12px 24px; }
.company-node-count .count-num { font-size: 32px; font-weight: 800; color: var(--accent); line-height: 1; }
.company-node-count .count-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; }
.node-table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.node-table-wrap h2 { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; padding: 16px 20px 0; }
.node-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.node-table thead { background: #171a1f; border-bottom: 1px solid var(--line); }
.node-table thead th { text-align: left; padding: 10px 16px; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.node-table tbody tr { border-bottom: 1px solid #2a2e33; }
.node-table tbody tr:last-child { border-bottom: none; }
.node-table tbody tr:hover { background: #25292e; }
.node-table tbody td { padding: 11px 16px; }

/* company info */
.company-info-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.company-info-header { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.company-info-name { font-size: 22px; font-weight: 800; color: var(--text); }
.company-info-code-badge { background: var(--accent-soft); border: 1px solid #2f6f42; color: #99d8ac; border-radius: 6px; padding: 4px 12px; font-size: 12px; font-weight: 700; }
.company-info-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(200px,1fr)); gap: 16px; }
.company-info-item { display: flex; flex-direction: column; gap: 6px; }
.company-info-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.company-info-value { font-size: 15px; color: var(--text); font-weight: 600; }
.company-info-value.accent { color: var(--accent); font-size: 22px; font-weight: 800; }

/* ha */
.ha-search-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.ha-field { display: flex; flex-direction: column; gap: 6px; }
.ha-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.ha-summary { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 16px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.ha-summary-info { flex: 1; }
.ha-summary-name { font-size: 20px; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.ha-summary-code { font-size: 13px; color: var(--muted); }
.ha-count-box { text-align: center; background: #2d1f3d; border: 1px solid #6e40c9; border-radius: 10px; padding: 12px 24px; }
.ha-count-box .count-num { font-size: 32px; font-weight: 800; color: #bc8cff; line-height: 1; }
.ha-count-box .count-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; }
.ha-table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.ha-table-wrap h2 { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; padding: 16px 20px 12px; }
.ha-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ha-table thead { background: #171a1f; border-bottom: 1px solid var(--line); }
.ha-table thead th { text-align: left; padding: 10px 16px; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.ha-table tbody tr { border-bottom: 1px solid #2a2e33; }
.ha-table tbody tr:last-child { border-bottom: none; }
.ha-table tbody tr:hover { background: #25292e; }
.ha-table tbody td { padding: 12px 16px; }
.ha-arrow { color: var(--muted); margin: 0 8px; }
.ha-node-old { color: var(--danger); font-weight: 600; }
.ha-node-new { color: var(--accent); font-weight: 600; }
.ha-date-cell { color: var(--text); font-size: 13px; }
.ha-id-badge { display: inline-block; background: #2d1f3d; border: 1px solid #6e40c9; color: #bc8cff; border-radius: 6px; padding: 2px 8px; font-size: 11px; font-weight: 700; }

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .ha-search-row { flex-direction: column; align-items: stretch; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-node-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .modal-box { min-width: auto !important; max-width: 95vw !important; margin: 10px; }
  .node-table { font-size: 11px; }
  .node-table th, .node-table td { padding: 8px 6px; }
  .ha-table { font-size: 11px; }
  .ha-table th, .ha-table td { padding: 8px 6px; }
  .page-header { flex-direction: column; gap: 8px; }
  .page-header h1 { font-size: 18px; }
  .search-row { flex-direction: column; }
  .search-input { min-width: auto !important; }
  .nav-links { flex-wrap: wrap; gap: 4px; }
  .nav-link { font-size: 11px; padding: 5px 8px; }
  .top-nav-inner { flex-direction: column; gap: 8px; }
  .company-info-grid { grid-template-columns: 1fr 1fr; }
  .pagination { flex-wrap: wrap; }
}


/* modal */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 9998; display: flex; align-items: center; justify-content: center; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; min-width: 360px; max-width: 480px; box-shadow: 0 8px 32px rgba(0,0,0,0.6); }


/* popup link */
.popup-link { display: none; }


/* insert status */
.insert-processing { color: var(--warn); display: inline-flex; align-items: center; gap: 8px; }
.insert-processing .spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--warn); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.insert-idle { color: var(--accent); }
