:root {
  --navy-dark: #102a4c;
  --blue-nav: #1b4b8a;
  --blue-primary: #1a4a8a;
  --blue-primary-hover: #143b6e;
  --bg-page: #f3f5f8;
  --bg-card: #ffffff;
  --bg-thead: #eef2f6;
  --border-color: #dde3ec;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --red-danger: #c93b32;
  --red-danger-hover: #a72d25;
  --green-ok: #15803d;
  --amber-warn: #b45309;
  --banner-bg: #fef9e7;
  --banner-border: #f3e2a7;
  --banner-text: #7c5b10;
  --radius-card: 10px;
  --radius-input: 7px;
  --shadow-card: 0 1px 4px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Cairo", "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  direction: rtl;
  font-size: 14px;
  line-height: 1.5;
}

/* Header */
.top-header {
  background: var(--navy-dark);
  color: #ffffff;
  padding: 12px 24px;
}

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

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
}

.brand-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
}

.company-badge {
  background: rgba(255, 255, 255, 0.1);
  padding: 4px 12px;
  border-radius: 999px;
  color: #e2e8f0;
}

.currency-badge {
  background: rgba(255, 255, 255, 0.18);
  padding: 4px 10px;
  border-radius: 999px;
  color: #ffffff;
  font-weight: 600;
}

/* Navigation Bar */
.main-nav {
  background: var(--blue-nav);
  padding: 8px 24px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.nav-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-tab {
  background: transparent;
  border: none;
  color: #e2e8f0;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 15px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-tab:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.nav-tab.active {
  background: #ffffff;
  color: var(--navy-dark);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* Page Layout */
.page-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 24px 36px;
}

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

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: #16243b;
}

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

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 16px 18px;
  margin-bottom: 16px;
}

.card-flush {
  padding: 0;
  overflow: hidden;
}

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

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--navy-dark);
}

/* Inline Forms (Matching Screenshot) */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px 14px;
  align-items: end;
}

.form-grid-5 {
  grid-template-columns: repeat(5, minmax(140px, 1fr));
}

.form-grid-4 {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

@media (max-width: 1100px) {
  .form-grid-5, .form-grid-4 {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  }
}

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

.field label {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  height: 37px;
  padding: 6px 10px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-input);
  background: #ffffff;
  color: var(--text-main);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field textarea {
  height: auto;
  min-height: 68px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--blue-primary);
  box-shadow: 0 0 0 3px rgba(26, 74, 138, 0.12);
}

.field-span-2 {
  grid-column: span 2;
}

.form-actions-end {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

/* Live preview bar inside certificate form */
.live-preview-strip {
  margin-top: 12px;
  padding: 9px 12px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 37px;
  padding: 0 18px;
  border: none;
  border-radius: var(--radius-input);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.btn-sm {
  height: 29px;
  padding: 0 11px;
  font-size: 12px;
  border-radius: 6px;
}

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

.btn-primary:hover {
  background: var(--blue-primary-hover);
}

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

.btn-secondary:hover {
  background: #cbd5e1;
}

.btn-success {
  background: #166534;
  color: #ffffff;
}

.btn-success:hover {
  background: #14532d;
}

.btn-outline {
  background: #ffffff;
  color: var(--blue-primary);
  border: 1px solid #cbd5e1;
}

.btn-outline:hover {
  background: #f8fafc;
  border-color: var(--blue-primary);
}

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

.btn-danger:hover {
  background: var(--red-danger-hover);
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

table.data-table thead th {
  background: var(--bg-thead);
  color: #1e293b;
  font-weight: 700;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

table.data-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid #edf1f7;
  vertical-align: middle;
}

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

table.data-table tfoot td {
  background: #f8fafc;
  font-weight: 700;
  padding: 11px 14px;
  border-top: 1px solid var(--border-color);
}

.num {
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: left;
  display: inline-block;
}

.td-num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.td-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: nowrap;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-green {
  background: #dcfce7;
  color: #166534;
}

.badge-amber {
  background: #fef3c7;
  color: #92400e;
}

.badge-blue {
  background: #dbeafe;
  color: #1e40af;
}

.badge-red {
  background: #fee2e2;
  color: #991b1b;
}

.badge-gray {
  background: #e2e8f0;
  color: #334155;
}

/* Bottom Yellow Info Banner (Matching Screenshot) */
.formula-banner {
  background: var(--banner-bg);
  border: 1px solid var(--banner-border);
  color: var(--banner-text);
  border-radius: 8px;
  padding: 11px 16px;
  font-size: 13px;
  line-height: 1.6;
  margin-top: 12px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.kpi-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  border-right: 4px solid var(--blue-primary);
}

.kpi-card.kpi-green { border-right-color: var(--green-ok); }
.kpi-card.kpi-amber { border-right-color: var(--amber-warn); }
.kpi-card.kpi-red { border-right-color: var(--red-danger); }

.kpi-label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--navy-dark);
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* Two-column dashboard charts & alerts */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

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

.progress-track {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 5px;
}

.progress-fill {
  height: 100%;
  background: var(--blue-primary);
  border-radius: 999px;
}

.progress-fill.danger { background: var(--red-danger); }
.progress-fill.success { background: var(--green-ok); }

/* Sub-tabs inside views */
.subtabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.subtab-btn {
  padding: 6px 14px;
  border-radius: 7px;
  border: 1px solid var(--border-color);
  background: #ffffff;
  color: var(--text-main);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.subtab-btn.active {
  background: var(--blue-primary);
  color: #ffffff;
  border-color: var(--blue-primary);
}

/* Alerts */
.alert-box {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}

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

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

/* Toasts */
.toast-container {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--navy-dark);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  max-width: 420px;
}

.toast.toast-error { background: var(--red-danger); }
.toast.toast-warn { background: #b45309; }
.toast.toast-ok { background: #166534; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.hidden,
.hidden {
  display: none !important;
}

.modal-dialog {
  background: #ffffff;
  border-radius: 12px;
  width: 100%;
  max-width: 920px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  background: var(--navy-dark);
  color: #ffffff;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

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

/* Official A4 Printable Certificate */
.print-sheet {
  border: 1px solid #cbd5e1;
  padding: 22px;
  background: #ffffff;
}

.print-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid var(--navy-dark);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.print-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 16px;
  background: #f8fafc;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}

.print-signatures {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-top: 34px;
  text-align: center;
  font-size: 13px;
}

.sig-box {
  border-top: 1px solid #94a3b8;
  padding-top: 8px;
}

@media print {
  .no-print {
    display: none !important;
  }
  body {
    background: #ffffff;
  }
  .modal-overlay {
    position: static;
    background: none;
    padding: 0;
    display: block !important;
  }
  .modal-dialog {
    box-shadow: none;
    max-height: none;
    max-width: 100%;
    border-radius: 0;
  }
  .modal-body {
    padding: 0;
    overflow: visible;
  }
  .print-sheet {
    border: none;
    padding: 0;
  }
}
