/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --muted: #718096;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --positive: #059669;
  --negative: #dc2626;
  --warning: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);

  --shopify-color: #96bf48;
  --square-color: #3e4348;
  --chase-color: #117aca;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────────── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.header-right { display: flex; align-items: center; gap: 12px; }

.status-bar { display: flex; align-items: center; gap: 8px; }

/* ── Tab Nav ─────────────────────────────────────────────── */
.tab-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  gap: 0;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Controls Bar ────────────────────────────────────────── */
.controls-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.date-presets { display: flex; gap: 4px; }

.preset-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.preset-btn:hover { border-color: var(--primary); color: var(--primary); }
.preset-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.date-range {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 8px;
}

.date-range input[type="date"] {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}
.date-range input[type="date"]:focus { outline: none; border-color: var(--primary); }

.date-sep { color: var(--muted); font-size: 12px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: #94a3b8; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.badge-source { background: #f1f5f9; color: var(--muted); }
.badge-source.connected { color: #fff; }
.badge-source[data-source="shopify"].connected { background: var(--shopify-color); }
.badge-source[data-source="square"].connected { background: var(--square-color); }
.badge-source[data-source="chase"].connected { background: var(--chase-color); }

.badge-cat { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 4px; }
.badge-income   { background: #d1fae5; color: #065f46; }
.badge-expense  { background: #fee2e2; color: #991b1b; }
.badge-refund   { background: #fef3c7; color: #92400e; }
.badge-platform_fee { background: #ede9fe; color: #5b21b6; }
.badge-payout   { background: #dbeafe; color: #1e40af; }
.badge-transfer { background: #f1f5f9; color: #475569; }

.badge-credit { background: #d1fae5; color: #065f46; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 4px; }
.badge-debit  { background: #fee2e2; color: #991b1b; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 4px; }

/* ── Main Layout ─────────────────────────────────────────── */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: relative;
}

/* ── Loading ─────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 200;
  font-size: 15px;
  color: var(--muted);
}
.hidden { display: none !important; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error / Warning Banners ─────────────────────────────── */
.error-banner {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
}
.warning-banner {
  background: #fef9c3;
  border: 1px solid #fde047;
  color: #854d0e;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.warning-banner button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  color: inherit;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}

/* ── KPI Grid ────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  line-height: 1;
  margin-bottom: 6px;
}
.kpi-value.positive { color: var(--positive); }
.kpi-value.negative { color: var(--negative); }

.kpi-sub {
  font-size: 12px;
  color: var(--muted);
}

.kpi-payout-row {
  display: block;
  font-size: 12px;
  line-height: 1.6;
  font-family: monospace;
}
.kpi-payout-row .kpi-muted {
  color: var(--muted);
}

#kpiAccountsCard { grid-column: span 2; }
.kpi-accounts-list { width: 100%; }
.kpi-account-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
}
.kpi-account-row:last-child { border-bottom: none; }
.kpi-account-name { color: var(--muted); white-space: nowrap; }
.kpi-account-bal { font-weight: 600; font-size: 14px; white-space: nowrap; }
.kpi-account-bal .kpi-muted { font-weight: normal; font-size: 11px; color: var(--muted); }

.kpi-cashflow-detail {
  font-size: 13px;
  font-weight: normal;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

/* ── Charts ──────────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.chart-card--full { width: 100%; }

.chart-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}

.chart-wrap {
  position: relative;
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart-wrap--tall { height: 200px; }

/* ── Accounts ────────────────────────────────────────────── */
.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

.accounts-section { }

.accounts-list {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.account-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  min-width: 200px;
}

.account-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.account-type { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.account-balance { font-size: 20px; font-weight: 700; color: var(--positive); }
.account-available { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Transactions Table ──────────────────────────────────── */
.transactions-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.transactions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.transactions-header .section-title { margin-bottom: 0; }

.tx-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tx-filters select,
.tx-filters input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
}
.tx-filters select:focus,
.tx-filters input:focus { outline: none; border-color: var(--primary); }
.tx-filters input { width: 200px; }

.table-wrap { overflow-x: auto; }

.tx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tx-table thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.tx-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.tx-table tbody tr:hover { background: #f8fafc; }
.tx-table tbody tr:last-child { border-bottom: none; }

.tx-table td {
  padding: 11px 16px;
  vertical-align: middle;
}

.tx-date { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx-desc { max-width: 300px; }
.tx-merchant { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tx-subcat { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tx-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.tx-amount.positive { color: var(--positive); }
.tx-amount.negative { color: var(--negative); }
.text-right { text-align: right; }
.tx-table th.text-right,
.tx-table td.text-right { width: 1%; white-space: nowrap; }

.source-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.source-shopify   { background: #f0f7e6; color: #4a7c0e; }
.source-square    { background: #f1f5f9; color: #334155; }
.source-chase     { background: #eff6ff; color: #1e40af; }
.source-chase_cc  { background: #fef3c7; color: #92400e; }
.source-chase_cc_2 { background: #fff7ed; color: #9a3412; }

/* ── CSV Upload Group ──────────────────────────────────────── */
.csv-upload-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.csv-account-select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  height: 28px;
}

.empty-row { text-align: center; color: var(--muted); padding: 40px 16px !important; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}
.tx-count { font-size: 12px; color: var(--muted); }
.page-controls { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .chart-card--sm .chart-wrap { height: 200px; }
}

@media (max-width: 780px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .main { padding: 16px; }
  .controls-bar { flex-wrap: wrap; }
  .tx-filters input { width: 140px; }
}

/* ── Transfer Breakdown ──────────────────────────────────── */
.transfer-summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}
.transfer-summary-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 16px;
  background: #f8fafc;
  border-radius: 8px;
  flex-wrap: wrap;
}
.transfer-summary-item--highlight {
  background: #fff5f5;
  border: 1px solid #fed7d7;
}
.transfer-label { font-weight: 600; font-size: 14px; }
.transfer-note  { font-size: 12px; color: var(--muted); flex: 1; }
.transfer-amount { font-weight: 700; font-size: 15px; margin-left: auto; white-space: nowrap; }
.transfer-items-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 10px; text-transform: uppercase; letter-spacing: .05em; }
.transfer-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.transfer-table th { text-align: left; padding: 6px 10px; border-bottom: 2px solid #e2e8f0; color: var(--muted); font-weight: 600; }
.transfer-table td { padding: 7px 10px; border-bottom: 1px solid #f1f5f9; }
.transfer-table tr:last-child td { border-bottom: none; }

/* ── Expense Breakdown ───────────────────────────────────── */
.expense-total-badge {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 8px;
}
.expense-breakdown-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 32px;
  align-items: start;
  margin-top: 16px;
}
.expense-donut-wrap {
  height: 260px;
}
.expense-categories-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.expense-cat-row {
  display: grid;
  grid-template-columns: 180px 90px 60px 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--border);
}
.expense-cat-row:hover { background: #f1f5f9; }
.expense-cat-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.expense-cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.expense-cat-total {
  font-size: 13px;
  font-weight: 600;
  text-align: right;
}
.expense-cat-pct {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}
.expense-cat-bar-wrap {
  flex: 1;
}
.expense-cat-bar-track {
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
}
.expense-cat-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.expense-cat-vendors {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--muted);
  padding: 0 0 2px 26px;
  display: none;
}
.expense-cat-row.expanded .expense-cat-vendors { display: block; }
.expense-cat-row { cursor: pointer; }

@media (max-width: 900px) {
  .expense-breakdown-grid { grid-template-columns: 1fr; }
  .expense-donut-wrap { height: 220px; }
  .expense-cat-row { grid-template-columns: 1fr 90px 60px; }
  .expense-cat-bar-wrap { display: none; }
}

/* ── Check Registry ──────────────────────────────────────── */
.section-desc {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}
.check-form {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 16px;
}
.check-form-fields {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.check-form-group { display: flex; flex-direction: column; gap: 4px; }
.check-form-group--wide { grid-column: span 2; }
.check-form-group label { font-size: 12px; font-weight: 500; color: var(--muted); }
.check-form-group input,
.check-form-group select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}
.check-form-group input:focus,
.check-form-group select:focus {
  outline: none;
  border-color: var(--primary);
}
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Login Screen ────────────────────────────────────────── */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  width: 360px;
}
.login-logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}
.login-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 24px;
}
.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--negative);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 16px;
}
.login-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.login-field input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}
.login-field input:focus {
  outline: none;
  border-color: var(--primary);
}
.btn-full { width: 100%; margin-top: 8px; }

/* ── Session bar ─────────────────────────────────────────── */
.session-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}
.session-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

/* ── Staff Time sub-tabs ─────────────────────────────────── */
.subtab-nav {
  display: flex;
  gap: 4px;
  padding: 16px 24px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 0;
}
.subtab-btn {
  padding: 8px 18px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.subtab-btn:hover { color: var(--text); }
.subtab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.subtab-panel { padding: 0; }

/* ── Inline time-entry edit inputs ───────────────────────── */
.te-input {
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.te-notes { min-width: 140px; }
