@layer theme, base, components, utilities;

/*
 * Filament Themes: the theme picker cards and the look of the built-in themes.
 *
 * Everything lives in `@layer components`, below Tailwind's `utilities` layer, so a utility class on a component
 * (rounded-full via extraAttributes, ...) still wins. Rules are namespaced (.fi-themes-*) or scoped to the
 * <meta name="filament-theme"> the plugin prints in the head; a theme that is not active matches nothing.
 * The radius rules skip buttons inside a `.fi-btn-group`, whose corners belong to Filament.
 * The first line above is required whenever a plugin stylesheet uses @layer: without it the layer order is not
 * established when this file loads first, and the panel's preflight loses to ours.
 */
@layer components {
    /* ------------------------------------------------------------------ picker */

    .fi-themes-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
        gap: 1rem;
    }

    .fi-themes-card {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem;
        text-align: start;
        color: inherit;
        background: transparent;
        border: 2px solid var(--gray-200, #e5e7eb);
        border-radius: 0.75rem;
        cursor: pointer;
        transition: border-color 0.15s, box-shadow 0.15s;
    }

    .fi-themes-card:hover {
        border-color: var(--primary-400, #a1a1aa);
    }

    .fi-themes-card:focus-visible {
        outline: 2px solid var(--primary-600, #2563eb);
        outline-offset: 2px;
    }

    .fi-themes-card[aria-pressed='true'] {
        border-color: var(--primary-600, #2563eb);
        box-shadow: 0 0 0 1px var(--primary-600, #2563eb);
    }

    :is(.dark) .fi-themes-card {
        border-color: var(--gray-700, #374151);
    }

    :is(.dark) .fi-themes-card[aria-pressed='true'] {
        border-color: var(--primary-500, #3b82f6);
        box-shadow: 0 0 0 1px var(--primary-500, #3b82f6);
    }

    .fi-themes-preview {
        display: grid;
        grid-template-columns: 1fr 1fr;
        overflow: hidden;
        border-radius: 0.5rem;
        border: 1px solid var(--fi-themes-light-line);
    }

    .fi-themes-half {
        display: flex;
        flex-direction: column;
        gap: 0.35rem;
        padding: 0.5rem;
    }

    .fi-themes-half-light {
        background: var(--fi-themes-light);
        --fi-themes-ink: var(--fi-themes-light-line);
    }

    .fi-themes-half-dark {
        background: var(--fi-themes-dark);
        --fi-themes-ink: var(--fi-themes-dark-line);
    }

    .fi-themes-bar {
        height: 0.4rem;
        width: 60%;
        border-radius: 999px;
        background: var(--fi-themes-primary-soft);
    }

    .fi-themes-line {
        height: 0.3rem;
        border-radius: 999px;
        background: var(--fi-themes-ink);
    }

    .fi-themes-line-short {
        width: 55%;
    }

    .fi-themes-btn {
        height: 0.9rem;
        width: 2.2rem;
        margin-top: 0.15rem;
        border-radius: 0.25rem;
        background: var(--fi-themes-primary);
    }

    .fi-themes-meta {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        padding-inline: 0.25rem;
    }

    .fi-themes-name {
        font-weight: 600;
    }

    .fi-themes-current {
        font-size: 0.75rem;
        padding: 0.05rem 0.5rem;
        border-radius: 999px;
        background: var(--primary-100, #dbeafe);
        color: var(--primary-800, #1e40af);
    }

    :is(.dark) .fi-themes-current {
        background: var(--primary-900, #1e3a8a);
        color: var(--primary-100, #dbeafe);
    }

    .fi-themes-dots {
        display: flex;
        gap: 0.3rem;
        padding-inline: 0.25rem;
    }

    .fi-themes-dots i {
        width: 0.7rem;
        height: 0.7rem;
        border-radius: 999px;
    }

    .fi-themes-description {
        padding-inline: 0.25rem;
        padding-bottom: 0.25rem;
        font-size: 0.8rem;
        color: var(--gray-600, #4b5563);
    }

    :is(.dark) .fi-themes-description {
        color: var(--gray-400, #9ca3af);
    }

    .fi-themes-swatches {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .fi-themes-swatch {
        width: 1.75rem;
        height: 1.75rem;
        border-radius: 999px;
        border: 2px solid transparent;
        cursor: pointer;
    }

    .fi-themes-swatch:focus-visible {
        outline: 2px solid var(--gray-950, #030712);
        outline-offset: 2px;
    }

    :is(.dark) .fi-themes-swatch:focus-visible {
        outline-color: #fff;
    }

    .fi-themes-swatch[aria-pressed='true'] {
        box-shadow:
            0 0 0 2px var(--fi-themes-ring, #fff),
            0 0 0 4px var(--gray-950, #030712);
    }

    :is(.dark) .fi-themes-swatch[aria-pressed='true'] {
        --fi-themes-ring: var(--gray-900, #111827);
        box-shadow:
            0 0 0 2px var(--gray-900, #111827),
            0 0 0 4px #fff;
    }

    .fi-themes-custom {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.75rem;
        margin-top: 1rem;
    }

    .fi-themes-custom input[type='color'] {
        width: 2.25rem;
        height: 2.25rem;
        padding: 0;
        border: 0;
        background: transparent;
        cursor: pointer;
    }

    .fi-themes-error {
        margin-top: 0.5rem;
        font-size: 0.875rem;
        color: var(--danger-600, #dc2626);
    }

    :is(.dark) .fi-themes-error {
        color: var(--danger-400, #f87171);
    }

    .fi-themes-reset {
        margin-top: 1rem;
    }

    /* ------------------------------------------------------------------ built-in themes
     * Colours come from the palettes the plugin registers (primary, gray, ...). What is left for CSS is shape:
     * corner radius and the surface of the sidebar / top bar. Scoped to the active theme only.
     */

    :root:has(meta[name='filament-theme'][content='nord']) :is(.fi-btn:not(.fi-btn-group > .fi-btn), .fi-input-wrp, .fi-section, .fi-dropdown-panel, .fi-ta-ctn, .fi-badge) {
        border-radius: 0.25rem;
    }

    :root:has(meta[name='filament-theme'][content='nord']) .fi-sidebar {
        background-color: var(--gray-100);
    }

    :root.dark:has(meta[name='filament-theme'][content='nord']) .fi-sidebar {
        background-color: var(--gray-900);
    }

    :root:has(meta[name='filament-theme'][content='dracula']) :is(.fi-btn:not(.fi-btn-group > .fi-btn), .fi-input-wrp, .fi-section, .fi-dropdown-panel, .fi-ta-ctn) {
        border-radius: 0.5rem;
    }

    :root:has(meta[name='filament-theme'][content='dracula']) .fi-sidebar {
        background-color: var(--gray-50);
        border-inline-end: 3px solid var(--primary-600);
    }

    :root.dark:has(meta[name='filament-theme'][content='dracula']) .fi-sidebar {
        background-color: var(--gray-950);
        border-inline-end-color: var(--primary-500);
    }

    :root:has(meta[name='filament-theme'][content='sunset']) :is(.fi-btn:not(.fi-btn-group > .fi-btn), .fi-input-wrp, .fi-section, .fi-dropdown-panel, .fi-ta-ctn) {
        border-radius: 0.875rem;
    }

    :root:has(meta[name='filament-theme'][content='sunset']) .fi-topbar {
        border-bottom: 3px solid var(--primary-500);
    }

    :root:has(meta[name='filament-theme'][content='ocean']) :is(.fi-btn:not(.fi-btn-group > .fi-btn), .fi-input-wrp, .fi-section, .fi-dropdown-panel, .fi-ta-ctn) {
        border-radius: 0.625rem;
    }

    :root:has(meta[name='filament-theme'][content='ocean']) .fi-sidebar {
        background-color: var(--gray-50);
    }

    :root.dark:has(meta[name='filament-theme'][content='ocean']) .fi-sidebar {
        background-color: var(--gray-900);
    }

    :root:has(meta[name='filament-theme'][content='forest']) :is(.fi-btn:not(.fi-btn-group > .fi-btn), .fi-input-wrp, .fi-section, .fi-dropdown-panel, .fi-ta-ctn) {
        border-radius: 0.375rem;
    }

    :root:has(meta[name='filament-theme'][content='forest']) .fi-topbar {
        border-bottom: 1px solid var(--primary-600);
    }

    :root.dark:has(meta[name='filament-theme'][content='forest']) .fi-topbar {
        border-bottom-color: var(--primary-500);
    }
}
