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

:root {
  --bg-primary: #0a0e1a;
  --bg-card: #111827;
  --bg-card-hover: #1a2236;
  --border: #1f2937;
  --border-light: #374151;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.12);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.12);
  --purple: #a78bfa;
  --purple-bg: rgba(167, 139, 250, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
}

body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.header {
  background: rgba(10, 14, 26, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.header h1 {
  font-size: 1.3rem;
  font-weight: 800;
  background: linear-gradient(135deg, #60a5fa, #a78bfa, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: 'Cairo', sans-serif;
  font-size: 0.85rem;
  cursor: pointer;
  direction: rtl;
  transition: border-color 0.2s;
  min-width: 0;
}

.filter-select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.sync-btn {
  background: var(--blue-bg);
  border: 1px solid var(--blue);
  color: var(--blue);
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: 'Cairo', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s;
  flex-shrink: 0;
}

.sync-btn:hover {
  background: var(--blue);
  color: white;
}

.sync-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.refresh-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
  flex-shrink: 0;
}

.refresh-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--blue);
}

.refresh-btn.spinning {
  animation: spin 1s linear infinite;
}

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

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 80vh;
  gap: 20px;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.loading p {
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Main Content */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* KPI Cards */
.kpi-section {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  transition: transform 0.2s, border-color 0.2s;
  overflow: hidden;
  position: relative;
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 100%;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.kpi-income::after { background: var(--green); }
.kpi-expense::after { background: var(--red); }
.kpi-profit::after { background: var(--blue); }
.kpi-booked::after { background: var(--purple); }

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-light);
}

.kpi-icon {
  font-size: 1.6rem;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  flex-shrink: 0;
}

.kpi-income .kpi-icon { background: var(--green-bg); }
.kpi-expense .kpi-icon { background: var(--red-bg); }
.kpi-profit .kpi-icon { background: var(--blue-bg); }
.kpi-booked .kpi-icon { background: var(--purple-bg); }

.kpi-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.kpi-label {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.kpi-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-income .kpi-value { color: var(--green); }
.kpi-expense .kpi-value { color: var(--red); }
.kpi-profit .kpi-value { color: var(--blue); }
.kpi-booked .kpi-value { color: var(--purple); }

/* Tabs */
.tabs-section {
  margin-bottom: 20px;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-card);
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 1;
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 12px;
  transition: all 0.2s;
  white-space: nowrap;
  min-width: fit-content;
}

.tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.tab.active {
  background: var(--blue);
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

/* Charts */
.charts-section {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

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

.chart-card h3 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-weight: 600;
}

.chart-wide {
  grid-column: 1 / -1;
}

/* Table */
.table-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

.table-section h3 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-weight: 600;
}

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: right;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(31, 41, 55, 0.5);
  font-size: 0.85rem;
  white-space: nowrap;
}

tbody tr {
  transition: background 0.15s;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.type-income {
  color: var(--green);
  font-weight: 600;
}

.type-expense {
  color: var(--red);
  font-weight: 600;
}

.amount-cell {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Footer */
.footer {
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ========== RESPONSIVE ========== */

/* Tablet */
@media (max-width: 1024px) {
  .kpi-section {
    grid-template-columns: repeat(2, 1fr);
  }

  .charts-section {
    grid-template-columns: 1fr;
  }
}

/* Mobile */
@media (max-width: 640px) {
  .header {
    padding: 10px 16px;
  }

  .header-content {
    flex-wrap: wrap;
  }

  .header h1 {
    font-size: 1.15rem;
    width: 100%;
    text-align: center;
    margin-bottom: 4px;
  }

  .header-controls {
    width: 100%;
    justify-content: center;
  }

  .filter-select {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  .main-content {
    padding: 12px;
  }

  /* Stack KPIs in 2x2 grid */
  .kpi-section {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
  }

  .kpi-card {
    padding: 14px;
    gap: 10px;
    border-radius: 12px;
  }

  .kpi-card::after {
    width: 3px;
  }

  .kpi-icon {
    font-size: 1.3rem;
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  .kpi-label {
    font-size: 0.7rem;
  }

  .kpi-value {
    font-size: 1.1rem;
  }

  /* Tabs scroll horizontally */
  .tabs-section {
    margin-bottom: 16px;
  }

  .tabs {
    border-radius: 12px;
  }

  .tab {
    padding: 8px 14px;
    font-size: 0.82rem;
    border-radius: 10px;
  }

  /* Charts */
  .charts-section {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 16px;
  }

  .chart-card {
    padding: 16px;
    border-radius: 12px;
  }

  .chart-card h3 {
    font-size: 0.85rem;
    margin-bottom: 12px;
  }

  /* Table */
  .table-section {
    padding: 16px 12px;
    border-radius: 12px;
    margin-bottom: 16px;
  }

  th, td {
    padding: 8px 10px;
    font-size: 0.78rem;
  }

  .footer {
    padding: 12px;
    font-size: 0.75rem;
  }
}

/* Small phones */
@media (max-width: 380px) {
  .kpi-section {
    grid-template-columns: 1fr;
  }

  .kpi-card {
    flex-direction: row;
    gap: 12px;
  }
}

/* View Toggle */
.view-toggle {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  justify-content: center;
}
.toggle-btn {
  padding: 6px 18px;
  border-radius: 20px;
  border: 1px solid #334155;
  background: transparent;
  color: #94a3b8;
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.toggle-btn.active {
  background: #06b6d4;
  color: #0f172a;
  border-color: #06b6d4;
  font-weight: 700;
}
.toggle-btn:hover:not(.active) {
  border-color: #06b6d4;
  color: #06b6d4;
}
