@font-face {
  font-family: 'MawridArabic';
  src: url('../fonts/arabic-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'MawridArabic';
  src: url('../fonts/arabic-bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Approved Mowarid Brand Identity (Icon #4 Palette) */
  --brand-indigo: #1E1B4B;
  --brand-indigo-2: #312E81;
  --brand-blue: #2563EB;
  --brand-blue-hover: #1D4ED8;
  --brand-teal: #0D9488;
  --brand-amber: #F59E0B;

  --bg: #F4F6FB;
  --surface: #FFFFFF;
  --surface-2: #EEF2F9;
  --border: #DCE3F0;
  --text: #0F172A;
  --text-muted: #526077;

  --success: #0D9488;
  --success-bg: #CCFBF1;
  --warning: #D97706;
  --warning-bg: #FEF3C7;
  --danger: #DC2626;
  --danger-bg: #FEE2E2;
  --info: #2563EB;
  --info-bg: #DBEAFE;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(30, 27, 75, 0.06);
  --shadow-lg: 0 12px 32px rgba(30, 27, 75, 0.14);
  --sidebar-w: 252px;
  --bottom-nav-h: 66px;
}

[data-theme="dark"] {
  --bg: #0B1020;
  --surface: #131B2E;
  --surface-2: #1B2540;
  --border: #263354;
  --text: #F1F5F9;
  --text-muted: #94A3B8;
  --success-bg: rgba(13, 148, 136, 0.18);
  --warning-bg: rgba(245, 158, 11, 0.18);
  --danger-bg: rgba(220, 38, 38, 0.2);
  --info-bg: rgba(37, 99, 235, 0.2);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: 'MawridArabic', -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--brand-blue); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  display: none;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--brand-indigo) 0%, var(--brand-indigo-2) 100%);
  color: #fff;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  padding: 20px 14px;
  flex-direction: column;
  z-index: 40;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 14px;
}
.sidebar-brand img {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: #fff;
  padding: 2px;
}
.sidebar-brand-title { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.sidebar-brand-sub { font-size: 0.78rem; color: rgba(255, 255, 255, 0.72); }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  min-height: 44px;
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.82);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.sidebar-link:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.sidebar-link.active {
  background: var(--brand-blue);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.75);
}

.main-wrap {
  flex: 1;
  min-width: 0;
  padding-bottom: calc(var(--bottom-nav-h) + 20px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar-title-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo { width: 34px; height: 34px; border-radius: 9px; }
.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.page-content {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 14px 28px;
}

/* Bottom Navigation (Mobile) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 40;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.72rem;
  color: var(--text-muted);
  min-height: 44px;
}
.bottom-nav a.active {
  color: var(--brand-blue);
  font-weight: 700;
}
.bottom-nav .nav-ico { font-size: 1.25rem; line-height: 1; }

@media (min-width: 901px) {
  .sidebar { display: flex; }
  .bottom-nav { display: none; }
  .topbar-logo { display: none; }
  .main-wrap {
    margin-right: var(--sidebar-w);
    padding-bottom: 24px;
  }
  .page-content { padding: 24px 28px 36px; }
}

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-title { margin: 0; font-size: 1.05rem; font-weight: 700; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 680px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 960px) {
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--brand-blue);
}
.stat-card.teal { border-top-color: var(--brand-teal); }
.stat-card.amber { border-top-color: var(--brand-amber); }
.stat-card.indigo { border-top-color: var(--brand-indigo-2); }
.stat-label { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 1.45rem; font-weight: 700; line-height: 1.25; }
.stat-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

/* Buttons (min-height 44px touch target) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--brand-blue); color: #fff; }
.btn-primary:hover { background: var(--brand-blue-hover); }
.btn-teal { background: var(--brand-teal); color: #fff; }
.btn-teal:hover { background: #0F766E; }
.btn-indigo { background: var(--brand-indigo); color: #fff; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-sm { min-height: 44px; padding: 0 12px; font-size: 0.85rem; }
.btn-icon { min-width: 44px; min-height: 44px; padding: 0; }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; }

/* Forms */
.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 5px;
  color: var(--text);
}
.input, select.input, textarea.input {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}
textarea.input { min-height: 88px; resize: vertical; }
.input:focus {
  outline: none;
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.field-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

/* Badges & Alerts */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.badge-draft { background: var(--surface-2); color: var(--text-muted); }
.badge-sent { background: var(--info-bg); color: var(--info); }
.badge-accepted, .badge-paid, .badge-approved { background: var(--success-bg); color: var(--success); }
.badge-rejected { background: var(--danger-bg); color: var(--danger); }
.badge-trial { background: var(--warning-bg); color: var(--warning); }

.alert {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(220, 38, 38, 0.25); }
.alert-warning { background: var(--warning-bg); color: #92400E; border: 1px solid rgba(217, 119, 6, 0.3); }
[data-theme="dark"] .alert-warning { color: #FCD34D; }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid rgba(37, 99, 235, 0.25); }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th, .table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
}
.table th {
  background: var(--surface-2);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.table tr:hover td { background: rgba(37, 99, 235, 0.03); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
/* inline-block only for inline elements — on <td>/<th> it breaks table layout */
span.num, strong.num, b.num, div.num { display: inline-block; }
td.num, th.num { display: table-cell; text-align: center; }

/* Quote Editor Lines */
.line-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
}
.line-row-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
}
.line-row-nums {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
@media (min-width: 720px) {
  .line-row-nums { grid-template-columns: 1fr 1fr 1.2fr 1.2fr; }
}

.totals-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 0.95rem;
}
.totals-row.grand {
  border-top: 2px solid var(--brand-indigo);
  margin-top: 8px;
  padding-top: 10px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--brand-blue);
}
.tafqit-box {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border-right: 4px solid var(--brand-teal);
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.92rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 680px;
  width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

/* Filter chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 700;
}
.chip.active { background: var(--brand-indigo); color: #fff; border-color: var(--brand-indigo); }

/* Image previews */
.img-preview {
  max-height: 84px;
  max-width: 180px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 4px;
  display: block;
  margin-top: 8px;
}

/* Toast */
.toast-wrap {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--brand-indigo);
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--brand-teal); }
.toast-danger { background: var(--danger); }
.toast-warning { background: #B45309; }

/* Empty State */
.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
}
.empty-state-ico { font-size: 2.2rem; margin-bottom: 8px; }

/* Onboarding Wizard */
.wizard-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.wizard-step {
  text-align: center;
  padding: 8px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}
.wizard-step.active { background: var(--brand-blue); color: #fff; }
.wizard-step.done { background: var(--success-bg); color: var(--success); }

/* Print Preview Sheet (on screen) */
.print-toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--brand-indigo);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.print-sheet {
  background: #fff;
  color: #0F172A;
  max-width: 210mm;
  margin: 18px auto;
  padding: 14mm;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.print-sheet.landscape-sheet { max-width: 297mm; }
.print-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  border-bottom: 3px solid var(--brand-indigo);
  padding-bottom: 12px;
  margin-bottom: 14px;
}
.print-logo { max-height: 68px; max-width: 150px; object-fit: contain; }
.print-doc-badge {
  background: var(--brand-indigo);
  color: #fff;
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  display: inline-block;
  margin-bottom: 6px;
}
.print-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  background: #F8FAFC;
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.88rem;
}
.print-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  margin-bottom: 14px;
}
.print-table th {
  background: #1E1B4B;
  color: #fff;
  padding: 8px 8px;
  text-align: right;
  font-weight: 700;
}
.print-table td {
  padding: 7px 8px;
  border-bottom: 1px solid #CBD5E1;
  text-align: right;
}
.print-table tbody tr:nth-child(even) { background: #F8FAFC; }
.print-summary {
  margin-right: auto;
  width: 100%;
  max-width: 340px;
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  padding: 10px 14px;
  background: #F8FAFC;
  font-size: 0.9rem;
}
.print-summary-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}
.print-summary-row.total {
  border-top: 2px solid #1E1B4B;
  margin-top: 6px;
  padding-top: 8px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #1E1B4B;
}
.print-tafqit {
  margin-top: 12px;
  padding: 8px 12px;
  border: 1px solid #0D9488;
  background: #F0FDFA;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.9rem;
}
.print-terms {
  margin-top: 14px;
  font-size: 0.84rem;
  white-space: pre-line;
  border-top: 1px solid #E2E8F0;
  padding-top: 10px;
}
.print-sign-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-top: 22px;
  padding-top: 12px;
  border-top: 1px dashed #CBD5E1;
}
.print-sign-img { max-height: 70px; max-width: 140px; object-fit: contain; }
.print-footer-note {
  margin-top: 18px;
  padding-top: 8px;
  border-top: 1px solid #CBD5E1;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.78rem;
  color: #475569;
  flex-wrap: wrap;
}
.watermark-trial {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-32deg);
  font-size: 5rem;
  font-weight: 700;
  color: rgba(220, 38, 38, 0.15);
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
  user-select: none;
}
