/* /Components/Pages/AIChat.razor.rz.scp.css */
/* NOTE on ::deep — Blazor CSS isolation rewrites a selector by appending this
   component's scope attribute to its LAST element, e.g. ".ai-markdown p" becomes
   ".ai-markdown p[b-xxxxx]". That attribute is only stamped on elements the Razor
   compiler emits. Claude's reply is injected as a MarkupString (see RenderMarkdown),
   and the chart-type icons are MarkupString too, so those <p>/<ul>/<svg> elements
   never carry it. "::deep" moves the scope onto the ancestor that IS compiler-emitted
   and leaves the rest of the selector plain, which is the only way these rules reach
   injected markup at all. */

/* Styles for the Markdown Claude's replies render into (see RenderMarkdown /
   AIChat.razor). Blazor CSS isolation scopes all of this to .ai-markdown
   elements inside AIChat.razor only — nothing here leaks to other pages.
   Deliberately plain CSS (not Tailwind's typography plugin), since we don't
   know whether that plugin is installed/configured in tailwind.config.js. */

.ai-markdown[b-sokx9ajc9p]  p {
    margin: 0 0 0.5rem 0;
    line-height: 1.45;
}

.ai-markdown[b-sokx9ajc9p]  p:last-child {
    margin-bottom: 0;
}

.ai-markdown[b-sokx9ajc9p]  ul,
.ai-markdown[b-sokx9ajc9p]  ol {
    margin: 0.25rem 0 0.6rem 1.15rem;
    padding: 0;
}

.ai-markdown[b-sokx9ajc9p]  ul {
    list-style-type: disc;
}

.ai-markdown[b-sokx9ajc9p]  ol {
    list-style-type: decimal;
}

.ai-markdown[b-sokx9ajc9p]  li {
    margin: 0.2rem 0;
    line-height: 1.4;
}

.ai-markdown[b-sokx9ajc9p]  li > ul,
.ai-markdown[b-sokx9ajc9p]  li > ol {
    margin-top: 0.2rem;
    margin-bottom: 0.2rem;
}

.ai-markdown[b-sokx9ajc9p]  ul:last-child,
.ai-markdown[b-sokx9ajc9p]  ol:last-child {
    margin-bottom: 0;
}

.ai-markdown[b-sokx9ajc9p]  strong {
    font-weight: 600;
}

/* Claude sometimes uses a bold line as a de-facto section header (e.g.
   "**Hallazgos críticos:**") rather than a real #heading — give real
   headings a bit more presence too, in case UseAdvancedExtensions() output
   ever includes one. */
.ai-markdown[b-sokx9ajc9p]  h1,
.ai-markdown[b-sokx9ajc9p]  h2,
.ai-markdown[b-sokx9ajc9p]  h3,
.ai-markdown[b-sokx9ajc9p]  h4 {
    font-size: 0.9rem;
    font-weight: 700;
    margin: 0.6rem 0 0.3rem 0;
}

.ai-markdown[b-sokx9ajc9p]  h1:first-child,
.ai-markdown[b-sokx9ajc9p]  h2:first-child,
.ai-markdown[b-sokx9ajc9p]  h3:first-child,
.ai-markdown[b-sokx9ajc9p]  h4:first-child {
    margin-top: 0;
}

.ai-markdown[b-sokx9ajc9p]  code {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 0.25rem;
    padding: 0.05rem 0.3rem;
    font-size: 0.8125rem;
}

.ai-markdown[b-sokx9ajc9p]  a {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ai-markdown[b-sokx9ajc9p]  blockquote {
    border-left: 3px solid rgba(0, 0, 0, 0.15);
    margin: 0.4rem 0;
    padding-left: 0.75rem;
    color: #4b5563; /* tailwind gray-600, matched by hex since this is plain CSS */
}

.ai-markdown[b-sokx9ajc9p]  hr {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin: 0.6rem 0;
}

/* ---------------------------------------------------------------------
   AI chart card — the container Chart.js/Plotly render into. One element
   tree serves BOTH the inline and the "desanclado" (undocked/expanded)
   state; only classes toggle, so the canvas/div is never torn down and
   re-created by the expand/collapse click (that would force a re-render
   round-trip through Blazor). Colors/tokens here match the dataviz skill's
   validated reference palette (chart chrome & ink section) so the card
   frame doesn't fight the series colors drawn inside it.
   ------------------------------------------------------------------- */

.ai-chart-backdrop[b-sokx9ajc9p] {
    position: fixed;
    inset: 0;
    background: rgba(11, 11, 11, 0.001); /* present in DOM even when invisible so opacity can transition */
    opacity: 0;
    pointer-events: none;
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    transition: opacity 0.28s ease, backdrop-filter 0.28s ease;
    z-index: 40;
}

.ai-chart-backdrop--visible[b-sokx9ajc9p] {
    background: rgba(11, 11, 11, 0.45);
    opacity: 1;
    pointer-events: auto;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.ai-chart-card[b-sokx9ajc9p] {
    position: relative;
    width: 100%;
    max-width: 640px;
    margin-top: 0.5rem;
    background: #fcfcfb;
    border: 1px solid rgba(11, 11, 11, 0.08);
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px -12px rgba(11, 11, 11, 0.18);
    overflow: hidden;
    z-index: 41;
    transition: box-shadow 0.28s ease, transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1),
        max-width 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), width 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.ai-chart-card:hover[b-sokx9ajc9p] {
    box-shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 12px 32px -12px rgba(11, 11, 11, 0.24);
}

/* "Desanclado": lifted off the chat flow into a centered overlay, large
   enough to actually read a busy chart's legend/labels. Chart.js and
   Plotly are both configured responsive + !maintainAspectRatio, so simply
   resizing this container is enough — no re-render call needed. */
.ai-chart-card--expanded[b-sokx9ajc9p] {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 1100px);
    max-width: min(92vw, 1100px);
    height: min(86vh, 720px);
    margin-top: 0;
    z-index: 50;
    box-shadow: 0 24px 64px -16px rgba(11, 11, 11, 0.45), 0 2px 8px rgba(11, 11, 11, 0.12);
}

/* ---------------------------------------------------------------------
   Whole-panel dock/undock ("anclar"/"maximizar") — the same pattern as
   ai-chart-backdrop/ai-chart-card--expanded above, one level up: instead of
   lifting just the chart out of the page flow, this lifts the entire
   assistant (header, history, input) into a fixed full-viewport card. Kept
   BELOW the chart's own expanded z-index (50) on purpose: if the user
   maximizes the whole panel and then also expands a chart inside it, the
   chart should still win and render on top of the maximized chat, exactly
   like it would on the un-maximized page.
   ------------------------------------------------------------------- */

.ai-page-backdrop[b-sokx9ajc9p] {
    position: fixed;
    inset: 0;
    background: rgba(11, 11, 11, 0.001);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
    z-index: 44;
}

.ai-page-backdrop--visible[b-sokx9ajc9p] {
    background: rgba(11, 11, 11, 0.4);
    opacity: 1;
    pointer-events: auto;
}

.ai-page--maximized[b-sokx9ajc9p] {
    position: fixed;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    max-width: none;
    width: auto;
    height: auto;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 24px 64px -16px rgba(11, 11, 11, 0.45), 0 2px 8px rgba(11, 11, 11, 0.12);
    z-index: 45;
}

@media (max-width: 480px) {
    .ai-page--maximized[b-sokx9ajc9p] {
        top: 0.5rem;
        left: 0.5rem;
        right: 0.5rem;
        bottom: 0.5rem;
    }
}

.ai-chart-card__header[b-sokx9ajc9p] {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
    background: linear-gradient(180deg, #ffffff 0%, #fcfcfb 100%);
    border-bottom: 1px solid #e1e0d9;
}

.ai-chart-card__icon[b-sokx9ajc9p] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: linear-gradient(135deg, #2a78d6 0%, #4a3aa7 100%);
    color: #ffffff;
    flex: 0 0 auto;
}

.ai-chart-card__icon[b-sokx9ajc9p]  svg {
    width: 15px;
    height: 15px;
}

.ai-chart-card__title[b-sokx9ajc9p] {
    font-size: 0.85rem;
    font-weight: 600;
    color: #0b0b0b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chart-card__spacer[b-sokx9ajc9p] {
    flex: 1 1 auto;
}

.ai-chart-card__btn[b-sokx9ajc9p] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex: 0 0 auto;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: #52514e;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.ai-chart-card__btn:hover[b-sokx9ajc9p] {
    background: rgba(11, 11, 11, 0.06);
    color: #0b0b0b;
}

.ai-chart-card__btn:active[b-sokx9ajc9p] {
    background: rgba(11, 11, 11, 0.1);
}

.ai-chart-card__btn svg[b-sokx9ajc9p] {
    width: 15px;
    height: 15px;
}

.ai-chart-card__body[b-sokx9ajc9p] {
    position: relative;
    height: 260px;
    padding: 0.75rem;
}

.ai-chart-card--expanded .ai-chart-card__body[b-sokx9ajc9p] {
    height: calc(100% - 48px); /* header is ~48px tall */
    padding: 1rem 1.25rem 1.25rem;
}

.ai-chart-card__body canvas[b-sokx9ajc9p],
.ai-chart-card__body > div[b-sokx9ajc9p] {
    width: 100% !important;
    height: 100% !important;
}

@media (max-width: 480px) {
    .ai-chart-card--expanded[b-sokx9ajc9p] {
        width: 96vw;
        max-width: 96vw;
        height: 80vh;
    }
}

/* Header control that is "on" (the table toggle while the table is open). */
.ai-chart-card__btn--on[b-sokx9ajc9p] {
    background: rgba(42, 120, 214, 0.12);
    color: #2a78d6;
}

.ai-chart-card__btn--on:hover[b-sokx9ajc9p] {
    background: rgba(42, 120, 214, 0.18);
    color: #2a78d6;
}

/* ---------------------------------------------------------------------
   Segmented control — the chart's shape switcher. One control, one
   selected state; it redraws the numbers already on screen rather than
   asking the assistant again.
   ------------------------------------------------------------------- */

.ai-seg[b-sokx9ajc9p] {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    margin-right: 2px;
    border-radius: 8px;
    background: rgba(11, 11, 11, 0.05);
    flex: 0 0 auto;
}

.ai-seg__btn[b-sokx9ajc9p] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 24px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #898781;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.ai-seg__btn[b-sokx9ajc9p]  svg {
    width: 14px;
    height: 14px;
}

.ai-seg__btn:hover[b-sokx9ajc9p] {
    color: #52514e;
}

.ai-seg__btn--on[b-sokx9ajc9p] {
    background: #ffffff;
    color: #2a78d6;
    box-shadow: 0 1px 2px rgba(11, 11, 11, 0.12);
}

/* ---------------------------------------------------------------------
   The numbers behind the chart
   ------------------------------------------------------------------- */

/* With the table open the card becomes a column: header fixed, chart
   flexible, table pinned under it with its own scroll. Without it the card
   keeps its simple auto height. */
.ai-chart-card--with-table[b-sokx9ajc9p] {
    display: flex;
    flex-direction: column;
}

.ai-chart-card--with-table .ai-chart-card__body[b-sokx9ajc9p] {
    flex: 1 1 auto;
    min-height: 180px;
}

.ai-chart-card--expanded.ai-chart-card--with-table .ai-chart-card__body[b-sokx9ajc9p] {
    height: auto;
}

.ai-chart-table[b-sokx9ajc9p] {
    flex: 0 0 auto;
    border-top: 1px solid #e1e0d9;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 240px;
}

.ai-chart-card--expanded .ai-chart-table[b-sokx9ajc9p] {
    max-height: 42%;
}

.ai-chart-table__bar[b-sokx9ajc9p] {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid #f0efec;
    flex: 0 0 auto;
}

.ai-chart-table__count[b-sokx9ajc9p] {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #898781;
}

.ai-chart-table__scroll[b-sokx9ajc9p] {
    overflow: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.ai-chart-table table[b-sokx9ajc9p] {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.ai-chart-table th[b-sokx9ajc9p],
.ai-chart-table td[b-sokx9ajc9p] {
    padding: 0.35rem 0.6rem;
    text-align: right;
    white-space: nowrap;
    border-bottom: 1px solid #f0efec;
}

/* First column is the category (a date, a cashier, a station) — the rest are
   numbers, which line up only with tabular figures. */
.ai-chart-table th:first-child[b-sokx9ajc9p],
.ai-chart-table td:first-child[b-sokx9ajc9p] {
    text-align: left;
    white-space: normal;
    min-width: 8rem;
}

.ai-chart-table td:not(:first-child)[b-sokx9ajc9p] {
    font-variant-numeric: tabular-nums;
    color: #0b0b0b;
}

.ai-chart-table thead th[b-sokx9ajc9p] {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #fcfcfb;
    font-weight: 600;
    color: #52514e;
    border-bottom: 1px solid #e1e0d9;
}

.ai-chart-table tbody tr:hover td[b-sokx9ajc9p] {
    background: rgba(42, 120, 214, 0.05);
}

.ai-chart-table tbody tr:last-child td[b-sokx9ajc9p] {
    border-bottom: none;
}

/* ---------------------------------------------------------------------
   Chat chrome: ghost buttons, message entrance, copy affordance, waiting
   ------------------------------------------------------------------- */

.ai-ghost-btn[b-sokx9ajc9p] {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.6rem;
    border: 1px solid #e1e0d9;
    border-radius: 8px;
    background: #ffffff;
    font-size: 0.78rem;
    font-weight: 500;
    color: #52514e;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ai-ghost-btn:hover[b-sokx9ajc9p] {
    background: #fcfcfb;
    border-color: #c3c2b7;
    color: #0b0b0b;
}

.ai-ghost-btn:disabled[b-sokx9ajc9p] {
    opacity: 0.5;
    cursor: default;
}

.ai-ghost-btn svg[b-sokx9ajc9p] {
    width: 14px;
    height: 14px;
}

.ai-ghost-btn--sm[b-sokx9ajc9p] {
    padding: 0.2rem 0.45rem;
    font-size: 0.72rem;
}

/* Messages arrive rather than appear. Short and subtle on purpose — this fires
   on every reply, and anything longer starts feeling slow instead of smooth. */
.ai-msg[b-sokx9ajc9p] {
    animation: ai-msg-in-b-sokx9ajc9p 0.22s ease-out both;
}

@keyframes ai-msg-in-b-sokx9ajc9p {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Copy sits inside the bubble's top-right corner and stays out of the way until
   the bubble is hovered — always-visible chrome on every message is noise. It
   remains keyboard-reachable: :focus-within keeps it shown when tabbed to. */
.ai-bubble-assistant[b-sokx9ajc9p] {
    padding-right: 2rem;
}

.ai-copy-btn[b-sokx9ajc9p] {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #898781;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.ai-copy-btn svg[b-sokx9ajc9p] {
    width: 14px;
    height: 14px;
}

.ai-bubble-assistant:hover .ai-copy-btn[b-sokx9ajc9p],
.ai-bubble-assistant:focus-within .ai-copy-btn[b-sokx9ajc9p] {
    opacity: 1;
}

.ai-copy-btn:hover[b-sokx9ajc9p] {
    background: rgba(11, 11, 11, 0.07);
    color: #0b0b0b;
}

.ai-copy-btn:focus-visible[b-sokx9ajc9p] {
    opacity: 1;
    outline: 2px solid #2a78d6;
    outline-offset: 1px;
}

/* Waiting indicator. A tool-use turn is several model round-trips plus the real
   report queries, so this can sit for a while — motion says "working", a static
   line of text says "stuck". It is not a progress bar: nothing on this page
   knows how far along the request is, so it never pretends to. */
.ai-dots[b-sokx9ajc9p] {
    display: inline-flex;
    align-items: flex-end;
    gap: 3px;
    height: 1em;
}

.ai-dots i[b-sokx9ajc9p] {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #898781;
    animation: ai-dot-b-sokx9ajc9p 1.1s ease-in-out infinite;
}

.ai-dots i:nth-child(2)[b-sokx9ajc9p] {
    animation-delay: 0.15s;
}

.ai-dots i:nth-child(3)[b-sokx9ajc9p] {
    animation-delay: 0.3s;
}

@keyframes ai-dot-b-sokx9ajc9p {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

/* Anyone who has asked the OS to cut motion gets none of the above. */
@media (prefers-reduced-motion: reduce) {
    .ai-msg[b-sokx9ajc9p],
    .ai-dots i[b-sokx9ajc9p] {
        animation: none;
    }

    .ai-chart-card[b-sokx9ajc9p],
    .ai-chart-backdrop[b-sokx9ajc9p],
    .ai-page-backdrop[b-sokx9ajc9p] {
        transition: none;
    }
}
