:root {
  --bg-top: #eef4fb;
  --bg-mid: #f7f9f3;
  --bg-bottom: #e8f4ef;
  --card: rgba(255, 255, 255, 0.88);
  --card-border: #d8e1ec;
  --text-main: #1f2f3f;
  --text-sub: #5a6d80;
  --primary: #2f6fb2;
  --primary-dark: #1f5b9b;
  --secondary: #e8eff8;
  --danger: #b74545;
  --success: #2d7f68;
  --shadow: 0 8px 24px rgba(35, 66, 102, 0.12);
  --radius: 14px;
  --table-header: #eaf1fb;
  --table-row: #ffffff;
  --table-row-alt: #f8fbff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Noto Sans KR", "Malgun Gothic", sans-serif;
  color: var(--text-main);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 48%, var(--bg-bottom) 100%);
  min-height: 100vh;
}

.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 20px 24px 14px;
  background: rgba(255, 255, 255, 0.6);
  border-bottom: 1px solid #d7e1ed;
  backdrop-filter: blur(6px);
}

.top-header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.4px;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--text-sub);
  font-size: 14px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.path-badge {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: #edf3fc;
  color: #305f93;
  border: 1px solid #d4e0ef;
  font-size: 12px;
  font-weight: 700;
}

.alert-area {
  padding: 10px 16px 0;
  display: grid;
  gap: 8px;
}

.alert {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  border: 1px solid;
}

.alert.error {
  background: #fdeaea;
  border-color: #efb7b7;
  color: #7f2323;
}

.alert.success {
  background: #e9f8f1;
  border-color: #b8e1cf;
  color: #1d674f;
}

.alert button {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  padding: 14px 16px 20px;
}

.sidebar,
.panel-card,
.content {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sidebar {
  padding: 14px;
  height: fit-content;
  position: sticky;
  top: 12px;
}

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

.sidebar-header h2 {
  margin: 0;
  font-size: 17px;
}

.sidebar-tools {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.selected-count {
  font-size: 13px;
  color: #365777;
  font-weight: 700;
}

.sidebar-hint {
  margin: 10px 2px 0;
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.45;
}

.doc-list {
  max-height: 60vh;
  overflow: auto;
  border: 1px solid #d6e0ed;
  border-radius: 10px;
  background: #f9fbff;
}

.doc-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid #e2e9f4;
}

.doc-item:last-child {
  border-bottom: none;
}

.doc-main {
  display: inline-grid;
  align-items: start;
  gap: 8px;
  min-width: 0;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  grid-template-areas:
    "check name tag"
    "check id tag";
}

.doc-main input {
  margin: 0;
  grid-area: check;
  align-self: center;
}

.doc-id {
  grid-area: id;
  color: #5b6f84;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-name {
  grid-area: name;
  color: #1f2f3f;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tag-inline {
  grid-area: tag;
  align-self: start;
  background: #eef4ff;
  border: 1px solid #d6e5ff;
  color: #355f96;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
}

.content {
  padding: 14px;
  min-height: 80vh;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  border-bottom: 1px solid #d7e2f0;
  padding-bottom: 8px;
  margin-bottom: 14px;
}

.tab {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  background: transparent;
  color: #415d7a;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.tab.active {
  color: var(--primary);
  border-color: #c4d8ef;
  background: #edf4fd;
}

.tab-panel {
  display: none;
  gap: 12px;
}

.tab-panel.active {
  display: grid;
}

.panel-card {
  padding: 12px;
}

.panel-card.inset {
  margin: 0;
  background: rgba(255, 255, 255, 0.92);
}

.panel-card.result-card {
  margin-top: 12px;
}

.panel-card.result-subcard {
  margin-top: 8px;
}

.panel-card h3 {
  margin: 0 0 10px;
  font-size: 18px;
  color: #284b72;
}

.panel-card h4 {
  margin: 0 0 8px;
  font-size: 15px;
  color: #2d517a;
}

.panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-row.between {
  justify-content: space-between;
}

.inline-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
}

.inline-controls .select-field {
  width: 240px;
  max-width: 100%;
  min-width: 220px;
}

.stack-controls {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.split-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
}

.settings-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-grid + .inline-controls {
  margin-top: 10px;
}

.controls-gap {
  margin-top: 12px;
}

.compare-token-grid {
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
}

.tfidf-settings-grid {
  grid-template-columns: minmax(0, 240px);
  margin-top: 10px;
}

.compare-doc-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 8px;
}

.doc-select-card {
  background: #f6faff;
  border: 1px solid #d5e2f0;
  box-shadow: none;
}

.doc-checklist {
  max-height: 220px;
  overflow: auto;
  border: 1px solid #d8e2ef;
  border-radius: 10px;
  background: #ffffff;
  padding: 6px;
}

.doc-check-item {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.doc-check-item:hover {
  background: #f2f7ff;
  border-color: #d7e3f3;
}

.doc-check-item input {
  margin: 0;
}

.doc-check-name {
  font-size: 13px;
  color: #1f3348;
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-check-id {
  font-size: 11px;
  color: #5f7083;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-check-item .tag-inline {
  grid-area: auto;
  align-self: center;
}

.label-title {
  font-size: 13px;
  color: #3b536d;
  margin-bottom: 6px;
}

.radio-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

label {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: #3b536d;
}

label.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-top: 20px;
}

.inline-controls label.check {
  padding-top: 0;
}

input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  border: 1px solid #cbd9ea;
  border-radius: 10px;
  padding: 9px 10px;
  background: #ffffff;
  color: var(--text-main);
  font: inherit;
}

textarea {
  resize: vertical;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary-dark);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--secondary);
  border-color: #cbd9ec;
  color: #32577f;
}

.btn-danger {
  background: #f8e8e8;
  border-color: #e3b5b5;
  color: #8a2c2c;
}

.status-text {
  font-size: 13px;
  color: #405a76;
}

#compareTfidfSelectionHint {
  font-weight: 700;
}

.panel-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-sub);
}

.structure-notice {
  min-height: 18px;
}

.right-actions {
  margin-left: auto;
  align-self: flex-start;
}

.function-word-box {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid #d8e1ed;
  border-radius: 10px;
  background: #f2f5f9;
  opacity: 0.8;
}

.function-word-box.enabled {
  opacity: 1;
}

.function-word-box label {
  width: 100%;
}

.function-word-box input[type="text"] {
  width: 100%;
}

.function-word-stats-card {
  background: #f4f6f9;
  border-color: #d8e1ed;
}

.function-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin-bottom: 10px;
  font-size: 13px;
  color: #354f6a;
}

.stat-value {
  font-weight: 800;
  color: #1f3f65;
}

.result-box {
  min-height: 140px;
  max-height: 320px;
  overflow: auto;
  margin: 8px 0 0;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #cfdced;
  background: #f7faff;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.45;
}

.table-wrap {
  margin-top: 8px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid #d6e0ed;
  border-radius: 10px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--table-row);
}

.data-table th,
.data-table td {
  border-bottom: 1px solid #dfe7f2;
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--table-header);
  color: #2a4e76;
  font-weight: 700;
}

.data-table tr:nth-child(even) td {
  background: var(--table-row-alt);
}

.empty-state {
  padding: 14px;
  text-align: center;
  color: var(--text-sub);
  font-size: 13px;
}

.muted {
  color: var(--text-sub);
  font-size: 12px;
}

.node-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.node-item {
  background: #eef5ff;
  border: 1px solid #d4e3f8;
  color: #315983;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}

.svg-wrap {
  margin-top: 10px;
  border: 1px solid #d6e0ed;
  border-radius: 10px;
  background: #fbfdff;
  overflow: auto;
  padding: 10px;
}

.keyword-a {
  color: #d9534f;
  font-weight: bold;
}

.keyword-b {
  color: #0275d8;
  font-weight: bold;
}

.case-card {
  background: #f8f9fa;
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  border: 1px solid #d8e1ed;
}

.occurrence-position {
  font-size: 0.9em;
  color: #666;
  margin: 4px 0 8px;
}

.case-text {
  white-space: pre-wrap;
  line-height: 1.5;
}

.matrix-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ops-view {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #d6e0ed;
  border-radius: 10px;
  background: #f9fbff;
  line-height: 1.8;
  word-break: break-all;
}

.op-delete {
  background: #ffe5e5;
  color: #8a2c2c;
  border-radius: 4px;
  padding: 0 2px;
}

.op-insert {
  background: #e3f0ff;
  color: #1f4f89;
  border-radius: 4px;
  padding: 0 2px;
}

.text-details {
  margin-top: 8px;
}

.text-details summary {
  cursor: pointer;
  color: #355f8c;
  font-weight: 700;
}

.accordion-section {
  border: 1px solid #d3e0ef;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 4px 14px rgba(47, 87, 134, 0.08);
  overflow: hidden;
}

.accordion-header {
  width: 100%;
  border: none;
  background: #e8f0fb;
  color: #274a72;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
}

.accordion-title {
  text-align: left;
}

.accordion-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.completed-mark {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #2e8c6f;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.completed-mark.visible {
  opacity: 1;
  transform: scale(1);
}

.accordion-arrow {
  color: #3d678f;
  font-size: 12px;
  transition: transform 0.25s ease;
}

.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  background: rgba(255, 255, 255, 0.82);
}

.accordion-content .panel-card.inset {
  border: none;
  box-shadow: none;
  border-radius: 0;
}

.accordion-section.open .accordion-content {
  max-height: 2200px;
}

.accordion-section.open .accordion-arrow {
  transform: rotate(180deg);
}

@media (max-width: 1080px) {
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compare-token-grid {
    grid-template-columns: 1fr;
  }

  .compare-doc-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
    position: static;
  }

  .layout.sidebar-open .sidebar {
    display: block;
  }

  #mobileSidebarToggle {
    display: inline-flex;
  }

  .split-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .tfidf-settings-grid {
    grid-template-columns: 1fr;
  }

  .accordion-header {
    font-size: 14px;
    padding: 11px 12px;
  }

  .function-stats-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 901px) {
  #mobileSidebarToggle {
    display: none;
  }
}
