/* ==========================================================================
   نظام تقفيل الخزينة والمصروفات - تصميم مالي احترافي متجاوب بالكامل مع الموبايل
   Responsive Mobile-First Financial Architecture
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  --font-main: 'Cairo', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* لوحة ألوان هادئة ومحترفة */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  --border-focus: #2563eb;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --primary: #0f172a;
  --primary-hover: #1e293b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;

  /* دلالات الحالات المالية */
  --overage-bg: #ecfdf5;
  --overage-text: #065f46;
  --overage-border: #a7f3d0;

  --shortage-bg: #fff1f2;
  --shortage-text: #9f1239;
  --shortage-border: #fecdd3;

  --balanced-bg: #f8fafc;
  --balanced-text: #334155;
  --balanced-border: #cbd5e1;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-main);
  direction: rtl;
  text-align: right;
  line-height: 1.5;
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* مسافة سفلية للموبايل لعدم حجب المحتوى بالشريط السفلي */
@media (max-width: 991px) {
  body {
    padding-bottom: 74px;
  }
}

.app-icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  stroke: currentColor;
}

/* ==========================================================================
   الهيكل العام والـ Navbar
   ========================================================================== */

.app-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

@media (max-width: 768px) {
  .app-container {
    padding: 16px 12px 30px;
  }
}

.top-navbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  gap: 14px;
}

@media (max-width: 768px) {
  .nav-inner {
    padding: 10px 14px;
  }
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-main);
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* روابط الديسكتوب */
.desktop-nav .nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13.5px;
  transition: all 0.15s ease;
}

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

.nav-link.active {
  background: var(--primary);
  color: #ffffff;
}

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

/* زر القائمة للموبايل */
.mobile-menu-toggle-btn {
  display: none;
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

@media (max-width: 991px) {
  .desktop-nav {
    display: none;
  }
  .mobile-menu-toggle-btn {
    display: flex;
  }
  .top-cta-btn {
    display: none;
  }
}

/* القائمة المنسدلة للهواتف (Drawer) */
.mobile-drawer {
  display: none;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
}

.mobile-drawer.open {
  display: block;
}

.mobile-drawer-inner {
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mobile-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-main);
  font-weight: 700;
  font-size: 14.5px;
  transition: background 0.12s ease;
}

.mobile-nav-link:hover,
.mobile-nav-link.active {
  background: var(--bg-subtle);
  color: var(--accent);
}

/* ==========================================================================
   شريط التنقل السفلي للموبايل (Mobile Bottom Navigation Bar)
   ========================================================================== */

.mobile-bottom-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 62px;
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  z-index: 998;
  align-items: center;
  justify-content: space-around;
  padding: 4px 6px;
  padding-bottom: max(4px, env(safe-area-inset-bottom));
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

@media (max-width: 991px) {
  .mobile-bottom-bar {
    display: flex;
  }
}

.bottom-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: #64748b;
  font-size: 11px;
  font-weight: 700;
  gap: 2px;
  flex: 1;
  height: 100%;
  transition: color 0.12s ease;
}

.bottom-bar-item.active {
  color: #0f172a;
}

.bottom-bar-action {
  position: relative;
}

.action-circle {
  width: 44px;
  height: 44px;
  background: var(--primary);
  color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -18px;
  border: 3px solid #ffffff;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.25);
  transition: transform 0.12s ease;
}

.bottom-bar-action:active .action-circle {
  transform: scale(0.94);
}

/* ==========================================================================
   الأزرار وعناصر التحكم
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  min-height: 38px;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

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

.btn-outline {
  background: #ffffff;
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover {
  background: var(--bg-subtle);
  border-color: #cbd5e1;
}

.btn-danger {
  background: #ffffff;
  border-color: #fecdd3;
  color: #be123c;
}
.btn-danger:hover {
  background: #fff1f2;
}

.btn-sm {
  padding: 5px 9px;
  min-height: 32px;
  font-size: 12.5px;
}

/* ==========================================================================
   البطاقات والكروت الإحصائية
   ========================================================================== */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 20px;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.card-title {
  font-size: 15.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 18px;
}

@media (max-width: 640px) {
  .card-body {
    padding: 14px;
  }
  .card-header {
    padding: 12px 14px;
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

@media (max-width: 640px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
}

@media (max-width: 420px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-main);
  letter-spacing: -0.5px;
  word-break: break-all;
}

@media (max-width: 640px) {
  .stat-value {
    font-size: 18px;
  }
}

.stat-hint {
  font-size: 11.5px;
  color: var(--text-light);
  margin-top: 3px;
  line-height: 1.3;
}

/* شارات الفارق (عجز / زيادة / متطابق) */
.badge-variance {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.badge-overage {
  background-color: var(--overage-bg);
  color: var(--overage-text);
  border: 1px solid var(--overage-border);
}

.badge-shortage {
  background-color: var(--shortage-bg);
  color: var(--shortage-text);
  border: 1px solid var(--shortage-border);
}

.badge-balanced {
  background-color: var(--balanced-bg);
  color: var(--balanced-text);
  border: 1px solid var(--balanced-border);
}

.badge-shift {
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 700;
}
.badge-day {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}
.badge-night {
  background: #e0e7ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
}

/* ==========================================================================
   الجداول وقوائم البيانات المتجاوبة
   ========================================================================== */

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 13.5px;
}

.data-table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .data-table th,
  .data-table td {
    padding: 8px 10px;
    font-size: 13px;
  }
}

.data-table tr:hover td {
  background-color: #f8fafc;
}

.money-cell {
  font-family: var(--font-mono);
  font-weight: 700;
  direction: ltr;
  text-align: left;
}

/* ==========================================================================
   شيت الإكسيل (مقارنة الورديات)
   ========================================================================== */

.excel-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

@media (max-width: 480px) {
  .excel-container {
    grid-template-columns: 1fr;
  }
}

.excel-sheet-card {
  background: #ffffff;
  border: 2px solid #cbd5e1;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.excel-sheet-header {
  background: #0f172a;
  color: #ffffff;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.excel-table th,
.excel-table td {
  border: 1px solid #cbd5e1;
  padding: 9px 12px;
  font-size: 13.5px;
}

.excel-table tr.item-row td:first-child {
  font-weight: 700;
  color: #334155;
  background: #f8fafc;
  width: 45%;
}

.excel-table tr.item-row td:last-child {
  font-family: var(--font-mono);
  font-weight: 700;
  text-align: center;
  font-size: 14.5px;
}

.excel-table tr.total-row td {
  background: #f1f5f9;
  font-weight: 800;
  font-size: 15.5px;
}

.excel-table tr.revenue-row td {
  background: #f8fafc;
  font-weight: 800;
  font-size: 15.5px;
}

.excel-table tr.diff-row td {
  font-weight: 800;
  font-size: 15.5px;
}

.diff-overage-row {
  background: #ecfdf5 !important;
  color: #065f46;
}

.diff-shortage-row {
  background: #fff1f2 !important;
  color: #9f1239;
}

/* ==========================================================================
   نماذج الإدخال والتجاوب مع الموبايل
   ========================================================================== */

.settlement-view-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
}

@media (max-width: 850px) {
  .settlement-view-layout {
    grid-template-columns: 1fr;
  }
}

.reports-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 850px) {
  .reports-grid {
    grid-template-columns: 1fr;
  }
}

.form-layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .form-layout {
    grid-template-columns: 1fr;
    display: flex;
    flex-direction: column-reverse; /* يظهر صندوق الحسابات الفورية أولاً على الموبايل */
  }
}

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

.form-label {
  display: block;
  font-weight: 700;
  font-size: 13px;
  color: #1e293b;
  margin-bottom: 5px;
}

.form-label .required {
  color: #e11d48;
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  min-height: 42px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 16px; /* 16px يمنع التقريب التلقائي في متصفح Safari على الآيفون */
  color: var(--text-main);
  background: #ffffff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.money-input {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  text-align: left;
  direction: ltr;
}

.calc-sheet-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.sheet-field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  gap: 12px;
}

@media (max-width: 600px) {
  .sheet-field-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .sheet-field-input-box {
    width: 100% !important;
  }
}

.sheet-field-row:hover {
  border-color: #cbd5e1;
}

.sheet-field-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.sheet-field-icon {
  width: 32px;
  height: 32px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.sheet-field-title {
  font-weight: 700;
  font-size: 14px;
}

.sheet-field-desc {
  font-size: 11.5px;
  color: var(--text-muted);
}

.sheet-field-input-box {
  width: 150px;
}

/* صندوق الملخص الحي المالي */
.live-summary-card {
  background: #0f172a;
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 20px;
  position: sticky;
  top: 75px;
  box-shadow: var(--shadow-md);
}

@media (max-width: 900px) {
  .live-summary-card {
    position: static;
    margin-bottom: 16px;
  }
}

.summary-title {
  font-size: 16px;
  font-weight: 800;
  padding-bottom: 12px;
  border-bottom: 1px solid #334155;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 14px;
}

.summary-row-label {
  color: #94a3b8;
  font-weight: 600;
}

.summary-row-val {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15.5px;
}

.summary-divider {
  border-top: 1px solid #334155;
  margin: 14px 0;
}

.summary-result-box {
  padding: 14px;
  border-radius: var(--radius-md);
  margin-top: 14px;
  text-align: center;
}

.result-overage {
  background: #064e3b;
  border: 1px solid #059669;
  color: #a7f3d0;
}

.result-shortage {
  background: #4c0519;
  border: 1px solid #e11d48;
  color: #fecdd3;
}

.result-balanced {
  background: #1e293b;
  border: 1px solid #475569;
  color: #e2e8f0;
}

.result-type-label {
  font-size: 13.5px;
  font-weight: 700;
  margin-bottom: 4px;
}

.result-amount {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

/* تفاصيل المصروفات والسلف الديناميكية */
.expense-builder-card {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius-md);
  padding: 14px;
  margin-top: 12px;
}

.expense-row-item {
  display: grid;
  grid-template-columns: 180px 110px 160px 1fr 38px;
  gap: 8px;
  align-items: center;
  background: #ffffff;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

@media (max-width: 768px) {
  .expense-row-item {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
    border: 1px solid #cbd5e1;
  }
}

.alert-box {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-danger {
  background: #fff1f2;
  color: #9f1239;
  border: 1px solid #fecdd3;
}

/* ==========================================================================
   المودال (Popups & Modals) المتجاوبة
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1050;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.modal-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: #ffffff;
  width: 100%;
  max-width: 500px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
}

.modal-footer {
  padding: 12px 18px;
  background: #f8fafc;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

/* ==========================================================================
   الطباعة (Print Styles)
   ========================================================================== */

@media print {
  body {
    background: #ffffff;
    color: #000000;
    padding-bottom: 0 !important;
  }
  .top-navbar, .mobile-bottom-bar, .no-print, .btn, .mobile-drawer {
    display: none !important;
  }
  .app-container {
    max-width: 100%;
    padding: 0;
  }
  .card, .excel-sheet-card {
    border: 1px solid #000000 !important;
    box-shadow: none !important;
  }
  .excel-sheet-header {
    background: #eeeeee !important;
    color: #000000 !important;
    border-bottom: 2px solid #000000;
  }
}
