:root {
  --bg: #ececec;
  --surface: #ffffff;
  --surface2: #f5f5f5;
  --border: #d0d0d0;
  --text: #222222;
  --text-dim: #777777;
  --accent: #0eafa6;
  --green: #2e7d32;
  --red: #c62828;
  --orange: #e65100;
  --yellow: #f9a825;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
* { box-shadow: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, monospace;
  color: var(--text);
  font-size: 0.65rem;
  line-height: 1.5;
}

a { color: var(--text); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────── */

.topbar {
  background: #000000;
  border-bottom: 3px solid var(--accent);
  box-shadow: -10px 10px 30px rgba(0, 0, 0, .3);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 {
  font-size: 1.2rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 1px;
}

.topbar h1 a { color: var(--accent); }

.topbar nav a {
  margin-left: 1.5rem;
  color: #aaaaaa;
  font-size: 0.9rem;
  font-weight: 500;
}
.topbar nav a:hover { color: #ffffff; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  padding-top: 50px;
}

/* ── Flash Messages ──────────────────────────────── */

.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  border: 1px solid;
}
.flash.success { background: #e8f5e9; color: var(--green); border-color: #a5d6a7; }
.flash.error { background: #ffebee; color: var(--red); border-color: #ef9a9a; }
.flash.warning { background: #fff3e0; color: var(--orange); border-color: #ffcc80; }

/* ── Cards ───────────────────────────────────────── */

.card {
  background: #ffffff;
  border: 5px solid white;
  border-radius: 8px;
  padding: .5rem;
  margin-bottom: 1.25rem;
  box-shadow: none;
}

.card h2 {
  font-size: 1.1rem;
  color: black;
  background: #ffffff;
  margin-right: 0px !important;
  padding: 10px !important;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: inset 100px -10px 140px rgb(255 255 255), 5px 3px 3px rgb(0 0 0 / 4%);
}

.card h3 {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin: 1rem 0 0.5rem;
}

/* ── Tables ──────────────────────────────────────── */

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

th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: var(--surface2);
  color: #444444;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
}

tbody {
  box-shadow: inset 200px 0px 100px rgb(245 227 162 / 22%);
}

td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #0eafa6;
  vertical-align: top;
  box-shadow: inset 5px 5px 210px rgba(255,255,255,1);
}

tr:hover td { background: #e0f5f3; }

tr.clickable-row {
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

tr.clickable-row:hover td {
  background: #ecf6f7;
  transform: scale(1.005);
}

td a { font-weight: 700; color: #222; text-decoration: underline; }

.factor-icon {
  font-size: 0.55rem;
  font-weight: 700;
  color: #888;
  text-decoration: none;
  margin-left: 5px;
  vertical-align: super;
}

.amount, .balance-info-row strong, .big-number, .summary-item span:last-child {
  font-variant-numeric: tabular-nums;
  font-family: 'SF Mono', Menlo, Monaco, 'Courier New', monospace;
}

/* Money values inside any pill or strong tag */
strong, .negative, .positive {
  font-variant-numeric: tabular-nums;
}

.card .collapse-toggle span[style*="background: white"],
div[style*="background: white"] {
  font-variant-numeric: tabular-nums;
}

.amount { text-align: right; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.dim { color: #000000; }

/* Category rows */
tr.category-header td {
  background: var(--surface2);
  font-weight: 700;
  padding: 0.25rem 0.75rem;
  border-top: 1px solid var(--border);
}
tr[class*="category-"] td { border-left: 1px solid black; }
tr[class*="category-"] td:first-child { border-left: none; }

tr.total-row td {
  font-weight: 700;
  border-top: 2px solid var(--border);
  background: var(--surface2);
}

tr.balance-row td {
  font-weight: 700;
  font-size: 1rem;
  background: #fff8ea57;
  border-top: 2px solid var(--accent);
}

/* ── Summary Box ─────────────────────────────────── */

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid #0eafa6;
}

.summary-item.total {
  font-weight: 700;
  font-size: 1.05rem;
  margin-top: 0.5rem;
  padding-top: 0.75rem;
}

.big-number {
  font-size: 1.8rem;
  font-weight: 700;
  color: #222222;
}

/* ── Forms ────────────────────────────────────────── */

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input, select, textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #222222;
  box-shadow: 0 0 0 1px #222222;
}

textarea { resize: vertical; min-height: 60px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* ── Buttons ─────────────────────────────────────── */

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: opacity 0.15s;
  font-weight: 500;
}
.btn:hover { opacity: 0.85; text-decoration: none; }

.btn-primary { background: #222222; color: #ffffff; font-weight: 600; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-outline {
  background: #f5ffea;
  border: 1px solid var(--border);
  color: #444444;
}
.btn-outline:hover { border-color: #222222; color: #222222; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }

.actions { display: flex; gap: 0.5rem; align-items: center; }
.actions form { margin: 0; }

/* ── Period Cards ────────────────────────────────── */

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

.period-card {
  background: var(--surface);
  border: 1px solid #0eafa6;
  border-radius: 8px;
  padding: 1rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 3px 5px 30px rgba(0, 0, 0, .2);
  cursor: pointer;
}
.period-card:hover {
  transform: scale(1.03);
  box-shadow: 5px 10px 40px rgba(0, 0, 0, .25);
}
.period-card.closed { opacity: 0.5; }

.period-card .dates {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.period-card .balances {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.5rem;
}

.period-card .balance-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.status-open { background: #e8f5e9; color: var(--green); }
.status-closed { background: #eeeeee; color: #777777; }
.status-pending { background: #fff3e0; color: var(--orange); }
.status-completed { background: #e8f5e9; color: var(--green); }
.previously-matched { background: #eeeeee; color: #888888; }

tr.eod-row td {
  opacity: 1;
  text-decoration: underline;
  background: #4d7c622b;
  filter: brightness(.75);
}

tr.adjustment-row td {
  background: #fff3e0 !important;
  font-style: italic;
  border-left: 3px solid var(--orange);
}

tr.adjustment-row td:first-child::before {
  content: '⚙ ';
  color: var(--orange);
  font-weight: 700;
  font-style: normal;
}

tr.highlight-row td {
  background: #fff8c5 !important;
  animation: highlight-pulse 2s ease-out;
}

@keyframes highlight-pulse {
  0%   { background: #ffd54f !important; }
  100% { background: #fff8c5 !important; }
}

.balance-info-row {
  background: #f7f7f7;
  padding: 20px;
}

#section-planned {
  padding: 20px;
}

#section-planned tbody tr,
#section-recurring-items tbody tr,
#section-onetime-items tbody tr,
#section-recurring-templates tbody tr,
#section-debt-accounts tbody tr,
#section-factor-list tbody tr,
#section-transactions tbody tr,
[id^="section-mercury-tx-"] tbody tr {
  height: 44px;
}

#section-planned tbody tr td,
#section-recurring-items tbody tr td,
#section-onetime-items tbody tr td,
#section-recurring-templates tbody tr td,
#section-debt-accounts tbody tr td,
#section-factor-list tbody tr td,
#section-transactions tbody tr td,
[id^="section-mercury-tx-"] tbody tr td {
  height: 44px;
  vertical-align: middle;
}

#section-partner, #section-profit {
  padding: 25px;
  background: #f2f2f2;
  border-radius: 8px;
  font-weight: 700;
}

#section-profit .summary-item span,
#section-profit .summary-item .negative,
#section-profit .summary-item .positive {
  color: #000 !important;
}

#section-profit .summary-item span:last-child,
#section-partner .summary-item span:last-child {
  font-family: 'SF Mono', Menlo, Monaco, 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
}

#section-profit .summary-item span:last-child {
  background: #fbfbfb;
  border-radius: 3px;
  padding: 5px;
}

/* ── Modal ───────────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
  overflow-y: auto;
}

.modal-window {
  background: #ffffff;
  border-radius: 8px;
  max-width: 700px;
  width: calc(100% - 40px);
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.modal-window .card {
  margin-bottom: 0 !important;
  box-shadow: none !important;
  border: none !important;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #666;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  z-index: 10;
}

.modal-close:hover {
  background: #f0f0f0;
  color: #000;
}

/* ── Reconciled Transaction Check ────────────────── */

.tx-check {
  display: inline-block;
  color: var(--green);
  font-size: 0.85rem;
  font-weight: 700;
  margin-right: 4px;
}

/* ── Description column bold for non-paid rows ──── */

tr:not(.row-paid):not(.row-cancelled) td:nth-child(4) {
  font-weight: 500;
  color: #000;
}

/* ── Paid / Cancelled Rows ───────────────────────── */

tr.row-paid td {
  opacity: 0.4;
  text-decoration: line-through;
  background: #4d7c6254;
  filter: brightness(.75);
}

tr.row-paid td:last-child {
  text-decoration: none;
  opacity: 0.7;
}

tr.row-cancelled td {
  opacity: 0.3;
  text-decoration: line-through;
}

tr.row-cancelled td:last-child {
  text-decoration: none;
  opacity: 0.5;
}

/* ── Category Tags ───────────────────────────────── */

.category-tag {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  margin-bottom: 2px;
}

.tag-debt { background: #f5f5f5; color: #666666; border: 1px solid #d0d0d0; }
.tag-credit { background: #e8f5e9; color: var(--green); border: 1px solid #a5d6a7; }
.tag-commission { background: #e3f2fd; color: #1565c0; border: 1px solid #90caf9; }
.tag-vendor { background: #ffebee; color: var(--red); border: 1px solid #ef9a9a; }
.tag-savings { background: #fff8e1; color: #f57f17; border: 1px solid #ffe082; }
.tag-amex { background: #e3f2fd; color: #0d47a1; border: 1px solid #90caf9; }
.tag-intuit { background: #f3e5f5; color: #6a1b9a; border: 1px solid #ce93d8; }

/* ── Potential Match Badges ───────────────────────── */

.match-row {
  background: #fffde7;
}

.match-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: var(--yellow);
  color: #222222;
  cursor: help;
  white-space: nowrap;
}

.match-detail {
  font-size: 0.6rem;
  color: var(--text-dim);
  margin-top: 2px;
  font-style: italic;
}

/* ── Mercury Logo ────────────────────────────────── */

.mercury-logo {
  height: 16px;
  width: 16px;
  vertical-align: middle;
  margin-right: 4px;
  display: inline-block;
}

.mercury-logo-lg {
  height: 28px;
  width: 28px;
  margin-right: 8px;
}

/* ── Collapsible Sections ────────────────────────── */

.card.collapsible {
  backdrop-filter: blur(20px) contrast(1.2);
}

.collapse-toggle {
  cursor: pointer;
  user-select: none;
}

.collapse-toggle:hover {
  opacity: 0.8;
}

.collapse-icon {
  display: inline-block;
  width: 1em;
  font-size: 0.7em;
  margin-right: 0.4rem;
  transition: transform 0.15s;
  color: #999999;
}

.collapse-count {
  font-weight: 400;
  font-size: 0.85rem;
  margin-left: 0.4rem;
}

tr.collapse-toggle td {
  cursor: pointer;
}

tr.collapse-toggle:hover td {
  background: #f0f0f0;
}

/* ── Sortable Table Headers ──────────────────────── */

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover {
  background: #e8e8e8;
}

th.sortable::after {
  content: ' \2195';
  font-size: 0.65rem;
  color: #aaa;
}

th.sortable.sort-asc::after {
  content: ' \2191';
  color: #222;
}

th.sortable.sort-desc::after {
  content: ' \2193';
  color: #222;
}

th.sortable.active-sort {
  color: #222;
}

/* ── Tag Input / Vendor Chips ────────────────────── */

.tag-input-wrapper {
  position: relative;
}

.tag-suggestions {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 4px 4px;
  z-index: 10;
  max-height: 180px;
  overflow-y: auto;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.tag-suggestion-item {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.tag-suggestion-item:hover {
  background: #f5f5f5;
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag-chip {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 500;
  background: #f0f0f0;
  color: #444;
  border: 1px solid #d0d0d0;
  cursor: pointer;
  transition: all 0.1s;
}

.tag-chip:hover {
  background: #e0e0e0;
  border-color: #999;
}

.tag-chip-active {
  background: #222;
  color: #fff;
  border-color: #222;
}

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 768px) {
  .summary-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; gap: 0.5rem; }
  .topbar nav a { margin-left: 0; margin-right: 1rem; }
}
