:root {
  color-scheme: light;
  --bg: #f3f5f2;
  --panel: #ffffff;
  --ink: #1e2529;
  --muted: #65717a;
  --line: #d8dfd8;
  --accent: #0f766e;
  --accent-strong: #0b5d56;
  --amber: #b97815;
  --rose: #a43b4f;
  --cream: #fff6d8;
  --cream-strong: #ffe8a3;
  --blue-soft: #e8f1fb;
  --shadow: 0 18px 50px rgba(31, 44, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 14px;
  height: 100vh;
  padding: 14px;
}

.side-panel,
.workspace > *,
.stats-panel,
.sheet-panel,
.drug-dock {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.side-panel {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  min-width: 0;
  overflow: auto;
}

.brand h1,
.stats-panel h2,
.table-toolbar h2,
.legend h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 25px;
  line-height: 1.18;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 130px;
  padding: 14px;
  border: 2px dashed #9fb9b5;
  border-radius: 8px;
  background: #f7fbfa;
  text-align: center;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: #eef9f7;
  transform: translateY(-1px);
}

.drop-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-bottom: 8px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  line-height: 1;
}

.drop-zone small {
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.4;
}

.status-box {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.status-box dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 0;
}

.status-box div {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 6px;
}

.status-box dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-box dd {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.legend h2 {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 800;
}

#resetHighlight {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.legend {
  padding: 13px;
  border-radius: 8px;
  background: var(--blue-soft);
  color: #26333d;
}

.legend p {
  margin: 8px 0 0;
  color: #3e4d56;
  font-size: 13px;
  line-height: 1.48;
}

.legend code {
  padding: 1px 5px;
  border-radius: 5px;
  background: #fff;
}

.workspace {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 218px;
  gap: 14px;
  min-width: 0;
  min-height: 0;
}

.stats-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 12px;
}

.stats-panel h2,
.table-toolbar h2 {
  font-size: 19px;
}

.stats-heading {
  display: grid;
  gap: 8px;
}

#statsScope {
  margin: 0;
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.summary-strip span {
  display: grid;
  gap: 3px;
  padding: 7px 9px;
  border-radius: 8px;
  background: #f4f7f5;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.summary-strip b {
  color: var(--ink);
}

.stats-table-wrap {
  max-height: 150px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

th {
  background: #edf4f2;
  color: #213733;
  font-size: 12px;
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
}

td {
  color: #263035;
  font-size: 13px;
}

.stats-table th,
.stats-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
}

.stats-table th:first-child,
.stats-table td:first-child {
  text-align: left;
}

.stats-table tr:last-child td {
  border-bottom: 0;
}

.stats-table .summary-row td {
  background: #fffaf0;
  font-weight: 900;
}

.stats-table .return-row td {
  color: var(--rose);
}

.sheet-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

#resetHighlight {
  padding: 8px 12px;
  font-weight: 800;
}

.table-scroll {
  min-height: 0;
  overflow: auto;
}

.data-table {
  min-width: 100%;
  table-layout: fixed;
}

.data-table th:nth-child(1),
.data-table td:nth-child(1) {
  width: 30%;
}

.data-table th:nth-child(2),
.data-table td:nth-child(2) {
  width: 8%;
}

.data-table th:nth-child(3),
.data-table td:nth-child(3),
.data-table th:nth-child(4),
.data-table td:nth-child(4),
.data-table th:nth-child(5),
.data-table td:nth-child(5),
.data-table th:nth-child(8),
.data-table td:nth-child(8) {
  width: 11%;
}

.data-table th:nth-child(6),
.data-table td:nth-child(6),
.data-table th:nth-child(7),
.data-table td:nth-child(7) {
  width: 9%;
}

.data-table th,
.data-table td {
  padding: 8px 10px;
  border-right: 1px solid #e7ece7;
  border-bottom: 1px solid #e7ece7;
  vertical-align: top;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.data-table tbody tr:nth-child(even) td {
  background: #fafbf9;
}

.data-table tbody tr.selected-drug td {
  background: var(--cream);
  box-shadow: inset 0 0 0 9999px rgba(255, 232, 163, 0.34);
}

.data-table tbody tr.focus-row td {
  background: var(--cream-strong);
}

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

.negative {
  color: var(--rose);
  font-weight: 800;
}

.category-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.cat-정제 {
  background: #eaf4ff;
  color: #24527a;
}

.cat-산제 {
  background: #fff1c2;
  color: #7b5200;
}

.cat-주사 {
  background: #e9f7ef;
  color: #14623a;
}

.drug-dock {
  min-height: 0;
  padding: 12px;
  overflow: hidden;
}

.dock-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
}

.dock-heading strong {
  color: var(--ink);
}

.drug-buttons {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  height: 164px;
  overflow: auto;
}

.drug-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 230px;
  padding: 5px 8px;
  border: 1px solid #cbd7d4;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.drug-button:hover,
.drug-button.active {
  border-color: var(--accent);
  background: #e9f8f5;
}

.drug-button span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drug-button em {
  flex: 0 0 auto;
  color: var(--amber);
  font-style: normal;
}

.empty-row td {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .side-panel {
    max-height: none;
  }

  .workspace {
    grid-template-rows: 56vh 220px;
  }

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