/* =========================================================================
   SHI Surveys — design tokens and shared components
   Identity: Saudi Association for Hearing Impairment (teal · sand · navy)
   ========================================================================= */

@font-face {
    font-family: "Cairo";
    src: url("/fonts/cairo/Cairo-Variable.ttf") format("truetype");
    font-weight: 200 1000;
    font-display: swap;
}

:root {
    --navy: #0b2851;
    --navy-deep: #061b38;
    --navy-soft: #eaf0f8;
    --teal: #078b83;
    --teal-dark: #006a66;
    --teal-soft: #e6f5f2;
    --teal-glow: rgba(7, 139, 131, .16);
    --sand: #c9a45f;
    --sand-deep: #9c7a36;
    --sand-soft: #fbf5e9;
    --red: #b93131;
    --red-soft: #fff0ef;
    --green: #19734a;
    --green-soft: #e9f7ef;
    --amber: #a86400;
    --amber-soft: #fff5e3;

    --accent: var(--teal);
    --accent-dark: var(--teal-dark);
    --accent-soft: var(--teal-soft);
    --accent-glow: var(--teal-glow);

    --ink: #13233b;
    --ink-2: #33445c;
    --muted: #66758a;
    --faint: #98a4b5;
    --line: #dfe6ee;
    --line-2: #eef2f6;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --background: #f3f6f9;

    --shadow-xs: 0 1px 2px rgba(12, 40, 75, .06);
    --shadow-sm: 0 6px 18px rgba(12, 40, 75, .06);
    --shadow: 0 14px 36px rgba(12, 40, 75, .09);
    --shadow-lg: 0 26px 64px rgba(12, 40, 75, .16);
    --ring: 0 0 0 4px var(--accent-glow);

    --r-xs: 8px;
    --r-sm: 12px;
    --r: 18px;
    --r-lg: 26px;
    --r-pill: 999px;

    --ease: cubic-bezier(.2, .8, .2, 1);
    --font: "Cairo", Tahoma, "Segoe UI", Arial, sans-serif;
}

.theme-navy { --accent: #1c4d8c; --accent-dark: var(--navy); --accent-soft: #e9f0fa; --accent-glow: rgba(28, 77, 140, .16); }
.theme-sand { --accent: #b8893a; --accent-dark: #8a6522; --accent-soft: #fbf3e4; --accent-glow: rgba(184, 137, 58, .18); }
.theme-green { --accent: #19734a; --accent-dark: #0f5535; --accent-soft: #e9f7ef; --accent-glow: rgba(25, 115, 74, .16); }
.theme-violet { --accent: #5b4bb7; --accent-dark: #43358f; --accent-soft: #efedfb; --accent-glow: rgba(91, 75, 183, .16); }
.theme-rose { --accent: #b8436b; --accent-dark: #8f2f51; --accent-soft: #fbecf1; --accent-glow: rgba(184, 67, 107, .16); }

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    margin: 0; min-height: 100vh; font-family: var(--font); font-size: 16px; line-height: 1.7; color: var(--ink);
    background: var(--background); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
img, video, svg { max-width: 100%; display: block; }
a { color: var(--accent-dark); text-decoration-thickness: 1px; text-underline-offset: 3px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 800; color: var(--navy); text-wrap: balance; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: var(--accent-glow); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.nowrap { white-space: nowrap; }

/* ---------- icons ---------- */
.i { display: inline-block; vertical-align: -.22em; width: 1.25em; height: 1.25em; flex: 0 0 auto; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.i-fill { fill: currentColor; stroke: none; }

/* ---------- buttons ---------- */
.btn {
    --b-bg: var(--surface); --b-fg: var(--ink); --b-bd: var(--line);
    display: inline-flex; align-items: center; justify-content: center; gap: .5em; min-height: 44px; padding: .55em 1.15em;
    border: 1px solid var(--b-bd); border-radius: var(--r-sm); background: var(--b-bg); color: var(--b-fg);
    font-weight: 700; font-size: .95rem; line-height: 1.2; text-decoration: none; white-space: nowrap;
    transition: transform .15s var(--ease), box-shadow .2s var(--ease), background .2s, border-color .2s, color .2s;
}
.btn:hover { border-color: color-mix(in srgb, var(--b-bd) 60%, var(--accent)); box-shadow: var(--shadow-xs); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; pointer-events: none; }
.btn-primary { --b-bg: var(--accent); --b-fg: #fff; --b-bd: var(--accent); box-shadow: 0 8px 20px var(--accent-glow); }
.btn-primary:hover { --b-bg: var(--accent-dark); --b-bd: var(--accent-dark); box-shadow: 0 10px 26px var(--accent-glow); }
.btn-navy { --b-bg: var(--navy); --b-fg: #fff; --b-bd: var(--navy); }
.btn-navy:hover { --b-bg: var(--navy-deep); }
.btn-soft { --b-bg: var(--accent-soft); --b-fg: var(--accent-dark); --b-bd: transparent; }
.btn-soft:hover { --b-bd: color-mix(in srgb, var(--accent) 35%, transparent); }
.btn-ghost { --b-bg: transparent; --b-bd: transparent; --b-fg: var(--ink-2); }
.btn-ghost:hover { --b-bg: var(--line-2); box-shadow: none; }
.btn-danger { --b-bg: var(--surface); --b-fg: var(--red); --b-bd: #f0c9c9; }
.btn-danger:hover { --b-bg: var(--red-soft); --b-bd: var(--red); }
.btn-danger-solid { --b-bg: var(--red); --b-fg: #fff; --b-bd: var(--red); }
.btn-sm { min-height: 36px; padding: .35em .85em; font-size: .88rem; border-radius: 10px; }
.btn-xs { min-height: 30px; padding: .2em .6em; font-size: .82rem; border-radius: 8px; gap: .35em; }
.btn-lg { min-height: 52px; padding: .7em 1.5em; font-size: 1.05rem; border-radius: 14px; }
.btn-xl { min-height: 60px; padding: .8em 2em; font-size: 1.15rem; border-radius: 16px; }
.btn-icon { width: 40px; min-height: 40px; padding: 0; }
.btn-icon.btn-sm { width: 34px; min-height: 34px; }
.btn-block { width: 100%; }
.btn .spinner { width: 1.1em; height: 1.1em; }

.spinner { display: inline-block; border: 2.5px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; align-content: start; }
.label { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--navy); font-size: .95rem; }
.label .i { color: var(--accent); }
.req { color: var(--red); font-weight: 800; }
.opt { color: var(--faint); font-weight: 600; font-size: .8rem; }
.hint { color: var(--muted); font-size: .85rem; }
.input, .select, .textarea {
    width: 100%; min-height: 50px; padding: .65em .95em; border: 1.5px solid var(--line); border-radius: var(--r-sm);
    background: var(--surface); color: var(--ink); transition: border-color .15s, box-shadow .15s, background .15s;
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.7; }
.select { appearance: none; padding-inline-start: 2.4em; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2366758a' 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-position: left .9em center; }
.input:hover, .select:hover, .textarea:hover { border-color: #c9d3de; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.input::placeholder, .textarea::placeholder { color: #aab4c2; }
.input[dir="ltr"], .input.ltr-input { text-align: right; direction: ltr; }
.is-invalid .input, .is-invalid .select, .is-invalid .textarea, .input.is-invalid { border-color: var(--red); background: #fffafa; }
.error-text { display: flex; align-items: center; gap: 6px; color: var(--red); font-size: .87rem; font-weight: 700; }
.error-text:empty { display: none; }

.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 44px; height: 26px; border-radius: 99px; background: #cfd8e3; position: relative; transition: background .2s; flex: 0 0 auto; }
.switch .track::after { content: ""; position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.18); transition: transform .2s var(--ease); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(-18px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }

.segmented { display: inline-flex; padding: 4px; gap: 4px; background: var(--line-2); border-radius: 12px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: inline-flex; align-items: center; gap: 6px; padding: .35em .9em; border-radius: 9px; font-weight: 700; font-size: .87rem; color: var(--muted); cursor: pointer; transition: background .15s, color .15s, box-shadow .15s; white-space: nowrap; }
.segmented input:checked + span { background: var(--surface); color: var(--navy); box-shadow: var(--shadow-xs); }
.segmented input:focus-visible + span { box-shadow: var(--ring); }
.segmented .seg-req input:checked + span { color: var(--red); }
.segmented .seg-opt input:checked + span { color: var(--accent-dark); }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.card-pad { padding: clamp(18px, 3vw, 28px); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line-2); }
.card-head h2, .card-head h3 { font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.card-body { padding: 20px 22px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: .18em .75em; border-radius: var(--r-pill); font-size: .8rem; font-weight: 800; white-space: nowrap; line-height: 1.6; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge-plain::before { display: none; }
.badge-green { color: var(--green); background: var(--green-soft); }
.badge-red { color: var(--red); background: var(--red-soft); }
.badge-sand { color: var(--sand-deep); background: var(--sand-soft); }
.badge-navy { color: #1c4d8c; background: var(--navy-soft); }
.badge-muted { color: var(--muted); background: var(--line-2); }
.badge-teal { color: var(--teal-dark); background: var(--teal-soft); }

.chip { display: inline-flex; align-items: center; gap: 7px; padding: .35em .85em; border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); font-size: .88rem; font-weight: 700; }
.chip .i { color: var(--accent); }

.alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px 18px; border-radius: var(--r-sm); border: 1px solid; font-weight: 600; }
.alert .i { margin-top: 3px; }
.alert-error { color: #8c1f1f; background: var(--red-soft); border-color: #f2cccc; }
.alert-success { color: #145c3b; background: var(--green-soft); border-color: #c5e8d4; }
.alert-info { color: #1c4d8c; background: var(--navy-soft); border-color: #cfdcef; }
.alert-warn { color: #7a4a00; background: var(--amber-soft); border-color: #f1dcb1; }

.empty { display: grid; justify-items: center; gap: 10px; padding: 48px 20px; text-align: center; color: var(--muted); }
.empty .empty-icon { width: 72px; height: 72px; display: grid; place-items: center; border-radius: 22px; background: var(--accent-soft); color: var(--accent); }
.empty .empty-icon .i { width: 34px; height: 34px; }
.empty h3 { color: var(--navy); font-size: 1.1rem; }

/* ---------- bars (results) ---------- */
.bars { display: grid; gap: 12px; }
.bar-row { display: grid; gap: 6px; }
.bar-top { display: flex; justify-content: space-between; gap: 12px; font-size: .92rem; }
.bar-top b { color: var(--navy); font-weight: 700; }
.bar-top span { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-track { height: 10px; border-radius: 99px; background: var(--line-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #5fd3c6)); min-width: 3px; transition: width .6s var(--ease); }
.bar-row.is-top .bar-fill { background: linear-gradient(90deg, var(--sand-deep), var(--sand)); }

/* ---------- toast ---------- */
.toast-host { position: fixed; inset-block-end: 22px; inset-inline-start: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 10px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 14px; background: var(--navy); color: #fff; box-shadow: var(--shadow-lg); font-weight: 700; animation: toast-in .3s var(--ease); }
.toast.is-error { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
