/* ==========================================================================
   الجمعية الشرعية لتعاون العاملين بالكتاب والسنة
   منظومة إدارة المكاتب والرعاية الاجتماعية
   Unified Design System & Styling
   ========================================================================== */

/* --- 1. TYPOGRAPHY & SELF-HOSTED FONTS (@font-face) --- */

@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/IBMPlexSansArabic-Regular.ttf') format('truetype');
}

@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/IBMPlexSansArabic-Medium.ttf') format('truetype');
}

@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/IBMPlexSansArabic-SemiBold.ttf') format('truetype');
}

@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/IBMPlexSansArabic-Bold.ttf') format('truetype');
}

@font-face {
  font-family: 'Noto Naskh Arabic';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/NotoNaskhArabic-Variable.ttf') format('truetype');
}

/* --- 2. CSS VARIABLES & COLOR PALETTE --- */

:root {
  /* Palette Direction */
  --paper: #F6F7F5;           /* Cool off-white body background, not cream */
  --surface: #FFFFFF;         /* Crisp white for cards, tables and dialogs */
  --surface-subtle: #EEF1EE;  /* Subtle header / table header background */
  --surface-hover: #F2F5F2;   /* Table row hover */
  
  --ink: #1E2A2C;             /* High-contrast slate-ink for crisp Arabic legibility */
  --ink-muted: #4F6163;       /* Secondary text */
  --ink-subtle: #7A8D8F;      /* Quiet timestamps, table labels */
  
  --hairline: #D8DDD8;        /* Architectural boundary hairline */
  --hairline-subtle: #E6EAE6; /* Soft field dividers */
  --hairline-focus: #244E27;  /* Focused elements */

  /* Primary Brand: Aligned with the association's official logo crescent green */
  --juniper: #244E27;
  --juniper-hover: #1B3B1D;
  --juniper-active: #132B15;
  --juniper-light: #EBF3EC;
  --juniper-hairline: #B8D3BA;
  
  /* Attention Accent: Brass (Used ONLY for attention/status highlights) */
  --brass: #A9802C;
  --brass-dark: #7E5F1E;
  --brass-light: #F9F5EC;
  --brass-hairline: #E8D9B8;
  
  /* Danger / Deletion */
  --danger: #A3392B;
  --danger-hover: #832C20;
  --danger-light: #FBEDEB;
  --danger-hairline: #EFC6C0;

  /* Backward compatibility for any JS referencing inline styles or vars */
  --primary: var(--juniper);
  --primary-hover: var(--juniper-hover);
  --primary-light: var(--juniper-light);
  --primary-dark: var(--juniper-active);
  --secondary: #3B6B75;
  --secondary-light: #E9F1F3;
  --accent: var(--brass);
  --accent-light: var(--brass-light);
  --bg-main: var(--paper);
  --bg-card: var(--surface);
  --border-color: var(--hairline);
  --text-main: var(--ink);
  --text-muted: var(--ink-muted);
  --text-light: var(--ink-subtle);

  /* Typography Setup */
  --font-family: 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'IBM Plex Sans Arabic', ui-monospace, SFMono-Regular, Consolas, monospace;

  /* Geometry & Layout */
  --sidebar-width: 280px;
  --radius-xs: 3px;
  --radius-sm: 5px;
  --radius-md: 7px;
  --radius-lg: 10px;
}

/* --- 3. RESET & BASE RULES --- */

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

html {
  font-size: 15px;
  scroll-behavior: smooth;
  background-color: var(--paper);
  color: var(--ink);
}

body {
  direction: rtl;
  text-align: right;
  font-family: var(--font-family);
  background-color: var(--paper);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Accessible focus ring */
:focus-visible {
  outline: 2px solid var(--juniper);
  outline-offset: 2px;
}

a {
  color: var(--juniper);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* --- 4. TOP NAVBAR & BRAND HEADER --- */

.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  display: block;
  object-fit: contain;
  height: auto;
}

.sidebar-logo {
  height: 44px;
  width: auto;
  flex-shrink: 0;
}

.mobile-logo {
  height: 36px;
  width: auto;
  flex-shrink: 0;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: var(--juniper);
  color: #ffffff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
  flex-shrink: 0;
  border: 1px solid var(--juniper-hover);
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.3;
}

.brand-subtitle {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

/* --- 5. APPLICATION LAYOUT (RTL SIDEBAR + MAIN VIEWPORT) --- */

#appSection {
  min-height: 100vh;
}

.app-layout {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* Persistent Right-Side Vertical Navigation (in RTL, first flex child sits on the right) */
.app-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--surface);
  border-inline-end: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
  overflow-y: auto;
}

.sidebar-brand-block {
  padding: 1.15rem 1.15rem 0.95rem;
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-brand-info h1 {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.35;
}

.sidebar-brand-info p {
  font-size: 0.74rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* Persistent Context Block: Current user, office, role */
.context-block {
  padding: 1rem 1.25rem;
  background: var(--paper);
  border-bottom: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.context-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.context-label {
  font-size: 0.78rem;
  color: var(--ink-subtle);
  font-weight: 500;
}

.context-value {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
}

.user-nav {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.user-nav-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.user-nav-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.user-nav-actions .btn {
  flex: 1;
}

/* Vertical Navigation Menu */
.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  border: none;
  margin: 0;
}

.nav-tab {
  width: 100%;
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--ink-muted);
  background: transparent;
  border: 1px solid transparent;
  border-inline-start: 3px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: right;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  white-space: nowrap;
}

.nav-tab:hover {
  background: var(--paper);
  color: var(--juniper);
}

.nav-tab.active {
  background: var(--juniper-light);
  color: var(--juniper);
  border-color: var(--juniper-hairline);
  border-inline-start-color: var(--juniper);
  border-inline-start-width: 3px;
  font-weight: 700;
}

.nav-tab-icon {
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0.85;
}

.sidebar-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--hairline);
  font-size: 0.75rem;
  color: var(--ink-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Main Content Viewport */
.app-viewport {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background-color: var(--paper);
}

.app-main-content {
  padding: 1.5rem 2rem;
  flex: 1;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* Mobile Top Bar (Hidden on desktop, shown on mobile) */
.mobile-top-bar {
  display: none;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  padding: 0.75rem 1rem;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 45;
}

.mobile-menu-btn {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.mobile-menu-btn:hover {
  background: var(--surface-subtle);
}

.sidebar-backdrop {
  display: none;
}

/* --- 6. STATS CONTEXT STRIP (Quiet, non-card-grid) --- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.stat-card {
  padding: 0.85rem 1.1rem;
  border-inline-end: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  background: transparent;
  box-shadow: none;
  min-width: 0;
  overflow: hidden;
}

.stat-card:last-child {
  border-inline-end: none;
}

.stat-title {
  color: var(--ink-muted);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value {
  font-size: clamp(1.15rem, 1.45vw, 1.55rem);
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-subtitle {
  font-size: 0.72rem;
  color: var(--ink-subtle);
  margin-top: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- 7. MEMORABLE ELEMENT: CATEGORY SWITCH SEGMENTED CONTROL --- */

.category-pills {
  display: inline-flex;
  background: #EAECE8;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
  margin-bottom: 1.25rem;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
}

.pill-btn {
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-muted);
  font-weight: 500;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  white-space: nowrap;
  transition: all 0.15s ease;
  user-select: none;
}

.pill-btn:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.5);
}

.pill-btn.active {
  background: var(--surface);
  color: var(--juniper);
  border-color: var(--hairline);
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.pill-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 9999px;
  background: #D8DDD8;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.pill-btn.active .pill-count {
  background: var(--juniper-light);
  color: var(--juniper);
  border: 1px solid var(--juniper-hairline);
}

/* --- 8. ACTION BAR & FILTERS --- */

.action-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.15rem;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
}

.filter-group input {
  min-width: 240px;
  flex: 1;
  max-width: 380px;
}

.filter-group select {
  width: auto;
  min-width: 160px;
}

/* --- 9. TABLES & DATA CORE --- */

.table-responsive {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  box-shadow: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 0.88rem;
}

thead {
  background: var(--surface-subtle);
  border-bottom: 2px solid var(--hairline);
}

th {
  padding: 0.65rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-muted);
  white-space: nowrap;
  letter-spacing: -0.2px;
  position: sticky;
  top: 0;
  background: var(--surface-subtle);
  z-index: 10;
}

td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--hairline-subtle);
  color: var(--ink);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background-color: var(--surface-hover);
}

/* Tabular numerals for codes, IDs and financial amounts */
.tabular-nums,
.cell-mono,
td:first-child,
td:nth-child(2),
td:nth-child(6) {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

/* Long Arabic names handling */
.cell-name,
td:nth-child(3) {
  min-width: 180px;
  max-width: 280px;
  white-space: normal;
  word-break: break-word;
}

.name-container {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.beneficiary-name {
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}

.empty-val {
  color: var(--ink-subtle);
  font-size: 0.82rem;
  font-style: normal;
}

.table-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

/* Pagination Strip */
#paginationContainer,
.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  margin-top: 0;
}

#paginationInfo,
#reviewPaginationInfo {
  font-size: 0.82rem;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.pagination-pages {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: 0 0.25rem;
}

.page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 0.4rem;
  font-size: 0.82rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  font-variant-numeric: tabular-nums;
}

.page-btn.active {
  background: var(--juniper);
  color: #ffffff;
  border-color: var(--juniper);
  font-weight: 700;
}

.page-btn:hover:not(.active):not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--juniper-hairline);
}

/* --- 10. BADGES (Quiet, dignified status labels) --- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: var(--radius-xs);
  border: 1px solid var(--hairline);
  line-height: 1.3;
}

.badge-primary {
  background: var(--juniper-light);
  color: var(--juniper);
  border-color: var(--juniper-hairline);
}

.badge-secondary {
  background: #EEF2F0;
  color: #38514C;
  border-color: #CAD5D1;
}

.badge-accent {
  background: var(--brass-light);
  color: var(--brass-dark);
  border-color: var(--brass-hairline);
}

.badge-danger {
  background: var(--danger-light);
  color: var(--danger-hover);
  border-color: var(--danger-hairline);
}

.badge-gray {
  background: #EAECEA;
  color: var(--ink-muted);
  border-color: var(--hairline);
}

.badge-office {
  background: #ECEFEA;
  color: #2D4741;
  border-color: #CDD6CD;
  font-size: 0.8rem;
}

.badge-role {
  background: var(--juniper-light);
  color: var(--juniper);
  border-color: var(--juniper-hairline);
}

/* Imported-from-legacy marker and the collapsed original-record section (admins only, never printed) */
.legacy-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 500;
  border-radius: var(--radius-xs);
  background: #EAEFEA;
  color: var(--ink-muted);
  border: 1px solid var(--hairline);
  white-space: nowrap;
  vertical-align: middle;
  line-height: 1.2;
  margin-inline-start: 0.4rem;
}

.legacy-section {
  margin-top: 1.25rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xs);
  background: #FBFBFA;
}

.legacy-section > summary {
  cursor: pointer;
  padding: 0.65rem 0.9rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.legacy-body {
  padding: 0.25rem 0.9rem 0.9rem;
  font-size: 0.85rem;
  overflow-x: auto;
}

.legacy-meta {
  margin: 0 0 0.5rem;
  color: var(--ink-muted);
  font-size: 0.8rem;
}

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

.legacy-table th,
.legacy-table td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--hairline);
  vertical-align: top;
  text-align: start;
  overflow-wrap: anywhere;
}

.legacy-table th {
  width: 32%;
  font-weight: 600;
  color: var(--ink-muted);
}

.legacy-table .legacy-table {
  margin: 0;
}

.legacy-empty {
  color: var(--ink-muted);
}

/* --- 11. BUTTONS & CONTROLS --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
  line-height: 1.4;
  white-space: nowrap;
  user-select: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: var(--juniper);
  color: #ffffff;
  border-color: var(--juniper-hover);
}
.btn-primary:hover:not(:disabled) {
  background: var(--juniper-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--hairline);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-subtle);
  border-color: var(--hairline-strong);
}

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger-hairline);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-light);
  border-color: var(--danger);
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.8rem;
  border-radius: var(--radius-xs);
}

.btn-block {
  width: 100%;
}

/* --- 12. FORMS & INPUTS --- */

.form-group {
  margin-bottom: 1.15rem;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
  font-size: 0.84rem;
  color: var(--ink);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="tel"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.92rem;
  transition: border-color 0.12s ease, outline 0.12s ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--ink-subtle);
  font-size: 0.86rem;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--juniper);
  outline-offset: 1px;
  border-color: var(--juniper);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%234F6163' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.75rem center;
  padding-left: 2rem;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.form-hint {
  font-size: 0.76rem;
  color: var(--ink-subtle);
  margin-top: 0.3rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-section-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--juniper);
  margin-bottom: 0.85rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--hairline);
}

/* --- 13. ALERTS & NOTIFICATIONS --- */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: 0.88rem;
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  line-height: 1.45;
}

.alert-danger {
  background: var(--danger-light);
  color: var(--danger-hover);
  border-color: var(--danger-hairline);
}

.alert-success {
  background: var(--juniper-light);
  color: var(--juniper);
  border-color: var(--juniper-hairline);
}

.alert-warning {
  background: var(--brass-light);
  color: var(--brass-dark);
  border-color: var(--brass-hairline);
}

/* --- 14. AUTHENTICATION (LOGIN VIEW) --- */

.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background-color: var(--paper);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
  width: 100%;
  max-width: 440px;
  padding: 2.25rem;
}

.auth-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.auth-logo {
  max-height: 90px;
  width: auto;
  margin: 0 auto 1.25rem;
  display: block;
}

/* The shared .brand-logo is display:block, so the login logo needs auto side margins to sit on the card's axis */
.login-logo {
  width: auto;
  max-width: 100%;
  max-height: 96px;
  margin: 0 auto 1.25rem;
}

.auth-header .brand-icon {
  margin: 0 auto 1rem;
  width: 48px;
  height: 48px;
  font-size: 1.35rem;
}

.auth-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.4rem;
}

.auth-subtitle,
.auth-header p {
  color: var(--ink-muted);
  font-size: 0.86rem;
  line-height: 1.5;
  font-weight: 500;
}

/* --- 15. MODALS & DIALOGS --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 42, 44, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--hairline);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 1.15rem 1.5rem;
  border-bottom: 1px solid var(--hairline);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-subtle);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 0 0.25rem;
}
.modal-close:hover {
  color: var(--ink);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

/* Modal footer: Primary action on the leading side (in RTL, first child is on the right) */
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  gap: 0.75rem;
  background: var(--surface-subtle);
  border-bottom-left-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

/* --- 15.5. LOOKUP LISTS AND IMPORT REVIEW SCREENS --- */

.screen-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}

.screen-note {
  color: var(--ink-muted);
  font-size: 0.82rem;
  margin-top: 2px;
  max-width: 62ch;
}

.inline-label {
  display: inline;
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

.table-message {
  text-align: center;
  color: var(--ink-muted);
  padding: 2rem 1rem;
}

/* Pending-count badge on a navigation item */
.nav-badge {
  margin-inline-start: auto;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  background: var(--brass);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* Lookup lists */
#lookupListTabs {
  flex-wrap: wrap;
}

.lookup-add-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  flex: 1;
  align-items: flex-end;
}

.lookup-add-fields .form-group {
  margin-bottom: 0;
  flex: 1 1 200px;
}

.lookup-add-fields .lookup-order-field {
  flex: 0 1 120px;
}

#lookupAddForm {
  align-items: flex-end;
}

.lookup-table td {
  white-space: normal;
}

.lookup-table td:nth-child(3) {
  min-width: 0;
  max-width: none;
  white-space: nowrap;
}

.lookup-table td:nth-child(1) {
  min-width: 180px;
}

.lookup-table .lookup-edit-label {
  min-width: 180px;
}

.lookup-table .lookup-edit-order {
  width: 6rem;
}

.lookup-table input {
  padding: 0.35rem 0.55rem;
  font-size: 0.88rem;
}

.row-inactive td {
  color: var(--ink-subtle);
}

/* Import review */
.review-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.count-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--hairline);
  border-radius: 9999px;
  background: var(--paper);
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.count-chip strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.count-chip[data-status="pending"] {
  background: var(--brass-light);
  border-color: var(--brass-hairline);
  color: var(--brass-dark);
}

.review-table td:nth-child(5) {
  white-space: normal;
}

.review-source {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.review-key {
  color: var(--ink-subtle);
  font-size: 0.76rem;
}

.modal-wide {
  max-width: 980px;
}

.review-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.75rem 1.25rem;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
}

.review-meta-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.review-meta-item > .badge {
  align-self: flex-start;
}

.review-meta-label {
  font-size: 0.74rem;
  color: var(--ink-subtle);
  font-weight: 600;
}

.review-section-title {
  margin: 1.25rem 0 0.6rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--juniper);
}

.review-notes {
  margin-top: 0.35rem;
  overflow-wrap: anywhere;
}

.review-case-table td {
  white-space: normal;
  min-width: 0;
  max-width: none;
}

.review-case-table td:first-child {
  white-space: nowrap;
}

.review-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}

.review-action-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
}

.review-action-card h4 {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
}

.review-action-card p {
  font-size: 0.82rem;
  color: var(--ink-muted);
  line-height: 1.55;
}

.review-action-card .btn {
  align-self: flex-start;
  margin-top: auto;
}

.review-action-card label {
  margin-bottom: 0;
}

.review-search-row {
  display: flex;
  gap: 0.5rem;
}

.review-link-results {
  max-height: 220px;
  overflow-y: auto;
}

.raw-section {
  margin-top: 0.6rem;
}

/* Values of imported legacy rows are free text: let long ones wrap instead of stretching the panel */
.legacy-table td {
  white-space: normal;
}

/* --- 16. RESPONSIVE BREAKPOINTS --- */

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

  .app-layout {
    flex-direction: column;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    height: 100vh;
    z-index: 60;
    transform: translateX(100%);
    transition: transform 0.2s ease-in-out;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  }

  .app-sidebar.sidebar-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(30, 42, 44, 0.45);
    z-index: 55;
  }

  .sidebar-backdrop.active {
    display: block;
  }

  .app-main-content {
    padding: 1rem;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .action-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group input,
  .filter-group select {
    max-width: none;
    width: 100%;
  }

  .review-search-row {
    flex-direction: column;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-card {
    border-bottom: 1px solid var(--hairline);
  }

  /* Two columns: the card on the second column has no divider at its end, an odd last card spans both */
  .stat-card:nth-child(2n) {
    border-inline-end: none;
  }

  .stat-card:last-child {
    border-bottom: none;
  }

  .stat-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 14px;
  }

  /* Compact 2-column stat grid: keep the five cards from filling the first screen */
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 1rem;
  }

  .stat-card {
    padding: 0.55rem 0.7rem;
  }

  .stat-title {
    font-size: 0.74rem;
    margin-bottom: 0.1rem;
  }

  .stat-value {
    font-size: 1.1rem;
  }

  .stat-subtitle {
    display: none;
  }

  .category-pills {
    width: 100%;
  }

  .pagination-bar {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    gap: 0.65rem;
  }

  .modal {
    max-height: 95vh;
  }

  .modal-footer {
    flex-direction: column-reverse;
  }

  .modal-footer .btn {
    width: 100%;
  }

  #paginationContainer {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    gap: 0.65rem;
  }

  .pagination-controls {
    justify-content: center;
  }

  .print-letterhead {
    flex-direction: column;
    text-align: center;
    gap: 0.75rem;
  }

  .print-org-block,
  .print-meta-block {
    text-align: center;
    flex: auto;
  }
}

/* --- 16.5. PRINT DOCUMENT SCREEN PREVIEW --- */

.print-voucher {
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-sm);
  padding: 1.5rem;
  background: var(--surface);
  position: relative;
}

.print-header {
  text-align: center;
  border-bottom: 2px solid var(--hairline);
  padding-bottom: 1rem;
  margin-bottom: 1.25rem;
}

.print-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.print-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--juniper);
  margin-bottom: 0.5rem;
}

.print-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  border: 1px solid var(--hairline);
}

.print-table th,
.print-table td {
  border: 1px solid var(--hairline);
  padding: 0.65rem 0.85rem;
  font-size: 0.9rem;
}

.print-letterhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 0.85rem;
  margin-bottom: 1rem;
}

.print-org-block {
  text-align: right;
  flex: 1;
}

.print-org-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 0.2rem;
  line-height: 1.35;
}

.print-branch-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--juniper);
  margin: 0 0 0.2rem;
}

.print-dept-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-muted);
  margin: 0;
}

.print-logo-block {
  flex: 0 0 auto;
  padding: 0 1rem;
  text-align: center;
}

.print-logo {
  max-height: 72px;
  width: auto;
  display: block;
  margin: 0 auto;
}

.print-meta-block {
  flex: 0 0 210px;
  text-align: left;
  font-size: 0.82rem;
  color: var(--ink-muted);
  line-height: 1.6;
}

.print-meta-row strong {
  color: var(--ink);
}

.print-title-bar {
  text-align: center;
  margin: 0.75rem 0 1rem;
}

.print-doc-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 0.35rem;
}

.print-table th {
  background: var(--surface-subtle);
  font-weight: 600;
  color: var(--ink);
}

.signature-row {
  margin-top: 2.5rem;
  display: flex;
  justify-content: space-between;
  text-align: center;
}

.signature-row > div {
  width: 30%;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--ink);
}

/* --- 17. OFFICIAL A4 PRINT STYLESHEET --- */

@media screen {
  .print-only {
    display: none !important;
  }
}

@page {
  size: A4 portrait;
  margin: 15mm 15mm 15mm 15mm;
}

@media print {
  /* Strict monochrome / paper clean reset */
  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    font-family: 'Noto Naskh Arabic', 'Times New Roman', serif !important;
    font-size: 11pt !important;
    line-height: 1.45 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Hide entire interactive UI */
  .no-print,
  .navbar,
  .mobile-top-bar,
  .app-sidebar,
  .sidebar-backdrop,
  .stats-grid,
  .action-bar,
  .category-pills,
  .modal-footer,
  .modal-close,
  .btn,
  #paginationContainer {
    display: none !important;
  }

  /* Unfold modal to act as the printed document canvas */
  .modal-overlay {
    position: static !important;
    background: none !important;
    padding: 0 !important;
    display: block !important;
    width: 100% !important;
    height: auto !important;
  }

  .modal {
    max-width: 100% !important;
    max-height: none !important;
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  .modal-body {
    padding: 0 !important;
    overflow: visible !important;
  }

  .print-only {
    display: block !important;
  }

  /* Printable Voucher Envelope */
  .print-voucher {
    position: relative !important;
    border: 2pt solid #000000 !important;
    padding: 20pt !important;
    margin: 0 !important;
    background: #ffffff !important;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* Draft Watermark Behind Voucher */
  .print-voucher::before {
    content: 'مسودة إدارية للمراجعة الميدانية';
    position: absolute;
    top: 40%;
    right: 15%;
    left: 15%;
    text-align: center;
    font-size: 38pt;
    font-weight: 700;
    color: rgba(0, 0, 0, 0.08) !important;
    transform: rotate(-25deg);
    pointer-events: none;
    z-index: 0;
    letter-spacing: 2px;
  }

  /* Print Header with Official Letterhead */
  .print-header {
    text-align: center !important;
    border-bottom: 2pt solid #000000 !important;
    padding-bottom: 8pt !important;
    margin-bottom: 12pt !important;
    position: relative !important;
    z-index: 1 !important;
  }

  .print-letterhead {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    border-bottom: 1pt solid #000000 !important;
    padding-bottom: 8pt !important;
    margin-bottom: 8pt !important;
  }

  .print-org-block {
    text-align: right !important;
    flex: 1 !important;
  }

  .print-org-name {
    font-size: 13pt !important;
    font-weight: 700 !important;
    color: #000000 !important;
    margin: 0 0 3pt !important;
    line-height: 1.25 !important;
  }

  .print-branch-name {
    font-size: 11pt !important;
    font-weight: 700 !important;
    color: #000000 !important;
    margin: 0 0 3pt !important;
  }

  .print-dept-name {
    font-size: 9.5pt !important;
    font-weight: 600 !important;
    color: #000000 !important;
    margin: 0 !important;
  }

  .print-logo-block {
    flex: 0 0 auto !important;
    padding: 0 12pt !important;
    text-align: center !important;
  }

  .print-logo {
    max-height: 65pt !important;
    width: auto !important;
    display: block !important;
    margin: 0 auto !important;
  }

  .print-meta-block {
    flex: 0 0 160pt !important;
    text-align: left !important;
    font-size: 8.5pt !important;
    line-height: 1.5 !important;
    color: #000000 !important;
  }

  .print-title-bar {
    text-align: center !important;
    margin: 6pt 0 !important;
  }

  .print-doc-title {
    font-size: 13pt !important;
    font-weight: 700 !important;
    margin-bottom: 4pt !important;
    color: #000000 !important;
  }

  /* Preserved Draft Tag: Dignified official stamp */
  .print-draft-tag {
    display: inline-block !important;
    border: 1.5pt solid #000000 !important;
    padding: 3pt 10pt !important;
    font-size: 10pt !important;
    font-weight: 700 !important;
    background: transparent !important;
    color: #000000 !important;
    border-radius: 0 !important;
    margin-top: 4pt !important;
  }

  /* Data Table */
  .print-table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 14pt 0 !important;
    position: relative !important;
    z-index: 1 !important;
  }

  .print-table th,
  .print-table td {
    border: 1pt solid #000000 !important;
    padding: 7pt 10pt !important;
    font-size: 10.5pt !important;
    color: #000000 !important;
  }

  .print-table th {
    background: #f5f5f5 !important;
    font-weight: 700 !important;
  }

  /* Official Signature Row */
  .signature-row {
    margin-top: 35pt !important;
    display: flex !important;
    justify-content: space-between !important;
    text-align: center !important;
    page-break-inside: avoid;
    break-inside: avoid;
    position: relative !important;
    z-index: 1 !important;
  }

  .signature-row > div {
    width: 30% !important;
    font-weight: 600 !important;
  }
}

/* --- Multi-office administration: bulk transfer, office controls, scoped lookups --- */
.case-bulk-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.case-select-col {
  width: 2.5rem;
  text-align: center;
}

.case-select-col input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  cursor: pointer;
}

.case-office-cell {
  white-space: normal;
  min-width: 120px;
}

.transfer-results {
  margin-top: 0.75rem;
}

.transfer-results .review-case-table td {
  white-space: normal;
}

.case-transfers {
  margin-top: 1rem;
}

.case-transfers td {
  white-space: normal;
}

.lookup-scope-badge {
  margin-inline-start: 0.35rem;
  vertical-align: middle;
}

#officeStatusMessage ul {
  margin: 0.4rem 1.2rem;
  padding: 0;
  list-style: disc;
}

#officeStatusMessage p {
  margin: 0.3rem 0;
}
/* The positional td rules above (nth-child 3 = wide name column) must not hit the added columns */
td.case-office-cell,
td.office-status-cell {
  min-width: 0;
  max-width: 160px;
  white-space: normal;
}

td.office-status-cell {
  white-space: nowrap;
}

#officeStatusMessage {
  display: block;
}