@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans+KR:wght@400;500;600;700&family=Oswald:wght@400;500;600;700&display=swap");

:root {
  --bg: #eef3f8;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --line: rgba(89, 73, 55, 0.22);
  --ink: #4f4740;
  --muted: rgba(79, 71, 64, 0.82);
  --accent: #f18f01;
  --accent-soft: rgba(241, 143, 1, 0.13);
  --green: #18794e;
  --amber: #9f6508;
  --error: #b33a3a;
  --shadow: 0 16px 28px rgba(82, 60, 46, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Malgun Gothic", "Segoe UI", sans-serif;
  color: var(--ink);
}

body.piece-body {
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.22), transparent 24%),
    linear-gradient(180deg, #c2c2c2 0%, #b6b6b6 100%) !important;
}

body.piece-body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 1px, transparent 1px 100%),
    linear-gradient(0deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 100%);
  background-size: 110px 110px;
}

body.portal-home.inbound-body.inbound-home.piece-body {
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.22), transparent 24%),
    linear-gradient(180deg, #c2c2c2 0%, #b6b6b6 100%) !important;
}

body.portal-home.inbound-body.inbound-home.piece-body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 1px, transparent 1px 100%),
    linear-gradient(0deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 100%);
  background-size: 110px 110px;
}

.piece-page {
  width: min(1700px, calc(100vw - 12px)) !important;
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  gap: 10px !important;
  align-content: start;
}

.page-header,
.piece-search-panel,
.piece-results-panel,
.piece-entry-panel,
.piece-cart-panel {
  border: 1px solid var(--line);
  border-radius: 0;
  background: linear-gradient(180deg, #ffffff, #f9fbfd);
  box-shadow: var(--shadow);
}

.page-header {
  position: relative;
  overflow: hidden;
  min-height: 0;
  padding: 24px 16px 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}

.page-header::before {
  content: "";
  position: absolute;
  top: 12px;
  left: 16px;
  right: 16px;
  height: 1px;
  background: rgba(241, 143, 1, 0.34);
}

.page-header h1 {
  position: relative;
  z-index: 1;
  margin: 0;
  color: var(--accent);
  font-family: "IBM Plex Sans KR", "Helvetica Neue", Arial, sans-serif;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.02;
}

.home-link,
button {
  appearance: none;
  border: 1px solid rgba(241, 143, 1, 0.34);
  border-radius: 0;
  background: linear-gradient(180deg, #f18f01, #e88300);
  color: #fff7ed;
  text-decoration: none;
  font: inherit;
  font-weight: 700;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 12px 22px rgba(121, 74, 31, 0.14);
}

button:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

.primary {
  border-color: rgba(241, 143, 1, 0.34);
  background: linear-gradient(180deg, #f18f01, #e88300);
  color: #fff7ed;
}

.primary:not(:disabled):hover,
button:not(:disabled):hover {
  border-color: rgba(241, 143, 1, 0.46);
  background: linear-gradient(180deg, #ff9e18, #ed8600);
  color: #fffaf3;
}

.home-link {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(241, 143, 1, 0.32);
  background: rgba(255, 255, 254, 0.98);
  color: #f18f01;
  box-shadow: none;
}

.home-link:hover {
  background: #f18f01;
  color: #fffaf1;
  border-color: #f18f01;
}

.piece-search-panel,
.piece-entry-panel,
.piece-cart-panel {
  padding: 14px;
}

.piece-search-form {
  display: flex;
  gap: 8px;
  align-items: end;
  width: min(50%, 720px);
  max-width: 100%;
}

.piece-search-toggle {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(89, 73, 55, 0.18);
  background: rgba(255, 255, 254, 0.74);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.piece-search-toggle input {
  width: 16px;
  min-height: 16px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.piece-search-field,
.piece-quantity-field {
  min-width: 0;
  display: grid;
  gap: 6px;
  flex: 1;
}

.piece-search-field span,
.piece-quantity-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(89, 73, 55, 0.18);
  border-radius: 0;
  background: rgba(255, 255, 254, 0.98);
  color: #4f4740;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}

.piece-status {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.piece-status.is-error {
  color: var(--error);
}

.piece-search-content {
  display: grid;
  grid-template-columns: minmax(280px, 720px) minmax(260px, 520px);
  gap: 12px;
  align-items: start;
  margin-top: 8px;
}

.piece-results-panel {
  min-height: 248px;
  overflow: hidden;
}

.piece-search-panel .piece-results-panel {
  width: 100%;
  min-height: 0;
  border-color: rgba(89, 73, 55, 0.18);
  background: rgba(255, 255, 254, 0.9);
  box-shadow: none;
}

.piece-results-panel.is-hidden {
  display: none;
}

.piece-cart-detail-panel.is-hidden {
  display: none;
}

.piece-results {
  max-height: 420px;
  overflow: auto;
}

.piece-search-panel .piece-results {
  max-height: 310px;
}

.product-result {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 0;
  border-bottom: 1px solid rgba(24, 34, 48, 0.08);
  border-radius: 0;
  padding: 12px 14px;
  text-align: left;
  background: transparent;
  color: var(--ink);
  box-shadow: none;
}

button.product-result:hover,
button.product-result.is-selected {
  background: var(--accent-soft);
  color: var(--ink);
  box-shadow: none;
}

button.product-result:hover .product-price,
button.product-result.is-selected .product-price {
  color: #5f5650;
}

.product-name {
  font-size: 15px;
  font-weight: 900;
}

.product-meta,
.product-usage-meta,
.selected-meta,
.cart-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
}

.product-usage-meta {
  display: block;
  color: #8f5d12;
}

.product-price {
  color: var(--accent);
  font-weight: 900;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.piece-entry-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 12px;
  align-items: stretch;
}

.piece-entry-panel.is-hidden {
  display: none;
}

.selected-product {
  min-height: 112px;
  border: 1px solid rgba(24, 34, 48, 0.12);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.72);
  padding: 12px;
  font-weight: 900;
  line-height: 1.55;
}

.selected-product.is-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.piece-add-form {
  display: grid;
  gap: 8px;
  align-content: end;
}

.piece-quantity-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.piece-cart-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.piece-cart-head h2 {
  margin: 0;
  font-size: 18px;
}

.piece-cart-head strong {
  color: var(--accent);
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.piece-price-summary-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  margin: 0 0 10px;
}

.piece-summary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.piece-summary-copy,
.piece-todo-transfer {
  width: max-content;
  min-width: 0;
  min-height: 34px;
  padding: 6px 9px;
  font-size: 13px;
  white-space: nowrap;
}

.piece-todo-transfer {
  border-color: #6f5a43;
  background: #6f5a43;
  color: #fff;
  font-weight: 900;
}

.piece-todo-transfer:hover:not(:disabled) {
  border-color: #574533;
  background: #574533;
}

.piece-price-summary {
  min-width: 0;
  min-height: 34px;
  display: flex;
  align-items: center;
  border: 1px solid rgba(241, 143, 1, 0.18);
  background: rgba(241, 143, 1, 0.08);
  color: #6f4a12;
  padding: 6px 10px;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.35;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.piece-price-summary.is-empty {
  border-color: rgba(24, 34, 48, 0.08);
  background: rgba(255, 255, 255, 0.54);
  color: var(--muted);
  font-size: 13px;
}

.piece-cart {
  display: grid;
  gap: 8px;
}

.cart-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(24, 34, 48, 0.1);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.72);
  padding: 10px;
}

.usage-cart-row {
  align-items: start;
}

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

.cart-name {
  font-weight: 900;
}

.cart-amount {
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cart-amount.is-muted {
  color: var(--muted);
}

.cart-remove {
  min-width: 34px;
  padding: 6px 8px;
  color: var(--error);
}

.usage-section {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  min-width: 0;
  border-top: 1px solid rgba(24, 34, 48, 0.08);
  padding-top: 10px;
}

.usage-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.usage-head strong {
  font-size: 13px;
  color: var(--ink);
}

.usage-more {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}

.usage-table-wrap {
  max-height: 430px;
  overflow: auto;
  border: 1px solid rgba(24, 34, 48, 0.08);
  background: rgba(255, 255, 255, 0.64);
}

.usage-table {
  width: 100%;
  min-width: 510px;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}

.usage-table th,
.usage-table td {
  border-bottom: 1px solid rgba(24, 34, 48, 0.07);
  padding: 6px 7px;
  text-align: left;
  vertical-align: top;
}

.usage-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f3ef;
  color: var(--muted);
  font-weight: 900;
  white-space: nowrap;
}

.usage-table th:nth-child(1),
.usage-table td:nth-child(1),
.usage-table th:nth-child(2),
.usage-table td:nth-child(2),
.usage-table th:nth-child(3),
.usage-table td:nth-child(3),
.usage-table th:nth-child(4),
.usage-table td:nth-child(4),
.usage-table th:nth-child(5),
.usage-table td:nth-child(5) {
  width: 20%;
}

.usage-table th:nth-child(1),
.usage-table td:nth-child(1),
.usage-table th:nth-child(3),
.usage-table td:nth-child(3) {
  overflow-wrap: anywhere;
  word-break: keep-all;
}

.usage-table th:nth-child(2),
.usage-table td:nth-child(2),
.usage-table th:nth-child(4),
.usage-table td:nth-child(4),
.usage-table th:nth-child(5),
.usage-table td:nth-child(5) {
  white-space: nowrap;
}

.usage-table th:nth-child(5),
.usage-table td:nth-child(5) {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.usage-table tbody tr {
  cursor: pointer;
}

.usage-table tbody tr:hover,
.usage-table tbody tr.is-selected-usage {
  background: rgba(241, 143, 1, 0.12);
}

.usage-table tbody tr.is-selected-usage td:first-child strong {
  color: #f18f01;
}

.usage-table strong {
  display: block;
  color: var(--ink);
  line-height: 1.35;
}

.usage-table span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 720px) {
  .usage-table {
    min-width: 372px;
    font-size: 12px;
  }

  .usage-table th,
  .usage-table td {
    padding: 4px 4px;
  }

  .usage-table th:nth-child(1),
  .usage-table td:nth-child(1) {
    width: 104px;
  }

  .usage-table th:nth-child(2),
  .usage-table td:nth-child(2) {
    width: 58px;
  }

  .usage-table th:nth-child(3),
  .usage-table td:nth-child(3) {
    width: 130px;
  }

  .usage-table th:nth-child(4),
  .usage-table td:nth-child(4) {
    width: 32px;
  }

  .usage-table th:nth-child(5),
  .usage-table td:nth-child(5) {
    width: 28px;
  }
}

.usage-empty {
  border: 1px solid rgba(24, 34, 48, 0.08);
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  padding: 12px;
  font-size: 13px;
  font-weight: 800;
}

.usage-empty.is-error {
  color: var(--error);
}

.piece-empty {
  margin: 0;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

@media (max-width: 860px) {
  .piece-search-form,
  .piece-search-content {
    grid-template-columns: 1fr;
  }

  .piece-search-form {
    display: grid;
    width: 100%;
  }

  .piece-search-panel .piece-results-panel {
    width: 100%;
  }

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

  .cart-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .cart-remove {
    grid-column: 2;
  }

  .usage-section {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .piece-page {
    width: calc(100vw - 16px) !important;
    padding: 8px !important;
    gap: 10px !important;
  }

  .piece-price-summary-row {
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 6px;
  }

  .piece-summary-copy,
  .piece-todo-transfer {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 12px;
  }

  .piece-summary-actions {
    align-self: stretch;
  }

  .piece-price-summary {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 13px;
    line-height: 1.35;
  }
}
