:root {
  --bg: #f5f7f9;
  --card-bg: #ffffff;
  --text: #1e2530;
  --muted: #64707d;
  --border: #dde3e9;
  --primary: #2660a4;
  --primary-dark: #1a4374;
  --warning-bg: #fff4e0;
  --warning-border: #e8a83c;
  --error-bg: #fdecec;
  --error-border: #d9534f;
  --success-bg: #e9f6ee;
  --success-border: #2f8f5f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

.topbar {
  background: var(--primary-dark);
  color: white;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}

.brand {
  color: white;
  font-weight: 700;
  text-decoration: none;
  font-size: 1.1rem;
}

.topnav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}

.topnav a {
  color: #d6e4f0;
  text-decoration: none;
  font-size: 0.92rem;
  padding: 4px 0;
}

.topnav a.active, .topnav a:hover {
  color: white;
  border-bottom: 2px solid white;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 18px 14px 60px;
}

h1 { font-size: 1.5rem; margin: 6px 0 14px; }
h2 { font-size: 1.15rem; margin: 24px 0 10px; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.year-picker select, .filter-bar select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  font-size: 1rem;
}

.inline-form {
  display: flex;
  gap: 8px;
  margin: 10px 0 20px;
}

.inline-form input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  width: 140px;
}

.grand-total-card {
  background: var(--primary);
  color: white;
  border-radius: 14px;
  padding: 22px;
  margin: 10px 0 20px;
}

.grand-total-label { font-size: 0.9rem; opacity: 0.9; }
.grand-total-amount { font-size: 2.2rem; font-weight: 700; }
.grand-total-sub { font-size: 0.85rem; opacity: 0.9; margin-top: 4px; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}

.category-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  text-decoration: none;
  color: var(--text);
  display: block;
}

.category-card:hover { border-color: var(--primary); }
.category-card.empty { opacity: 0.6; }
.category-card-label { font-size: 0.82rem; color: var(--muted); min-height: 2.4em; }
.category-card-amount { font-size: 1.3rem; font-weight: 700; margin-top: 4px; }
.category-card-count { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 22px 0;
}

.btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-secondary { background: #e9eff5; }

.recent-list { list-style: none; padding: 0; }
.recent-list li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.recent-cat { color: var(--muted); flex: 1; }
.recent-date { flex: 0 0 100px; color: var(--muted); }
.recent-amount { font-weight: 600; }

.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.filter-bar input[type="search"] { width: 180px; }
.filter-date-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0;
  white-space: nowrap;
}
.filter-date-label input { width: auto; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: 10px; overflow: hidden; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; white-space: nowrap; }
th { background: #e9eff5; color: var(--muted); font-weight: 600; }
.row-actions a { margin-right: 10px; }

.link-btn {
  background: none;
  border: none;
  color: #b03a2e;
  cursor: pointer;
  padding: 0;
  font-size: 0.9rem;
  text-decoration: underline;
}

.empty-state { color: var(--muted); padding: 20px 0; }

.expense-form { max-width: 520px; }
.field { margin-bottom: 16px; }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 160px; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 1rem;
  background: white;
  color: var(--text);
}
#category-picker { max-width: 420px; margin-bottom: 16px; }
.category-fixed { color: var(--muted); }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 0.92rem; border: 1px solid; }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); }
.alert-error { background: var(--error-bg); border-color: var(--error-border); }
.alert-success { background: var(--success-bg); border-color: var(--success-border); }

.fx-note { font-size: 0.82rem; color: var(--muted); margin-top: -8px; }
.receipt-status { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.existing-receipt { font-size: 0.85rem; margin-top: 6px; }
.receipt-pending-list, .receipt-existing-list {
  list-style: none;
  padding: 0;
  margin: 8px 0;
  font-size: 0.88rem;
}
.receipt-pending-list li, .receipt-existing-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.receipt-pending-list button {
  background: none;
  border: none;
  color: #b03a2e;
  cursor: pointer;
  padding: 0;
  font-size: 0.85rem;
  text-decoration: underline;
  width: auto;
}

.form-actions { display: flex; gap: 10px; margin-top: 22px; }

.settings-section { margin-bottom: 34px; }
.hint { color: var(--muted); font-size: 0.88rem; }
.rate-table { margin-bottom: 12px; }
.rate-form { display: flex; gap: 8px; flex-wrap: wrap; }
.rate-form input { width: auto; flex: 1; min-width: 130px; }

.compare-table td:not(:first-child), .compare-table th:not(:first-child) { text-align: right; }
.totals-row { font-weight: 700; background: #e9eff5; }

.pattern-form { max-width: 560px; }
.day-checkboxes { display: flex; gap: 10px; flex-wrap: wrap; }
.day-checkbox {
  display: flex;
  align-items: center;
  gap: 5px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.9rem;
  width: auto;
  margin-bottom: 0;
  cursor: pointer;
}
.day-checkbox input { width: auto; }

.pattern-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}
.pattern-card.inactive { opacity: 0.6; }
.pattern-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.pattern-meta { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }
.pattern-actions { display: flex; gap: 10px; align-items: center; }
.generate-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.generate-form label { margin: 0; }
.generate-form input { width: auto; }

.tag-auto {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
}

@media (max-width: 480px) {
  .grand-total-amount { font-size: 1.8rem; }
  th, td { font-size: 0.82rem; padding: 8px; }
}
