:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d7dde3;
  --line-strong: #b8c2cc;
  --text: #1f2933;
  --muted: #64748b;
  --accent: #0f6f66;
  --accent-dark: #0a554f;
  --danger: #b42318;
  --used: #eef8f4;
  --header: #edf1f5;
  --warn: #fff7d6;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1180px;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Noto Sans KR", sans-serif;
  font-size: 14px;
}

button,
input,
select,
.file-button {
  font: inherit;
}

button,
.file-button {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  padding: 7px 12px;
  white-space: nowrap;
}

button:hover,
.file-button:hover {
  border-color: #7a8a99;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

button.primary:hover {
  background: var(--accent-dark);
}

button.danger {
  border-color: #efb4ad;
  color: var(--danger);
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

input,
select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  padding: 0 9px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.app-header p {
  margin: 5px 0 0;
  color: var(--muted);
}

.message-area {
  max-width: 520px;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--muted);
  text-align: right;
}

.message-area.success {
  border-color: #b7dfd5;
  background: #eef8f4;
  color: #0a554f;
}

.message-area.error {
  border-color: #efb4ad;
  background: #fff1f0;
  color: var(--danger);
}

.top-tabs,
.sub-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.tab-button,
.sub-tab {
  min-height: 36px;
  border-color: transparent;
  background: transparent;
  font-weight: 700;
}

.tab-button.active,
.sub-tab.active {
  border-color: var(--accent);
  background: #eef8f4;
  color: var(--accent-dark);
}

.app-shell {
  padding: 16px;
}

.tab-panel,
.db-panel {
  display: none;
}

.tab-panel.active,
.db-panel.active {
  display: block;
}

.panel,
.summary-panel,
.result-panel,
.toolbar,
.db-toolbar,
.composition-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
}

.panel h2,
.summary-panel h2,
.result-panel h2,
.db-toolbar h2 {
  margin: 0;
  font-size: 16px;
}

.field-label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
}

.toolbar.compact {
  justify-content: flex-start;
  align-items: center;
  margin: 12px 0;
}

.toolbar.compact input {
  max-width: 360px;
}

.toolbar.compact select {
  max-width: 180px;
}

.style-controls {
  width: 260px;
}

.search-wrap {
  width: min(520px, 45%);
}

.toolbar-actions,
.button-row,
.result-actions,
.composition-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

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

.table-wrap {
  max-height: 620px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.db-table-wrap {
  max-height: 650px;
}

.data-table,
.summary-table,
.result-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table th,
.data-table td,
.result-table th,
.result-table td,
.summary-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px;
  vertical-align: middle;
}

.data-table th,
.result-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--header);
  font-size: 12px;
  text-align: left;
  white-space: nowrap;
}

.data-table td,
.result-table td {
  background: #ffffff;
}

.data-table tr.used-row td,
.result-table .used-row td {
  background: var(--used);
}

.data-table th:first-child,
.data-table td:first-child {
  width: 52px;
  text-align: center;
}

#fabricTable th:nth-child(2),
#fabricTable td:nth-child(2) {
  min-width: 330px;
}

#fabricTable th:nth-child(3),
#fabricTable td:nth-child(3) {
  min-width: 230px;
}

.number-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.yy-input {
  width: 86px;
  text-align: right;
}

.summary-panel {
  position: sticky;
  top: 12px;
  padding: 14px;
}

.summary-meta {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 14px 0;
}

.summary-meta div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f9fafb;
}

.summary-meta span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.summary-meta strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 18px;
}

.summary-table td:first-child {
  color: var(--muted);
  font-weight: 700;
}

.summary-table td:last-child {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.summary-table tr.total-row td {
  background: var(--header);
  color: var(--text);
}

.current-care-label-area {
  margin-top: 14px;
}

.live-care-generator h3 {
  margin: 0 0 8px;
  font-size: 13px;
}

.live-care-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  margin-top: 8px;
}

.live-care-card > strong {
  display: block;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--header);
}

.live-care-card pre {
  margin: 0;
  padding: 10px;
  font: 700 13px/1.5 Arial, "Noto Sans KR", sans-serif;
  white-space: pre-wrap;
}

.live-care-warning,
.live-care-note {
  margin: 0 10px 10px;
  border-radius: 6px;
  padding: 7px 8px;
  font-size: 11px;
}

.live-care-warning {
  border: 1px solid #f0d98c;
  background: var(--warn);
  color: #6b4e00;
}

.live-care-note {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: var(--muted);
}

.panel-title-row,
.db-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.db-toolbar {
  padding: 14px;
}

.count-badge {
  min-width: 26px;
  border-radius: 999px;
  background: var(--header);
  color: var(--muted);
  text-align: center;
  padding: 3px 8px;
  font-weight: 700;
}

.saved-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.saved-item {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #ffffff;
}

.saved-item.active {
  border-color: var(--accent);
  background: #eef8f4;
}

.saved-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  font-weight: 700;
}

.mini-button {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.result-panel {
  margin-top: 0;
}

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

.care-label-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #f9fafb;
}

.care-label-options label,
.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.care-label-options input,
.inline-check input {
  width: auto;
  min-height: auto;
}

.result-area {
  padding: 14px;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.result-section {
  margin-bottom: 26px;
  page-break-inside: avoid;
}

.result-section h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
  align-items: start;
}

.care-label-preview {
  margin: 0 0 16px;
}

.care-label-preview h4 {
  margin: 0 0 10px;
  font-size: 14px;
}

.care-label-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
}

.care-label-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.care-label-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--header);
}

.care-label-card pre {
  min-height: 116px;
  margin: 0;
  padding: 12px;
  font: 700 14px/1.55 Arial, "Noto Sans KR", sans-serif;
  white-space: pre-wrap;
}

.care-label-message {
  margin: 0 10px 10px;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
}

.care-label-message p {
  margin: 4px 0 0;
}

.care-label-message.warning {
  border: 1px solid #f0d98c;
  background: var(--warn);
  color: #6b4e00;
}

.care-label-message.note {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: var(--muted);
}

.result-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.result-table th,
.result-table td {
  font-size: 12px;
}

.db-warning {
  margin: 8px 0 0;
  border: 1px solid #f0d98c;
  border-radius: 6px;
  background: var(--warn);
  padding: 8px 10px;
  color: #6b4e00;
}

.validation-area {
  margin: 12px 0;
  border: 1px solid #efb4ad;
  border-radius: 8px;
  background: #fff1f0;
  padding: 12px 14px;
  color: var(--danger);
}

.validation-area ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.composition-list {
  display: grid;
  gap: 12px;
}

.composition-card {
  padding: 12px;
  width: fit-content;
  max-width: 100%;
}

.composition-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.composition-head input {
  min-width: 260px;
  max-width: 420px;
  font-weight: 700;
}

.composition-components-table {
  width: auto;
  min-width: min(100%, 458px);
  max-width: 100%;
}

.composition-components-table .composition-component-row {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 90px auto;
  gap: 8px;
  align-items: center;
}

.composition-components-table th,
.composition-components-table td,
.composition-components-table th:first-child,
.composition-components-table td:first-child {
  width: auto;
  min-width: 0;
  border-right: 0;
  text-align: left;
}

.composition-components-table .material-select {
  width: 100%;
  min-width: 260px;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composition-components-table .component-ratio-input {
  width: 90px;
  max-width: 90px;
  text-align: right;
}

.compact-table th,
.compact-table td {
  padding: 6px;
}

.compact-table select {
  max-width: 320px;
}

.compact-table input {
  max-width: 130px;
  text-align: right;
}

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

.ok-text {
  color: var(--accent-dark);
  font-weight: 700;
}

.error-text {
  color: var(--danger);
  font-weight: 700;
}

.backup-panel .button-row {
  margin-top: 16px;
}

.unmapped-list {
  margin-top: 16px;
}

.unmapped-list h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.unmapped-list p {
  margin: 0 0 10px;
  color: var(--muted);
}

.hidden {
  display: none;
}

@media print {
  body {
    min-width: 0;
    background: #ffffff;
  }

  .app-header,
  .top-tabs,
  .toolbar,
  .content-grid,
  .result-toolbar {
    display: none;
  }

  .app-shell {
    padding: 0;
  }

  .tab-panel {
    display: none;
  }

  #results {
    display: block;
  }

  .result-panel {
    border: 0;
    box-shadow: none;
    margin: 0;
  }

  .result-area {
    padding: 0;
  }

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

  .result-table th {
    position: static;
  }
}
