/* ===========================================================================
   Civil_pro design system, layered on top of Bootstrap 5.
   Tokens, navbars, sidebars, cards, forms, badges, code blocks, RTL helpers.
   =========================================================================== */

:root {
  --cp-primary: #2563eb;
  --cp-primary-dark: #1d4ed8;
  --cp-accent: #f97316;
  --cp-success: #16a34a;
  --cp-danger: #dc2626;
  --cp-text: #0f172a;
  --cp-muted: #64748b;
  --cp-border: #e2e8f0;
  --cp-bg: #f8fafc;
  --cp-surface: #ffffff;
  --cp-sidebar-bg: #0f172a;
  --cp-sidebar-fg: #e2e8f0;
  --cp-sidebar-active: #2563eb;
  --cp-admin-bg: #020617;
  --cp-admin-accent: #ec4899;
  --cp-radius: 0.6rem;
  --cp-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --cp-shadow-md: 0 6px 18px rgba(15, 23, 42, 0.08);
  --cp-font-latin: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --cp-font-arabic: 'Cairo', 'Segoe UI', 'Tahoma', sans-serif;
}

html,
body {
  min-height: 100%;
  background-color: var(--cp-bg);
  color: var(--cp-text);
  font-family: var(--cp-font-arabic);
  direction: rtl;
  text-align: right;
}

.cp-arabic,
[lang='ar'] {
  font-family: var(--cp-font-arabic);
  direction: rtl;
  text-align: right;
}

a {
  color: var(--cp-primary);
}
a:hover {
  color: var(--cp-primary-dark);
}

.cp-app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}
.cp-app-shell--admin .cp-sidebar {
  background: var(--cp-admin-bg);
}

@media (max-width: 992px) {
  .cp-app-shell {
    grid-template-columns: 1fr;
  }
  .cp-sidebar {
    display: none;
  }
  .cp-sidebar.is-open {
    display: block;
    position: fixed;
    top: 0;
    inset-inline-end: 0;
    bottom: 0;
    width: 260px;
    z-index: 1040;
  }
}

.cp-sidebar {
  background: var(--cp-sidebar-bg);
  color: var(--cp-sidebar-fg);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.cp-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: white;
  font-size: 1.05rem;
}
.cp-sidebar__brand .bi {
  font-size: 1.4rem;
  color: var(--cp-accent);
}
.cp-sidebar__plan {
  font-size: 0.75rem;
  color: #cbd5f5;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--cp-radius);
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.cp-sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.cp-sidebar__nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--cp-radius);
  color: var(--cp-sidebar-fg);
  text-decoration: none;
  transition: background-color 0.15s ease;
  font-size: 0.92rem;
}
.cp-sidebar__nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: white;
}
.cp-sidebar__nav a.is-active {
  background: var(--cp-sidebar-active);
  color: white;
}
.cp-sidebar__nav .bi {
  font-size: 1rem;
}
.cp-sidebar__section-title {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: #94a3b8;
  margin: 0.75rem 0 0.25rem;
}

.cp-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.cp-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--cp-surface);
  border-bottom: 1px solid var(--cp-border);
  padding: 0.85rem 1.25rem;
  box-shadow: var(--cp-shadow-sm);
}
.cp-sticky-test-bar {
  position: sticky;
  top: 0;
  z-index: 1100;
  width: 100%;
  text-align: center;
  padding: 0.45rem 0.75rem;
  background: #fef3c7;
  color: #7c2d12;
  border-bottom: 1px solid #f59e0b;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.cp-topbar__title {
  font-weight: 600;
  font-size: 1.05rem;
}
.cp-topbar__user {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
.cp-main {
  padding: 1.5rem;
  flex: 1;
  min-width: 0;
}

.cp-card {
  background: var(--cp-surface);
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-radius);
  box-shadow: var(--cp-shadow-sm);
  padding: 1.25rem;
}
.cp-card + .cp-card {
  margin-top: 1rem;
}
.cp-card__title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.cp-ai-settings__card {
  display: flex;
  flex-direction: column;
}
.cp-ai-settings__header {
  border-bottom: 1px solid var(--cp-border);
  padding-bottom: 0.75rem;
}
.cp-ai-settings__test {
  margin-top: 0.25rem;
}
.cp-ai-settings__save-form .form-text {
  font-size: 0.75rem;
}
.cp-card__sub {
  color: var(--cp-muted);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.cp-stat {
  background: var(--cp-surface);
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.cp-stat__label {
  color: var(--cp-muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.cp-stat__value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--cp-text);
}

.cp-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cp-badge--free {
  background: #e0f2fe;
  color: #075985;
}
.cp-badge--expert {
  background: #fef3c7;
  color: #92400e;
}
.cp-badge--admin {
  background: #fce7f3;
  color: #9d174d;
}
.cp-badge--ok {
  background: #dcfce7;
  color: #166534;
}
.cp-badge--err {
  background: #fee2e2;
  color: #991b1b;
}

.cp-public {
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3a8a 0%, #0ea5e9 100%);
  color: white;
}
.cp-public__inner {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}
.cp-public-card {
  background: white;
  color: var(--cp-text);
  border-radius: var(--cp-radius);
  box-shadow: 0 20px 60px rgba(2, 6, 23, 0.35);
  padding: 2rem;
  width: 100%;
  max-width: 460px;
}
.cp-public-card--wide {
  max-width: 920px;
}
.cp-public__brand {
  font-weight: 700;
  font-size: 1.4rem;
  margin-bottom: 0.25rem;
}
.cp-public__sub {
  color: var(--cp-muted);
  margin-bottom: 1.4rem;
}

.cp-form-floating-icon {
  position: relative;
}
.cp-form-floating-icon .bi {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--cp-muted);
}
.cp-form-floating-icon .form-control {
  padding-left: 2.3rem;
}

.cp-toolbar {
  position: sticky;
  top: 0.5rem;
  background: var(--cp-surface);
  border-radius: var(--cp-radius);
  border: 1px solid var(--cp-border);
  box-shadow: var(--cp-shadow-md);
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  z-index: 10;
}

.cp-chat {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1rem;
  min-height: 70vh;
}
@media (max-width: 992px) {
  .cp-chat {
    grid-template-columns: 1fr;
  }
}
.cp-chat__sidebar {
  background: var(--cp-surface);
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-radius);
  padding: 1rem;
  overflow-y: auto;
}
.cp-chat__thread--relative {
  position: relative;
}
.cp-chat-bootstrap-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--cp-radius);
}
.cp-chat-bootstrap-overlay__card {
  max-width: 320px;
  padding: 1.5rem;
}
.cp-chat__thread {
  background: var(--cp-surface);
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-radius);
  display: flex;
  flex-direction: column;
  min-height: 70vh;
}
.cp-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.cp-msg {
  border-radius: var(--cp-radius);
  padding: 0.7rem 0.9rem;
  max-width: 80%;
  white-space: pre-wrap;
}
.cp-msg--user {
  background: var(--cp-primary);
  color: white;
  align-self: flex-end;
}
.cp-msg--assistant {
  background: #f1f5f9;
  align-self: flex-start;
}
.cp-msg img {
  max-width: 100%;
  border-radius: var(--cp-radius);
  margin-top: 0.5rem;
}
.cp-chat__composer {
  border-top: 1px solid var(--cp-border);
  padding: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.cp-wizard__steps {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.cp-wizard__step {
  flex: 1 1 0;
  text-align: center;
  padding: 0.65rem 0.5rem;
  border-radius: var(--cp-radius);
  background: #e2e8f0;
  color: var(--cp-muted);
  font-size: 0.85rem;
  font-weight: 600;
}
.cp-wizard__step.is-active {
  background: var(--cp-primary);
  color: white;
}
.cp-wizard__step.is-done {
  background: var(--cp-success);
  color: white;
}

/* ----- Questionnaire: group picker & reference ----- */
.cp-group-pick {
  display: block;
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-radius);
  background: var(--cp-surface);
  box-shadow: var(--cp-shadow-sm);
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}
.cp-group-pick:hover {
  border-color: #cbd5e1;
  box-shadow: var(--cp-shadow-md);
}
.cp-group-pick.is-selected {
  border-color: var(--cp-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}
.cp-border-lg-end {
  border-bottom: 1px solid var(--cp-border);
}
@media (min-width: 992px) {
  .cp-border-lg-end {
    border-bottom: none;
    border-inline-end: 1px solid var(--cp-border);
  }
}
.cp-example-bullets {
  margin: 0;
  padding-inline-start: 1.1rem;
  max-height: 11rem;
  overflow-y: auto;
}
.cp-example-bullets li {
  margin-bottom: 0.2rem;
}
.cp-example-chip {
  max-width: 100%;
  white-space: normal;
  text-align: start;
  line-height: 1.25;
}
.cp-details-ref {
  border: 1px solid var(--cp-border);
  border-radius: var(--cp-radius);
  padding: 0.75rem 1rem;
  background: var(--cp-surface);
}
.cp-details-ref summary {
  cursor: pointer;
  list-style: none;
}
.cp-details-ref summary::-webkit-details-marker {
  display: none;
}
.cp-accordion-item + .cp-accordion-item {
  margin-top: 0.35rem;
}
.cp-review-scroll {
  max-height: min(70vh, 520px);
  overflow-y: auto;
}
.cp-review-section + .cp-review-section {
  border-top: 1px solid var(--cp-border);
  padding-top: 1rem;
}
.cp-q-row .form-label {
  line-height: 1.45;
}

.cp-section-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.cp-section-buttons .cp-section-btn {
  flex: 1 1 140px;
  text-align: start;
  padding: 0.65rem 0.85rem;
}
.cp-section-buttons .cp-section-btn.active {
  background: var(--cp-primary);
  border-color: var(--cp-primary);
  color: #fff;
}
.cp-section-buttons .cp-section-btn.active .text-muted {
  color: rgba(255, 255, 255, 0.85) !important;
}
.cp-questionnaire .cp-q-conditional.d-none,
.cp-questionnaire .cp-garage-block.d-none {
  display: none !important;
}
.cp-questionnaire #groupQuestionsWrap .cp-q-conditional:not(.d-none) {
  display: block;
}
.cp-section-buttons .cp-section-btn {
  cursor: pointer;
}

.cp-print {
  background: white;
  color: black;
}
@media print {
  .cp-sidebar,
  .cp-topbar,
  .cp-sticky-test-bar,
  .cp-toolbar,
  .cp-no-print {
    display: none !important;
  }
  .cp-main {
    padding: 0;
  }
}

/* Field help (? popover) */
.cp-label-with-help {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.cp-field-help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.25rem;
  margin: -0.35rem 0;
  border: none;
  background: transparent;
  color: var(--cp-muted);
  line-height: 1;
  vertical-align: middle;
  cursor: help;
}
.cp-field-help-btn:hover,
.cp-field-help-btn:focus {
  color: var(--cp-primary);
  outline: none;
}
.cp-field-help-btn .bi {
  font-size: 1.05rem;
}
.cp-field-help-popover {
  max-width: 22rem;
  direction: rtl;
  text-align: right;
  font-family: var(--cp-font-arabic);
}
.cp-field-help-popover .popover-body {
  font-size: 0.875rem;
  line-height: 1.55;
}
.cp-help-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--cp-text);
}
.cp-help-section {
  margin-bottom: 0.5rem;
}
.cp-help-section strong {
  color: var(--cp-text);
}
.cp-feature-help-inline {
  display: inline-flex;
  vertical-align: middle;
  margin-inline-start: 0.35rem;
}
.cp-feature-help-card {
  position: relative;
  z-index: 3;
  flex-shrink: 0;
}

/* Public / app footer */
.cp-public--with-footer {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.cp-public--with-footer .cp-public__inner {
  flex: 1;
}
.cp-site-footer {
  border-top: 1px solid var(--cp-border);
  background: var(--cp-surface);
  padding: 1.25rem 1.5rem;
  margin-top: 2rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--cp-muted);
}
.cp-site-footer a {
  color: var(--cp-primary);
  text-decoration: none;
}
.cp-site-footer a:hover {
  text-decoration: underline;
}
.cp-site-footer__nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem 0.75rem;
}
.cp-content .cp-site-footer {
  margin-top: 1.5rem;
}
