/* ============================================================================
   ThinkSpark — Premium Admin Login
   UI/UX only. No backend coupling. All theming via CSS custom properties.
   Sections: 1 Tokens · 2 Base · 3 Layout · 4 Brand panel · 5 Decorations
             6 Auth card · 7 Form controls · 8 Button · 9 Misc · 10 Responsive
             11 Accessibility / reduced-motion
   ========================================================================== */

/* ── 1. Design tokens ─────────────────────────────────────────────────── */
:root {
    /* Brand gradient stops (per spec) */
    --ts-grad-1: #6C4CF1;
    --ts-grad-2: #4F46E5;
    --ts-grad-3: #8B5CF6;

    /* Surfaces (dark theme) */
    --ts-bg: #07070D;
    --ts-bg-2: #0B0B14;
    --ts-surface: rgba(22, 22, 34, 0.72);
    --ts-surface-solid: #14141F;
    --ts-elevated: rgba(255, 255, 255, 0.04);

    /* Borders & lines */
    --ts-border: rgba(255, 255, 255, 0.09);
    --ts-border-strong: rgba(255, 255, 255, 0.16);
    --ts-ring: rgba(108, 76, 241, 0.55);

    /* Text */
    --ts-text: #F4F4F7;
    --ts-text-muted: #A7A7B5;
    --ts-text-faint: #71717F;

    /* Feedback */
    --ts-danger: #F87171;
    --ts-danger-bg: rgba(248, 113, 113, 0.10);
    --ts-danger-border: rgba(248, 113, 113, 0.35);
    --ts-success: #34D399;

    /* Effects */
    --ts-radius: 16px;
    --ts-radius-sm: 11px;
    --ts-radius-pill: 999px;
    --ts-shadow-card: 0 24px 70px -24px rgba(0, 0, 0, 0.85), 0 4px 24px -8px rgba(76, 70, 229, 0.25);
    --ts-shadow-btn: 0 12px 28px -8px rgba(108, 76, 241, 0.65);
    --ts-shadow-btn-hover: 0 18px 40px -10px rgba(108, 76, 241, 0.8);
    --ts-blur: 22px;

    --ts-font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --ts-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ── 2. Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

html { max-width: 100%; overflow-x: hidden; }

.ts-body {
    margin: 0;
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: var(--ts-font);
    color: var(--ts-text);
    background: var(--ts-bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

/* Icons fill their fixed-size container by default. Low specificity (single
   element selector) so any element-level size rule (e.g. .ts-submit__arrow)
   can override it. */
svg { display: block; width: 100%; height: 100%; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ── 3. Layout shell (split screen) ───────────────────────────────────── */
.ts-shell {
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    max-width: 100%;
}

/* ── 4. Brand panel ───────────────────────────────────────────────────── */
.ts-brand {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    display: flex;
    background: linear-gradient(135deg, var(--ts-grad-2) 0%, var(--ts-grad-1) 48%, var(--ts-grad-3) 100%);
}

/* Animated gradient mesh overlay */
.ts-brand__mesh {
    position: absolute;
    inset: -25%;
    z-index: 0;
    background:
        radial-gradient(40% 40% at 20% 25%, rgba(139, 92, 246, 0.85), transparent 70%),
        radial-gradient(45% 45% at 80% 20%, rgba(108, 76, 241, 0.75), transparent 70%),
        radial-gradient(50% 50% at 70% 85%, rgba(79, 70, 229, 0.85), transparent 72%),
        radial-gradient(40% 40% at 25% 80%, rgba(167, 139, 250, 0.55), transparent 70%);
    filter: saturate(1.1);
    animation: ts-mesh 18s var(--ts-ease) infinite alternate;
}

@keyframes ts-mesh {
    0%   { transform: translate3d(0, 0, 0) scale(1); }
    50%  { transform: translate3d(2.5%, -2%, 0) scale(1.08) rotate(2deg); }
    100% { transform: translate3d(-2%, 2.5%, 0) scale(1.05) rotate(-2deg); }
}

.ts-brand__inner {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 40px;
    width: 100%;
    max-width: 560px;
    margin-inline: auto;
    padding: clamp(36px, 5vw, 64px);
    color: #fff;
}

/* Logo */
.ts-logo { display: inline-flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; width: fit-content; }
.ts-logo__mark {
    display: grid; place-items: center;
    width: 42px; height: 42px; padding: 9px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.16);
    backdrop-filter: blur(6px);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.ts-logo__text { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.02em; }

/* Headline + copy */
.ts-headline {
    margin: 0 0 16px;
    font-size: clamp(2.1rem, 3.4vw, 3.1rem);
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -0.03em;
    text-wrap: balance;
}
.ts-subhead {
    margin: 0 0 36px;
    max-width: 46ch;
    font-size: 1.02rem;
    line-height: 1.65;
    color: rgba(255, 255, 255, 0.82);
}

/* Feature cards */
.ts-features { list-style: none; margin: 0 0 34px; padding: 0; display: grid; gap: 14px; }
.ts-feature {
    display: flex; align-items: center; gap: 16px;
    padding: 16px 18px;
    border-radius: var(--ts-radius-sm);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(8px);
    transition: transform 0.4s var(--ts-ease), background 0.4s var(--ts-ease), border-color 0.4s var(--ts-ease);
}
.ts-feature:hover { transform: translateY(-3px); background: rgba(255, 255, 255, 0.13); border-color: rgba(255, 255, 255, 0.28); }
.ts-feature__icon { flex: 0 0 auto; display: grid; place-items: center; width: 42px; height: 42px; padding: 10px; border-radius: 11px; background: rgba(255, 255, 255, 0.16); color: #fff; }
.ts-feature__body { display: flex; flex-direction: column; gap: 2px; }
.ts-feature__title { font-weight: 600; font-size: 0.97rem; }
.ts-feature__text { font-size: 0.86rem; color: rgba(255, 255, 255, 0.74); }

/* Statistics cards */
.ts-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.ts-stat {
    padding: 16px;
    border-radius: var(--ts-radius-sm);
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(6px);
}
.ts-stat__value { display: block; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.ts-stat__label { font-size: 0.78rem; color: rgba(255, 255, 255, 0.72); }

/* Brand footer: status + copyright */
.ts-brand__footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 0.84rem; color: rgba(255, 255, 255, 0.78); }
.ts-status { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.ts-status__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ts-success); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7); animation: ts-pulse 2.4s ease-out infinite; }
@keyframes ts-pulse { 0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6); } 70% { box-shadow: 0 0 0 9px rgba(52, 211, 153, 0); } 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); } }

/* ── 5. Floating shapes + particles ───────────────────────────────────── */
.ts-brand__shapes { position: absolute; inset: 0; z-index: 1; }
.ts-shape { position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.55; }
.ts-shape--1 { width: 380px; height: 380px; top: -120px; right: -90px; background: rgba(255, 255, 255, 0.5); animation: ts-float 14s ease-in-out infinite; }
.ts-shape--2 { width: 300px; height: 300px; bottom: -110px; left: -70px; background: rgba(167, 139, 250, 0.65); animation: ts-float 18s ease-in-out infinite reverse; }
.ts-shape--3 { width: 220px; height: 220px; top: 45%; left: 55%; background: rgba(108, 76, 241, 0.5); animation: ts-float 16s ease-in-out infinite; }
@keyframes ts-float { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-26px, 30px); } }

.ts-particles { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.ts-particles span { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); opacity: 0; animation: ts-rise 9s linear infinite; }
.ts-particles span:nth-child(1) { left: 12%; animation-delay: 0s;   animation-duration: 11s; }
.ts-particles span:nth-child(2) { left: 24%; animation-delay: 2.4s; animation-duration: 9s;  width: 4px; height: 4px; }
.ts-particles span:nth-child(3) { left: 38%; animation-delay: 4.1s; animation-duration: 13s; }
.ts-particles span:nth-child(4) { left: 51%; animation-delay: 1.2s; animation-duration: 10s; width: 5px; height: 5px; }
.ts-particles span:nth-child(5) { left: 63%; animation-delay: 5.5s; animation-duration: 12s; }
.ts-particles span:nth-child(6) { left: 74%; animation-delay: 3.2s; animation-duration: 9.5s; width: 4px; height: 4px; }
.ts-particles span:nth-child(7) { left: 85%; animation-delay: 6.3s; animation-duration: 14s; }
.ts-particles span:nth-child(8) { left: 93%; animation-delay: 0.8s; animation-duration: 11.5s; width: 5px; height: 5px; }
@keyframes ts-rise { 0% { transform: translateY(105%) scale(0.6); opacity: 0; } 12% { opacity: 0.9; } 88% { opacity: 0.9; } 100% { transform: translateY(-10%) scale(1); opacity: 0; } }

/* ── 6. Auth side + glass card ────────────────────────────────────────── */
.ts-auth {
    position: relative;
    min-width: 0; /* grid item: prevent content from forcing overflow */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    padding: clamp(28px, 4vw, 56px);
    background:
        radial-gradient(70% 55% at 70% 0%, rgba(108, 76, 241, 0.16), transparent 60%),
        linear-gradient(180deg, var(--ts-bg-2), var(--ts-bg));
}

.ts-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    margin-inline: auto;
    padding: clamp(28px, 3vw, 40px);
    border-radius: var(--ts-radius);
    background: var(--ts-surface);
    border: 1px solid var(--ts-border);
    backdrop-filter: blur(var(--ts-blur));
    -webkit-backdrop-filter: blur(var(--ts-blur));
    box-shadow: var(--ts-shadow-card);
}
/* Gradient border glow */
.ts-card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(135deg, rgba(108, 76, 241, 0.7), rgba(139, 92, 246, 0.15) 40%, transparent 70%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
}

.ts-card__head { text-align: center; margin-bottom: 26px; }
.ts-card__logo { display: inline-grid; place-items: center; width: 52px; height: 52px; padding: 13px; margin-bottom: 16px; border-radius: 14px; color: #fff; background: linear-gradient(135deg, var(--ts-grad-1), var(--ts-grad-3)); box-shadow: var(--ts-shadow-btn); }
.ts-card__title { margin: 0 0 6px; font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.ts-card__subtitle { margin: 0; font-size: 0.93rem; color: var(--ts-text-muted); }

/* Error alert */
.ts-alert { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 22px; padding: 13px 15px; border-radius: var(--ts-radius-sm); background: var(--ts-danger-bg); border: 1px solid var(--ts-danger-border); color: var(--ts-danger); }
.ts-alert__icon { flex: 0 0 auto; width: 20px; height: 20px; margin-top: 1px; }
.ts-alert__body { font-size: 0.88rem; line-height: 1.5; }
.ts-alert__body p { margin: 0; }
.ts-alert__body p + p { margin-top: 4px; }

/* ── 7. Form controls ─────────────────────────────────────────────────── */
.ts-form { display: flex; flex-direction: column; gap: 18px; }
.ts-field { display: flex; flex-direction: column; gap: 8px; }
.ts-field__row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.ts-field__label { font-size: 0.85rem; font-weight: 600; color: var(--ts-text); letter-spacing: 0.01em; }

.ts-control { position: relative; display: flex; align-items: center; }
.ts-control__icon { position: absolute; left: 14px; width: 19px; height: 19px; color: var(--ts-text-faint); pointer-events: none; transition: color 0.25s var(--ts-ease); }

/* Style the real Django-rendered <input> via its wrapper.
   The admin renders these widgets with Unfold's Tailwind classes baked into
   the element (e.g. `bg-white w-full`); those utilities are inert on this
   standalone page, so we override the box model authoritatively here. The
   high-specificity selector + !important guarantee our theme always wins
   regardless of the widget's class attribute. */
.ts-form .ts-control input,
.ts-form .ts-control input[type="text"],
.ts-form .ts-control input[type="password"],
.ts-form .ts-control input[type="email"] {
    box-sizing: border-box;
    width: 100% !important;
    min-width: 0;
    height: 50px;
    margin: 0;
    padding: 0 16px 0 44px;
    font-family: inherit;
    font-size: 0.96rem;
    line-height: 1.2;
    color: var(--ts-text) !important;
    background: var(--ts-elevated) !important;
    border: 1px solid var(--ts-border) !important;
    border-radius: var(--ts-radius-sm) !important;
    box-shadow: none;
    outline: none;
    transition: border-color 0.25s var(--ts-ease), box-shadow 0.25s var(--ts-ease), background 0.25s var(--ts-ease);
    -webkit-appearance: none;
    appearance: none;
}
.ts-control--password input { padding-right: 48px !important; }
.ts-control input::placeholder { color: var(--ts-text-faint); }
.ts-form .ts-control input:hover { border-color: var(--ts-border-strong) !important; }
.ts-form .ts-control input:focus {
    border-color: var(--ts-grad-1) !important;
    background: rgba(108, 76, 241, 0.08) !important;
    box-shadow: 0 0 0 4px var(--ts-ring) !important;
}
.ts-control:focus-within .ts-control__icon { color: var(--ts-grad-3); }
/* Autofill: Chrome forces a light background and dark text on autofilled
   fields. Mask it with an inset box-shadow the size of the field and force the
   themed text colour. High specificity + !important so it beats the base rule. */
.ts-form .ts-control input:-webkit-autofill,
.ts-form .ts-control input:-webkit-autofill:hover,
.ts-form .ts-control input:-webkit-autofill:focus,
.ts-form .ts-control input:-webkit-autofill:active {
    -webkit-text-fill-color: var(--ts-text) !important;
    -webkit-box-shadow: 0 0 0 1000px var(--ts-surface-solid) inset !important;
    box-shadow: 0 0 0 1000px var(--ts-surface-solid) inset !important;
    border: 1px solid var(--ts-border) !important;
    caret-color: var(--ts-text) !important;
    transition: background-color 9999s ease-in-out 0s; /* defeat autofill bg fade */
}
.ts-form .ts-control input:-webkit-autofill:focus {
    border-color: var(--ts-grad-1) !important;
}

/* Invalid state */
.ts-form .ts-field.is-invalid .ts-control input { border-color: var(--ts-danger-border) !important; }
.ts-form .ts-field.is-invalid .ts-control input:focus { box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.25) !important; }
.ts-field__error { margin: 0; font-size: 0.82rem; color: var(--ts-danger); }

/* Password show/hide toggle */
.ts-toggle { position: absolute; right: 8px; display: grid; place-items: center; width: 34px; height: 34px; padding: 7px; border: 0; border-radius: 9px; background: transparent; color: var(--ts-text-faint); cursor: pointer; transition: color 0.2s var(--ts-ease), background 0.2s var(--ts-ease); }
.ts-toggle:hover { color: var(--ts-text); background: rgba(255, 255, 255, 0.06); }
.ts-toggle__hide { display: none; }
.ts-toggle.is-visible .ts-toggle__show { display: none; }
.ts-toggle.is-visible .ts-toggle__hide { display: block; }

/* Options row: remember me */
.ts-options { display: flex; align-items: center; justify-content: space-between; margin-top: 2px; }
.ts-check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 0.88rem; color: var(--ts-text-muted); }
.ts-check__input { position: absolute; opacity: 0; width: 0; height: 0; }
.ts-check__box { display: grid; place-items: center; width: 20px; height: 20px; padding: 3px; border-radius: 6px; border: 1px solid var(--ts-border-strong); background: var(--ts-elevated); color: transparent; transition: all 0.2s var(--ts-ease); }
.ts-check__box svg { opacity: 0; transition: opacity 0.15s var(--ts-ease); }
.ts-check__input:checked + .ts-check__box { background: linear-gradient(135deg, var(--ts-grad-1), var(--ts-grad-3)); border-color: transparent; color: #fff; }
.ts-check__input:checked + .ts-check__box svg { opacity: 1; }
.ts-check__input:focus-visible + .ts-check__box { box-shadow: 0 0 0 4px var(--ts-ring); }

/* Inline links */
.ts-link { font-size: 0.83rem; font-weight: 500; color: var(--ts-grad-3); text-decoration: none; transition: color 0.2s var(--ts-ease); }
.ts-link:hover { color: #b9a4ff; text-decoration: underline; }

/* ── 8. Submit button ─────────────────────────────────────────────────── */
.ts-submit {
    position: relative;
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    width: 100%;
    height: 52px;
    margin-top: 6px;
    padding: 0 20px;
    font-family: inherit; font-size: 0.98rem; font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--ts-grad-1) 0%, var(--ts-grad-2) 50%, var(--ts-grad-3) 100%);
    background-size: 200% 100%;
    border: 0; border-radius: var(--ts-radius-sm);
    box-shadow: var(--ts-shadow-btn);
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.25s var(--ts-ease), box-shadow 0.25s var(--ts-ease), background-position 0.5s var(--ts-ease);
}
.ts-submit:hover { transform: translateY(-2px); background-position: 100% 0; box-shadow: var(--ts-shadow-btn-hover); }
.ts-submit:active { transform: translateY(0); }
.ts-submit__arrow { width: 18px; height: 18px; transition: transform 0.25s var(--ts-ease); }
.ts-submit:hover .ts-submit__arrow { transform: translateX(4px); }
.ts-submit__spinner { display: none; width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35); border-top-color: #fff; animation: ts-spin 0.7s linear infinite; }
@keyframes ts-spin { to { transform: rotate(360deg); } }

/* Loading state (toggled by JS) */
.ts-submit.is-loading { pointer-events: none; opacity: 0.85; }
.ts-submit.is-loading .ts-submit__spinner { display: block; }
.ts-submit.is-loading .ts-submit__arrow { display: none; }

/* ── 9. Card footer + page copyright ──────────────────────────────────── */
.ts-card__foot { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--ts-border); text-align: center; }
.ts-badge { display: inline-flex; align-items: center; gap: 7px; font-size: 0.78rem; color: var(--ts-text-faint); }
.ts-badge svg { width: 15px; height: 15px; color: var(--ts-success); }
.ts-copyright { margin: 0; font-size: 0.78rem; color: var(--ts-text-faint); text-align: center; }

/* ── 10. Responsive ───────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .ts-shell { grid-template-columns: 1fr; }
    .ts-brand { display: none; }
    .ts-auth { min-height: 100vh; min-height: 100dvh; }
}

@media (max-width: 480px) {
    .ts-card { padding: 24px 20px; border-radius: 14px; }
    .ts-card__title { font-size: 1.32rem; }
    .ts-auth { padding: 20px 16px; }
}

/* Large screens: let the brand copy breathe */
@media (min-width: 1440px) {
    .ts-brand__inner { max-width: 600px; }
}

/* ── 11. Accessibility ────────────────────────────────────────────────── */
:focus-visible { outline: none; }
.ts-link:focus-visible,
.ts-logo:focus-visible,
.ts-toggle:focus-visible,
.ts-submit:focus-visible { box-shadow: 0 0 0 4px var(--ts-ring); border-radius: var(--ts-radius-sm); }

@media (prefers-reduced-motion: reduce) {
    .ts-brand__mesh,
    .ts-shape,
    .ts-particles span,
    .ts-status__dot,
    .ts-submit__spinner { animation: none !important; }
    *, *::before, *::after { transition-duration: 0.01ms !important; }
}
