/* ============ RESET & BASE ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #F5F7FA;
  color: #333;
  min-height: 100vh;
}

/* ============ LAYOUT ============ */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  background: #1A2332;
  color: #B0BEC5;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header { padding: 20px 16px 12px; border-bottom: 1px solid #2D3A4A; }

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
}
.logo span { color: #4FC3F7; font-weight: 400; margin-left: 4px; }

.user-info {
  margin-top: 8px;
  font-size: 0.85rem;
  color: #78909C;
}
.user-info .role-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  margin-left: 4px;
}
.role-badge.admin { background: #E91E63; color: #fff; }
.role-badge.analyst { background: #4CAF50; color: #fff; }
.role-badge.loader { background: #FF9800; color: #fff; }

/* Navigation */
.nav { flex: 1; padding: 12px 0; }
.nav-group { margin-bottom: 4px; }
.nav-group-title {
  padding: 8px 16px 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #546E7A;
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  padding: 10px 16px 10px 24px;
  color: #B0BEC5;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: #2D3A4A; color: #fff; }
.nav-item.active { background: #2D3A4A; color: #fff; border-left-color: #4FC3F7; }
.nav-item .badge {
  margin-left: auto;
  background: #FF9800;
  color: #fff;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid #2D3A4A;
}

.content {
  margin-left: 250px;
  flex: 1;
  padding: 24px 32px;
  min-height: 100vh;
}

/* ============ LOGIN ============ */
.login-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, #1A2332 0%, #2D3A4A 50%, #1976D2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  width: 100vw;
  height: 100vh;
}
.login-card {
  background: #fff;
  padding: 48px 40px;
  border-radius: 16px;
  width: 400px;
  box-shadow: 0 25px 70px rgba(0,0,0,0.35);
  text-align: center;
}
.login-logo {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  background: linear-gradient(135deg, #1976D2, #4FC3F7);
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px rgba(25, 118, 210, 0.4);
}
.logo-mark {
  color: #fff;
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1;
}
.login-card h2 {
  font-size: 1.6rem;
  color: #1A2332;
  margin-bottom: 6px;
  font-weight: 700;
}
.login-subtitle {
  color: #78909C;
  margin-bottom: 28px;
  font-size: 0.92rem;
}
.login-card input {
  width: 100%;
  padding: 14px 18px;
  border: 1.5px solid #E0E0E0;
  border-radius: 10px;
  font-size: 1rem;
  margin-bottom: 12px;
  outline: none;
  transition: all 0.2s;
}
.login-card input:focus {
  border-color: #1976D2;
  box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
}
.login-card .btn-block {
  padding: 14px;
  font-size: 1rem;
  margin-top: 4px;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
  text-decoration: none;
}
.btn-primary { background: #1976D2; color: #fff; }
.btn-primary:hover { background: #1565C0; }
.btn-success { background: #43A047; color: #fff; }
.btn-success:hover { background: #388E3C; }
.btn-danger { background: #E53935; color: #fff; }
.btn-danger:hover { background: #D32F2F; }
.btn-outline {
  background: transparent;
  border: 1px solid #B0BEC5;
  color: #B0BEC5;
}
.btn-outline:hover { background: #2D3A4A; color: #fff; }
.btn-link { background: none; border: none; color: #78909C; font-size: 0.85rem; cursor: pointer; }
.btn-link:hover { color: #4FC3F7; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============ PAGE HEADER ============ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 { font-size: 1.5rem; color: #1A2332; font-weight: 600; }

/* ============ CARDS ============ */
.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.metric-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.metric-card .label { font-size: 0.8rem; color: #78909C; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.metric-card .value { font-size: 1.6rem; font-weight: 700; font-family: 'SF Mono', 'Fira Code', monospace; }
.metric-card .trend { font-size: 0.85rem; margin-top: 4px; }
.trend.up { color: #43A047; }
.trend.down { color: #E53935; }

.card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 16px;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: #1A2332;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid #ECEFF1;
}

/* ============ TABLES ============ */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th {
  text-align: left;
  padding: 10px 12px;
  background: #F5F7FA;
  font-weight: 600;
  color: #546E7A;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid #E0E0E0;
  white-space: nowrap;
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid #ECEFF1;
  vertical-align: middle;
}
tr:hover td { background: #F5F7FA; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-mono { font-family: 'SF Mono', 'Fira Code', monospace; }

/* Amount styling */
.amount { font-family: 'SF Mono', 'Fira Code', monospace; font-weight: 500; white-space: nowrap; }
.amount.income { color: #43A047; }
.amount.expense { color: #E53935; }

/* Status badges */
.status { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 0.8rem; font-weight: 500; }
.status.uncategorized { background: #FFF3E0; color: #E65100; }
.status.categorized { background: #E8F5E9; color: #2E7D32; }
.status.technical { background: #E3F2FD; color: #1565C0; }

/* ============ FORMS ============ */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  color: #546E7A;
  margin-bottom: 4px;
  font-weight: 500;
}
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #E0E0E0;
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}
.form-control:focus { border-color: #4FC3F7; box-shadow: 0 0 0 3px rgba(79, 195, 247, 0.15); }
select.form-control { cursor: pointer; }

.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

/* ============ UPLOAD ZONE ============ */
.upload-zone {
  border: 2px dashed #B0BEC5;
  border-radius: 12px;
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #FAFAFA;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: #4FC3F7;
  background: #E1F5FE;
}
.upload-zone .icon { font-size: 2.5rem; margin-bottom: 8px; }
.upload-zone .text { color: #546E7A; }
.upload-zone .hint { font-size: 0.8rem; color: #90A4AE; margin-top: 4px; }
.upload-zone input[type="file"] { display: none; }

/* ============ WIZARD STEPS ============ */
.wizard-steps {
  display: flex;
  margin-bottom: 32px;
  padding: 0;
  list-style: none;
}
.wizard-step {
  flex: 1;
  text-align: center;
  padding: 12px;
  position: relative;
  color: #90A4AE;
  font-size: 0.85rem;
  font-weight: 500;
}
.wizard-step::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 0;
  width: 50%;
  height: 2px;
  background: #E0E0E0;
  transform: translateX(50%);
}
.wizard-step:last-child::after { display: none; }
.wizard-step .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #E0E0E0;
  color: #fff;
  font-weight: 700;
  margin-bottom: 4px;
}
.wizard-step.active .step-num { background: #1976D2; }
.wizard-step.done .step-num { background: #43A047; }
.wizard-step.active, .wizard-step.done { color: #1A2332; }

/* ============ BALANCE CHECK ============ */
.balance-check {
  display: flex;
  gap: 24px;
  align-items: center;
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 16px;
}
.balance-check.match { background: #E8F5E9; border: 1px solid #A5D6A7; }
.balance-check.mismatch { background: #FFF3E0; border: 1px solid #FFCC80; }
.balance-value { text-align: center; flex: 1; }
.balance-value .label { font-size: 0.8rem; color: #546E7A; }
.balance-value .val { font-size: 1.4rem; font-weight: 700; font-family: 'SF Mono', monospace; }
.balance-diff { font-size: 1.2rem; font-weight: 700; }
.balance-diff.ok { color: #43A047; }
.balance-diff.bad { color: #E53935; }

/* ============ DDS REPORT TABLE ============ */
.dds-table { font-size: 0.85rem; }
.dds-table th { padding: 8px 10px; font-size: 0.75rem; }
.dds-table td { padding: 6px 10px; }
.dds-table .row-group > td { font-weight: 700; background: #ECEFF1; }
.dds-table .row-group.expandable { cursor: pointer; }
.dds-table .row-group.expandable:hover > td { background: #E0E0E0; }
.dds-table .row-leaf > td:first-child { padding-left: 32px; }
.dds-table .row-leaf.depth-2 > td:first-child { padding-left: 48px; }
.dds-table .row-total > td { font-weight: 700; border-top: 2px solid #1A2332; background: #E8EAF6; }
.dds-table .clickable { cursor: pointer; }
.dds-table .clickable:hover { background: #E1F5FE; text-decoration: underline; }

/* ============ FILTERS BAR ============ */
.filters-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: end;
}
.filters-bar .form-group { margin-bottom: 0; min-width: 150px; }
.filters-bar .form-control { padding: 8px 10px; font-size: 0.85rem; }

/* ============ PAGINATION ============ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  font-size: 0.85rem;
  color: #78909C;
}

/* ============ INLINE EDIT ============ */
td.editable { cursor: pointer; position: relative; }
td.editable:hover { background: #E1F5FE; }
td.editing { padding: 4px; }
td.editing select, td.editing input {
  width: 100%;
  padding: 6px 8px;
  border: 2px solid #4FC3F7;
  border-radius: 4px;
  font-size: 0.85rem;
  outline: none;
}

/* ============ CHART CONTAINER ============ */
.chart-container {
  position: relative;
  height: 300px;
  margin-bottom: 16px;
}

/* ============ ALERT ============ */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.alert-success { background: #E8F5E9; color: #2E7D32; border: 1px solid #A5D6A7; }
.alert-warning { background: #FFF3E0; color: #E65100; border: 1px solid #FFCC80; }
.alert-error { background: #FFEBEE; color: #C62828; border: 1px solid #EF9A9A; }
.alert-info { background: #E3F2FD; color: #1565C0; border: 1px solid #90CAF9; }

.error-msg { color: #E53935; font-size: 0.85rem; margin-top: 8px; }

/* ============ DEMO BANNER ============ */
.demo-banner {
  background: linear-gradient(135deg, #1976D2, #4FC3F7);
  color: #fff;
  padding: 12px 24px;
  border-radius: 12px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.demo-banner .text { font-size: 0.95rem; }
.demo-banner .btn { background: #fff; color: #1976D2; }
.demo-banner .btn:hover { background: #E3F2FD; }

/* ============ CHECKBOX ============ */
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #1976D2;
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #B0BEC5; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #78909C; }

/* ============ STATUS / SECTION HEADERS ============ */
.section-title {
  font-size: 1.05rem;
  color: #1A2332;
  margin: 24px 0 8px;
  font-weight: 600;
}
.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 24px 0 8px;
}
.section-title-row h3 { font-size: 1.05rem; color: #1A2332; margin: 0; font-weight: 600; }
.muted-hint { font-size: 0.8rem; color: #78909C; }

/* Metric card variations with gradient backgrounds */
.metric-card.gradient-blue { background: linear-gradient(135deg, #1976D215, #1976D205); }
.metric-card.gradient-green { background: linear-gradient(135deg, #43A04715, #43A04705); }
.metric-card.gradient-red { background: linear-gradient(135deg, #E5393515, #E5393505); }
.metric-card.gradient-purple { background: linear-gradient(135deg, #9C27B015, #9C27B005); }
.metric-card.gradient-orange { background: linear-gradient(135deg, #FF980015, #FF980005); }
.metric-card.gradient-cyan { background: linear-gradient(135deg, #00BCD415, #00BCD405); }
.metric-card.dimmed { opacity: 0.7; border: 1px dashed #B0BEC5; }

.metric-card .label-uppercase {
  font-size: 0.8rem;
  color: #78909C;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.metric-card .value-md { font-size: 1.2rem; font-weight: 700; color: #546E7A; }
.metric-card .value-sm { font-size: 0.85rem; }
.metric-card .sub-text { font-size: 0.75rem; color: #78909C; margin-top: 2px; }
.metric-card .body-text { font-size: 0.8rem; color: #78909C; margin-top: 10px; line-height: 1.5; }

/* Status colors as text */
.color-good { color: #43A047; }
.color-warning { color: #FF9800; }
.color-bad { color: #E53935; }
.color-info { color: #1976D2; }
.color-purple { color: #9C27B0; }
.color-muted { color: #78909C; }

/* Insight cards (success / alert / info) */
.insight-card {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.88rem;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.insight-card .icon { font-size: 1.2rem; flex-shrink: 0; }
.insight-card.alert { background: #FFEBEE; color: #C62828; border-left: 3px solid #EF9A9A; }
.insight-card.success { background: #E8F5E9; color: #2E7D32; border-left: 3px solid #A5D6A7; }
.insight-card.info { background: #E3F2FD; color: #1565C0; border-left: 3px solid #90CAF9; }

/* Sortable table headers */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #ECEFF1; }
th.sortable.active { color: #1976D2; }

/* Quick filter buttons */
.btn-quick {
  padding: 4px 10px;
  background: #ECEFF1;
  border: 1px solid #E0E0E0;
  border-radius: 12px;
  font-size: 0.75rem;
  color: #546E7A;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-quick:hover {
  background: #1976D2;
  color: white;
  border-color: #1976D2;
}

/* Dual range slider (two stacked range inputs) */
.dual-range {
  position: relative;
  height: 28px;
}
.dual-range input[type="range"] {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  appearance: none;
  background: transparent;
  pointer-events: none;
  height: 28px;
  margin: 0;
}
.dual-range input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: #ECEFF1;
  border-radius: 2px;
}
.dual-range input[type="range"]::-moz-range-track {
  height: 4px;
  background: #ECEFF1;
  border-radius: 2px;
}
.dual-range input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1976D2;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  cursor: pointer;
  pointer-events: auto;
  margin-top: -7px;
  transition: transform 0.1s;
}
.dual-range input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1976D2;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  cursor: pointer;
  pointer-events: auto;
}
.dual-range input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.2);
}
.dual-range input[type="range"]:focus { outline: none; }

/* ============ INSIGHT BADGES ============ */
.insight-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}
.insight-badge.good { background: #E8F5E9; color: #2E7D32; }
.insight-badge.warning { background: #FFF3E0; color: #E65100; }
.insight-badge.bad { background: #FFEBEE; color: #C62828; }
.insight-badge.neutral { background: #ECEFF1; color: #546E7A; }

.insight-text {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #E0E0E0;
  font-size: 0.82rem;
  color: #546E7A;
  line-height: 1.5;
}
.insight-text strong { color: #1A2332; }

/* ============ LOADING ============ */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #E0E0E0;
  border-top-color: #1976D2;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: #78909C;
  gap: 12px;
}
