:root {
  --bg: #dfe3e8;
  --panel: #eef1f4;
  --ink: #111111;
  --tab: #cfd5dc;
  --tab-active: #ffffff;
  --line: #000000;
  --coord: #d7dce2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #e7ebf0 0%, #d8dde5 100%);
  color: var(--ink);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 18px 24px 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.topbar p {
  margin: 4px 0 0;
  color: #4f5965;
  font-size: 13px;
}

.save-button {
  border: 1px solid #1f4e79;
  background: #2e75b6;
  color: #ffffff;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.save-button:hover {
  filter: brightness(1.05);
}

.sheet-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 24px 14px;
}

.sheet-tab {
  border: 1px solid #aab3bd;
  border-bottom: none;
  background: var(--tab);
  color: #25303b;
  padding: 10px 14px;
  border-radius: 10px 10px 0 0;
  font-size: 13px;
  cursor: pointer;
}

.sheet-tab.active {
  background: var(--tab-active);
  font-weight: 700;
}

.sheet-stage {
  flex: 1;
  padding: 0 16px 20px;
}

.sheet-root {
  background: #ffffff;
  border: 1px solid #b6bec7;
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 18px 40px rgba(28, 39, 51, 0.1);
}

.summary-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  grid-template-areas:
    "switcher switcher"
    "sheet insights"
    "recommend insights";
  gap: 16px;
  align-items: start;
}

.panel-switcher {
  grid-area: switcher;
  display: none;
  gap: 8px;
  flex-wrap: wrap;
  position: sticky;
  top: 8px;
  z-index: 5;
  padding: 2px 0;
}

.panel-switch {
  border: 1px solid #b9c4cf;
  background: rgba(255, 255, 255, 0.95);
  color: #243647;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.panel-switch.active {
  border-color: #1f4e79;
  background: #2e75b6;
  color: #fff;
}

.workspace-section {
  min-width: 0;
}

.workspace-section-sheet {
  grid-area: sheet;
}

.workspace-section-recommend {
  grid-area: recommend;
}

.workspace-section-insights {
  grid-area: insights;
}

.main-panel {
  min-width: 0;
}

.sheet-title {
  margin: 2px 0 10px;
  font-size: 15px;
  font-weight: 700;
  color: #33404d;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #d0d5db;
  border-radius: 12px;
  background: #fff;
}

.main-grid-wrap {
  max-height: calc(100vh - 240px);
  max-width: 100%;
  width: 100%;
}

.coord-top {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: min-content;
  grid-column: 2;
  grid-row: 1;
  border-left: 1px solid var(--coord);
  border-top: 1px solid var(--coord);
}

.coord-left {
  display: grid;
  grid-auto-rows: min-content;
  grid-column: 1;
  grid-row: 2;
  border-left: 1px solid var(--coord);
  border-top: 1px solid var(--coord);
}

.coord-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #5d6772;
  background: #f0f3f6;
  border-right: 1px solid var(--coord);
  border-bottom: 1px solid var(--coord);
  user-select: none;
}

.coord-top-cell {
  height: 100%;
}

.coord-left-cell {
  height: 100%;
}

.table-holder {
  grid-column: 2;
  grid-row: 2;
  overflow: visible;
  min-width: max-content;
}

.coord-corner {
  grid-column: 1;
  grid-row: 1;
  width: 44px;
  height: 100%;
  background: #f0f3f6;
  border-right: 1px solid var(--coord);
  border-bottom: 1px solid var(--coord);
}

table.sheet-table {
  border-collapse: collapse;
  table-layout: fixed;
  background: #ffffff;
}

.sheet-table td {
  border: 1px solid var(--line);
  padding: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  vertical-align: middle;
  line-height: 1;
}

.sheet-table tr:nth-child(2) td {
  font-weight: 700;
  font-size: 12px;
  background: #f7f9fc;
  color: #111111;
}

.duplicate-column {
  background: #f7dddd !important;
}

.duplicate-name {
  background: #f4bcbc !important;
  box-shadow: inset 0 0 0 2px #d05a5a;
}

.simple-sheet .sheet-table td {
  font-family: "Malgun Gothic", sans-serif;
  font-size: 12px;
}

.editable-cell {
  outline: none;
  cursor: text;
}

.editable-cell:focus {
  background: #fff5d9;
  box-shadow: inset 0 0 0 2px #e1b742;
}

.highlight-cell {
  box-shadow: inset 0 0 0 2px var(--highlight-color, #2b78ff);
}

.selected-cell {
  box-shadow: inset 0 0 0 3px var(--highlight-color, #2b78ff);
  outline: 1px solid var(--highlight-color, #2b78ff);
  outline-offset: -1px;
}

.range-selected-cell {
  background-color: #dbeafe !important;
  box-shadow: inset 0 0 0 2px #2563eb;
}

.range-label {
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  padding: 0 4px;
  white-space: nowrap;
}

.hl-token {
  border-radius: 3px;
  padding: 0 2px;
  color: #111;
  font-weight: 700;
}

.summary-sidebar {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 80px);
  overflow: auto;
  background: #f6f8fb;
  border: 1px solid #ccd3db;
  border-radius: 12px;
  padding: 14px 12px;
}

.recommendation-mount {
  margin-top: 14px;
}

.recommend-panel {
  background: linear-gradient(180deg, #f7f9fc 0%, #eef3f8 100%);
  border: 1px solid #d4dbe3;
  border-radius: 12px;
  padding: 14px;
}

.recommend-panel h3 {
  margin: 0;
  font-size: 17px;
}

.recommend-hint {
  margin: 6px 0 0;
  color: #5d6772;
  font-size: 12px;
}

.recommend-empty {
  margin-top: 12px;
  color: #5d6772;
  font-size: 13px;
}

.program-info-card {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #c7d6e6;
  border-radius: 10px;
  background: #ffffff;
}

.program-info-label {
  color: #4f6f94;
  font-size: 12px;
  font-weight: 700;
}

.program-info-title {
  margin-top: 4px;
  color: #1f2b36;
  font-size: 14px;
  font-weight: 700;
}

.program-info-meta {
  margin-top: 3px;
  color: #607080;
  font-size: 12px;
}

.program-info-detail {
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px dashed #d7e2ee;
  color: #334455;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.program-info-detail-label {
  display: block;
  margin-bottom: 3px;
  color: #4f6f94;
  font-weight: 700;
  font-size: 12px;
}

.recommend-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.recommend-badge {
  border: 1px solid #b9c7d6;
  background: #ffffff;
  color: #1f2b36;
  border-radius: 999px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.recommend-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(31, 43, 54, 0.12);
  border-color: #7aa0c7;
}

.badge-name {
  font-weight: 700;
}

.badge-meta {
  font-size: 11px;
  color: #607080;
}

.summary-sidebar h3,
.summary-sidebar h4 {
  margin: 0;
}

.summary-sidebar h3 {
  font-size: 18px;
}

.summary-section {
  margin-top: 14px;
}

.summary-section h4 {
  font-size: 14px;
  margin-bottom: 8px;
}

.summary-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.summary-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  background: #ffffff;
  border: 1px solid #d6dce3;
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 12px;
  cursor: pointer;
  transition: box-shadow 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.summary-row:nth-child(odd) {
  background: #fbfcfe;
}

.summary-row:hover {
  transform: translateY(-1px);
  border-color: #9fb3c8;
}

.active-summary-row {
  box-shadow: inset 0 0 0 3px var(--summary-highlight, #2b78ff);
  border-color: var(--summary-highlight, #2b78ff);
  background: color-mix(in srgb, var(--summary-highlight, #2b78ff) 10%, white);
}

.summary-row .value,
.triple-values b {
  font-variant-numeric: tabular-nums;
  color: #111;
  border-radius: 4px;
  padding: 0 4px;
}

.summary-row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-row .value {
  font-weight: 700;
}

.summary-head {
  background: transparent;
  border: none;
  padding: 0 2px 6px;
  color: #536171;
}

.summary-row-wide {
  grid-template-columns: 28px minmax(0, 1fr) auto;
}

.triplet {
  font-size: 11px;
}

.triple-values {
  display: grid;
  grid-template-columns: repeat(3, 28px);
  gap: 6px;
  text-align: center;
}

.rank {
  font-weight: 700;
  color: #7a2f2f;
  text-align: center;
}

@media (max-width: 1279px) {
  .summary-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "switcher"
      "sheet"
      "recommend"
      "insights";
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    margin-left: 0;
  }

  .main-grid-wrap {
    max-height: calc(100vh - 300px);
  }

  .summary-sidebar {
    position: static;
    max-height: none;
  }
}

@media (max-width: 900px) {
  .sheet-stage {
    padding: 0 10px 16px;
  }

  .sheet-root {
    padding: 10px;
    border-radius: 12px;
  }

  .topbar {
    padding: 16px 14px 8px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .save-button {
    flex: 1 1 calc(50% - 6px);
    min-height: 42px;
    padding: 10px 12px;
  }

  .range-label {
    flex-basis: 100%;
    padding: 4px 2px 0;
  }

  .main-grid-wrap {
    max-height: calc(100vh - 360px);
  }

  .change-log-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .change-log-arrow {
    display: none;
  }
}

@media (max-width: 680px) {
  .panel-switcher {
    display: flex;
  }

  .summary-layout[data-active-panel="sheet"] .workspace-section-recommend,
  .summary-layout[data-active-panel="sheet"] .workspace-section-insights,
  .summary-layout[data-active-panel="recommend"] .workspace-section-sheet,
  .summary-layout[data-active-panel="recommend"] .workspace-section-insights,
  .summary-layout[data-active-panel="insights"] .workspace-section-sheet,
  .summary-layout[data-active-panel="insights"] .workspace-section-recommend {
    display: none;
  }
}

.cell-range-dragging,
.cell-range-dragging * {
  user-select: none !important;
}

.change-log-mount {
  margin-top: 0;
}

.change-log-panel {
  background: #fffdf7;
  border: 1px solid #e5d7aa;
  border-radius: 12px;
  padding: 14px;
}

.change-log-panel h3 {
  margin: 0;
  font-size: 16px;
}

.change-log-hint {
  margin: 6px 0 10px;
  color: #6b5f3a;
  font-size: 12px;
}

.change-log-list {
  max-height: 220px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.change-log-row {
  display: grid;
  grid-template-columns: 150px 48px minmax(80px, 1fr) 18px minmax(80px, 1fr);
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  background: #ffffff;
  border: 1px solid #eee1bd;
  border-radius: 8px;
  font-size: 12px;
}

.change-log-time {
  color: #64748b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.change-log-address {
  color: #1d4ed8;
}

.change-log-before {
  color: #991b1b;
  text-decoration: line-through;
  overflow-wrap: anywhere;
}

.change-log-after {
  color: #166534;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.change-log-arrow {
  color: #64748b;
  text-align: center;
}

.change-log-empty {
  color: #64748b;
  font-size: 13px;
  padding: 8px;
}

.right-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
