/* ==========================================================
   Design System — فاز ۴ (RTL، فونت فارسی، تیره/روشن)
   همه رنگ‌ها و اندازه‌ها از متغیرهای CSS می‌آیند؛ فاز ۱۶ فقط همین‌ها را بازنویسی می‌کند.
   ========================================================== */

/* فونت: فایل را طبق docs/PHASE-04.md در assets/fonts بگذارید؛ در نبودش فونت سیستم استفاده می‌شود */
@font-face {
    font-family: "Vazirmatn";
    src: local("Vazirmatn"), url("../fonts/Vazirmatn-Variable.woff2") format("woff2");
    font-weight: 100 900;
    font-display: swap;
}

:root {
    --font: "Vazirmatn", Tahoma, "Segoe UI", system-ui, sans-serif;
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef1f8;
    --text: #1c2333;
    --muted: #5f6a82;
    --border: #e3e7f0;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --on-primary: #ffffff;
    --ok: #047857;   --ok-bg: #ecfdf5;   --ok-border: #a7f3d0;
    --warn: #b45309; --warn-bg: #fffbeb; --warn-border: #fde68a;
    --bad: #b91c1c;  --bad-bg: #fef2f2;  --bad-border: #fecaca;
    --info: #1d4ed8; --info-bg: #eff6ff; --info-border: #bfdbfe;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
    --gap: 1rem;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f1420; --surface: #171e2e; --surface-2: #1f2840; --text: #e6eaf5; --muted: #98a2bb; --border: #29334d;
        --primary: #6366f1; --primary-hover: #7578f3;
        --ok: #34d399;   --ok-bg: #0f2a22;   --ok-border: #1d5a45;
        --warn: #fbbf24; --warn-bg: #2d2410; --warn-border: #6b5316;
        --bad: #f87171;  --bad-bg: #2f1517;  --bad-border: #6e2a2d;
        --info: #60a5fa; --info-bg: #11213d; --info-border: #24467c;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #0f1420; --surface: #171e2e; --surface-2: #1f2840; --text: #e6eaf5; --muted: #98a2bb; --border: #29334d;
    --primary: #6366f1; --primary-hover: #7578f3;
    --ok: #34d399;   --ok-bg: #0f2a22;   --ok-border: #1d5a45;
    --warn: #fbbf24; --warn-bg: #2d2410; --warn-border: #6b5316;
    --bad: #f87171;  --bad-bg: #2f1517;  --bad-border: #6e2a2d;
    --info: #60a5fa; --info-bg: #11213d; --info-border: #24467c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
    color-scheme: dark;
}

/* ---------- پایه ---------- */
*, *::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); line-height: 1.9; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; }
h1, h2, h3 { line-height: 1.5; margin: 0 0 .6rem; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; margin-top: 1.4rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .8rem; }
a { color: var(--primary); }
code { background: var(--surface-2); padding: 0 .35rem; border-radius: 6px; font-size: .9em; }
pre { text-align: left; background: #0f172a; color: #e2e8f0; padding: 1rem; border-radius: var(--radius-sm); overflow: auto; font-size: .8rem; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.icon { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.25em; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- چیدمان ---------- */
.wrap { max-width: 760px; margin: 0 auto; padding: 1.5rem 1rem 2.5rem; width: 100%; }
.wrap-wide { max-width: 1100px; }
.stack > * + * { margin-top: var(--gap); }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.hero { text-align: center; }
.hero .code { font-size: 4rem; margin: 0; color: var(--primary); }
.muted { color: var(--muted); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 800; color: var(--text); text-decoration: none; }
.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 1.5rem 1rem; }

/* ---------- کارت و نشان ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.badge { display: inline-block; padding: 0 .65rem; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.badge-ok { background: var(--ok-bg); color: var(--ok); } .badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); } .badge-info { background: var(--info-bg); color: var(--info); }
.ok { color: var(--ok); font-weight: 700; } .warn { color: var(--warn); font-weight: 700; } .bad { color: var(--bad); font-weight: 700; }

/* ---------- دکمه ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1.25rem; border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--primary); color: var(--on-primary); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background .15s; }
.btn:hover { background: var(--primary-hover); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); } .btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--primary); } .btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--bad); color: #fff; } .btn-danger:hover { background: var(--bad); filter: brightness(.9); }
.btn-sm { padding: .25rem .8rem; font-size: .88rem; } .btn-lg { padding: .75rem 1.8rem; font-size: 1.1rem; }
.card > .btn, .card > a.btn { margin-top: .6rem; }
.icon-btn { display: inline-flex; padding: .45rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- فرم ---------- */
label { display: block; font-weight: 600; margin: .9rem 0; }
input:not([type="checkbox"]):not([type="radio"]), select, textarea { display: block; width: 100%; margin-top: .3rem; padding: .55rem .75rem; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 1.1rem; height: 1.1rem; vertical-align: -.2rem; margin-inline-end: .4rem; }
label small, .hint { display: block; font-weight: 400; margin-top: .2rem; color: var(--muted); font-size: .85rem; }
label small.bad, .field-error { color: var(--bad); font-weight: 600; }
input.is-invalid, select.is-invalid, textarea.is-invalid { border-color: var(--bad); }

/* ---------- جدول ---------- */
.table-wrap { overflow-x: auto; margin: 1rem 0; }
table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.table-wrap table { margin: 0; }
th, td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); text-align: right; }
th { background: var(--surface-2); font-size: .9rem; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }

/* ---------- هشدار ---------- */
.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); margin: 1rem 0; border: 1px solid var(--info-border); background: var(--info-bg); color: var(--info); }
.alert-ok, .alert.ok-box { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); }
.alert-warn, .warn-box { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); }
.alert-bad, .bad-box { background: var(--bad-bg); border-color: var(--bad-border); color: var(--bad); }
.alert .icon { margin-inline-end: .4rem; }
.warn-box p, .warn-box textarea { color: var(--text); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* ---------- پیشرفت و مراحل ---------- */
progress { width: 100%; height: 14px; margin: .5rem 0 1rem; accent-color: var(--primary); }
.spinner { display: inline-block; width: 1.1em; height: 1.1em; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -.2em; }
@keyframes spin { to { transform: rotate(360deg); } }
.steps { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-bottom: 1rem; font-size: .85rem; }
.step { padding: .25rem .8rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); }
.step b { color: var(--primary); }
.step.current { border-color: var(--primary); color: var(--text); font-weight: 700; }
.step.done { color: var(--ok); }

/* ---------- مودال (عنصر dialog) ---------- */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 1.5rem; width: min(92vw, 460px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(8, 12, 24, .55); }
dialog .modal-actions { display: flex; gap: .6rem; justify-content: flex-start; margin-top: 1.2rem; }

/* ---------- توست ---------- */
.toasts { position: fixed; inset-block-end: 1rem; inset-inline-start: 1rem; z-index: 50; display: flex; flex-direction: column; gap: .5rem; max-width: min(92vw, 380px); }
.toast { display: flex; gap: .6rem; align-items: center; padding: .7rem 1rem; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); border-inline-start: 4px solid var(--info); box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
.toast-ok { border-inline-start-color: var(--ok); } .toast-warn { border-inline-start-color: var(--warn); } .toast-bad { border-inline-start-color: var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- دکمه تغییر تم: ماه در روشن، خورشید در تیره ---------- */
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .i-sun { display: inline; }
    :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print { .topbar, .foot, .toasts, .btn { display: none !important; } body { background: #fff; color: #000; } .card { box-shadow: none; } }

/* ───── پروفایل کاربری (فاز ۱۳) ───── */
.avatar { position: relative; overflow: hidden; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: cover; display: block; }
a.user-chip { color: inherit; text-decoration: none; }
a.user-chip:hover .user-name { text-decoration: underline; }
.profile-grid { display: grid; gap: var(--gap); grid-template-columns: minmax(240px, 300px) 1fr; align-items: start; }
.profile-forms { display: grid; gap: var(--gap); }
.profile-grid > *, .profile-forms > * { min-width: 0; }
.profile-side input[type="file"] { max-width: 100%; }
.profile-forms h2, .profile-side h2 { margin-top: 0; }
.profile-side { text-align: center; }
.profile-side label, .profile-side .row { text-align: start; }
.profile-side .row { justify-content: center; }
.profile-avatar { position: relative; flex: none; width: 112px; height: 112px; margin: 0 auto .75rem; border-radius: 50%; overflow: hidden; display: grid; place-items: center; font-size: 2.8rem; font-weight: 800; color: var(--primary); background: var(--surface-2); border: 2px solid var(--border); }
.profile-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: cover; display: block; }
.profile-name { margin: 0 0 .15rem; font-size: 1.2rem; word-break: break-word; }
.profile-remove { margin-top: .5rem; }
.profile-meta { margin: 1.25rem 0 0; padding-top: 1rem; border-top: 1px solid var(--border); text-align: start; }
.profile-meta > div { display: flex; justify-content: space-between; gap: .5rem; padding: .25rem 0; font-size: .9rem; }
.profile-meta dt { color: var(--muted); }
.profile-meta dd { margin: 0; font-weight: 600; }
@media (max-width: 760px) { .profile-grid { grid-template-columns: 1fr; } }

/* ───── تنظیمات عمومی، لوگو و پایین سایت (فاز ۱۵) ───── */
.brand-logo { height: 28px; width: auto; max-width: 140px; vertical-align: middle; margin-inline-end: .5rem; }
.brand-mark-img { position: relative; overflow: hidden; background: transparent !important; }
.brand-mark-img img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: contain; display: block; }
.foot-contact { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem 1.2rem; margin-bottom: .6rem; }
.foot-contact a { color: inherit; }
.settings-form { display: grid; gap: var(--gap); max-width: 720px; }
.settings-form h2 { margin-top: 0; }
.asset-field { display: grid; gap: .3rem; }
.asset-preview { max-width: 240px; max-height: 80px; object-fit: contain; padding: .4rem; border: 1px dashed var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.asset-favicon { width: 40px; height: 40px; }
