/* ============================================================
   Financial Dashboard - Dark RTL Arabic Stylesheet
   ============================================================ */

/* --- CSS Variables --- */
: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);

  --yellow: #f59e0b;
  --yellow-bg: rgba(245, 158, 11, 0.12);

  --radius: 16px;
  --radius-sm: 10px;

  --shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --transition: 0.2s ease;
}

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

html {
  direction: rtl;
  scroll-behavior: smooth;
}

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

a {
  color: var(--blue);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: #60a5fa;
}

/* --- Custom Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) var(--bg-primary);
}

/* ============================================================
   1. NAV BAR
   ============================================================ */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 64px;
  background: rgba(10, 14, 26, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.nav-logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-logo img {
  height: 32px;
  width: auto;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.nav-link.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

/* ============================================================
   2. LOADING
   ============================================================ */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
}

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

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

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

/* ============================================================
   3. PAGE
   ============================================================ */
.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ============================================================
   4. FILTER BAR
   ============================================================ */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.filter-bar select,
.filter-bar input {
  padding: 8px 14px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Cairo', sans-serif;
  font-size: 0.875rem;
  direction: rtl;
  transition: border-color var(--transition);
  cursor: pointer;
}

.filter-bar select:focus,
.filter-bar input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}

.filter-bar label {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
}

/* ============================================================
   5. KPI CARDS
   ============================================================ */
.kpi-section {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  border-right: 4px solid var(--blue);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}

.kpi-card:hover {
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.kpi-card.green { border-right-color: var(--green); }
.kpi-card.red { border-right-color: var(--red); }
.kpi-card.blue { border-right-color: var(--blue); }
.kpi-card.purple { border-right-color: var(--purple); }

.kpi-card .icon {
  font-size: 1.5rem;
  margin-bottom: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
}

.kpi-card.green .icon { background: var(--green-bg); color: var(--green); }
.kpi-card.red .icon { background: var(--red-bg); color: var(--red); }
.kpi-card.blue .icon { background: var(--blue-bg); color: var(--blue); }
.kpi-card.purple .icon { background: var(--purple-bg); color: var(--purple); }

.kpi-card .label {
  display: block;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.kpi-card .value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

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

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

.chart-card:hover {
  border-color: var(--border-light);
}

.chart-card h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.chart-card canvas {
  width: 100% !important;
  max-height: 320px;
}

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

/* ============================================================
   7. TABLES
   ============================================================ */
.table-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 28px;
  overflow: hidden;
}

.table-section h3 {
  font-size: 1rem;
  font-weight: 700;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

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

.table-section table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
  font-size: 0.875rem;
}

.table-section th {
  padding: 12px 16px;
  text-align: right;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--bg-primary);
  border-bottom: 2px solid var(--border);
}

.table-section td {
  padding: 12px 16px;
  text-align: right;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.table-section tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

.table-section tbody tr:hover {
  background: var(--bg-card-hover);
}

.table-section tbody tr:last-child td {
  border-bottom: none;
}

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

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

/* ============================================================
   8. FORMS
   ============================================================ */
.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 28px;
}

.form-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

.form-grid label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  direction: rtl;
  transition: all var(--transition);
}

.form-grid textarea {
  resize: vertical;
  min-height: 100px;
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}

.form-grid input::placeholder,
.form-grid textarea::placeholder {
  color: var(--text-muted);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

/* ============================================================
   9. BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-primary:hover {
  background: #2563eb;
}

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.btn-danger {
  background: var(--red);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

/* ============================================================
   10. PROPERTY CARDS
   ============================================================ */
.property-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 28px;
}

.property-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  transition: all var(--transition);
}

.property-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow);
}

.property-card .property-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.property-card .kpi-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 0.875rem;
}

.property-card .kpi-row + .kpi-row {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.property-card .kpi-row .kpi-label {
  color: var(--text-muted);
  font-weight: 600;
}

.property-card .kpi-row .kpi-value {
  font-weight: 700;
  color: var(--text-primary);
}

.property-card .kpi-row.income .kpi-value { color: var(--green); }
.property-card .kpi-row.expenses .kpi-value { color: var(--red); }
.property-card .kpi-row.profit .kpi-value { color: var(--blue); }
.property-card .kpi-row.margin .kpi-value { color: var(--purple); }

.property-card .commission-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--purple);
  background: var(--purple-bg);
  border-radius: 20px;
}

/* ============================================================
   11. SYNC LOG
   ============================================================ */
.sync-log {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 28px;
  max-height: 400px;
  overflow-y: auto;
}

.sync-log pre {
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.8rem;
  line-height: 1.8;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  direction: ltr;
  text-align: left;
}

.sync-log .log-success { color: var(--green); }
.sync-log .log-error { color: var(--red); }
.sync-log .log-info { color: var(--blue); }
.sync-log .log-warn { color: var(--yellow); }

/* ============================================================
   12. SPLIT BADGE
   ============================================================ */
.split-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--yellow);
  background: var(--yellow-bg);
  border-radius: 20px;
  white-space: nowrap;
}

/* ============================================================
   13. PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
}

/* ============================================================
   14. FOOTER
   ============================================================ */
.footer {
  text-align: center;
  padding: 32px 20px;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* ============================================================
   15. ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.page {
  animation: fadeIn 0.35s ease;
}

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

  .charts-section {
    grid-template-columns: repeat(2, 1fr);
  }

  .property-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================================
   17. RESPONSIVE - Small Tablet (max-width: 768px)
   ============================================================ */
@media (max-width: 768px) {
  .nav {
    padding: 0 16px;
    height: 56px;
  }

  .nav-links {
    gap: 2px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-link {
    padding: 6px 12px;
    font-size: 0.82rem;
  }

  .page {
    padding: 16px 14px;
  }

  .kpi-section {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .kpi-card .value {
    font-size: 1.25rem;
  }

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

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .span-2 {
    grid-column: auto;
  }

  .property-grid {
    grid-template-columns: 1fr;
  }

  .page-header h2 {
    font-size: 1.25rem;
  }

  .table-section th,
  .table-section td {
    padding: 10px 12px;
  }
}

/* ============================================================
   18. RESPONSIVE - Mobile (max-width: 480px)
   ============================================================ */
@media (max-width: 480px) {
  .nav {
    padding: 0 12px;
  }

  .nav-logo {
    font-size: 1.05rem;
  }

  .page {
    padding: 12px 10px;
  }

  .kpi-section {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .kpi-card {
    padding: 14px;
  }

  .kpi-card .icon {
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
  }

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

  .kpi-card .label {
    font-size: 0.72rem;
  }

  .chart-card {
    padding: 14px;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar select,
  .filter-bar input {
    width: 100%;
  }

  .form-card {
    padding: 16px;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }

  .table-section th,
  .table-section td {
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  .property-card {
    padding: 16px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
