:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2f6fed;
  --primary-text: #ffffff;
  --danger: #e0473e;
  --danger-bg: #fdecec;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1e2128;
    --text: #f2f3f5;
    --muted: #9aa1ac;
    --border: #2c313a;
    --primary: #4f8cff;
    --primary-text: #ffffff;
    --danger: #ff6b61;
    --danger-bg: #3a2020;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 3rem;
  overflow-x: hidden;
}

main {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.app-header {
  max-width: 600px;
  margin: 0 auto;
  padding: 1.25rem 1rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.grand-total {
  text-align: right;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
}

.grand-total strong {
  font-size: 1.1rem;
  color: var(--text);
}

.receipt-meta {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.receipt-meta input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.card-header h2 {
  margin: 0;
  font-size: 1.1rem;
  flex: 1;
  min-width: 0;
}

.pool-total {
  font-weight: 600;
  white-space: nowrap;
}

.totals-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
}

.pool-share {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

summary {
  font-weight: 600;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem 0;
}

.capture-label {
  display: block;
  text-align: center;
  margin-top: 0.75rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.6rem 1.2rem;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
  width: 100%;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  width: 100%;
  margin-top: 0.75rem;
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.reset-btn {
  width: 100%;
  margin: 0.5rem 0 1.5rem;
}

.preview-wrap {
  margin-top: 0.75rem;
  text-align: center;
}

.preview-wrap img {
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.progress-wrap {
  margin-top: 0.75rem;
}

.progress-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.2s ease;
}

.progress-status {
  margin: 0.4rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.hidden {
  display: none;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.item-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.item-fields {
  display: flex;
  gap: 0.5rem;
}

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

.item-price {
  width: 5.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.item-fields input {
  min-height: 44px;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: 1;
}

.chip {
  min-height: 36px;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--chip-color, var(--primary));
  background: transparent;
  color: var(--chip-color, var(--primary));
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  word-break: break-word;
}

.chip-back {
  border-color: var(--muted);
  color: var(--muted);
}

.btn-delete {
  min-width: 36px;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--danger);
  cursor: pointer;
  flex-shrink: 0;
}

.btn-share {
  min-width: 36px;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.pool-card {
  --pool-color: var(--primary);
  border-top: 4px solid var(--pool-color);
}

.pool-name-input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  border-radius: 8px;
  padding: 0.2rem 0.4rem;
}

.pool-name-input:focus {
  border-color: var(--border);
  background: var(--bg);
}

.add-pool-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.add-pool-form input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

.add-pool-form button {
  width: auto;
  height: 44px;
  min-height: 0;
  margin-top: 0;
  white-space: nowrap;
}

.empty-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

#pools-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 640px) {
  .item-fields {
    flex-direction: row;
  }
}
