/* ==================================================================
   Darosalam Form — Design foundation
   Shared design tokens, reset and UI primitives.
   Loaded by BOTH the public survey page and the admin results page.
   Light theme · RTL-first · logical properties throughout.
   ================================================================== */

@import url('../fonts/fonts.css');

/* ------------------------------------------------------------------
   1. Design tokens
   ------------------------------------------------------------------ */
:root {
  /* --- Brand: deep teal / emerald --- */
  --brand-50:  #ecfdf7;
  --brand-100: #d1fae7;
  --brand-200: #a7f3d4;
  --brand-300: #6ee7bb;
  --brand-400: #34d3a0;
  --brand-500: #10b981;
  --brand-600: #0d9488;
  --brand-700: #0f766e;
  --brand-800: #115e59;
  --brand-900: #134e4a;
  --brand-950: #052e2b;

  /* --- Accent: warm amber --- */
  --accent-50:  #fffbeb;
  --accent-100: #fef3c7;
  --accent-200: #fde68a;
  --accent-400: #fbbf24;
  --accent-500: #f59e0b;
  --accent-600: #d97706;
  --accent-700: #b45309;

  /* --- Neutrals --- */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  /* --- Semantic --- */
  --success-50: #ecfdf5;  --success-500: #10b981;  --success-700: #047857;
  --danger-50:  #fef2f2;  --danger-100:  #fee2e2;  --danger-200: #fecaca;
  --danger-500: #ef4444;  --danger-600:  #dc2626;  --danger-700: #b91c1c;
  --warn-50:    #fffbeb;  --warn-500:    #f59e0b;  --warn-700:    #b45309;
  --info-50:    #eff6ff;  --info-100:    #dbeafe;  --info-200:   #bfdbfe;
  --info-500:   #3b82f6;  --info-700:    #1d4ed8;

  /* --- Surfaces & text --- */
  --bg:            #f4f7f7;
  --bg-tint:       #eef4f3;
  --surface:       #ffffff;
  --surface-2:     var(--slate-50);
  --surface-3:     var(--slate-100);
  --border:        var(--slate-200);
  --border-strong: var(--slate-300);
  --text:          var(--slate-900);
  --text-2:        var(--slate-700);
  /* Secondary text. Darkened from --slate-500 so it clears 4.5:1 on every
     surface in the palette (white 5.3:1 · --bg-tint 4.7:1), not just white. */
  --text-muted:    #5f6d80;
  /* DECORATION ONLY — 2.6:1 on white. Never use this for text. */
  --text-faint:    var(--slate-400);
  --text-on-brand: #ffffff;

  /* --- Typography --- */
  --font-fa:  'Vazirmatn', 'Vazir', 'Ravi', 'Segoe UI', Tahoma, system-ui, -apple-system, sans-serif;
  --font-num: 'Vazirmatn', 'Vazir', 'Ravi', ui-monospace, 'Segoe UI', Tahoma, sans-serif;

  --fs-2xs:  0.6875rem;  /* 11px */
  --fs-xs:   0.75rem;    /* 12px */
  --fs-sm:   0.8125rem;  /* 13px */
  --fs-base: 0.9375rem;  /* 15px */
  --fs-md:   1rem;       /* 16px */
  --fs-lg:   1.125rem;   /* 18px */
  --fs-xl:   1.3125rem;  /* 21px */
  --fs-2xl:  1.625rem;   /* 26px */
  --fs-3xl:  2rem;       /* 32px */
  --fs-4xl:  2.5rem;     /* 40px */

  --lh-tight: 1.35;
  --lh-snug:  1.6;
  --lh-body:  1.95;   /* generous leading for Persian readability */

  /* --- Spacing scale --- */
  --sp-1: 0.25rem;  --sp-2: 0.5rem;   --sp-3: 0.75rem;  --sp-4: 1rem;
  --sp-5: 1.25rem;  --sp-6: 1.5rem;   --sp-7: 1.75rem;  --sp-8: 2rem;
  --sp-10: 2.5rem;  --sp-12: 3rem;    --sp-16: 4rem;    --sp-20: 5rem;

  /* --- Radii --- */
  --r-xs: 6px;   --r-sm: 10px;  --r-md: 14px;
  --r-lg: 18px;  --r-xl: 24px;  --r-2xl: 32px;  --r-full: 999px;

  /* --- Elevation (soft, brand-tinted) --- */
  --sh-xs: 0 1px 2px rgba(15, 23, 42, .05);
  --sh-sm: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --sh-md: 0 4px 12px rgba(15, 23, 42, .07), 0 2px 4px rgba(15, 23, 42, .04);
  --sh-lg: 0 12px 28px rgba(15, 23, 42, .09), 0 4px 10px rgba(15, 23, 42, .04);
  --sh-xl: 0 24px 56px rgba(15, 23, 42, .12), 0 8px 20px rgba(15, 23, 42, .05);
  --sh-brand: 0 10px 24px rgba(13, 148, 136, .22);
  --sh-inset: inset 0 1px 0 rgba(255, 255, 255, .6);

  /* --- School logo --------------------------------------------------------
     The logo is supplied as artwork with its own dark green ground, so it is
     placed as a self-contained rounded tile rather than tinted by the theme.
     --logo-ground matches the artwork's corners, so a tile shows no seam even
     while the image is still loading. */
  --logo-ground: #062924;
  --sh-logo:    0 6px 16px rgba(6, 41, 36, .26);
  --sh-logo-sm: 0 3px 8px rgba(6, 41, 36, .22);

  /* --- Motion --- */
  --ease:        cubic-bezier(.4, 0, .2, 1);
  --ease-out:    cubic-bezier(.16, 1, .3, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --dur-fast: 140ms;
  --dur:      240ms;
  --dur-slow: 420ms;

  /* --- Layout --- */
  --container:      56rem;   /* 896px — comfortable reading measure */
  --container-wide: 82rem;   /* 1312px — admin tables */
  --ring:        0 0 0 3px rgba(13, 148, 136, .28);
  --ring-danger: 0 0 0 3px rgba(239, 68, 68, .25);

  --header-h: 4rem;
  color-scheme: light;
}

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

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + var(--sp-6));
  -moz-tab-size: 4;
  tab-size: 4;
}

body {
  font-family: var(--font-fa);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-weight: 400;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

img, picture, svg, video, canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

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

button { background: none; border: none; cursor: pointer; }
button:disabled { cursor: not-allowed; }

p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }

h1, h2, h3, h4, h5, h6 {
  line-height: var(--lh-tight);
  font-weight: 700;
  text-wrap: balance;
}

a { color: var(--brand-700); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--brand-800); }

ul, ol { padding-inline-start: 1.4em; }

hr { border: none; border-top: 1px solid var(--border); margin-block: var(--sp-6); }

::selection { background: var(--brand-200); color: var(--brand-950); }

/* Tabular figures for counters and tables */
.nums { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------
   3. Focus visibility (accessibility)
   ------------------------------------------------------------------ */
:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--brand-600);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

.skip-link {
  position: absolute;
  inset-block-start: -100%;
  inset-inline-start: var(--sp-4);
  z-index: 999;
  background: var(--brand-700);
  color: var(--text-on-brand);
  padding: var(--sp-3) var(--sp-5);
  border-radius: 0 0 var(--r-md) var(--r-md);
  font-weight: 600;
  box-shadow: var(--sh-lg);
  transition: inset-block-start var(--dur) var(--ease);
}
.skip-link:focus-visible { inset-block-start: 0; color: var(--text-on-brand); }

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------------
   4. Layout primitives
   ------------------------------------------------------------------ */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--sp-5);
}
.container-wide { max-width: var(--container-wide); }

@media (max-width: 30rem) {
  .container { padding-inline: var(--sp-4); }
}

.stack > * + * { margin-block-start: var(--flow, var(--sp-4)); }

/* ------------------------------------------------------------------
   5. Card
   ------------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
}

/* ------------------------------------------------------------------
   6. Buttons
   ------------------------------------------------------------------ */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text-2);
  --btn-bd: var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0.7rem 1.35rem;
  min-height: 2.875rem;
  font-size: var(--fs-base);
  font-weight: 600;
  line-height: 1.2;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-md);
  box-shadow: var(--sh-xs);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--slate-400); color: var(--text); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled, .btn[aria-disabled='true'] { opacity: .55; pointer-events: none; }
.btn svg { flex: none; width: 1.15em; height: 1.15em; }

.btn-primary {
  --btn-fg: var(--text-on-brand);
  --btn-bd: transparent;
  background: linear-gradient(135deg, var(--brand-600), var(--brand-700) 55%, var(--brand-800));
  box-shadow: var(--sh-brand), var(--sh-inset);
}
.btn-primary:hover {
  color: var(--text-on-brand);
  background: linear-gradient(135deg, var(--brand-500), var(--brand-600) 55%, var(--brand-700));
  border-color: transparent;
  box-shadow: 0 14px 30px rgba(13, 148, 136, .3), var(--sh-inset);
}

.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--brand-50); color: var(--brand-800); border-color: transparent; }

.btn-danger { --btn-fg: var(--danger-600); --btn-bd: var(--danger-200); --btn-bg: var(--danger-50); }
.btn-danger:hover { background: var(--danger-100); border-color: var(--danger-500); color: var(--danger-700); }

.btn-lg { padding: 0.95rem 2rem; min-height: 3.375rem; font-size: var(--fs-lg); border-radius: var(--r-lg); }
.btn-sm { padding: 0.45rem 0.9rem; min-height: 2.25rem; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-icon { padding: 0; width: 2.5rem; min-height: 2.5rem; }
.btn-block { width: 100%; }

/* The compact variants are 36–40px tall: fine for a mouse, below the 44px
   minimum for a finger. Touch devices get the floor without costing the
   desktop layout its density. */
@media (pointer: coarse) {
  .btn-sm { min-height: 2.75rem; }
  .btn-icon { width: 2.75rem; min-height: 2.75rem; }
}

/* ------------------------------------------------------------------
   7. Form fields
   ------------------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }

.label {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text-2);
}

.input, .textarea, .select {
  width: 100%;
  padding: 0.8rem 1rem;
  font-size: var(--fs-base);
  line-height: var(--lh-snug);
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-xs);
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              background-color var(--dur-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }

.input:hover, .textarea:hover, .select:hover { border-color: var(--border-strong); }

.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: var(--ring);
  background: var(--surface);
}

/* The soft `--ring` glow is only ~1.4:1 against white — far below the 3:1 a
   focus indicator needs — and the `outline: none` above out-specifies the
   global :focus-visible rule. Keyboard focus gets a real outline back here. */
.input:focus-visible, .textarea:focus-visible, .select:focus-visible {
  outline: 2px solid var(--brand-700);
  outline-offset: 1px;
}

.textarea {
  min-height: 7.5rem;
  resize: vertical;
  line-height: var(--lh-body);
}

.input[aria-invalid='true'], .textarea[aria-invalid='true'] { border-color: var(--danger-500); }
.input[aria-invalid='true']:focus, .textarea[aria-invalid='true']:focus { box-shadow: var(--ring-danger); }

.select {
  appearance: none;
  padding-inline-end: 2.4rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 1.1rem;
  cursor: pointer;
  /* `background-position` has no logical keyword, so the RTL placement (the
     chevron sits at the inline-end = visual left) is the default and LTR
     overrides it. Never hard-code one side without the counterpart. */
  background-position: left 0.85rem center;
}
:where([dir='ltr']) .select { background-position: right 0.85rem center; }

.hint { font-size: var(--fs-sm); color: var(--text-muted); }
.error-text { font-size: var(--fs-sm); color: var(--danger-600); font-weight: 500; }

/* ------------------------------------------------------------------
   8. Badges & pills
   ------------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0.3rem 0.75rem;
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.6;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge-brand   { background: var(--brand-50);   color: var(--brand-800);   border-color: var(--brand-200); }
.badge-accent  { background: var(--accent-50);  color: var(--accent-700);  border-color: var(--accent-200); }
.badge-success { background: var(--success-50); color: var(--success-700); border-color: var(--brand-200); }
.badge-danger  { background: var(--danger-50);  color: var(--danger-700);  border-color: var(--danger-200); }

/* ------------------------------------------------------------------
   9. Scrollbars
   ------------------------------------------------------------------ */
* { scrollbar-width: thin; scrollbar-color: var(--slate-300) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--slate-300);
  border: 2px solid var(--bg);
  border-radius: var(--r-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--slate-400); }

/* ------------------------------------------------------------------
   10. Utilities
   ------------------------------------------------------------------ */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.hidden { display: none !important; }

/* ------------------------------------------------------------------
   11. Motion preferences
   ------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ------------------------------------------------------------------
   12. Print
   ------------------------------------------------------------------ */
@media print {
  :root { --bg: #fff; }
  body { background: #fff; font-size: 11pt; }
  .no-print { display: none !important; }
  .card { box-shadow: none; border-color: #999; break-inside: avoid; }
}
