/* ==========================================================================
   Farewell survey — single stylesheet (RTL, light theme)
   ========================================================================== */

@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
    --bg: #f6f5f1;
    --surface: #ffffff;
    --surface-2: #faf9f6;
    --border: #e5e2da;
    --border-strong: #cfcac0;
    --text: #1c2326;
    --text-2: #4d5a60;
    --muted: #7a858b;

    --primary: #1f5c57;
    --primary-hover: #184a46;
    --primary-soft: #e8f1ef;
    --primary-ring: rgba(31, 92, 87, .22);
    --accent: #a0722e;
    --accent-soft: #f6eedf;

    --danger: #b42318;
    --danger-soft: #fdf1ef;
    --success: #1c7a4c;
    --success-soft: #e9f5ee;
    --warning-soft: #fdf6e3;
    --warning: #8a5a00;

    --track: #eceae4;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(28, 35, 38, .04), 0 6px 24px rgba(28, 35, 38, .05);
    --font: "Vazirmatn", Tahoma, "Segoe UI", system-ui, sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.8;
    text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.5; margin: 0; font-weight: 700; }
p { margin: 0 0 .75rem; }
a { color: var(--primary); text-underline-offset: 3px; }
a:hover { color: var(--primary-hover); }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--primary-ring); outline-offset: 2px; border-radius: 6px; }

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

.num { font-feature-settings: "tnum"; unicode-bidi: plaintext; }

/* ── Layout ─────────────────────────────────────────────────────────────── */

.page { max-width: 700px; margin: 0 auto; padding: 32px 16px 48px; }
.page--wide { max-width: 1180px; }

.site-footer {
    text-align: center; color: var(--muted); font-size: .85rem;
    padding: 8px 16px 32px;
}
.site-footer a { color: var(--text-2); }

/* ── Hero ───────────────────────────────────────────────────────────────── */

.hero { text-align: center; margin-bottom: 24px; }
.hero__emblem {
    width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 16px;
    display: grid; place-items: center;
    background: var(--accent-soft); color: var(--accent);
}
.hero__emblem svg { width: 28px; height: 28px; }
.eyebrow { color: var(--accent); font-weight: 500; font-size: .9rem; margin: 0 0 4px; }
.hero h1 { font-size: clamp(1.5rem, 4vw, 1.9rem); margin-bottom: 12px; }
.hero__lead { color: var(--text-2); max-width: 600px; margin: 0 auto .5rem; }

.meta {
    list-style: none; margin: 16px 0 0; padding: 0;
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.meta li {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 999px; padding: 3px 12px; font-size: .85rem; color: var(--text-2);
}
.meta svg { width: 15px; height: 15px; color: var(--primary); flex: none; }

/* ── Cards ──────────────────────────────────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}
.card + .card { margin-top: 16px; }
.card__title { font-size: 1.1rem; margin-bottom: 4px; }
.card__sub { color: var(--muted); font-size: .88rem; margin-bottom: 16px; }

@media (max-width: 480px) {
    .page { padding-top: 20px; }
    .tiles.tiles--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
    .tiles--3 .tile { padding: 12px; }
    .tiles--3 .tile__value { font-size: 1.3rem; }
    .tiles--3 .tile__note { display: none; }
    .card { padding: 18px 16px; }
}

/* ── Form steps ─────────────────────────────────────────────────────────── */

.step { border: 0; margin: 0; padding: 0; min-width: 0; }
.step + .step { border-top: 1px solid var(--border); margin-top: 24px; padding-top: 24px; }

.step__legend {
    float: right; width: 100%;   /* escapes the legacy fieldset-legend box quirks */
    display: flex; align-items: flex-start; gap: 10px;
    padding: 0; margin-bottom: 14px;
    font-weight: 700; font-size: 1.02rem; line-height: 1.6;
}
.step__num {
    flex: none; width: 26px; height: 26px; border-radius: 50%;
    display: inline-grid; place-items: center; margin-top: 1px;
    background: var(--primary-soft); color: var(--primary);
    font-size: .85rem; font-weight: 700;
}
.step__legend + * { clear: both; }
.step__legend small { display: block; font-weight: 400; color: var(--muted); font-size: .85rem; }

.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }

.input {
    display: block; width: 100%;
    font: inherit; color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 10px 14px; min-height: 48px;
    transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: #a3aaae; }
.input:hover { border-color: #b7b1a5; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
textarea.input { min-height: 88px; resize: vertical; line-height: 1.8; }
.is-invalid .input, .input[aria-invalid="true"] { border-color: var(--danger); }
.is-invalid .input:focus { box-shadow: 0 0 0 4px rgba(180, 35, 24, .15); }

.field-error {
    display: flex; gap: 6px; align-items: flex-start;
    color: var(--danger); font-size: .87rem; margin: 8px 0 0;
}
.field-error::before { content: "!"; flex: none; width: 18px; height: 18px; margin-top: 3px; border-radius: 50%; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; display: grid; place-items: center; }

/* Radio / checkbox cards */
.choices { display: grid; gap: 8px; }
.choices--grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 420px) { .choices--grid { grid-template-columns: 1fr; } }

.choice {
    position: relative;
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px; min-height: 52px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); cursor: pointer;
    transition: border-color .15s, background-color .15s;
}
.choice:hover { border-color: var(--border-strong); background: var(--surface-2); }
.choice input {
    flex: none; width: 20px; height: 20px; margin: 0;
    accent-color: var(--primary); cursor: pointer;
}
.choice__text { display: flex; flex-direction: column; line-height: 1.55; }
.choice__hint { color: var(--muted); font-size: .8rem; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice:has(input:focus-visible) { box-shadow: 0 0 0 4px var(--primary-ring); }
.is-invalid .choice { border-color: #efc4be; }

/* Conditional follow-up fields */
.follow-up {
    margin-top: 10px; padding: 14px;
    background: var(--surface-2); border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
}
.follow-up.is-collapsed { display: none; }   /* noscript.css re-shows it without JS */
.follow-up label { display: block; font-weight: 500; font-size: .92rem; margin-bottom: 6px; }

.amount { display: flex; align-items: stretch; }
.amount .input {
    border-start-end-radius: 0; border-end-end-radius: 0;
    font-size: 1.15rem; font-weight: 500; letter-spacing: .02em; text-align: right;
}
.amount__unit {
    display: grid; place-items: center; padding: 0 14px;
    border: 1px solid var(--border-strong); border-inline-start: 0;
    border-start-end-radius: var(--radius-sm); border-end-end-radius: var(--radius-sm);
    background: var(--surface-2); color: var(--text-2); font-size: .92rem;
}
.amount-words { min-height: 1.6em; color: var(--primary); font-size: .88rem; font-weight: 500; margin: 6px 0 0; }

.counter { color: var(--muted); font-size: .8rem; text-align: left; margin-top: 4px; }

.privacy-note { display: flex; gap: 8px; justify-content: center; align-items: flex-start; color: var(--muted); font-size: .85rem; margin: 16px auto 0; max-width: 560px; }
.privacy-note svg { width: 16px; height: 16px; flex: none; margin-top: 4px; }

.hp { position: absolute; inset-inline-start: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font: inherit; font-weight: 500; font-size: .98rem;
    min-height: 46px; padding: 8px 22px;
    border-radius: var(--radius-sm); border: 1px solid transparent;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background-color .15s, border-color .15s, color .15s;
}
.btn svg { width: 18px; height: 18px; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-hover); color: #fff; }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--surface-2); color: var(--text); }
.btn--ghost { background: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--track); color: var(--text); }
.btn--danger { background: var(--surface); color: var(--danger); border-color: #efc4be; }
.btn--danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn--sm { min-height: 36px; padding: 4px 12px; font-size: .88rem; }
.btn--block { width: 100%; }
.btn[disabled], .btn.is-busy { opacity: .65; cursor: progress; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.actions--end { justify-content: flex-end; }
@media (max-width: 480px) { .actions .btn { flex: 1 1 auto; } }

/* ── Alerts ─────────────────────────────────────────────────────────────── */

.alert {
    display: flex; gap: 10px; align-items: flex-start;
    border-radius: var(--radius-sm); padding: 12px 14px; font-size: .92rem;
    margin-bottom: 16px; border: 1px solid transparent;
}
.alert svg { width: 20px; height: 20px; flex: none; margin-top: 2px; }
.alert--error { background: var(--danger-soft); color: #7a1a12; border-color: #f3cdc7; }
.alert--success { background: var(--success-soft); color: #145c39; border-color: #c5e5d2; }
.alert--info { background: var(--primary-soft); color: #174541; border-color: #cfe2df; }
.alert--warning { background: var(--warning-soft); color: var(--warning); border-color: #f0dfb1; }

/* ── Review panel ───────────────────────────────────────────────────────── */

.review__list { margin: 0; display: grid; gap: 0; }
.review__row { display: grid; grid-template-columns: 140px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.review__row:last-child { border-bottom: 0; }
.review__row dt { color: var(--muted); font-size: .9rem; }
.review__row dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
@media (max-width: 480px) { .review__row { grid-template-columns: 1fr; gap: 2px; } }

.tags { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.tag {
    display: inline-block; padding: 1px 10px; border-radius: 999px;
    background: var(--primary-soft); color: #174541; font-size: .82rem; font-weight: 500; line-height: 1.9;
}
.tag--muted { background: var(--track); color: var(--text-2); }
.tag--accent { background: var(--accent-soft); color: #6d4c1b; }

/* ── Status pages (thanks / closed / already / error) ───────────────────── */

.status { text-align: center; padding: 36px 24px; }
.status__icon {
    width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%;
    display: grid; place-items: center; background: var(--success-soft); color: var(--success);
}
.status__icon svg { width: 32px; height: 32px; }
.status__icon--muted { background: var(--track); color: var(--text-2); }
.status__icon--warn { background: var(--warning-soft); color: var(--warning); }
.status h1 { font-size: 1.4rem; margin-bottom: 8px; }
.status p { color: var(--text-2); max-width: 480px; margin-inline: auto; }
.status .actions { justify-content: center; }
.status .review__list { text-align: start; margin-top: 20px; border-top: 1px solid var(--border); }

/* ── Stat tiles ─────────────────────────────────────────────────────────── */

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.tile {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow);
}
.tile__label { color: var(--text-2); font-size: .85rem; margin: 0; }
.tile__value { font-size: 1.6rem; font-weight: 700; line-height: 1.4; margin: 4px 0 0; }
.tile__value small { font-size: .85rem; font-weight: 500; color: var(--text-2); }
.tile__note { color: var(--muted); font-size: .78rem; margin: 2px 0 0; }

/* ── Bar charts (native <progress>, one hue, direct labels) ─────────────── */

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.bar__head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.bar__label { font-size: .93rem; font-weight: 500; }
.bar__label small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }
.bar__value { font-size: .9rem; color: var(--text); white-space: nowrap; font-weight: 500; }
.bar__value span { color: var(--muted); font-weight: 400; margin-inline-start: 6px; }
.bar__detail { color: var(--muted); font-size: .78rem; margin-top: 2px; }

progress.bar {
    display: block; width: 100%; height: 10px;
    -webkit-appearance: none; appearance: none;
    border: 0; border-radius: 4px; overflow: hidden;
    background: var(--track); color: var(--primary);
}
progress.bar::-webkit-progress-bar { background: var(--track); border-radius: 4px; }
progress.bar::-webkit-progress-value { background: var(--primary); border-radius: 4px; }
progress.bar::-moz-progress-bar { background: var(--primary); border-radius: 4px; }
.bars li:hover progress.bar::-webkit-progress-value { background: var(--primary-hover); }

.chart-note { color: var(--muted); font-size: .82rem; margin: 14px 0 0; display: flex; gap: 6px; }
.chart-note svg { width: 16px; height: 16px; flex: none; margin-top: 3px; }

/* Timeline (SVG) */
.chart-scroll { overflow-x: auto; }
.timeline { width: 100%; min-width: 640px; height: auto; display: block; overflow: visible; }
.timeline .grid { stroke: var(--track); stroke-width: 1; }
.timeline .baseline { stroke: var(--border-strong); stroke-width: 1; }
.timeline .col { fill: var(--primary); }
.timeline .col:hover { fill: var(--primary-hover); }
.timeline .hit { fill: transparent; }
.timeline .hit:hover + .col, .timeline g:hover .col { fill: var(--primary-hover); }
.timeline text { font-family: var(--font); fill: var(--muted); font-size: 11px; }
.timeline .val { fill: var(--text-2); font-weight: 500; }

/* ── Results / dashboard grid ───────────────────────────────────────────── */

.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-2 > .card + .card { margin-top: 0; }
@media (max-width: 380px) { .grid-2 { grid-template-columns: 1fr; } }

.figure { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.figure strong { font-size: 1.5rem; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 0; }
.kv div { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.kv dt { color: var(--muted); font-size: .8rem; }
.kv dd { margin: 0; font-weight: 700; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 28px 0 12px; }
.section-head h2 { font-size: 1.15rem; }
.section-head .actions { margin-top: 0; }

/* ── Admin chrome ───────────────────────────────────────────────────────── */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar__inner {
    max-width: 1180px; margin: 0 auto; padding: 10px 16px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand__mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.brand__mark svg { width: 18px; height: 18px; }
.topbar__nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topbar__user { color: var(--muted); font-size: .85rem; margin-inline-end: 6px; }
.inline-form { display: inline; margin: 0; }

.status-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 2px 12px; font-size: .85rem; font-weight: 500; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill--open { background: var(--success-soft); color: var(--success); }
.pill--closed { background: var(--track); color: var(--text-2); }

.login { max-width: 400px; margin: 8vh auto 0; }
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-weight: 500; margin-bottom: 6px; font-size: .92rem; }

/* Filters */
.filters { display: grid; gap: 10px; grid-template-columns: 2fr repeat(3, 1fr) auto; align-items: end; }
.filters label { display: block; font-size: .8rem; color: var(--text-2); margin-bottom: 4px; }
.filters .input { min-height: 42px; padding: 6px 12px; font-size: .92rem; }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%234d5a60' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-position: left 12px center; background-size: 11px 8px; background-repeat: no-repeat; padding-left: 32px; }
.filters__actions { display: flex; gap: 6px; }
@media (max-width: 900px) { .filters { grid-template-columns: 1fr 1fr; } .filters__search { grid-column: 1 / -1; } .filters__actions { grid-column: 1 / -1; } }
@media (max-width: 480px) { .filters { grid-template-columns: 1fr; } }

/* Responses table → cards on mobile */
.table-wrap { overflow-x: auto; margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: start; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { background: var(--surface-2); color: var(--text-2); font-weight: 500; font-size: .82rem; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fcfbf8; }
.table .col-idx { width: 48px; color: var(--muted); }
.table .col-name { font-weight: 500; min-width: 140px; }
.table .col-note { max-width: 260px; overflow-wrap: anywhere; color: var(--text-2); }
.table .col-date { white-space: nowrap; color: var(--text-2); }
.table .muted { color: var(--muted); }

@media (max-width: 760px) {
    .table-wrap { border: 0; overflow: visible; }
    .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 14px; margin-bottom: 10px; }
    .table td { border: 0; padding: 5px 0; display: grid; grid-template-columns: 120px 1fr; gap: 8px; }
    .table td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }
    .table .col-idx { display: none; }
    .table .col-note { max-width: none; }
}

.pagination { display: flex; gap: 6px; justify-content: center; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.pagination .current { font-weight: 700; padding: 0 8px; }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

.suggestions { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.suggestions li { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; }
.suggestions p { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.suggestions small { color: var(--muted); }

/* ── Print ──────────────────────────────────────────────────────────────── */

@media print {
    body { background: #fff; font-size: 12pt; }
    .no-print, .topbar, .site-footer, .filters, .pagination, .actions { display: none !important; }
    .card, .tile { box-shadow: none; break-inside: avoid; border-color: #bbb; }
    .page { max-width: none; padding: 0; }
    progress.bar { border: 1px solid #999; }
    .table-wrap { overflow: visible; }
}
