/* ═══════════════════════════════════════════════════════════
   مطابقة الصناديق اليومية — ERP Financial Dashboard UI
   ═══════════════════════════════════════════════════════════ */

#page-cash-reconciliation {
  background: #f1f5f9;
  min-height: 360px;
  width: 100%;
  box-sizing: border-box;
}

#page-cash-reconciliation.page {
  contain: none !important;
  max-width: none;
  margin: 0;
  box-shadow: none;
  border-radius: 0;
  overflow: visible;
}

#page-cash-reconciliation.active {
  display: block !important;
  min-height: calc(100vh - var(--topbar-h, 56px) - 40px);
  width: 100%;
}

#cash-recon-app-root {
  min-height: 200px;
  width: 100%;
  box-sizing: border-box;
}

.cr-app {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 4px 0 32px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* ── Header ───────────────────────────────────────────── */

.cr-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px 24px;
  padding: 20px 24px;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.cr-eyebrow {
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.cr-page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.3;
}

.cr-page-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: #64748b;
  line-height: 1.5;
}

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

/* ── Buttons ──────────────────────────────────────────── */

.cr-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

.cr-btn-primary {
  background: linear-gradient(180deg, #714b67 0%, #5c3d54 100%);
  color: #fff;
  border-color: #5c3d54;
  box-shadow: 0 2px 6px rgba(113, 75, 103, 0.25);
}

.cr-btn-primary:hover {
  background: linear-gradient(180deg, #5c3d54 0%, #4a3144 100%);
}

.cr-btn-secondary {
  background: #fff;
  color: #334155;
  border-color: #cbd5e1;
}

.cr-btn-secondary:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.cr-btn-ghost {
  background: transparent;
  color: #475569;
  border-color: transparent;
}

.cr-btn-ghost:hover {
  background: #f1f5f9;
}

.cr-btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.cr-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.cr-btn-primary:disabled {
  background: #94a3b8;
  border-color: #94a3b8;
  box-shadow: none;
}

.cr-btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.cr-kpi-grid {
  display: grid !important;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
}

@media (max-width: 1400px) {
  .cr-kpi-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .cr-kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

.cr-kpi-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  border-top: 3px solid #cbd5e1;
}

.cr-kpi-total { border-top-color: #3b82f6; }
.cr-kpi-pending { border-top-color: #f59e0b; }
.cr-kpi-variance { border-top-color: #ef4444; }
.cr-kpi-last { border-top-color: #8b5cf6; }
.cr-kpi-approved { border-top-color: #10b981; }
.cr-kpi-rejected { border-top-color: #64748b; }

.cr-kpi-icon {
  font-size: 22px;
  line-height: 1;
  opacity: 0.9;
}

.cr-kpi-value {
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.2;
  direction: ltr;
  text-align: right;
}

.cr-kpi-label {
  font-size: 12px;
  font-weight: 700;
  color: #334155;
  margin-top: 2px;
}

.cr-kpi-hint {
  font-size: 10px;
  color: #94a3b8;
  margin-top: 4px;
  line-height: 1.35;
}

/* ── Panels ───────────────────────────────────────────── */

.cr-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  overflow: hidden;
}

.cr-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #f1f5f9;
  background: #fafbfc;
}

.cr-panel-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: #1e293b;
}

.cr-filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px 16px;
  padding: 18px;
  align-items: end;
}

.cr-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cr-field span {
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
}

.cr-field em {
  color: #ef4444;
  font-style: normal;
}

.cr-field input,
.cr-field select,
.cr-field textarea {
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: #0f172a;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.cr-field input:focus,
.cr-field select:focus,
.cr-field textarea:focus {
  outline: none;
  border-color: #714b67;
  box-shadow: 0 0 0 3px rgba(113, 75, 103, 0.12);
}

.cr-field-full {
  grid-column: 1 / -1;
}

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

/* ── Toolbar & Search ─────────────────────────────────── */

.cr-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid #f1f5f9;
}

.cr-search-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
  max-width: 420px;
}

.cr-search-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  opacity: 0.5;
  pointer-events: none;
}

.cr-search-input {
  width: 100%;
  padding: 9px 36px 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  font-size: 13px;
  font-family: inherit;
  background: #f8fafc;
}

.cr-search-input:focus {
  outline: none;
  border-color: #714b67;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(113, 75, 103, 0.1);
}

.cr-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.cr-pagesize {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #64748b;
}

.cr-pagesize select {
  padding: 5px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 12px;
}

.cr-refresh-hint {
  font-size: 11px;
  color: #94a3b8;
}

/* ── Data Table ───────────────────────────────────────── */

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

.cr-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.cr-data-table thead {
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 1;
}

.cr-data-table th {
  padding: 11px 14px;
  text-align: right;
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}

.cr-data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
  color: #334155;
}

.cr-data-table tbody tr:hover {
  background: #f8fafc;
}

.cr-data-table .num,
.cr-amount {
  text-align: left;
  font-family: 'Consolas', 'Segoe UI Mono', monospace;
  font-size: 11px;
  direction: ltr;
  line-height: 1.5;
}

.cr-cur {
  font-size: 10px;
  color: #94a3b8;
  font-weight: 600;
}

.cr-link {
  color: #714b67;
  text-decoration: none;
  font-weight: 700;
}

.cr-link:hover {
  text-decoration: underline;
}

.cr-date {
  font-weight: 600;
  color: #1e293b;
}

.cr-user {
  font-size: 12px;
}

.cr-dt {
  font-size: 11px;
  color: #64748b;
  white-space: nowrap;
}

.cr-box-cell .cr-box-name {
  font-weight: 600;
  color: #1e293b;
}

.cr-sub {
  font-size: 10px;
  color: #94a3b8;
  margin-top: 2px;
}

.cr-muted {
  color: #94a3b8;
  font-style: italic;
}

.cr-diff-warn {
  color: #dc2626 !important;
  font-weight: 700;
}

.cr-status-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.cr-td-actions {
  width: 48px;
  text-align: center;
}

/* ── Badges ───────────────────────────────────────────── */

.cr-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.cr-badge-balanced { background: #d1fae5; color: #065f46; }
.cr-badge-variance { background: #fee2e2; color: #991b1b; }
.cr-st-draft { background: #e5e7eb; color: #374151; }
.cr-st-submitted { background: #ffedd5; color: #c2410c; }
.cr-st-review { background: #fef3c8; color: #b45309; }
.cr-st-returned { background: #fce7f3; color: #9d174d; }
.cr-st-rejected { background: #fee2e2; color: #991b1b; }
.cr-st-approved { background: #d1fae5; color: #065f46; }
.cr-st-closed { background: #1f2937; color: #f9fafb; }
.cr-diff-matched { color: #059669; }
.cr-diff-shortage { color: #dc2626; }
.cr-diff-overage { color: #2563eb; }
.cr-in { color: #059669; }
.cr-out { color: #dc2626; }

/* ── Action Menu ──────────────────────────────────────── */

.cr-action-menu {
  position: relative;
  display: inline-block;
}

.cr-menu-panel {
  display: none;
  position: absolute;
  left: 0;
  top: 100%;
  z-index: 50;
  min-width: 168px;
  margin-top: 4px;
  padding: 6px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

.cr-menu-panel.is-open {
  display: block;
}

.cr-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: 12px;
  font-family: inherit;
  color: #334155;
  cursor: pointer;
  text-align: right;
}

.cr-menu-item:hover {
  background: #f1f5f9;
}

.cr-menu-item.is-danger {
  color: #dc2626;
}

/* ── Pagination ───────────────────────────────────────── */

.cr-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid #f1f5f9;
  background: #fafbfc;
}

.cr-page-info {
  font-size: 12px;
  color: #64748b;
}

.cr-page-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cr-page-num {
  font-size: 12px;
  font-weight: 700;
  color: #334155;
  min-width: 48px;
  text-align: center;
}

/* ── Empty State ──────────────────────────────────────── */

.cr-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
  text-align: center;
}

.cr-empty-illus {
  width: 120px;
  margin-bottom: 20px;
  opacity: 0.85;
}

.cr-empty-illus svg {
  width: 100%;
  height: auto;
}

.cr-empty-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 800;
  color: #1e293b;
}

.cr-empty-desc {
  margin: 0 0 20px;
  font-size: 13px;
  color: #64748b;
  max-width: 360px;
  line-height: 1.6;
}

.cr-empty {
  text-align: center;
  padding: 32px;
  color: #94a3b8;
}

/* ── Modal ────────────────────────────────────────────── */

.cr-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 10050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.cr-modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
}

.cr-modal-lg {
  max-width: 520px;
}

.cr-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid #f1f5f9;
}

.cr-modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: #0f172a;
}

.cr-modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: #f1f5f9;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
}

.cr-modal-body {
  padding: 20px;
}

.cr-modal-intro {
  margin: 0 0 16px;
  font-size: 13px;
  color: #64748b;
  line-height: 1.55;
}

.cr-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.cr-form-grid .cr-field-full {
  grid-column: 1 / -1;
}

.cr-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid #f1f5f9;
  background: #fafbfc;
}

.cr-panel-body {
  padding: 18px;
}

/* ── Detail view ──────────────────────────────────────── */

.cr-detail-kpis {
  grid-template-columns: repeat(6, 1fr);
}

@media (max-width: 1200px) {
  .cr-detail-kpis { grid-template-columns: repeat(3, 1fr); }
}

.cr-detail-meta-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

@media (max-width: 900px) {
  .cr-detail-meta-grid { grid-template-columns: repeat(2, 1fr); }
}

.cr-meta-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
}

.cr-meta-label {
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.cr-meta-card strong {
  font-size: 14px;
  color: #1e293b;
}

.cr-meta-sub {
  font-size: 11px;
  color: #64748b;
}

.cr-alert {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.cr-alert-warn {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

.cr-alert-danger {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.cr-alert-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.cr-row-variance {
  background: #fffbeb !important;
}

.cr-row-variance:hover {
  background: #fef3c7 !important;
}

.cr-actual-input {
  width: 110px;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: 12px;
  font-family: 'Consolas', monospace;
  text-align: left;
  direction: ltr;
}

.cr-actual-input:focus {
  outline: none;
  border-color: #714b67;
  box-shadow: 0 0 0 3px rgba(113, 75, 103, 0.12);
}

.cr-movements-panel,
.cr-audit-panel {
  margin-top: 0;
}

.cr-movements-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  padding: 12px 18px;
  border-top: 1px solid #f1f5f9;
  background: #fafbfc;
  font-size: 12px;
  color: #64748b;
}

.cr-count-grand {
  margin-top: 14px;
  padding: 12px 14px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  font-size: 14px;
  color: #166534;
}

.cr-count-grand strong {
  font-size: 18px;
  direction: ltr;
  display: inline-block;
}

/* ── Settings ─────────────────────────────────────────── */

.cr-setting-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 13px;
  color: #334155;
  cursor: pointer;
}

.cr-setting-check input {
  margin-top: 2px;
  accent-color: #714b67;
}

.cr-setting-check:hover {
  background: #f1f5f9;
}

/* ── Reports ──────────────────────────────────────────── */

.cr-report-summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cr-report-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
}

.cr-report-row:last-child {
  border-bottom: none;
}

.cr-report-label {
  color: #64748b;
  font-weight: 600;
}

.cr-box-status-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 18px;
}

@media (max-width: 900px) {
  .cr-box-status-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Detail / Legacy compat ───────────────────────────── */

.cr-page .cr-toolbar,
.cr-toolbar.cr-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.cr-danger {
  border-color: #dc2626 !important;
  color: #dc2626 !important;
}

.cr-settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.cr-setting-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.cr-setting-row input[type="text"] {
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.cr-settings-actions {
  grid-column: 1 / -1;
  margin-top: 8px;
}

.cr-meta {
  margin-bottom: 12px;
  font-size: 13px;
  color: #64748b;
}

.cr-table th,
.cr-table td,
.cr-lines-table input.cr-reason-input {
  vertical-align: middle;
}

.cr-lines-table input.cr-reason-input {
  width: 100%;
  min-width: 120px;
  padding: 4px 6px;
  font-size: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.cr-actions {
  white-space: nowrap;
}

/* Legacy table inside detail */
.cr-table .num {
  text-align: left;
  font-family: monospace;
  direction: ltr;
}
