/* ============================================================
   Accounting System - Custom Styles (RTL Arabic)
   ============================================================ */

/* Google Fonts - Arabic */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800&display=swap');

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0891b2;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #2563eb;
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --body-bg: #f1f5f9;
  --card-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --card-radius: 12px;
  --transition: .2s ease;
}

* { box-sizing: border-box; }

body {
  font-family: 'Cairo', sans-serif;
  font-size: 14px;
  background: var(--body-bg);
  color: #1e293b;
  direction: rtl;
  text-align: right;
}

/* ── SIDEBAR ─────────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: 0;
  right: 0;  /* RTL: sidebar on the right */
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  z-index: 1000;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

.sidebar-brand {
  padding: 20px 16px;
  border-bottom: 1px solid #1e293b;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-height);
}

.sidebar-brand .brand-logo {
  width: 40px;
  height: 40px;
  background: var(--primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-brand .brand-text {
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.3;
}

.sidebar-brand .brand-text small {
  display: block;
  color: #94a3b8;
  font-weight: 400;
  font-size: 11px;
}

.sidebar-section {
  padding: 8px 0;
}

.sidebar-section-title {
  color: #475569;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 8px 20px 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: #94a3b8;
  text-decoration: none;
  transition: all var(--transition);
  border-radius: 0;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
}

.sidebar-item:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
  text-decoration: none;
}

.sidebar-item.active {
  background: var(--primary);
  color: #fff;
}

.sidebar-item .icon {
  width: 20px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
}

.sidebar-item .badge-count {
  margin-right: auto;
  margin-left: 0;
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  padding: 1px 6px;
  line-height: 16px;
}

.sidebar-submenu {
  display: none;
  background: #0a1628;
}

.sidebar-submenu.show { display: block; }

.sidebar-submenu .sidebar-item {
  padding-right: 52px;
  font-size: 13px;
}

.sidebar-item .arrow {
  margin-right: auto;
  margin-left: 0;
  transition: transform var(--transition);
  font-size: 11px;
}

.sidebar-item[aria-expanded="true"] .arrow {
  transform: rotate(-90deg);
}

/* ── MAIN CONTENT ────────────────────────────────────────── */
#main-content {
  margin-right: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin var(--transition);
}

/* ── TOPBAR ──────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 900;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.topbar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  color: #64748b;
  cursor: pointer;
  padding: 4px;
}

.topbar-breadcrumb {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: #1e293b;
}

.topbar-breadcrumb small {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: #94a3b8;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: #f1f5f9;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  text-decoration: none;
}

.topbar-btn:hover { background: #e2e8f0; color: #1e293b; }

.notif-badge {
  position: absolute;
  top: -2px;
  left: -2px;  /* RTL adjusted */
  width: 16px;
  height: 16px;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  border: 2px solid #e2e8f0;
}

/* ── PAGE CONTENT ────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 24px;
}

/* ── CARDS ───────────────────────────────────────────────── */
.card {
  border: none;
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  background: #fff;
}

.card-header {
  background: #fff;
  border-bottom: 1px solid #f1f5f9;
  padding: 16px 20px;
  font-weight: 600;
  font-size: 15px;
  border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
}

.card-body { padding: 20px; }

/* ── STAT CARDS ──────────────────────────────────────────── */
.stat-card {
  border-radius: var(--card-radius);
  padding: 20px;
  color: #fff;
  position: relative;
  overflow: hidden;
  border: none;
}

.stat-card .stat-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 48px;
  opacity: .15;
}

.stat-card .stat-value {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.stat-card .stat-label {
  font-size: 13px;
  opacity: .85;
}

.stat-card .stat-change {
  font-size: 11px;
  margin-top: 8px;
  opacity: .9;
}

.stat-primary { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.stat-success { background: linear-gradient(135deg, #16a34a, #15803d); }
.stat-warning { background: linear-gradient(135deg, #d97706, #b45309); }
.stat-danger  { background: linear-gradient(135deg, #dc2626, #b91c1c); }
.stat-info    { background: linear-gradient(135deg, #0891b2, #0e7490); }
.stat-purple  { background: linear-gradient(135deg, #7c3aed, #6d28d9); }

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
  font-family: 'Cairo', sans-serif;
  font-weight: 600;
  border-radius: 8px;
  transition: all var(--transition);
  font-size: 13.5px;
}

.btn-sm { font-size: 12px; border-radius: 6px; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── TABLES ──────────────────────────────────────────────── */
.table { font-size: 13.5px; }
.table th {
  font-weight: 600;
  color: #64748b;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom-width: 1px;
  background: #f8fafc;
  white-space: nowrap;
}
.table td { vertical-align: middle; }
.table-hover tbody tr:hover { background: #f8fafc; }

/* ── FORMS ───────────────────────────────────────────────── */
.form-label {
  font-weight: 600;
  font-size: 13px;
  color: #374151;
  margin-bottom: 6px;
}

.form-control, .form-select {
  font-family: 'Cairo', sans-serif;
  font-size: 13.5px;
  border-radius: 8px;
  border-color: #d1d5db;
  transition: border-color var(--transition), box-shadow var(--transition);
  direction: rtl;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.input-group .form-control { border-radius: 8px !important; }

/* ── MODALS ──────────────────────────────────────────────── */
.modal-content {
  border: none;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
}

.modal-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-radius: 16px 16px 0 0;
  padding: 16px 24px;
}

.modal-header .btn-close {
  filter: brightness(0) invert(1);
}

.modal-title { font-weight: 700; font-size: 16px; }

.modal-footer {
  border-top: 1px solid #f1f5f9;
  padding: 12px 20px;
}

/* ── BADGES ──────────────────────────────────────────────── */
.badge { font-size: 11px; font-weight: 600; border-radius: 6px; padding: 3px 8px; }

/* ── DATATABLE ───────────────────────────────────────────── */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  font-family: 'Cairo', sans-serif;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
  border-radius: 6px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: #f1f5f9 !important;
  border-color: #d1d5db !important;
  color: #1e293b !important;
  border-radius: 6px;
}

/* ── SELECT2 RTL ─────────────────────────────────────────── */
.select2-container--default .select2-selection--single {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  height: 38px;
  font-family: 'Cairo', sans-serif;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 36px;
  padding-right: 12px;
  font-size: 13.5px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
  right: auto;
  left: 8px;
}

/* ── LOGIN PAGE ──────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px rgba(0,0,0,.25);
}

.login-logo {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: #fff;
  margin: 0 auto 20px;
}

/* ── INVOICE PRINT ───────────────────────────────────────── */
@media print {
  #sidebar, #topbar, .no-print { display: none !important; }
  #main-content { margin-right: 0 !important; }
  .page-content { padding: 0 !important; }
  .invoice-print-area { page-break-inside: avoid; }
}

.invoice-watermark {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg);
  font-size: 80px;
  font-weight: 900;
  opacity: .06;
  pointer-events: none;
  white-space: nowrap;
  z-index: 9999;
}

/* ── MOBILE ──────────────────────────────────────────────── */
@media (max-width: 991px) {
  #sidebar {
    transform: translateX(100%);  /* RTL: slides from right */
  }
  #sidebar.open {
    transform: translateX(0);
  }
  #main-content { margin-right: 0; }
  .topbar-toggle { display: flex; }
  .page-content { padding: 16px; }
}

/* ── INVOICE ITEMS TABLE ─────────────────────────────────── */
.invoice-items-table .form-control {
  min-width: 80px;
}
.item-row-drag { cursor: move; color: #94a3b8; }

/* ── UTILITIES ───────────────────────────────────────────── */
.text-muted { color: #94a3b8 !important; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.rounded-lg { border-radius: var(--card-radius) !important; }
.gap-2 { gap: 8px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #94a3b8;
}
.empty-state i { font-size: 48px; margin-bottom: 16px; opacity: .4; }
.empty-state h5 { color: #64748b; margin-bottom: 8px; }

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

.page-header h4 {
  margin: 0;
  font-weight: 700;
  font-size: 18px;
}

/* ── NOTIFICATION DROPDOWN ───────────────────────────────── */
.notif-item {
  padding: 10px 16px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
  transition: background var(--transition);
}
.notif-item:hover { background: #f8fafc; }
.notif-item.unread { background: #eff6ff; }
.notif-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

/* ── FLATPICKR RTL ───────────────────────────────────────── */
.flatpickr-calendar { font-family: 'Cairo', sans-serif !important; }

/* ── LOADING OVERLAY ─────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.spinner-grow-sm { width: .5rem; height: .5rem; }

/* ── CUSTOM SCROLLBAR ────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
