:root {
  color-scheme: light;
  --bg: #f2ede3;
  --panel: #fffaf3;
  --text: #1f1a14;
  --muted: #6e6257;
  --border: #d7cbb9;
  --accent: #b85c38;
  --accent-dark: #8f472b;
  --error-bg: #f8dfd6;
  --error-text: #7f2510;
  font-family: Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(184, 92, 56, 0.14), transparent 32%),
    linear-gradient(180deg, #f7f1e8 0%, var(--bg) 100%);
  color: var(--text);
}

.page {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 48px 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  box-shadow: 0 20px 50px rgba(72, 52, 34, 0.08);
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1;
}

h2 {
  font-size: 1.4rem;
  margin-bottom: 16px;
}

.intro {
  margin: 16px 0 0;
  color: var(--muted);
  max-width: 52ch;
  line-height: 1.5;
}

.upload-form {
  display: grid;
  gap: 14px;
  margin-top: 28px;
}

label {
  font-weight: 700;
}

input[type="file"] {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: #fff;
}

button {
  width: fit-content;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: var(--accent);
  color: #fffaf3;
  font: inherit;
  cursor: pointer;
}

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

.secondary-button,
.ghost-button {
  font: inherit;
}

.secondary-button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.secondary-button:hover {
  background: #f8f1e7;
}

.ghost-button {
  padding: 10px 14px;
  background: transparent;
  color: var(--accent-dark);
  border: 1px solid rgba(184, 92, 56, 0.28);
}

.ghost-button:hover {
  background: rgba(184, 92, 56, 0.1);
}

.message {
  margin-top: 20px;
  padding: 14px 16px;
  border-radius: 12px;
}

.error {
  background: var(--error-bg);
  color: var(--error-text);
}

.results {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.ocr-heading {
  margin-top: 28px;
}

dl {
  display: grid;
  gap: 12px;
  margin: 0;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(215, 203, 185, 0.65);
}

dt {
  font-weight: 700;
}

dd {
  margin: 0;
  color: var(--muted);
  text-align: right;
}

.receipt-amount-input {
  display: inline-grid;
  grid-template-columns: auto minmax(84px, 110px);
  gap: 8px;
  align-items: center;
  justify-items: end;
}

.receipt-amount-input span {
  color: var(--muted);
}

.receipt-amount-input input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  text-align: right;
  color: var(--text);
  background: #fff;
}

.receipt-amount-input input:focus {
  outline: 2px solid rgba(184, 92, 56, 0.18);
  border-color: rgba(184, 92, 56, 0.42);
}

.ocr-output,
.empty-state {
  margin: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
}

.ocr-output {
  overflow-x: auto;
  white-space: pre-wrap;
  line-height: 1.45;
  font-family: "Courier New", Courier, monospace;
}

.empty-state {
  color: var(--muted);
  line-height: 1.5;
}

.validation-message {
  margin: 16px 0 0;
  padding: 14px 16px;
  border-radius: 12px;
  line-height: 1.5;
}

.validation-ok {
  background: #e4f2e2;
  color: #214d1f;
}

.validation-warning {
  background: #f7e6c8;
  color: #704d14;
}

.candidate-list,
.pass-list {
  display: grid;
  gap: 14px;
}

.item-editor {
  display: grid;
  gap: 14px;
}

.editor-intro {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.item-editor-header,
.item-row {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) minmax(140px, 0.9fr) auto;
  gap: 12px;
  align-items: center;
}

.item-editor-header {
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.95rem;
}

.item-editor-rows {
  display: grid;
  gap: 10px;
}

.item-row {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
}

.item-main {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.item-primary {
  display: grid;
  gap: 8px;
}

.item-source {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.2;
}

.info-button {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(184, 92, 56, 0.28);
  border-radius: 999px;
  background: #fff;
  color: var(--accent-dark);
  font-weight: 700;
  line-height: 1;
}

.info-button:hover {
  background: rgba(184, 92, 56, 0.1);
}

.item-row input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fffdf9;
  color: var(--text);
  font: inherit;
}

.item-row input:focus {
  outline: 2px solid rgba(184, 92, 56, 0.2);
  border-color: var(--accent);
}

.price-input {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  background: #fffdf9;
}

.price-input span {
  color: var(--muted);
}

.price-input input {
  border: 0;
  padding-left: 0;
  padding-right: 0;
  background: transparent;
}

.price-input input:focus {
  outline: 0;
}

.editor-actions {
  display: flex;
  justify-content: flex-start;
}

.splitter {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.person-creator {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 18px;
}

.person-creator input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.splitter-summary,
.assignment-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.charge-toggle {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
  color: var(--text);
}

.charge-toggle input {
  width: 18px;
  height: 18px;
}

.splitter-status {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
}

.status-line-ok {
  background: #e4f2e2;
  color: #214d1f;
}

.status-line-warning {
  background: #f7e6c8;
  color: #704d14;
}

.status-icon {
  font-size: 1rem;
  line-height: 1;
}

.splitter-empty {
  margin-top: 16px;
}

.person-message {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: #efe7db;
  color: var(--muted);
  line-height: 1.45;
}

.splitter-summary {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.splitter-items-heading {
  margin-top: 28px;
}

.person-total-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  background: #fff;
  cursor: pointer;
}

.person-total-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.person-total-card h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.person-total-card-active {
  border-color: #7eb8e8;
  box-shadow: inset 0 0 0 1px rgba(64, 132, 190, 0.22);
  background: #eaf5ff;
}

.person-total-detail {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.remove-person-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font: inherit;
  line-height: 1;
}

.remove-person-icon-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.assignment-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.assignment-card {
  display: grid;
  gap: 12px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.assignment-card:hover {
  background: #f8f1e7;
}

.assignment-card-inactive {
  cursor: default;
}

.assignment-card-inactive:hover {
  background: #fff;
}

.assignment-card-selected {
  border-color: #7eb8e8;
  box-shadow: inset 0 0 0 1px rgba(64, 132, 190, 0.22);
  background: #eaf5ff;
}

.assignment-card-unassigned {
  border-color: #d98787;
  box-shadow: inset 0 0 0 1px rgba(193, 89, 89, 0.18);
}

.assignment-card-disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.assignment-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.assignment-price-block {
  display: grid;
  gap: 4px;
}

.assignment-price-block:last-child {
  justify-items: end;
}

.assignment-card-top h3 {
  font-size: 1.05rem;
}

.assignment-each {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.2;
}

.assignment-source {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.assignment-actions {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
}

.assignment-label {
  color: var(--muted);
  font-size: 0.92rem;
}

.mini-button {
  width: auto;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.mini-button:hover {
  background: #f8f1e7;
}

.assignment-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.picker-chip {
  width: auto;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.picker-chip-active {
  border-color: #7eb8e8;
  background: #eaf5ff;
  color: #235781;
  font-weight: 700;
}

.secondary-button-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.item-row-deleted {
  background: #f9e3dc;
  border-color: #e2b8ab;
}

.item-row-deleted .item-source,
.item-row-deleted input,
.item-row-deleted .price-input span,
.item-row-deleted .info-button {
  color: #8b5e52;
  text-decoration: line-through;
}

.item-row-deleted input {
  background: transparent;
}

.item-row-deleted .info-button {
  background: transparent;
}

.candidate-card,
.pass-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  background: #fff;
}

.candidate-card {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.candidate-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.candidate-card strong {
  white-space: nowrap;
}

.pass-card h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.debug-panel {
  margin-top: 28px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.72);
}

.debug-panel summary {
  cursor: pointer;
  font-weight: 700;
}

.debug-panel[open] summary {
  margin-bottom: 16px;
}

@media (max-width: 640px) {
  .panel {
    padding: 24px;
  }

  dl div {
    flex-direction: column;
    gap: 6px;
  }

  dd {
    text-align: left;
  }

  .candidate-card {
    flex-direction: column;
  }

  .item-editor-header {
    display: none;
  }

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

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

  .person-creator {
    flex-direction: column;
    align-items: stretch;
  }
}
