/* ==========================================================================
   KRIN — Design Tokens
   Single source of truth for color, type, space, radius, shadow and motion.
   Consumed by every component; theme overrides only re-declare these tokens.
   Scale variables (font/space/radius/shadow) make the Custom Theme real.
   ========================================================================== */

:root {
    color-scheme: light;

    /* ---- Scale knobs (changed by the Custom Theme editor) ---- */
    --ds-font-size-scale: 1;
    --ds-space-scale: 1;
    --ds-radius-scale: 1;
    --ds-shadow-strength: 1;

    /* ---- Brand ramp (custom theme edits these seven stops) ---- */
    --ds-brand-50: #ecfdf7;
    --ds-brand-100: #d1faec;
    --ds-brand-200: #a7f3d8;
    --ds-brand-300: #6ee7be;
    --ds-brand-400: #34d3a1;
    --ds-brand-500: #0f9d78;
    --ds-brand-600: #0b7d61;
    --ds-brand-700: #0a634f;
    --ds-brand-800: #0a4f41;
    --ds-brand-900: #094137;

    /* ---- Accent / status ---- */
    --ds-color-accent: #6d5efc;
    --ds-color-info: #2563eb;
    --ds-color-success: #0f9d58;
    --ds-color-warning: #d97706;
    --ds-color-danger: #dc2626;
    --ds-color-neutral: #64748b;

    --ds-color-info-soft: #e0edff;
    --ds-color-success-soft: #dcfce7;
    --ds-color-warning-soft: #fef3c7;
    --ds-color-danger-soft: #fee2e2;
    --ds-color-accent-soft: #eceafe;

    /* ---- Surfaces (light) ---- */
    --ds-surface-canvas: #f4f7f9;
    --ds-surface-base: #ffffff;
    --ds-surface-raised: #ffffff;
    --ds-surface-sunken: #eef2f6;
    --ds-surface-sidebar: #ffffff;
    --ds-surface-header: rgba(255, 255, 255, 0.86);
    --ds-surface-hover: #f1f5f9;
    --ds-surface-active: var(--ds-brand-50);
    --ds-surface-inverse: #0f172a;
    --ds-surface-overlay: rgba(15, 23, 42, 0.48);

    /* ---- Text ---- */
    --ds-text-strong: #0f172a;
    --ds-text-base: #1e293b;
    --ds-text-muted: #64748b;
    --ds-text-subtle: #94a3b8;
    --ds-text-inverse: #f8fafc;
    --ds-text-on-brand: #ffffff;
    --ds-text-link: var(--ds-brand-700);

    /* ---- Borders ---- */
    --ds-border-subtle: #e6ebf1;
    --ds-border-base: #d8e0e8;
    --ds-border-strong: #b9c4d0;
    --ds-border-focus: var(--ds-brand-500);

    /* ---- Typography ---- */
    --ds-font-family: "Vazirmatn", "Segoe UI", Tahoma, "Iranian Sans", sans-serif;
    --ds-font-family-mono: "Vazirmatn", ui-monospace, "Cascadia Code", Consolas, monospace;
    --ds-font-size-xs: calc(0.6875rem * var(--ds-font-size-scale));
    --ds-font-size-sm: calc(0.8125rem * var(--ds-font-size-scale));
    --ds-font-size-md: calc(0.9375rem * var(--ds-font-size-scale));
    --ds-font-size-lg: calc(1.0625rem * var(--ds-font-size-scale));
    --ds-font-size-xl: calc(1.3125rem * var(--ds-font-size-scale));
    --ds-font-size-2xl: calc(1.625rem * var(--ds-font-size-scale));
    --ds-font-size-3xl: calc(2rem * var(--ds-font-size-scale));
    --ds-line-tight: 1.3;
    --ds-line-normal: 1.7;
    --ds-font-weight-regular: 400;
    --ds-font-weight-medium: 500;
    --ds-font-weight-semibold: 600;
    --ds-font-weight-bold: 700;

    /* ---- Spacing scale (4px base) ---- */
    --ds-space-0: 0;
    --ds-space-1: calc(0.25rem * var(--ds-space-scale));
    --ds-space-2: calc(0.5rem * var(--ds-space-scale));
    --ds-space-3: calc(0.75rem * var(--ds-space-scale));
    --ds-space-4: calc(1rem * var(--ds-space-scale));
    --ds-space-5: calc(1.25rem * var(--ds-space-scale));
    --ds-space-6: calc(1.5rem * var(--ds-space-scale));
    --ds-space-8: calc(2rem * var(--ds-space-scale));
    --ds-space-10: calc(2.5rem * var(--ds-space-scale));
    --ds-space-12: calc(3rem * var(--ds-space-scale));
    --ds-space-16: calc(4rem * var(--ds-space-scale));

    /* ---- Radius ---- */
    --ds-radius-xs: calc(6px * var(--ds-radius-scale));
    --ds-radius-sm: calc(9px * var(--ds-radius-scale));
    --ds-radius-md: calc(13px * var(--ds-radius-scale));
    --ds-radius-lg: calc(18px * var(--ds-radius-scale));
    --ds-radius-xl: calc(26px * var(--ds-radius-scale));
    --ds-radius-pill: 999px;

    /* ---- Shadow ---- */
    --ds-shadow-xs: 0 1px 2px rgba(15, 23, 42, calc(0.06 * var(--ds-shadow-strength)));
    --ds-shadow-sm: 0 2px 6px rgba(15, 23, 42, calc(0.07 * var(--ds-shadow-strength)));
    --ds-shadow-md: 0 10px 26px rgba(15, 23, 42, calc(0.09 * var(--ds-shadow-strength)));
    --ds-shadow-lg: 0 18px 48px rgba(15, 23, 42, calc(0.15 * var(--ds-shadow-strength)));
    --ds-shadow-focus: 0 0 0 3px rgba(15, 157, 120, 0.28);

    /* ---- Motion ---- */
    --ds-duration-instant: 90ms;
    --ds-duration-fast: 160ms;
    --ds-duration-base: 240ms;
    --ds-duration-slow: 420ms;
    --ds-ease-standard: cubic-bezier(0.2, 0, 0, 1);
    --ds-ease-out: cubic-bezier(0.16, 1, 0.3, 1);

    /* ---- Layout ---- */
    --ds-sidebar-width: 264px;
    --ds-sidebar-collapsed-width: 76px;
    --ds-header-height: 64px;
    --ds-content-max: 1440px;
    --ds-z-sidebar: 40;
    --ds-z-header: 50;
    --ds-z-dropdown: 60;
    --ds-z-drawer: 70;
    --ds-z-modal: 80;
    --ds-z-toast: 90;
    --ds-z-context: 100;
}

/* ---- Dark theme: only token re-declarations ---- */
:root[data-theme="dark"] {
    color-scheme: dark;

    --ds-surface-canvas: #0b1220;
    --ds-surface-base: #101a2c;
    --ds-surface-raised: #16223a;
    --ds-surface-sunken: #0c1526;
    --ds-surface-sidebar: #0d1626;
    --ds-surface-header: rgba(16, 26, 44, 0.86);
    --ds-surface-hover: #1b2941;
    --ds-surface-active: rgba(15, 157, 120, 0.18);
    --ds-surface-inverse: #f8fafc;
    --ds-surface-overlay: rgba(2, 6, 23, 0.62);

    --ds-text-strong: #f8fafc;
    --ds-text-base: #e2e8f0;
    --ds-text-muted: #94a3b8;
    --ds-text-subtle: #64748b;
    --ds-text-inverse: #0f172a;
    --ds-text-on-brand: #ffffff;
    --ds-text-link: var(--ds-brand-300);

    --ds-border-subtle: #1f2c44;
    --ds-border-base: #2a3954;
    --ds-border-strong: #3b4d6e;

    /* Brighter focus ring so keyboard focus stays visible on dark surfaces. */
    --ds-border-focus: var(--ds-brand-300);
    --ds-shadow-focus: 0 0 0 3px rgba(110, 231, 190, 0.38);

    --ds-color-info-soft: rgba(37, 99, 235, 0.18);
    --ds-color-success-soft: rgba(15, 157, 88, 0.18);
    --ds-color-warning-soft: rgba(217, 119, 6, 0.2);
    --ds-color-danger-soft: rgba(220, 38, 38, 0.2);
    --ds-color-accent-soft: rgba(109, 94, 252, 0.22);
}

/* ---- High-contrast preference ---- */
:root[data-contrast="high"] {
    --ds-border-base: var(--ds-border-strong);
    --ds-text-muted: var(--ds-text-base);
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
    :root {
        --ds-duration-instant: 0ms;
        --ds-duration-fast: 0ms;
        --ds-duration-base: 0ms;
        --ds-duration-slow: 0ms;
    }
}
