/* ── Variables ── */
:root {
  --navy: #1a365d;
  --navy-dark: #122849;
  --navy-light: #2a4a7f;
  --orange: #ed8936;
  --orange-dark: #c97322;
  --green: #38a169;
  --red: #e53e3e;
  --yellow: #d69e2e;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --white: #ffffff;
  --sidebar-w: 240px;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  min-height: 100vh;
  display: flex;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--navy);
  color: var(--white);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  transition: transform 0.2s;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.logo-icon { font-size: 28px; }
.logo-title { font-size: 16px; font-weight: 700; line-height: 1.2; }
.logo-sub { font-size: 11px; opacity: 0.6; margin-top: 2px; }

.nav-links { list-style: none; padding: 12px 0; flex: 1; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.nav-link:hover { background: rgba(255,255,255,0.1); color: var(--white); }
.nav-link.active {
  background: var(--orange);
  color: var(--white);
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.badge {
  margin-left: auto;
  background: var(--red);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}

/* ── Mobile header ── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--navy);
  color: white;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  z-index: 200;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.hamburger {
  background: none; border: none; color: white; font-size: 22px; cursor: pointer; padding: 4px 8px;
}
.mobile-title { font-size: 16px; font-weight: 700; }

/* ── Main content ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  min-height: 100vh;
}

/* ── Sections ── */
.section { display: none; }
.section.active { display: block; }

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 24px;
}
.section-subtitle {
  font-size: 16px;
  font-weight: 600;
  color: var(--navy);
  margin: 28px 0 12px;
}

.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.section-header-row .page-title { margin-bottom: 0; }

/* ── Stat Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--navy-light);
}
.stat-card.accent { border-left-color: var(--orange); }
.stat-card.warn { border-left-color: var(--yellow); }
.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1;
  margin-bottom: 8px;
}
.stat-card.accent .stat-value { color: var(--orange-dark); }
.stat-card.warn .stat-value { color: var(--yellow); }
.stat-label { font-size: 13px; color: var(--gray-600); font-weight: 500; }

/* ── Bank Accounts List ── */
.bank-accounts-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.bank-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--navy-light);
}
.bank-card .bank-name { font-size: 13px; color: var(--gray-600); margin-bottom: 6px; font-weight: 500; }
.bank-card .bank-balance { font-size: 20px; font-weight: 700; color: var(--navy); }

.dashboard-quick-links { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--navy); color: white; }
.btn-primary:hover { background: var(--navy-dark); }
.btn-orange { background: var(--orange); color: white; }
.btn-orange:hover { background: var(--orange-dark); }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: #2d8658; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #c53030; }
.btn-outline {
  background: transparent;
  border: 2px solid var(--gray-200);
  color: var(--gray-600);
}
.btn-outline:hover { border-color: var(--navy); color: var(--navy); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Filter Tabs ── */
.filter-tabs, .report-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.tab {
  padding: 7px 18px;
  border: 2px solid var(--gray-200);
  background: white;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--gray-600);
  transition: all 0.15s;
}
.tab:hover { border-color: var(--navy); color: var(--navy); }
.tab.active { background: var(--navy); border-color: var(--navy); color: white; }

/* ── Changes List ── */
.change-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
  border-left: 4px solid var(--orange);
  transition: box-shadow 0.15s;
}
.change-card:hover { box-shadow: var(--shadow-md); }
.change-card.status-approved { border-left-color: var(--green); }
.change-card.status-rejected { border-left-color: var(--red); opacity: 0.75; }
.change-card.status-applied { border-left-color: var(--navy-light); }
.change-card.status-rolled_back { border-left-color: var(--gray-400); opacity: 0.7; }

.change-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 20px 12px;
  gap: 12px;
  flex-wrap: wrap;
}
.change-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.change-type {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--navy);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
}
.change-time { font-size: 12px; color: var(--gray-400); }
.change-status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
}
.status-pending .change-status-badge { background: #fef3c7; color: #92400e; }
.status-approved .change-status-badge { background: #d1fae5; color: #065f46; }
.status-rejected .change-status-badge { background: #fee2e2; color: #991b1b; }
.status-applied .change-status-badge { background: #dbeafe; color: #1e40af; }
.status-rolled_back .change-status-badge { background: #f3f4f6; color: var(--gray-600); }

.change-desc {
  padding: 0 20px 12px;
  font-size: 14px;
  color: var(--gray-800);
  line-height: 1.5;
}

.change-diff {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0 20px 16px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--gray-200);
  font-size: 12px;
}
.diff-before, .diff-after { padding: 12px 14px; }
.diff-before {
  background: #fff5f5;
  border-right: 1px solid var(--gray-200);
}
.diff-after { background: #f0fff4; }
.diff-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.diff-before .diff-label { color: var(--red); }
.diff-after .diff-label { color: var(--green); }
.diff-field { margin-bottom: 4px; }
.diff-field-name { color: var(--gray-400); }
.diff-field-val { color: var(--gray-800); font-weight: 500; }
.diff-field-val.changed { color: var(--orange-dark); font-weight: 700; }

.change-actions {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
  flex-wrap: wrap;
}
.change-approved-by {
  font-size: 12px;
  color: var(--gray-400);
  padding: 12px 20px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
}

/* ── Transactions / Tables ── */
.filters-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.search-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.search-input:focus { outline: none; border-color: var(--navy); }
.filter-select, .filter-date {
  padding: 8px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: white;
}
.filter-select:focus, .filter-date:focus { outline: none; border-color: var(--navy); }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }

.results-count { font-size: 13px; color: var(--gray-400); margin-bottom: 10px; }

.table-wrapper { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  font-size: 13px;
}
.data-table th {
  background: var(--navy);
  color: white;
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  user-select: none;
}
.data-table th.sortable-col { cursor: pointer; }
.data-table th.sortable-col:hover { background: var(--navy-light); }
.data-table th.sort-asc::after { content: ' ▲'; font-size: 10px; }
.data-table th.sort-desc::after { content: ' ▼'; font-size: 10px; }
.data-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }
.data-table tr.clickable { cursor: pointer; }
.data-table .amount-pos { color: var(--green); font-weight: 600; }
.data-table .amount-neg { color: var(--red); font-weight: 600; }
.recon-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  display: inline-block;
}
.recon-cleared { background: #dbeafe; color: #1e40af; }
.recon-reconciled { background: #d1fae5; color: #065f46; }
.recon-unreconciled { background: #fee2e2; color: #991b1b; }

.pagination {
  display: flex;
  gap: 6px;
  margin-top: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--gray-200);
  background: white;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.page-btn.active { background: var(--navy); border-color: var(--navy); color: white; }
.page-btn:hover:not(.active) { border-color: var(--navy); color: var(--navy); }

/* ── Reports ── */
.report-filters {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.report-filters label { font-size: 14px; display: flex; gap: 8px; align-items: center; }
.report-filters input[type="date"] { padding: 7px 10px; border: 1px solid var(--gray-200); border-radius: 6px; font-size: 14px; }

.report-content { display: none; }
.report-content.active { display: block; }

.pnl-section { background: white; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.pnl-section-header {
  background: var(--navy);
  color: white;
  padding: 10px 18px;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
}
.pnl-row { display: flex; justify-content: space-between; padding: 8px 18px; border-bottom: 1px solid var(--gray-100); font-size: 13px; }
.pnl-row:last-child { border-bottom: none; }
.pnl-row.subtotal {
  background: var(--gray-50);
  font-weight: 700;
  border-top: 2px solid var(--gray-200);
}
.pnl-total-row {
  background: var(--navy);
  color: white;
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 15px;
}
.amount-col { text-align: right; min-width: 100px; }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--navy);
  color: white;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  max-width: 320px;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.warn { background: var(--yellow); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: white;
  border-radius: var(--radius);
  padding: 28px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
}
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--gray-400);
}
.modal-title { font-size: 18px; font-weight: 700; color: var(--navy); margin-bottom: 16px; }
.modal-field { margin-bottom: 10px; font-size: 14px; }
.modal-field-label { font-weight: 600; color: var(--gray-600); min-width: 140px; display: inline-block; }

/* ── Loading / Empty ── */
.loading { color: var(--gray-400); font-size: 14px; padding: 32px; text-align: center; }
.empty-state { color: var(--gray-400); font-size: 14px; padding: 48px; text-align: center; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: none;
    box-shadow: 4px 0 20px rgba(0,0,0,0.2);
  }
  .mobile-header { display: flex; }
  .main-content { margin-left: 0; padding: 80px 16px 24px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .change-diff { grid-template-columns: 1fr; }
  .diff-before { border-right: none; border-bottom: 1px solid var(--gray-200); }
  .section-header-row { flex-direction: column; align-items: flex-start; }
  .filters-row { flex-direction: column; }
  .search-input { min-width: 0; }
}
