/* ==========================================================================
   KRIN — Base layer
   Local fonts, reset, typography, RTL foundations, utilities and animations.
   ========================================================================== */

/* ---------- Local fonts (no CDN at runtime) ---------- */
@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/Vazirmatn-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/Vazirmatn-Medium.woff2") format("woff2");
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/Vazirmatn-SemiBold.woff2") format("woff2");
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/Vazirmatn-Bold.woff2") format("woff2");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

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

* {
    margin: 0;
}

html {
    font-size: calc(100% * var(--ds-font-size-scale));
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    /* WCAG 2.2 (focus not obscured): keep focused targets clear of the sticky header. */
    scroll-padding-top: calc(var(--ds-header-height) + var(--ds-space-4));
}

body {
    min-height: 100vh;
    background: var(--ds-surface-canvas);
    color: var(--ds-text-base);
    font-family: var(--ds-font-family);
    font-size: var(--ds-font-size-md);
    line-height: var(--ds-line-normal);
    font-weight: var(--ds-font-weight-regular);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

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

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

h1, h2, h3, h4, h5, h6 {
    color: var(--ds-text-strong);
    line-height: var(--ds-line-tight);
    font-weight: var(--ds-font-weight-bold);
    letter-spacing: -0.01em;
}

h1 { font-size: var(--ds-font-size-2xl); }
h2 { font-size: var(--ds-font-size-xl); }
h3 { font-size: var(--ds-font-size-lg); }
h4 { font-size: var(--ds-font-size-md); }

p { margin: 0; }

a {
    color: var(--ds-text-link);
    text-decoration: none;
    transition: color var(--ds-duration-fast) var(--ds-ease-standard);
}
a:hover { color: var(--ds-brand-600); }

code, kbd, samp, pre {
    font-family: var(--ds-font-family-mono);
    font-size: 0.85em;
}

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

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

/* ---------- Scrollbar ---------- */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--ds-border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
    background: var(--ds-border-strong);
    border-radius: var(--ds-radius-pill);
    border: 3px solid transparent;
    background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--ds-text-subtle); }

/* ---------- Layout utilities ---------- */
.ds-container {
    width: min(var(--ds-content-max), 100% - var(--ds-space-8));
    margin-inline: auto;
}

.ds-stack { display: flex; flex-direction: column; gap: var(--ds-space-4); }
.ds-stack-sm { display: flex; flex-direction: column; gap: var(--ds-space-2); }
.ds-cluster { display: flex; flex-wrap: wrap; gap: var(--ds-space-3); align-items: center; }
.ds-between { display: flex; flex-wrap: wrap; gap: var(--ds-space-3); align-items: center; justify-content: space-between; }
.ds-grid { display: grid; gap: var(--ds-space-4); }
.ds-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ds-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ds-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ds-grid-auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* ---------- Legacy utility aliases (kept for existing views) ---------- */
.container { width: min(var(--ds-content-max), 100% - var(--ds-space-8)); margin-inline: auto; }
.grid { display: grid; gap: var(--ds-space-4); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: var(--ds-space-4); }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--ds-space-3); margin-top: var(--ds-space-4); }
.actions-row { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); }
.inline-form { display: inline; margin: 0; }
.muted { color: var(--ds-text-muted); }
.mono { font-family: var(--ds-font-family-mono); direction: ltr; unicode-bidi: embed; font-size: var(--ds-font-size-sm); }
.text-center { text-align: center; }
.text-start { text-align: start; }
.span-2 { grid-column: 1 / -1; }
.hidden { display: none !important; }
.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;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-1);
    color: var(--ds-brand-700);
    background: var(--ds-surface-active);
    border-radius: var(--ds-radius-pill);
    padding: 0.2rem 0.7rem;
    font-size: var(--ds-font-size-xs);
    font-weight: var(--ds-font-weight-bold);
    letter-spacing: 0.03em;
}

/* ---------- Motion ---------- */
@keyframes ds-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ds-rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes ds-slide-in-end { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes ds-slide-in-start { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes ds-pop-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
@keyframes ds-spin { to { transform: rotate(360deg); } }
@keyframes ds-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes ds-shimmer { 100% { transform: translateX(-100%); } }

.ds-animate-in { animation: ds-rise-in var(--ds-duration-base) var(--ds-ease-out) both; }
.ds-animate-fade { animation: ds-fade-in var(--ds-duration-base) var(--ds-ease-standard) both; }

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

@media (max-width: 1080px) {
    .ds-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .ds-grid-3, .grid-3 { grid-template-columns: 1fr; }
    .ds-grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
    .ds-grid-4 { grid-template-columns: 1fr; }
    .ds-container, .container { width: min(var(--ds-content-max), 100% - var(--ds-space-5)); }
}
