:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --accent: #2d6a4f;
  --accent-light: #d8f3dc;
  --border: #e5e7eb;
  --warn: #b45309;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  background: var(--accent);
  color: white;
  padding: 1rem 1.5rem;
}

header h1 { margin: 0; font-size: 1.35rem; }

nav {
  margin-top: 0.5rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

nav a { color: #ecfdf5; font-weight: 500; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.stat {
  background: var(--accent-light);
  border-radius: 8px;
  padding: 1rem;
}

.stat .label { color: var(--muted); font-size: 0.85rem; }
.stat .value { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.stat-hint { font-size: 0.75rem; margin: 0.25rem 0 0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; }

.grocery-list-total td {
  border-top: 2px solid var(--border);
  border-bottom: none;
}

.bar-row { margin-bottom: 0.6rem; }
.bar-label { display: flex; justify-content: space-between; font-size: 0.9rem; }
.bar-track {
  background: #e5e7eb;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 999px;
}

.insight {
  border-left: 4px solid var(--accent);
  padding-left: 0.75rem;
  margin-bottom: 1rem;
}

.insight h3 { margin: 0 0 0.25rem; font-size: 1rem; }
.insight p { margin: 0; color: var(--muted); }

.category-block { margin-bottom: 1.5rem; }
.category-block h3 {
  margin: 0 0 0.5rem;
  color: var(--accent);
}

.filters {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 1rem;
}

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }

input, select, textarea, button {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

button, .btn {
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  display: inline-block;
}

button:hover, .btn:hover { opacity: 0.9; text-decoration: none; }

.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.8rem;
}

.on-list-badge {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.grocery-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.reminder-row-form {
  margin: 0;
}

.reminder-row-form select {
  font: inherit;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  max-width: 10rem;
}

.envelope-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.envelope-card {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: box-shadow 0.15s ease;
}

.envelope-card:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  text-decoration: none;
}

.envelope-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.envelope-card h3 {
  margin: 0;
  font-size: 1.15rem;
}

.envelope-balance {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.envelope-balance.negative,
.envelope-balance-box.negative .value {
  color: #b42318;
}

.envelope-meta,
.envelope-flow {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

.amount-in { color: #1b7a3d; }
.amount-out { color: #b42318; }

.envelope-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.envelope-balance-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  text-align: right;
}

.envelope-balance-box.negative {
  background: #fef2f2;
  border-color: #fecaca;
}

.envelope-balance-box .label {
  font-size: 0.8rem;
  color: var(--muted);
}

.envelope-balance-box .value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}

.ledger-table .num {
  text-align: right;
  white-space: nowrap;
}

.ledger-total td {
  border-top: 2px solid var(--border);
  border-bottom: none;
}

.ledger-add-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem 1rem;
  align-items: end;
}

.ledger-add-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.ledger-add-form .form-hint {
  grid-column: 1 / -1;
  margin: 0;
}

.inline-form {
  margin: 0;
}

.btn-danger {
  background: #b42318;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
}

.btn-muted {
  background: #e5e7eb;
  color: var(--text);
}

.page-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}

.edit-hint {
  border-left: 4px solid var(--accent);
}

.edit-hint-list {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
}

.edit-hint-list li {
  margin-bottom: 0.35rem;
}

.trip-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}

.card-header-row h3 {
  margin: 0;
}

.category-select {
  min-width: 7.5rem;
  padding: 0.25rem 0.35rem;
  font-size: 0.9rem;
}

.category-form {
  margin: 0;
}

.line-item-row {
  display: grid;
  grid-template-columns: 1fr 1fr 120px 80px 100px 40px;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.muted { color: var(--muted); font-size: 0.9rem; }

.alert {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.alert-success {
  background: #d8f3dc;
  border: 1px solid #95d5b2;
  color: #1b4332;
}

.alert-error {
  background: #fde8e8;
  border: 1px solid #f5c2c2;
  color: #7f1d1d;
}

.alert-warning {
  background: #fff3cd;
  border: 1px solid #ffda6a;
  color: #664d03;
}

.plan-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.plan-header h3 { margin: 0 0 0.25rem; }

.reminders-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
}

.replace-label {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

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

.ocr-box {
  width: 100%;
  min-height: 120px;
  font-family: monospace;
  font-size: 0.85rem;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.period-selector {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

.period-selector label {
  color: #ecfdf5;
  font-size: 0.75rem;
  margin: 0;
}

.period-selector select {
  min-width: 280px;
  background: white;
  color: var(--text);
}

.period-banner {
  margin: 0 0 1rem;
}

.period-archive ul.period-links {
  list-style: none;
  padding: 0;
  margin: 0;
}

.period-links li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.period-links li:last-child {
  border-bottom: none;
}

@media (max-width: 700px) {
  .line-item-row { grid-template-columns: 1fr; }

  .period-selector {
    align-items: stretch;
    width: 100%;
  }

  .period-selector select {
    min-width: 0;
    width: 100%;
  }

  .period-links li {
    flex-direction: column;
    align-items: flex-start;
  }
}

.pantry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

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

.pantry-card.level-low { border-color: var(--warn); }
.pantry-card.level-empty { border-color: #b91c1c; background: #fef2f2; }

.pantry-card-name { font-weight: 600; margin-bottom: 0.25rem; }
.pantry-card-meta { font-size: 0.85rem; margin-bottom: 0.75rem; }

.pantry-level-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.btn-level {
  background: #e5e7eb;
  color: var(--text);
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 4px;
  border: none;
  cursor: pointer;
}

.btn-level.active { background: var(--accent); color: white; }

.pantry-undo { margin-top: 0.25rem; }
.muted-btn { background: #9ca3af; }
.warn-text { color: var(--warn); }
.scan-input { width: 100%; font-size: 1.25rem; padding: 0.75rem; margin: 0.5rem 0; }
.scan-result { min-height: 1.5rem; margin: 0.5rem 0; }
.hidden { display: none; }
.buy-today-card h3 { margin-top: 0; }
.actions-cell form { display: inline-block; margin-right: 0.25rem; }
.suggestion-list { list-style: none; padding: 0; }
.suggestion-list li { margin-bottom: 0.5rem; }

