/* =====================================================================
   TulpiGo shared UI layer — obsidian tokens, tactile wave buttons,
   session-aware profile pill. Loaded by every public page.

   Principles (see docs/KNOWLEDGE_BASE.md §4):
   - Refactoring UI: depth from light (top highlight + two-part shadow),
     hairline separation instead of heavy borders, one accent per action.
   - Microinteractions: the wave starts on pointerdown so feedback lands
     before the click completes — it never delays the action itself.
   - Design of Everyday Things: hover lift + press compression are the
     signifiers; every state change is visible within 100ms.
   ===================================================================== */

:root {
    --tg-void: #030508;
    --tg-titanium: #080C14;
    --tg-titanium-2: #0D1322;
    --tg-hairline: rgba(255, 255, 255, 0.06);
    --tg-hairline-strong: rgba(255, 255, 255, 0.10);
    --tg-starlight: #FFFFFF;
    --tg-cashmere: #94A3B8;
    --tg-champagne: #E6C78B;
    --tg-champagne-deep: #C9A45C;
    --tg-champagne-soft: #F4E6C4;
    --tg-ice: #A5F3FC;
    --tg-ice-deep: #67E8F9;
    --tg-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

[hidden] { display: none !important; }

/* Before JS paints the profile pill, hide the logged-out controls for
   visitors who already hold a session token (set by an inline <head> probe). */
html[data-auth="in"] [data-auth-when="out"] { display: none !important; }
html:not([data-auth="in"]) [data-auth-when="in"] { display: none !important; }

/* ---------------------------------------------------------------------
   Wave buttons
   --------------------------------------------------------------------- */
.wave-btn {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transform: translate3d(0, 0, 0);
    transition:
        transform 180ms var(--tg-ease-out),
        box-shadow 220ms ease,
        border-color 220ms ease,
        background-color 220ms ease,
        color 220ms ease;
}
.wave-btn > * { position: relative; }

/* Cursor-proximity glow: JS writes --wx/--wy while the pointer is over the button. */
.wave-btn::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(140px circle at var(--wx, 50%) var(--wy, 50%), var(--wave-glow, rgba(255, 255, 255, 0.16)), transparent 70%);
    opacity: 0;
    transition: opacity 240ms ease;
}
.wave-btn:hover::before { opacity: 1; }
.wave-btn:hover { transform: translate3d(0, -1px, 0); }
.wave-btn:active {
    transform: translate3d(0, 0, 0) scale(0.98);
    transition-duration: 90ms;
}
.wave-btn:focus-visible {
    outline: 2px solid var(--tg-champagne);
    outline-offset: 3px;
}
.wave-btn:disabled,
.wave-btn[aria-disabled="true"] {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.wave-fill {
    position: absolute;
    z-index: -1;
    left: var(--wave-x);
    top: var(--wave-y);
    width: var(--wave-size);
    height: var(--wave-size);
    margin-left: calc(var(--wave-size) / -2);
    margin-top: calc(var(--wave-size) / -2);
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle, var(--wave-core, rgba(255, 255, 255, 0.34)) 0%, var(--wave-edge, rgba(255, 255, 255, 0.14)) 62%, transparent 72%);
    transform: scale(0);
    animation: tg-wave-flood 560ms var(--tg-ease-out) forwards;
    transition: opacity 420ms ease;
}
.wave-fill.is-fading { opacity: 0; }

@keyframes tg-wave-flood {
    to { transform: scale(1); }
}

/* Primary — champagne metal, dark ink. Light from above: lighter top edge,
   tight dark shadow beneath, a softer ambient shadow further out. */
.tg-btn-primary {
    --wave-core: rgba(255, 252, 240, 0.65);
    --wave-edge: rgba(255, 246, 220, 0.25);
    --wave-glow: rgba(255, 250, 235, 0.45);
    color: #17120A;
    font-weight: 700;
    background-color: var(--tg-champagne);
    background-image: linear-gradient(180deg, #F1DAA7 0%, #E2C07F 100%);
    border: 1px solid rgba(255, 236, 196, 0.55);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.55),
        0 1px 2px rgba(0, 0, 0, 0.55),
        0 10px 28px -12px rgba(230, 199, 139, 0.45);
}
.tg-btn-primary:hover {
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        0 2px 4px rgba(0, 0, 0, 0.5),
        0 16px 36px -14px rgba(230, 199, 139, 0.6);
}
.tg-btn-primary:active {
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        0 1px 1px rgba(0, 0, 0, 0.6);
}

/* Glass — titanium surface, starlight text, champagne wave. */
.tg-btn-glass {
    --wave-core: rgba(230, 199, 139, 0.30);
    --wave-edge: rgba(230, 199, 139, 0.10);
    --wave-glow: rgba(230, 199, 139, 0.14);
    color: var(--tg-starlight);
    font-weight: 600;
    background-color: rgba(13, 19, 34, 0.78);
    border: 1px solid var(--tg-hairline-strong);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 1px 2px rgba(0, 0, 0, 0.6),
        0 12px 28px -16px rgba(0, 0, 0, 0.9);
}
.tg-btn-glass:hover {
    border-color: rgba(230, 199, 139, 0.32);
    background-color: rgba(16, 23, 40, 0.88);
}

/* Ice — the cool accent, used for the second platform CTA. */
.tg-btn-ice {
    --wave-core: rgba(165, 243, 252, 0.30);
    --wave-edge: rgba(165, 243, 252, 0.10);
    --wave-glow: rgba(165, 243, 252, 0.14);
}
.tg-btn-ice:hover { border-color: rgba(165, 243, 252, 0.32); }

.tg-btn-sm { height: 2.5rem; padding: 0 1rem; border-radius: 0.75rem; font-size: 0.8125rem; }
.tg-btn-md { height: 3rem; padding: 0 1.25rem; border-radius: 0.875rem; font-size: 0.875rem; }
.tg-btn-lg { height: 3.5rem; padding: 0 1.25rem; border-radius: 1rem; font-size: 0.9375rem; }

.tg-btn-quiet {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    height: 2.5rem;
    padding: 0 0.875rem;
    border-radius: 0.75rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #CBD5E1;
    text-decoration: none;
    transition: color 180ms ease, background-color 180ms ease;
}
.tg-btn-quiet:hover { color: var(--tg-starlight); background-color: rgba(255, 255, 255, 0.04); }
.tg-btn-quiet:focus-visible { outline: 2px solid var(--tg-champagne); outline-offset: 2px; }

/* ---------------------------------------------------------------------
   Profile pill + dropdown
   --------------------------------------------------------------------- */
.tg-profile { position: relative; }

.tg-profile-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    height: 2.5rem;
    max-width: 15rem;
    padding: 0 0.75rem 0 0.25rem;
    border-radius: 9999px;
    background-color: rgba(13, 19, 34, 0.85);
    border: 1px solid var(--tg-hairline-strong);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 1px 2px rgba(0, 0, 0, 0.5);
    color: var(--tg-starlight);
    cursor: pointer;
    transition: border-color 200ms ease, background-color 200ms ease, transform 160ms var(--tg-ease-out);
}
.tg-profile-trigger:hover { border-color: rgba(230, 199, 139, 0.35); background-color: rgba(16, 23, 40, 0.95); }
.tg-profile-trigger:active { transform: scale(0.98); }
.tg-profile-trigger:focus-visible { outline: 2px solid var(--tg-champagne); outline-offset: 2px; }
.tg-profile-trigger[aria-expanded="true"] { border-color: rgba(230, 199, 139, 0.45); }

.tg-avatar {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #17120A;
    background-image: linear-gradient(160deg, #F4E6C4 0%, #D9B675 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.tg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.tg-avatar-lg { width: 2.75rem; height: 2.75rem; font-size: 0.9375rem; }

.tg-profile-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--tg-starlight);
}
.tg-profile-chevron {
    font-size: 0.625rem;
    color: var(--tg-cashmere);
    transition: transform 200ms var(--tg-ease-out);
}
.tg-profile-trigger[aria-expanded="true"] .tg-profile-chevron { transform: rotate(180deg); }

.tg-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    z-index: 60;
    width: 17rem;
    padding: 0.375rem;
    border-radius: 1rem;
    background-color: rgba(13, 19, 34, 0.98);
    border: 1px solid var(--tg-hairline-strong);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        0 4px 8px rgba(0, 0, 0, 0.45),
        0 28px 60px -20px rgba(0, 0, 0, 0.9);
    transform-origin: top right;
    animation: tg-menu-in 160ms var(--tg-ease-out);
}
@keyframes tg-menu-in {
    from { opacity: 0; transform: translateY(-4px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.tg-menu-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.75rem 0.875rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid var(--tg-hairline);
}
.tg-menu-identity { min-width: 0; }
.tg-menu-name {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--tg-starlight);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tg-menu-email {
    font-size: 0.75rem;
    color: var(--tg-cashmere);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tg-menu-plan {
    display: inline-block;
    margin-top: 0.375rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--tg-champagne-soft);
    background-color: rgba(230, 199, 139, 0.12);
}

.tg-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.625rem 0.75rem;
    border-radius: 0.625rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #CBD5E1;
    text-align: left;
    text-decoration: none;
    background: none;
    border: 0;
    cursor: pointer;
    transition: background-color 140ms ease, color 140ms ease;
}
.tg-menu-item i { width: 1rem; text-align: center; color: var(--tg-cashmere); transition: color 140ms ease; }
.tg-menu-item:hover,
.tg-menu-item:focus-visible { background-color: rgba(255, 255, 255, 0.05); color: var(--tg-starlight); outline: none; }
.tg-menu-item:hover i,
.tg-menu-item:focus-visible i { color: var(--tg-champagne); }
.tg-menu-sep { height: 1px; margin: 0.25rem 0.5rem; background-color: var(--tg-hairline); }
.tg-menu-item.is-danger:hover,
.tg-menu-item.is-danger:focus-visible { color: #FCA5A5; }
.tg-menu-item.is-danger:hover i,
.tg-menu-item.is-danger:focus-visible i { color: #FCA5A5; }

/* Stacked variant for the mobile drawer. */
.tg-mobile-account {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding-top: 0.75rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--tg-hairline);
}
.tg-mobile-account .tg-menu-head { border-bottom: 0; margin-bottom: 0; padding-left: 0.5rem; }

/* ---------------------------------------------------------------------
   Toast
   --------------------------------------------------------------------- */
.tg-toast-stack {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    pointer-events: none;
}
.tg-toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 16rem;
    max-width: 26rem;
    padding: 0.75rem 1rem;
    border-radius: 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #E2E8F0;
    background-color: rgba(13, 19, 34, 0.97);
    border: 1px solid var(--tg-hairline-strong);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4), 0 24px 48px -20px rgba(0, 0, 0, 0.9);
    animation: tg-toast-in 220ms var(--tg-ease-out);
    transition: opacity 200ms ease, transform 200ms ease;
}
.tg-toast i { color: var(--tg-champagne); }
.tg-toast.is-error i { color: #FCA5A5; }
.tg-toast.is-success i { color: #6EE7B7; }
.tg-toast.is-leaving { opacity: 0; transform: translateY(6px); }
@keyframes tg-toast-in {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .wave-btn,
    .wave-btn:hover,
    .wave-btn:active { transform: none; }
    .wave-fill { animation-duration: 1ms; }
    .tg-menu,
    .tg-toast { animation: none; }
}
