/**
 * base.css
 * -----------------------------------------------------------------------
 * Design tokens (CSS custom properties) + base/reset styles for the EAP
 * PWA. RTL-first: uses logical properties (margin-inline-start, etc.)
 * instead of left/right so the whole app stays mirror-safe.
 *
 * Color tokens are taken VERBATIM from spec §1.2:
 *   yellow  FFFFF8E1  -> user-input cell background
 *   gray    FFF2F4F7  -> computed/derived cell background (never editable)
 *   red     FFFEE4E2  -> flagged / needs-attention state
 *   navy    FF17384D  -> section/nav header bars
 *   teal    FF0F766E  -> sub-section header bars / dynamic-list markers
 *   blue    FF2F75B5  -> table column-header row background
 * -----------------------------------------------------------------------
 */

/* =========================================================================
   1. DESIGN TOKENS
   ========================================================================= */
:root {
  /* --- Spreadsheet-fidelity colors (spec §1.2) --- */
  --color-input-bg: #FFF8E1;        /* yellow: user-input cell */
  --color-input-border: #E8D48A;
  --color-computed-bg: #F2F4F7;     /* gray: computed/derived cell */
  --color-computed-bg-alt: #EAF3F8; /* alt gray used in some sheets */
  --color-computed-text: #4B5563;
  --color-attention-bg: #FEE4E2;    /* light red: flagged/needs-attention */
  --color-attention-border: #F4A9A3;
  --color-attention-text: #7A271A;
  --color-header-navy: #17384D;     /* section/nav header bars */
  --color-header-navy-text: #FFFFFF;
  --color-subheader-teal: #0F766E;  /* sub-section header bars */
  --color-subheader-teal-text: #FFFFFF;
  --color-table-header-blue: #2F75B5; /* table column-header row */
  --color-table-header-blue-text: #FFFFFF;

  /* --- Status colors (derived, for pills/badges — not in spec but needed
         for a coherent "clean modern humanitarian-tool" aesthetic) --- */
  --color-status-ok: #15803D;       /* سليم / جاهز / مغلق (closed=good) */
  --color-status-ok-bg: #DCFCE7;
  --color-status-warn: #B45309;     /* غير مكتمل */
  --color-status-warn-bg: #FEF3C7;
  --color-status-danger: #B42318;   /* غير سليم / مرفوض */
  --color-status-danger-bg: #FEE4E2;
  --color-status-neutral: #475467;  /* غير مستخدم */
  --color-status-neutral-bg: #F2F4F7;

  /* --- Neutral palette --- */
  --color-bg: #F7F9FB;
  --color-surface: #FFFFFF;
  --color-border: #D8DFE6;
  --color-text: #1D2939;
  --color-text-muted: #667085;
  --color-link: #2F75B5;

  /* --- Typography --- */
  --font-family-base: 'Tajawal', 'Cairo', 'Segoe UI', Tahoma, system-ui, -apple-system, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-md: 1.125rem;
  --font-size-lg: 1.375rem;
  --font-size-xl: 1.75rem;
  --font-size-xxl: 2.25rem;
  --line-height-base: 1.6;

  /* --- Spacing scale --- */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;

  /* --- Radii / shadows --- */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.10);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);

  /* --- Layout --- */
  --header-height: 3.5rem;
  --max-content-width: 960px;

  /* --- Tap targets (mobile field use) --- */
  --tap-target-min: 44px;
}

/* =========================================================================
   2. RESET
   ========================================================================= */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  /* Respect device text-size preferences; do not hardcode px root size. */
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  direction: rtl;
}

img, svg {
  max-width: 100%;
  display: block;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--color-link);
}

/* =========================================================================
   3. APP SHELL
   ========================================================================= */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background: var(--color-header-navy);
  color: var(--color-header-navy-text);
  padding: var(--space-5) var(--space-4);
  text-align: center;
}

.app-header__title {
  margin: 0 0 var(--space-2) 0;
  font-size: var(--font-size-lg);
  font-weight: 700;
}

.app-header__subtitle {
  margin: 0;
  font-size: var(--font-size-sm);
  opacity: 0.85;
}

.app-main {
  flex: 1;
  max-width: var(--max-content-width);
  margin-inline: auto;
  padding: var(--space-5) var(--space-4);
  width: 100%;
}

.placeholder-note {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  color: var(--color-text-muted);
  margin-block-end: var(--space-4);
}

/* =========================================================================
   4. HEADER BAR VARIANTS (section/nav = navy, sub-section = teal, table = blue)
   ========================================================================= */
.header-bar--navy {
  background: var(--color-header-navy);
  color: var(--color-header-navy-text);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-weight: 700;
}

.header-bar--teal {
  background: var(--color-subheader-teal);
  color: var(--color-subheader-teal-text);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.table-header-row {
  background: var(--color-table-header-blue);
  color: var(--color-table-header-blue-text);
  font-weight: 600;
}

/* =========================================================================
   5. FORM FIELD CONVENTIONS (yellow input / gray computed / red attention)
   ========================================================================= */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-block-end: var(--space-4);
}

.field__label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
}

.field__label--required::after {
  content: ' *';
  color: var(--color-status-danger);
}

.field__hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.field__error {
  font-size: var(--font-size-xs);
  color: var(--color-status-danger);
}

.input,
.select,
.textarea {
  min-height: var(--tap-target-min);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-sm);
  background: var(--color-input-bg);
  font-size: var(--font-size-base);
  width: 100%;
}

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

.textarea {
  min-height: calc(var(--tap-target-min) * 2);
  resize: vertical;
}

/* Computed/derived cell — never user-editable */
.field--computed .input,
.field--computed .select,
.field--computed .textarea,
.computed-cell {
  background: var(--color-computed-bg);
  color: var(--color-computed-text);
  border-color: var(--color-border);
  cursor: not-allowed;
}

/* Flagged / needs-attention state */
.field--attention .input,
.field--attention .select,
.field--attention .textarea,
.attention-cell {
  background: var(--color-attention-bg);
  border-color: var(--color-attention-border);
  color: var(--color-attention-text);
}

/* =========================================================================
   6. STATUS PILLS / BADGES
   ========================================================================= */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  font-size: var(--font-size-xs);
  font-weight: 700;
  /* Pills are mostly short state words ("سليم"/"مفتوح"), but several
     screens (Stage 8's gate-reason summary, dashboard stage rows, output
     notices) reuse this component for full reason sentences. A hard
     nowrap here was the root cause of several page-wide horizontal
     overflows on narrow phones — wrapping is a no-op for short content
     and safely breaks long content onto multiple lines instead. */
  white-space: normal;
  max-width: 100%;
  overflow-wrap: break-word;
  text-align: start;
  line-height: 1.35;
}

.pill--ok {
  background: var(--color-status-ok-bg);
  color: var(--color-status-ok);
}
.pill--warn {
  background: var(--color-status-warn-bg);
  color: var(--color-status-warn);
}
.pill--danger {
  background: var(--color-status-danger-bg);
  color: var(--color-status-danger);
}
.pill--neutral {
  background: var(--color-status-neutral-bg);
  color: var(--color-status-neutral);
}

/* =========================================================================
   7. CARDS / SURFACES
   ========================================================================= */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}

.card + .card {
  margin-block-start: var(--space-4);
}

/* =========================================================================
   8. BUTTONS (large tap targets for field use on phones)
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-target-min);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.btn:active {
  filter: brightness(0.92);
}

.btn--primary {
  background: var(--color-header-navy);
  color: var(--color-header-navy-text);
}

.btn--secondary {
  background: var(--color-subheader-teal);
  color: var(--color-subheader-teal-text);
}

.btn--outline {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}

.btn--danger {
  background: var(--color-status-danger);
  color: #fff;
}

/* =========================================================================
   9. BREADCRUMB NAV (السابق / لوحة ابدأ هنا / التالي — spec §1.3)
   ========================================================================= */
.breadcrumb-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  background: var(--color-header-navy);
  color: var(--color-header-navy-text);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  margin-block-end: var(--space-4);
  flex-wrap: wrap;
}

.breadcrumb-bar a {
  color: var(--color-header-navy-text);
  text-decoration: none;
  font-size: var(--font-size-sm);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}

.breadcrumb-bar a:hover,
.breadcrumb-bar a:focus-visible {
  background: rgba(255, 255, 255, 0.15);
}

/* =========================================================================
   10. TABLES (repeating-row entry, cap-aware)
   ========================================================================= */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.data-table th {
  background: var(--color-table-header-blue);
  color: var(--color-table-header-blue-text);
  padding: var(--space-2) var(--space-3);
  text-align: start;
  position: sticky;
  inset-block-start: 0;
}

.data-table td {
  padding: var(--space-2) var(--space-3);
  border-block-end: 1px solid var(--color-border);
}

.data-table tbody tr:hover {
  background: rgba(47, 117, 181, 0.06);
}

/* =========================================================================
   11. RESPONSIVE BREAKPOINTS (mobile-first)
   ========================================================================= */
@media (min-width: 640px) {
  .app-header__title {
    font-size: var(--font-size-xl);
  }
  .app-main {
    padding-inline: var(--space-6);
  }
}

@media (min-width: 1024px) {
  .app-header__title {
    font-size: var(--font-size-xxl);
  }
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
