@use "sass:map";
@use "styleboost/utilities/functions" as *;
@use "styleboost/utilities/contrast" as contrast;
@use "styleboost/utilities/mixins" as *;
@use "styleboost/utilities/boot";

// The CSS cascade layers.
// This list can be changed to modify the importance of the layers,
// but removing a layer from this list does not mean it won't get made.
$layers: (
	"reset",
	"defaults",
	"patterns",
	"components",
	"themes",
	"utilities",
	"overrides",
) !default;

// The default colors
$colors: (
	"red":     #dc3535,
	"orange":  #fd7e14,
	"yellow":  #ffc107,
	"olive":   #808000,
	"lime":    #94d82d,
	"green":   #008000,
	"teal":    #20c997,
	"cyan":    #0dcaf0,
	"blue":    #0d6efd,
	"navy":    #1310f2,
	"indigo":  #5d10f2,
	"purple":  #6f42c1,
	"grape":   #be4bdb,
	"cerise":  #D63384,
	"pink":    #f95f8f,
	"salmon":  #fa5e57,
) !default;

// Optional extra colors
$extra-colors: () !default;

// The default shades
$shades: (
	"black" : #000,
	"gray"  : #a4adb6,
	"white" : #fff,
) !default;

// Optional extra shades
$extra-shades: () !default;

// The default themes
$themes: (
	"primary"   : "blue",
	"secondary" : "gray-600",
	"success"   : "green",
	"info"      : "cyan",
	"warning"   : "yellow",
	"danger"    : "red",
	"bright"    : "gray-100",
	"dim"       : "gray-900",
	"truthy"    : "green",
	"falsy"     : "red",
	"inactive"  : "gray-400",
) !default;

// Optional extra themes
$extra-themes: () !default;

// The default modes
$modes: (
	"light": (
		// Special instruction for text colors
		"text": (
			"suffix"   : "700",
			"action"   : "shade",
			"args"     : 40%,
			"contrast" : true,
		),

		// Default types
		"core": (
			"suffix": "500",
			"action": false,
		),
		"accent": (
			"action": "complement",
		),
		"bg": (
			"suffix": "100",
			"action": "tint",
			"args"  : 80%,
		),
		"bg-subtle": (
			"suffix": "200",
			"action": "tint",
			"args"  : 10%,
		),

		// Surface colors for elevated elements like cards
		"surface": (
			"suffix": "50",
			"action": "tint",
			"args"  : 90%,
		),

		// Border variations
		"border": (
			"suffix": "300",
			"action": "tint",
			"args"  : 50%,
		),
		"border-hover": (
			"suffix": "400",
			"action": "tint",
			"args"  : 30%,
		),
		"border-focus": (
			"suffix": "500",
			"action": "tint",
			"args"  : 10%,
		),
		"border-flashy": (
			"suffix": "600",
			"action": "shade",
			"args"  : 20%,
		),

		// Dividers and separators (lighter than borders)
		"divider": (
			"suffix": "200",
			"action": "tint",
			"args"  : 70%,
		),
		"runner": (
			"suffix": "200",
			"action": "tint",
			"args"  : 60%,

			"theme_overrides": (
				// The "bright" theme should actually turn the accent color into a shade
				"bright": (
					"action": "shade",
					"args"  : 5%,
				)
			),
		),

		// Shadow color for drop shadows
		"shadow": (
			"suffix": "900",
			"action": "shade",
			"args"  : 60%,
		),

		// Emphasis and subtle variations
		"emphasis": (
			"suffix": "600",
			"action": "shade",
			"args"  : 20%,
		),
		"light": (
			"suffix": "100",
			"action": "tint",
			"args"  : 10%,
		),
		"subtle": (
			"suffix": "200",
			"action": "tint",
			"args"  : 10%,
		),
		"subtle-hover": (
			"suffix": "400",
			"action": "tint",
			"args"  : 20%,
		),
	),
	"dark": (
		// Special instruction for text colors
		"text": (
			"suffix"   : "300",
			"action"   : "tint",
			"args"     : 40%,
			"contrast" : true,
		),

		// Default types
		"core": (
			"suffix": "500",
			"action": false,
		),
		"accent": (
			"action": "complement",
		),
		"bg": (
			"suffix": "900",
			"action": "shade",
			"args"  : 80%,
		),
		"bg-subtle": (
			"suffix": "800",
			"action": "tint",
			"args"  : 10%,
		),

		// Surface colors for elevated elements like cards
		"surface": (
			"suffix": "950",
			"action": "shade",
			"args"  : 90%,
		),

		// Border variations
		"border": (
			"suffix": "700",
			"action": "shade",
			"args"  : 50%,
		),
		"border-hover": (
			"suffix": "600",
			"action": "shade",
			"args"  : 30%,
		),
		"border-focus": (
			"suffix": "500",
			"action": "shade",
			"args"  : 10%,
		),
		"border-flashy": (
			"suffix": "400",
			"action": "tint",
			"args"  : 20%,
		),

		// Dividers and separators (lighter than borders in dark mode)
		"divider": (
			"suffix": "800",
			"action": "shade",
			"args"  : 70%,
		),
		"runner": (
			"suffix": "700",
			"action": "shade",
			"args"  : 40%,

			"theme_overrides": (
				// The "dim" theme should actually turn the accent color into a tint
				"dim": (
					"action": "tint",
					"args"  : 20%,
				)
			),
		),

		// Shadow color for drop shadows
		"shadow": (
			"suffix": "950",
			"action": "shade",
			"args"  : 95%,
		),

		// Emphasis and subtle variations
		"emphasis": (
			"suffix": "200",
			"action": "tint",
			"args"  : 20%,
		),
		"light": (
			"suffix": "100",
			"action": "tint",
			"args"  : 10%,
		),
		"subtle": (
			"suffix": "800",
			"action": "shade",
			"args"  : 60%,
		),
		"subtle-hover": (
			"suffix": "600",
			"action": "shade",
			"args"  : 20%,
		),
	),
) !default;

// The default mode & theme
$default-mode: "light" !default;
$default-theme: "bright" !default;

// The default component themes
$components: (
	"body": $default-theme,
) !default;

// The default radius
$radius: (
	"none" : 0,
	"sm"   : 0.2rem,
	"md"   : 0.4rem,
	"lg"   : 0.6rem,
	"xl"   : 0.8rem,
	"xxl"  : 1.0rem,
) !default;

// Modern shadow system for visual hierarchy and depth
// Based on Material Design 3 principles with proper dark/light mode support
$shadows: (
	"none": "none",
	"sm": "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
	"base": "0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)",
	"md": "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",
	"lg": "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",
	"xl": "0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",
	"2xl": "0 25px 50px -12px rgba(0, 0, 0, 0.25)",
	"inner": "inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)",
) !default;

// Dark mode shadow variants that use lighter colors for visibility
$dark-shadows: (
	"none": "none",
	"sm": "0 1px 2px 0 rgba(255, 255, 255, 0.05)",
	"base": "0 1px 3px 0 rgba(255, 255, 255, 0.1), 0 1px 2px 0 rgba(255, 255, 255, 0.06)",
	"md": "0 4px 6px -1px rgba(255, 255, 255, 0.1), 0 2px 4px -1px rgba(255, 255, 255, 0.06)",
	"lg": "0 10px 15px -3px rgba(255, 255, 255, 0.1), 0 4px 6px -2px rgba(255, 255, 255, 0.05)",
	"xl": "0 20px 25px -5px rgba(255, 255, 255, 0.1), 0 10px 10px -5px rgba(255, 255, 255, 0.04)",
	"2xl": "0 25px 50px -12px rgba(255, 255, 255, 0.25)",
	"inner": "inset 0 2px 4px 0 rgba(255, 255, 255, 0.06)",
) !default;

// The contrast ratio to reach against white, to determine if color changes from "light" to "dark". Acceptable values for WCAG 2.0 are 3, 4.5 and 7.
// See https://www.w3.org/TR/WCAG20/#visual-audio-contrast-contrast
// Using 7.0 (AAA) instead of 4.5 (AA) for better readability
$min-contrast-ratio: 7.0 !default;

/// @type color
$contrast-dark-default: black !default;

/// @type color
$contrast-light-default: white !default;

/// @type string
$planifolia-colorspace: 'lab' !default;

// Menu variables
$menu-arrow-content: "\f105" !default;
$menu-arrow-font: "Font Awesome 6 Pro", "Font Awesome 6 Free" !default;

// Default animation duration
$animation-duration: 0.3s !default;

// Modern spacing system based on 8px grid
// Using mathematical progression for consistent visual hierarchy
$spacing: (
	"0"   : 0,
	"1"   : 0.25rem,  // 4px
	"2"   : 0.5rem,   // 8px
	"3"   : 0.75rem,  // 12px
	"4"   : 1rem,     // 16px
	"5"   : 1.25rem,  // 20px
	"6"   : 1.5rem,   // 24px
	"8"   : 2rem,     // 32px
	"10"  : 2.5rem,   // 40px
	"12"  : 3rem,     // 48px
	"16"  : 4rem,     // 64px
	"20"  : 5rem,     // 80px
	"24"  : 6rem,     // 96px
	"32"  : 8rem,     // 128px
) !default;

// Modern typography scale following type scale principles
// Using modular scale (1.125 - Major Second) for harmonious progression
$typography: (
	"xs"    : 0.75rem,   // 12px
	"sm"    : 0.875rem,  // 14px
	"base"  : 1rem,      // 16px
	"lg"    : 1.125rem,  // 18px
	"xl"    : 1.25rem,   // 20px
	"2xl"   : 1.5rem,    // 24px
	"3xl"   : 1.875rem,  // 30px
	"4xl"   : 2.25rem,   // 36px
	"5xl"   : 3rem,      // 48px
	"6xl"   : 3.75rem,   // 60px
	"7xl"   : 4.5rem,    // 72px
	"8xl"   : 6rem,      // 96px
	"9xl"   : 8rem,      // 128px
) !default;

// Line height scale for optimal readability
$line-heights: (
	"none"    : 0,
	"minimal" : 1,
	"tight"   : 1.25,
	"snug"    : 1.375,
	"normal"  : 1.5,
	"relaxed" : 1.625,
	"loose"   : 2,
) !default;

// Font weight scale for proper hierarchy
$font-weights: (
	"thin"       : 100,
	"extralight" : 200,
	"light"      : 300,
	"normal"     : 400,
	"medium"     : 500,
	"semibold"   : 600,
	"bold"       : 700,
	"extrabold"  : 800,
	"black"      : 900,
) !default;

// Letter spacing for better readability
$letter-spacings: (
	"tighter" : -0.05em,
	"tight"   : -0.025em,
	"normal"  : 0,
	"wide"    : 0.025em,
	"wider"   : 0.05em,
	"widest"  : 0.1em,
) !default;

// The default non-color values
$default-properties: (
	"size-font"          : 1em,
	"style-border"       : solid,
	"size-border"        : 1px,
	"size-border-inner"  : 1px,
	"size-border-radius" : 4px,
	"duration-animation" : $animation-duration,
) !default;

// Extra default properties
$extra-default-properties: () !default;

// The container horizontal gap, which acts as the offset for breakpoints
$tablet: 768px !default;
$small-desktop: 960px !default;
$medium-desktop: 1152px !default;
$large-desktop: 1440px !default;

// All our breakpoints
$breakpoints: (
	"phone"          : ("until": $tablet),
	"tablet"         : ("from": $tablet),
	"any-desktop"    : ("from": $small-desktop),
	"small-desktop"  : ("from": $small-desktop, "until": $medium-desktop),
	"medium-desktop" : ("from": $medium-desktop, "until": $large-desktop),
	"large-desktop"  : ("from": $large-desktop),
) !default;

// Optional extra modes
$extra-modes: () !default;

// Set the defaults in the boot module
$temp: boot.setDefaultMode($default-mode);
$temp: boot.setDefaultTheme($default-theme);

// Set the minimum contrast ratio
$temp: boot.setMinContrastRatio($min-contrast-ratio);

// Merge all the values
$colors: boot.initColors($colors, $extra-colors);
$shades: boot.initShades($shades, $extra-shades);
$themes: boot.initThemes($themes, $extra-themes);
$modes: boot.initModes($modes, $extra-modes);
$default_property_values: boot.initDefaultProperties($default-properties, $extra-default-properties);
$components: boot.initComponents($components);

// Declare all the layers in their order
@layer #{$layers};

@layer defaults {
	:root {
		@include boot.outputRanges();
		@include boot.outputNumberedColors();
		@include boot.outputRGBColors();

		@include map-to-properties($radius, '--radius-');
		@include boot.outputDefaultProperties($default_property_values, 't-current');

		// Shadow system for light mode (default)
		@include map-to-properties($shadows, '--shadow-');

		// Modern spacing system
		@include map-to-properties($spacing, '--spacing-');

		// Modern typography scale
		@include map-to-properties($typography, '--text-');

		// Line height scale
		@include map-to-properties($line-heights, '--leading-');

		// Font weight scale
		@include map-to-properties($font-weights, '--font-');

		// Letter spacing scale
		@include map-to-properties($letter-spacings, '--tracking-');

		// @TODO: implement this in the themes
		--image-t-current-chevron: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23f0f2f6' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
	}

	// Responsive spacing adjustments for mobile devices
	@media (max-width: 768px) {
		// Reduce spacing on mobile for better space utilization
		--spacing-8: 1.5rem;   // Reduce from 2rem
		--spacing-12: 2rem;    // Reduce from 3rem
		--spacing-16: 2.5rem;  // Reduce from 4rem
		--spacing-20: 3rem;    // Reduce from 5rem
		--spacing-24: 3.5rem;  // Reduce from 6rem
		--spacing-32: 4rem;    // Reduce from 8rem
		
		// Slightly smaller text on mobile
		--text-5xl: 2.5rem;    // Reduce from 3rem
		--text-6xl: 3rem;      // Reduce from 3.75rem
		--text-7xl: 3.5rem;    // Reduce from 4.5rem
		--text-8xl: 4rem;      // Reduce from 6rem
		--text-9xl: 5rem;      // Reduce from 8rem
	}
}

@if should_add_exports() {
	:export {
		@include boot.outputExports();
	}
}

@layer themes {
	@include boot.outputModeColors();
	@include boot.outputThemeProperties();
}