:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #201d1a;
  --ink-soft: #5c574f;
  --line: #e4e0d8;
  --accent: #a45c2c;
  --accent-ink: #ffffff;
  --ok: #3f7a4d;
  --off: #b0a99c;
  --danger: #b8442f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(32, 29, 26, 0.06), 0 4px 16px rgba(32, 29, 26, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --panel: #221f1c;
    --ink: #f1ede6;
    --ink-soft: #b8b0a3;
    --line: #38342e;
    --accent: #d98a4f;
    --accent-ink: #1a1512;
    --ok: #6fbf7e;
    --off: #6b6459;
    --danger: #e2725a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

header.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 14px 20px;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

header.topbar h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 650;
  white-space: nowrap;
}

.config-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.config-bar select {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 12.5px;
  max-width: 160px;
}

.config-bar button {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

.config-bar button:hover { color: var(--ink); border-color: var(--accent); }

.config-bar .config-delete {
  color: var(--danger);
  border-color: var(--line);
  padding: 6px 9px;
}

.config-bar .config-delete:hover { background: var(--danger); color: #fff; }

.search-wrap {
  position: relative;
  flex: 1 1 260px;
  min-width: 180px;
}

.search-wrap input {
  width: 100%;
  padding: 9px 34px 9px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

.search-wrap input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 16px;
  display: none;
  padding: 2px 6px;
}

.search-bulk {
  display: none;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--ink-soft);
}

.search-bulk button {
  font-size: 13px;
  padding: 6px 10px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  padding: 20px;
  max-width: 1300px;
  margin: 0 auto;
  align-items: start;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

main#lots {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.lot {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.lot.hidden, .section.hidden, .item.hidden { display: none !important; }

.lot-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid transparent;
}

.lot.open .lot-head {
  border-bottom-color: var(--line);
}

.lot-head .name {
  font-weight: 650;
  font-size: 14.5px;
  flex: 1;
}

.lot-head .amount {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-size: 13.5px;
}

.chevron {
  transition: transform 0.15s ease;
  color: var(--ink-soft);
  font-size: 12px;
  width: 14px;
}

.lot.open .chevron { transform: rotate(90deg); }

.lot-body {
  display: none;
  padding: 4px 16px 14px;
}

.lot.open .lot-body { display: block; }

.pair-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 16px 0;
}

.pair-tabs button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 10px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.pair-tabs button small {
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

.pair-tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.section {
  margin-top: 10px;
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}

.section:first-child { border-top: none; margin-top: 4px; }

.section-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
}

.section-head .title {
  font-weight: 600;
  font-size: 13.5px;
  flex: 1;
}

.section-head .amount {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-size: 13px;
}

.items { display: flex; flex-direction: column; }

.item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0 6px 24px;
  border-radius: 6px;
}

.item:hover { background: rgba(164, 92, 44, 0.06); }

.item input[type="checkbox"], .section-head input[type="checkbox"], .lot-head input[type="checkbox"] {
  margin-top: 3px;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.item .label {
  flex: 1;
  min-width: 0;
}

.item .title-line {
  font-size: 13.5px;
  cursor: pointer;
}

.item .desc {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 1px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item.checked .desc, .item.checked .title-line { opacity: 1; }
.item:not(.checked) .title-line, .item:not(.checked) .desc { opacity: 0.45; }

.item .meta {
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  padding-top: 1px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.qty-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.qty-input {
  width: 56px;
  padding: 3px 5px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.qty-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.unit-label {
  color: var(--ink-soft);
}

.qty-reset {
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
}

.amount-label {
  min-width: 150px;
  text-align: right;
}

mark {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

.lot.disabled-variant { opacity: 0.55; }
.lot.disabled-variant .item, .lot.disabled-variant .section-head { pointer-events: none; }

aside#summary {
  position: sticky;
  top: 78px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  font-size: 13.5px;
}

aside#summary h2 {
  font-size: 14px;
  margin: 0 0 12px;
}

.row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  align-items: center;
}

.row.total {
  border-top: 1px solid var(--line);
  margin-top: 8px;
  padding-top: 10px;
  font-weight: 650;
  font-size: 14.5px;
}

.row.grand {
  border-top: 2px solid var(--accent);
  margin-top: 8px;
  padding-top: 12px;
  font-weight: 700;
  font-size: 16.5px;
}

.row .val { font-variant-numeric: tabular-nums; white-space: nowrap; }

.row.chf-row {
  padding-top: 0;
  margin-top: -2px;
  font-size: 11.5px;
  color: var(--muted, #888);
}

.rate-input {
  display: flex;
  align-items: center;
  gap: 4px;
}

.rate-input input {
  width: 52px;
  padding: 3px 5px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  text-align: right;
}

.fees-note {
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-top: 10px;
  line-height: 1.4;
}

.save-indicator {
  font-size: 11px;
  color: var(--ok);
  height: 14px;
  margin-top: 10px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.save-indicator.show { opacity: 1; }

.notes-section {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.notes-section h3 {
  font-size: 13px;
  margin: 0 0 8px;
  color: var(--ink-soft);
}

.notes-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.notes-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 13px;
  line-height: 1.35;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--bg);
}

.notes-item .notes-text {
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: text;
}

.notes-edit,
.notes-remove {
  border: none;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px 3px;
  flex-shrink: 0;
}

.notes-edit:hover { color: var(--accent); }
.notes-remove:hover { color: var(--danger); }

.notes-item.editing { padding: 4px; }

.notes-edit-input {
  flex: 1;
  width: 100%;
  padding: 5px 7px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
}

.notes-edit-input:focus { outline: none; }

.notes-empty {
  font-size: 12px;
  color: var(--ink-soft);
  font-style: italic;
  margin: 0 0 8px;
}

.notes-form {
  display: flex;
  gap: 6px;
}

.notes-form input {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
}

.notes-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.notes-form button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 6px;
  padding: 0 12px;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
}

.notes-form button:hover { opacity: 0.9; }

.export-btn {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13.5px;
  font-weight: 650;
  cursor: pointer;
  text-align: center;
}

.export-btn:hover { opacity: 0.9; }

button {
  font-family: inherit;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12.5px;
  padding: 0;
  text-decoration: underline;
}

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.toolbar button {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 12.5px;
  cursor: pointer;
}

.toolbar button:hover { color: var(--ink); border-color: var(--accent); }

.reduction-max-btn {
  border-color: var(--danger) !important;
  color: var(--danger) !important;
}
.reduction-max-btn:hover {
  background: var(--danger) !important;
  color: #fff !important;
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 40px 20px;
  font-size: 13.5px;
}
