/* Finance OS - Dark Theme */
:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #242736;
  --bg-hover: #2a2d3a;
  --border: #2e3142;
  --text-primary: #e4e6f0;
  --text-secondary: #8b8fa3;
  --text-muted: #5d6178;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --green: #00b894;
  --green-bg: rgba(0,184,148,0.12);
  --red: #e17055;
  --red-bg: rgba(225,112,85,0.12);
  --amber: #fdcb6e;
  --amber-bg: rgba(253,203,110,0.12);
  --blue: #74b9ff;
  --blue-bg: rgba(116,185,255,0.12);
  --sidebar-width: 220px;
  --radius: 8px;
  --radius-lg: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-light);
  letter-spacing: -0.3px;
}

.company-name {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  display: block;
}

.nav-links {
  list-style: none;
  padding: 8px 8px;
  flex: 1;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  margin-bottom: 1px;
}

.nav-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-link.active { background: var(--accent); color: #fff; }
.nav-icon { font-size: 10px; width: 16px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

.fiscal-year { margin-bottom: 4px; }
.user-info { color: var(--text-secondary); }

/* Main Content */
main {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 24px 32px;
  min-height: 100vh;
  max-width: 1400px;
}

/* Page Header */
.page-header {
  margin-bottom: 24px;
}

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

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

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.kpi-delta {
  font-size: 12px;
  margin-top: 4px;
  font-weight: 500;
}

.kpi-delta.positive { color: var(--green); }
.kpi-delta.negative { color: var(--red); }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.data-table tr:hover td { background: var(--bg-hover); }
.data-table tr:last-child td { border-bottom: none; }

/* Status badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Forms */
input, select, textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
}

.form-group { margin-bottom: 14px; }

/* Charts (Canvas-based) */
.chart-container {
  position: relative;
  width: 100%;
  height: 250px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Bar chart (CSS) */
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding-top: 10px; }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar {
  width: 100%;
  max-width: 40px;
  border-radius: 4px 4px 0 0;
  transition: height 0.5s ease;
  min-height: 2px;
}
.bar-label { font-size: 10px; color: var(--text-muted); }
.bar-value { font-size: 11px; font-weight: 600; }

/* Waterfall chart */
.waterfall { display: flex; gap: 6px; align-items: flex-end; height: 200px; }
.waterfall-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}
.waterfall-segment {
  width: 32px;
  border-radius: 3px;
  min-height: 2px;
}
.waterfall-label { font-size: 10px; color: var(--text-muted); margin-top: 4px; }
.waterfall-value { font-size: 11px; font-weight: 600; margin-bottom: 4px; }

/* Flags/Alerts */
.flags-panel { display: flex; flex-direction: column; gap: 8px; }
.flag-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
}

.flag-item.critical { background: var(--red-bg); border-left: 3px solid var(--red); }
.flag-item.warning { background: var(--amber-bg); border-left: 3px solid var(--amber); }
.flag-item.info { background: var(--blue-bg); border-left: 3px solid var(--blue); }

.flag-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.flag-text { line-height: 1.4; }
.flag-title { font-weight: 600; }
.flag-detail { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }

/* Sliders */
.slider-group {
  margin-bottom: 16px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.slider-label { font-size: 12px; color: var(--text-secondary); }
.slider-value { font-size: 13px; font-weight: 600; color: var(--accent-light); }

input[type="range"] {
  -webkit-appearance: none;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  border: none;
  padding: 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

/* Upload zones */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(108,92,231,0.05);
}

.drop-zone-icon { font-size: 32px; color: var(--text-muted); margin-bottom: 8px; }
.drop-zone-text { font-size: 14px; color: var(--text-secondary); }
.drop-zone-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Chat interface */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
}

.chat-message {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  padding: 0 4px;
}

.chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.chat-avatar.user { background: var(--accent); color: #fff; }
.chat-avatar.ai { background: var(--green-bg); color: var(--green); }

.chat-bubble {
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  max-width: 80%;
  font-size: 14px;
  line-height: 1.6;
}

.chat-bubble.ai { background: var(--bg-secondary); border: 1px solid var(--border); }

.chat-input-area {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.chat-input-area input {
  flex: 1;
}

/* Expense breakdown mini chart */
.expense-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.expense-bar-label {
  width: 120px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
  flex-shrink: 0;
}

.expense-bar-track {
  flex: 1;
  height: 20px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}

.expense-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.expense-bar-amount {
  width: 80px;
  font-size: 12px;
  font-weight: 600;
}

/* Color palette for charts */
.color-salaries { background: #6c5ce7; }
.color-contractors { background: #a29bfe; }
.color-infra { background: #74b9ff; }
.color-stripe { background: #fdcb6e; }
.color-saas { background: #00b894; }
.color-sales { background: #e17055; }
.color-wise { background: #fab1a0; }
.color-other { background: #636e72; }
.color-revenue { background: var(--green); }

/* Remittance tracker */
.remittance-month {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.remittance-month.overdue { background: var(--red-bg); }
.remittance-month.due-soon { background: var(--amber-bg); }
.remittance-month.paid { background: var(--green-bg); }

/* Toast */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  animation: slideIn 0.3s ease;
  max-width: 350px;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.warning { border-left: 3px solid var(--amber); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-overlay.hidden { display: none; }

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Responsive */
@media (max-width: 1024px) {
  .grid-2, .grid-3, .grid-2-1 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}

@media (max-width: 768px) {
  #sidebar { display: none; }
  main { margin-left: 0; padding: 16px; }
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Transition for page loads */
.page-enter {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cohort table */
.cohort-cell {
  text-align: center;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 500;
}

.cohort-cell.high { background: rgba(0,184,148,0.3); color: var(--green); }
.cohort-cell.mid { background: rgba(253,203,110,0.3); color: var(--amber); }
.cohort-cell.low { background: rgba(225,112,85,0.3); color: var(--red); }

/* Export cards */
.export-card {
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.export-card-info h4 { font-size: 14px; margin-bottom: 2px; }
.export-card-info p { font-size: 12px; color: var(--text-muted); }

/* Stripe live badge */
.stripe-badge {
  background: rgba(0,184,148,0.1);
  border: 1px solid rgba(0,184,148,0.3);
  border-radius: var(--radius);
  padding: 8px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.stripe-badge.stale {
  background: rgba(253,203,110,0.1);
  border-color: rgba(253,203,110,0.3);
}

/* Top progress bar */
#progress-bar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: 3px;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
#progress-bar.active { opacity: 1; }
#progress-bar .bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light), var(--accent));
  background-size: 200% 100%;
  animation: progressShimmer 1.2s ease-in-out infinite;
  border-radius: 0 2px 2px 0;
}
@keyframes progressShimmer {
  0% { background-position: 200% 0; width: 15%; }
  50% { width: 65%; }
  100% { background-position: -200% 0; width: 90%; }
}

/* Skeleton loading */
@keyframes skeletonPulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.55; }
}
.skeleton {
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  animation: skeletonPulse 1.4s ease-in-out infinite;
}
.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  border-radius: 4px;
}
.skeleton-text.lg { height: 28px; width: 40%; }
.skeleton-text.md { height: 18px; width: 60%; }
.skeleton-text.sm { height: 12px; width: 80%; }
.skeleton-kpi {
  height: 96px;
  border-radius: var(--radius);
}
.skeleton-card {
  border-radius: var(--radius-lg);
  padding: 20px;
  min-height: 180px;
}
.skeleton-chart {
  height: 200px;
  border-radius: var(--radius);
}
.skeleton-row {
  height: 44px;
  margin-bottom: 4px;
  border-radius: 4px;
}
.skeleton-badge {
  height: 38px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

/* Data freshness indicator */
.freshness-bar {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 0;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.freshness-bar span { white-space: nowrap; }

/* Duplicate badge */
.badge-duplicate {
  background: rgba(225,112,85,0.2);
  color: var(--red);
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 3px;
}

/* Mobile hamburger */
#mobile-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

/* Mobile responsive */
@media (max-width: 768px) {
  #mobile-toggle { display: flex; }
  #sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  #content {
    margin-left: 0 !important;
    padding: 16px !important;
    padding-top: 56px !important;
  }
  #progress-bar { left: 0; }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .grid-2, .grid-2-1, .grid-3 {
    grid-template-columns: 1fr !important;
  }
  .data-table { font-size: 11px; }
  .card { padding: 12px; }
  .page-header h2 { font-size: 20px; }
  .tabs { flex-wrap: wrap; }
  .tab { font-size: 12px; padding: 6px 10px; }
  .chart-container { height: 150px !important; }
}
