/* ── AI Floating Action Button ─────────────────────────────── */

/* gradient ring colors (cyan → sky-blue → indigo-blue) */
:root {
    --ai-grad-from: #22d3ee;
    --ai-grad-mid:  #3b82f6;
    --ai-grad-to:   #4f46e5;
}

/* Allows conic-gradient angle to be animated in @keyframes */
@property --ai-spin {
    syntax: '<angle>';
    inherits: false;
    initial-value: 0deg;
}

#ai-fab {
    position: fixed;
    bottom: 68px;   /* above the timeline scale bar */
    right: 28px;
    /* Sit above task panel (901) and timeline-select-container, so the FAB
       is reachable in every view, including the compact <=560px layout where
       the top bar widens to host the T logo + avatar. */
    z-index: 1100;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: 5px solid transparent;  /* thicker ring */
    cursor: pointer;
    display: flex !important;
    visibility: visible !important;
    opacity: 1;
    align-items: center;
    justify-content: center;
    /* silver inner + gradient ring */
    background:
        radial-gradient(circle, #f4f6f8 0%, #e8ecf0 100%) padding-box,
        linear-gradient(135deg, var(--ai-grad-from), var(--ai-grad-mid), var(--ai-grad-to)) border-box;
    color: #1c1c1e;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.14);
    transition: transform 0.2s ease, box-shadow 0.25s ease;
    animation: ai-fab-glow 3s ease-in-out infinite;
    overflow: visible;  /* allow ::before to extend outside */
    touch-action: none;
    overscroll-behavior: none;
}

/* Spinning arc overlay — plays once on click */
#ai-fab::before {
    content: '';
    position: absolute;
    /* -5px = exactly aligns with the button's 5px transparent border edge */
    inset: -5px;
    border-radius: 50%;
    background: conic-gradient(
        from var(--ai-spin),
        #22d3ee   0deg,
        #3b82f6  80deg,
        #818cf8 140deg,
        /* smooth fade-out so the arc tail blends invisibly */
        rgba(129, 140, 248, 0) 190deg,
        transparent 191deg,
        transparent 360deg
    );
    /*
     * Donut mask calibrated to the button's border:
     *   pseudo size = 54px + 5px*2 = 64px → half-radius = 32px
     *   inner edge of border = 32 - 5 = 27px = 27/32 ≈ 84%
     *   → show only the outer 16% band = the border ring
     */
    -webkit-mask: radial-gradient(farthest-side, transparent 83%, #000 84%);
    mask:         radial-gradient(farthest-side, transparent 83%, #000 84%);
    pointer-events: none;
    opacity: 0;
    z-index: 2;
}

#ai-fab.spinning::before {
    animation: ai-ring-spin 0.75s linear 1 forwards;
}

#ai-fab.spinning-close::before {
    animation: ai-ring-spin-reverse 0.75s linear 1 forwards;
}

@keyframes ai-ring-spin {
    0%   { --ai-spin: 0deg;    opacity: 1; }
    80%  { --ai-spin: 360deg;  opacity: 1; }
    100% { --ai-spin: 360deg;  opacity: 0; }
}

@keyframes ai-ring-spin-reverse {
    0%   { --ai-spin: 0deg;    opacity: 1; }
    80%  { --ai-spin: -360deg; opacity: 1; }
    100% { --ai-spin: -360deg; opacity: 0; }
}

/* Stars shimmer with gradient colors on click */
#ai-fab.spinning .ai-icon {
    animation: ai-star-shimmer 0.75s ease-out forwards;
}

@keyframes ai-star-shimmer {
    0%   { color: #1c1c1e; }
    15%  { color: #22d3ee; }
    45%  { color: #3b82f6; }
    75%  { color: #818cf8; }
    100% { color: #1c1c1e; }
}

#ai-fab:hover {
    transform: scale(1.08);
    box-shadow:
        0 4px 18px rgba(0, 0, 0, 0.15),
        0 0 0 5px rgba(34, 211, 238, 0.18);
}

#ai-fab:active {
    transform: scale(0.96);
}

/* Rotate right on open */
#ai-fab[aria-expanded="true"] .ai-icon {
    animation: ai-icon-rotate-open 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Rotate left on close */
#ai-fab.closing-rotate .ai-icon {
    animation: ai-icon-rotate-close 0.32s cubic-bezier(0.55, 0, 0.45, 1) forwards;
}

@keyframes ai-icon-rotate-open {
    0%   { transform: rotate(0deg);   }
    100% { transform: rotate(180deg); }
}

@keyframes ai-icon-rotate-close {
    0%   { transform: rotate(180deg); }
    100% { transform: rotate(0deg);   }
}

@keyframes ai-fab-glow {
    0%, 100% { box-shadow: 0 2px 12px rgba(0,0,0,0.14), 0 0 0 0   rgba(79, 70, 229, 0); }
    50%      { box-shadow: 0 2px 12px rgba(0,0,0,0.14), 0 0 0 7px rgba(79, 70, 229, 0.11); }
}

/* sparkle icon */
#ai-fab .ai-icon {
    width: 24px;
    height: 24px;
    pointer-events: none;
    position: relative;
    z-index: 3;  /* above ::before ring */
}

/* ── AI Panel ─────────────────────────────────────────────── */

#ai-panel {
    --ai-panel-text-color: var(--app-text-color, #1b1b1b);
    --ai-panel-muted-text: var(--text-muted, #666666);
    --ai-panel-border-color: var(--border-soft, #dddddd);
    --ai-panel-divider-color: color-mix(in srgb, var(--border-soft, #dddddd) 78%, transparent);
    --ai-panel-footer-bg: color-mix(in srgb, var(--app-background, #ffffff) 88%, var(--surface-muted, #f7f7f7));
    --ai-panel-input-bg: var(--surface-muted, #f7f7f7);
    --ai-panel-input-text: var(--app-text-color, #1b1b1b);
    --ai-panel-input-border: color-mix(in srgb, var(--border-soft, #dddddd) 92%, transparent);
    --ai-panel-input-placeholder: color-mix(in srgb, var(--app-text-color, #1b1b1b) 38%, transparent);
    --ai-panel-section-bg: color-mix(in srgb, var(--surface-muted, #f7f7f7) 58%, var(--app-background, #ffffff));
    --ai-panel-section-border: color-mix(in srgb, var(--border-soft, #dddddd) 96%, transparent);
    --ai-panel-section-shadow: 0 12px 24px rgba(15, 23, 42, 0.06);
    position: fixed;
    bottom: 134px;   /* above the FAB */
    right: 28px;
    /* Sit just below the FAB (1100) but above other timeline overlays. */
    z-index: 1099;
    width: min(680px, calc(100vw - 32px));
    max-height: min(82vh, 820px);
    border-radius: 16px;
    background: var(--app-background, #fff);
    border: 1px solid var(--ai-panel-border-color);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    display: none;
    flex-direction: column;
    overflow: hidden;
    touch-action: pan-y;
    overscroll-behavior-x: none;
    color: var(--ai-panel-text-color);
    /* animation base state — overridden by .open / .closing */
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    transform-origin: bottom right;
}

body.theme-day #ai-panel,
body.theme-white #ai-panel {
    --ai-panel-border-color: #d6d2c9;
    --ai-panel-divider-color: rgba(60, 44, 24, 0.12);
    --ai-panel-footer-bg: #f7f4ec;
    --ai-panel-input-bg: #fffdf7;
    --ai-panel-input-border: #cdc4b4;
    --ai-panel-input-placeholder: rgba(59, 45, 23, 0.45);
    --ai-panel-section-bg: #fbf8f1;
    --ai-panel-section-border: #d9d0c0;
    --ai-panel-section-shadow: 0 10px 26px rgba(68, 52, 31, 0.06);
}

body.theme-night-1 #ai-panel {
    --ai-panel-muted-text: rgba(255, 255, 255, 0.68);
    --ai-panel-border-color: rgba(255, 255, 255, 0.14);
    --ai-panel-divider-color: rgba(255, 255, 255, 0.08);
    --ai-panel-footer-bg: #151515;
    --ai-panel-input-bg: #0f0f0f;
    --ai-panel-input-text: #f3f3f3;
    --ai-panel-input-border: #424242;
    --ai-panel-input-placeholder: rgba(255, 255, 255, 0.38);
    --ai-panel-section-bg: rgba(255, 255, 255, 0.04);
    --ai-panel-section-border: rgba(255, 255, 255, 0.16);
    --ai-panel-section-shadow: 0 18px 30px rgba(0, 0, 0, 0.22);
}

body.theme-night-2 #ai-panel {
    --ai-panel-muted-text: rgba(255, 255, 255, 0.68);
    --ai-panel-border-color: rgba(255, 255, 255, 0.12);
    --ai-panel-divider-color: rgba(255, 255, 255, 0.07);
    --ai-panel-footer-bg: #101010;
    --ai-panel-input-bg: #090909;
    --ai-panel-input-text: #f6f6f6;
    --ai-panel-input-border: #3e3e3e;
    --ai-panel-input-placeholder: rgba(255, 255, 255, 0.36);
    --ai-panel-section-bg: rgba(255, 255, 255, 0.035);
    --ai-panel-section-border: rgba(255, 255, 255, 0.14);
    --ai-panel-section-shadow: 0 18px 30px rgba(0, 0, 0, 0.26);
}

#ai-panel.open {
    display: flex;
    animation: ai-panel-in 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

#ai-panel.closing {
    display: flex;
    animation: ai-panel-out 0.22s cubic-bezier(0.55, 0, 0.45, 1) forwards;
}

@keyframes ai-panel-in {
    0%   { opacity: 0; transform: translateY(20px) scale(0.93); }
    60%  { opacity: 1; transform: translateY(-4px) scale(1.01); }
    100% { opacity: 1; transform: translateY(0)   scale(1);    }
}

@keyframes ai-panel-out {
    0%   { opacity: 1; transform: translateY(0)   scale(1);    }
    100% { opacity: 0; transform: translateY(14px) scale(0.94); }
}

/* header */
.ai-panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--ai-panel-divider-color);
    background: linear-gradient(135deg, var(--ai-grad-from), var(--ai-grad-mid), var(--ai-grad-to));
    color: #fff;
    touch-action: pan-y;
}

.ai-panel-header .ai-panel-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.ai-panel-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    font-family: 'Montserrat', sans-serif;
    letter-spacing: 0.02em;
}

.ai-panel-header .ai-panel-badge-meta {
    margin-left: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.ai-panel-header .ai-panel-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 2px 8px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.2);
}

.ai-panel-header .ai-panel-badge-note {
    font-size: 9px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.82);
}

/* body */
.ai-panel-body {
    flex: 1;
    padding: 20px 18px;
    overflow-y: auto;
    touch-action: pan-y;
    overscroll-behavior-x: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-align: center;
    color: var(--ai-panel-muted-text);
    font-family: 'Montserrat', sans-serif;
}

.ai-panel-body .ai-placeholder-icon {
    width: 48px;
    height: 48px;
    opacity: 0.25;
}

.ai-panel-body p {
    margin: 0;
    font-size: 13px;
    line-height: 1.55;
}

.ai-panel-workspace-body {
    align-items: stretch;
    justify-content: flex-start;
    gap: 16px;
    text-align: left;
}

.ai-panel-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    text-align: center;
    padding: 20px 16px 14px;
    border: 1px dashed var(--ai-panel-section-border);
    border-radius: 18px;
    background: var(--ai-panel-section-bg);
}

.ai-panel-empty-state p {
    max-width: 460px;
}

.ai-panel-empty-state .ai-panel-empty-example {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(100%, 560px);
    max-width: 560px;
    padding: 0;
    border: none;
    background: transparent;
    text-align: left;
}

.ai-panel-empty-state .ai-panel-empty-example-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: color-mix(in srgb, var(--ai-panel-muted-text) 90%, transparent);
    text-align: center;
}

.ai-panel-empty-state .ai-panel-empty-example-copy {
    margin: 0;
    max-width: none;
    font-size: 11px;
    line-height: 1.65;
    color: color-mix(in srgb, var(--ai-panel-text-color, #1b1b1b) 78%, var(--ai-panel-muted-text));
    font-style: italic;
    text-align: justify;
    opacity: 0.95;
}

.ai-example-carousel {
    width: 100%;
    gap: 12px;
}

.ai-example-carousel-header {
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: center;
}

.ai-example-carousel-hint {
    max-width: 420px;
    font-size: 11px;
    line-height: 1.4;
    color: var(--ai-panel-muted-text);
    text-align: center;
}

.ai-example-carousel-stage {
    width: 100%;
}

.ai-example-slide {
    width: 100%;
}

.ai-example-slide-surface {
    display: grid;
    width: 100%;
    gap: 12px;
    padding: 16px 18px;
    border: 1px solid color-mix(in srgb, var(--ai-panel-section-border) 92%, transparent);
    border-radius: 20px;
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--ai-panel-section-bg) 92%, transparent), color-mix(in srgb, var(--app-background, #ffffff) 90%, var(--ai-panel-section-bg))),
        color-mix(in srgb, var(--ai-panel-section-bg) 88%, transparent);
    color: var(--ai-panel-text-color);
    cursor: pointer;
    text-align: left;
    box-shadow: 0 16px 30px color-mix(in srgb, var(--ai-grad-mid) 8%, transparent);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
    font: inherit;
}

.ai-example-slide-surface:hover,
.ai-example-slide-surface:focus-visible {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--ai-grad-mid) 34%, var(--ai-panel-section-border));
    box-shadow: 0 20px 36px color-mix(in srgb, var(--ai-grad-mid) 12%, transparent);
    outline: none;
}

.ai-example-slide-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.ai-example-slide-kicker {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border: 1px solid color-mix(in srgb, var(--ai-panel-section-border) 88%, transparent);
    border-radius: 999px;
    background: color-mix(in srgb, var(--app-background, #ffffff) 42%, transparent);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ai-panel-muted-text);
}

.ai-example-slide-use {
    font-size: 11px;
    line-height: 1.3;
    color: color-mix(in srgb, var(--ai-panel-muted-text) 92%, transparent);
}

.ai-example-slide-title {
    margin: 0;
    font-size: 18px;
    line-height: 1.28;
    font-weight: 700;
    color: var(--ai-panel-text-color);
}

.ai-example-slide-prompt {
    max-height: 154px;
    overflow-y: auto;
    padding-right: 6px;
}

.ai-example-carousel .ai-panel-empty-example-copy {
    color: color-mix(in srgb, var(--ai-panel-text-color, #1b1b1b) 82%, var(--ai-panel-muted-text));
    font-size: 12px;
    line-height: 1.72;
    text-align: left;
    font-style: normal;
    opacity: 1;
}

.ai-example-carousel-controls {
    display: grid;
    grid-template-columns: 36px auto 36px;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: fit-content;
    margin: 0 auto;
}

.ai-example-carousel-arrow {
    display: inline-flex;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--ai-panel-section-border);
    border-radius: 999px;
    background: color-mix(in srgb, var(--ai-panel-section-bg) 74%, var(--app-background, #ffffff));
    color: var(--ai-panel-text-color);
    cursor: pointer;
    font: inherit;
    font-size: 15px;
    line-height: 1;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.ai-example-carousel-arrow:hover,
.ai-example-carousel-arrow:focus-visible {
    background: color-mix(in srgb, var(--ai-grad-mid) 14%, var(--ai-panel-section-bg));
    border-color: color-mix(in srgb, var(--ai-grad-mid) 34%, var(--ai-panel-section-border));
    outline: none;
    transform: translateY(-1px);
}

.ai-example-carousel-dots {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-example-carousel-dot {
    width: 8px;
    height: 8px;
    border: none;
    border-radius: 999px;
    background: color-mix(in srgb, var(--ai-panel-muted-text) 60%, transparent);
    cursor: pointer;
    padding: 0;
    transition: width 0.15s ease, background-color 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}

.ai-example-carousel-dot:hover,
.ai-example-carousel-dot:focus-visible {
    opacity: 0.9;
    transform: scale(1.05);
    outline: none;
}

.ai-example-carousel-dot.is-active {
    width: 22px;
    background: linear-gradient(135deg, var(--ai-grad-from), var(--ai-grad-mid), var(--ai-grad-to));
}

.ai-panel-status {
    display: block;
    min-height: 1.4em;
    color: var(--ai-panel-muted-text);
}

/* footer input area */
.ai-panel-footer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--ai-panel-divider-color);
    background: var(--ai-panel-footer-bg);
    touch-action: pan-y;
    overscroll-behavior-x: none;
}

.ai-panel-composer {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 6px;
}

.ai-panel-composer-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ai-panel-muted-text);
}

.ai-panel-footer textarea {
    flex: 1;
    border: 1px solid var(--ai-panel-input-border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    font-family: 'Montserrat', sans-serif;
    background-color: var(--ai-panel-input-bg);
    background-image: none;
    color: var(--ai-panel-input-text);
    caret-color: var(--ai-panel-input-text);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
    min-height: 88px;
    resize: vertical;
}

.ai-panel-footer textarea::placeholder {
    color: var(--ai-panel-input-placeholder);
}

.ai-panel-footer textarea:focus {
    border-color: var(--ai-grad-mid);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ai-grad-mid) 20%, transparent);
}

.ai-panel-footer button {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, var(--ai-grad-from), var(--ai-grad-mid), var(--ai-grad-to));
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.ai-panel-footer button:hover {
    opacity: 0.85;
}

.ai-panel-footer button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 560px) {
    #ai-fab {
          /* iOS can keep html/body clipped to the layout viewport while fixed
              elements render against a wider visual viewport. Anchor the FAB to
              the layout viewport here so it stays inside the clipped root box. */
          position: absolute;
        /* Must stay visible even though the top selector bar widens to
           include the T logo and avatar at this breakpoint. */
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 70px);
        right: 14px;
        width: 50px;
        height: 50px;
    }

    #ai-panel {
        position: absolute;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 138px);
        right: 12px;
        left: 12px;
        width: auto;
        max-height: 74vh;
    }

    .ai-panel-footer textarea {
        font-size: 16px;
    }

    .ai-panel-header .ai-panel-badge {
        font-size: 12px;
        padding: 3px 9px;
    }
}

@media (max-width: 480px) {
    #ai-fab {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 68px);
        right: 12px;
        width: 48px;
        height: 48px;
        font-size: 20px;
    }

    #ai-panel {
        bottom: calc(env(safe-area-inset-bottom, 0px) + 130px);
        right: 12px;
        left: 12px;
        width: auto;
        max-height: 72vh;
    }

    .ai-panel-footer {
        align-items: stretch;
    }

    .ai-example-slide-surface {
        gap: 10px;
        padding: 14px 14px;
    }

    .ai-example-slide-title {
        font-size: 15px;
    }

    .ai-example-slide-prompt {
        max-height: 112px;
    }

    .ai-example-carousel .ai-panel-empty-example-copy {
        font-size: 11px;
    }

    .ai-example-carousel-hint {
        font-size: 10px;
    }

    .ai-example-slide-use {
        font-size: 10px;
    }
}
