:root {
  --paper: #f7f4ed;
  --ink: #182321;
  --muted: #64706b;
  --line: #d8d1c4;
  --field: #fffdf8;
  --cedar: #274c43;
  --cedar-2: #37695d;
  --copper: #b96233;
  --gold: #d4a017;
  --danger: #b3261e;
  --shadow: 0 18px 50px rgba(24, 35, 33, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(39, 76, 67, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(39, 76, 67, 0.06) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.workspace {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: clamp(280px, 52vw, 640px);
  height: auto;
  flex: 0 1 auto;
  object-fit: contain;
}

.brand-copy {
  min-width: 0;
}

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

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.16;
}

.maker {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tab,
.button {
  border: 1px solid var(--cedar);
  background: var(--field);
  color: var(--cedar);
  min-height: 40px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.tab.active,
.button.primary {
  background: var(--cedar);
  color: #ffffff;
}

.button.warn {
  border-color: var(--copper);
  color: var(--copper);
}

button:disabled,
.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.view {
  display: none;
  padding: 24px;
}

.view.active {
  display: block;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

.panel {
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.82);
  border-radius: 8px;
  padding: 18px;
}

.span-4 {
  grid-column: span 4;
}

.span-8 {
  grid-column: span 8;
}

.span-12 {
  grid-column: span 12;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--ink);
  padding: 0 10px;
}

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

.item-picker {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 140px auto;
  gap: 12px;
  align-items: end;
}

.search-box {
  position: relative;
}

.suggestions {
  position: absolute;
  z-index: 20;
  width: 100%;
  top: calc(100% + 6px);
  left: 0;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: var(--shadow);
}

.suggestion {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
}

.suggestion:hover {
  background: rgba(212, 160, 23, 0.15);
}

.code {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-weight: 800;
  color: var(--cedar);
}

code {
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(39, 76, 67, 0.08);
  font-family: "Cascadia Mono", Consolas, monospace;
}

.selected-item {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.7);
  color: var(--muted);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.empty-state {
  margin: 0;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.65);
  color: var(--muted);
}

.qty-cell {
  max-width: 120px;
}

.line-table .line-action-cell {
  white-space: nowrap;
}

.option-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 14px;
}

.option-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option-table input {
  min-width: 110px;
}

.option-table .actions {
  min-width: 150px;
}

.option-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 4px 8px 4px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}

.option-pill button {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--field);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--cedar);
  color: #ffffff;
  font-size: 13px;
}

.summary-pivot-table {
  min-width: max-content;
}

.summary-pivot-table th:nth-child(1),
.summary-pivot-table td:nth-child(1) {
  min-width: 130px;
}

.summary-pivot-table th:nth-child(2),
.summary-pivot-table td:nth-child(2) {
  min-width: 180px;
}

.summary-pivot-table th:nth-child(n + 4),
.summary-pivot-table td:nth-child(n + 4) {
  min-width: 120px;
  text-align: right;
  white-space: nowrap;
}

#summary-table,
#transactions-table {
  overflow-x: auto;
}

.status {
  min-height: 24px;
  color: var(--cedar);
  font-weight: 700;
}

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

.status.warning {
  color: var(--copper);
}

.muted {
  color: var(--muted);
}

@media (max-width: 860px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: center;
  }

  .brand {
    align-items: center;
    gap: 10px;
  }

  .brand-logo {
    width: min(100%, 420px);
  }

  .brand-copy {
    min-width: 0;
  }

  .view {
    padding: 16px;
  }

  .item-picker {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: stretch;
  }

  .section-heading .button {
    width: 100%;
  }

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

  .span-4,
  .span-8,
  .span-12 {
    grid-column: span 12;
  }

  table {
    display: block;
    overflow-x: auto;
  }

  .responsive-lines {
    display: block;
    border-collapse: separate;
    background: transparent;
    overflow: visible;
  }

  .responsive-lines thead {
    display: none;
  }

  .responsive-lines tbody {
    display: grid;
    gap: 12px;
  }

  .responsive-lines tr {
    display: grid;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
    overflow: hidden;
  }

  .responsive-lines td {
    display: grid;
    grid-template-columns: minmax(82px, 34%) minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
  }

  .responsive-lines td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }

  .responsive-lines td:last-child {
    border-bottom: 0;
  }

  .responsive-lines .qty-cell {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .responsive-lines .line-action-cell {
    display: block;
  }

  .responsive-lines .line-action-cell::before {
    display: none;
  }

  .responsive-lines .line-action-cell .button {
    width: 100%;
  }
}
