/* ===================================
   Layout variables. Colours and fonts come from the design system
   (WareVision.Design tokens.css); the old --ct-* names are aliases there.
   =================================== */
:root {
    --container-max-width: 1100px;
    /* Sidebar dimensions */
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 64px;
}

/* ===================================
   Info Tooltip Icons - Lighter Gray
   =================================== */
.fa-info-circle,
.fa-circle-info {
    color: var(--ink-faint) !important;
}

/* Info icons in alerts should inherit alert color */
.alert .fa-info-circle,
.alert .fa-circle-info {
    color: inherit !important;
}

/* ===================================
   Templates Page Styles
   =================================== */
.templates-root .swatch {
    width: 36px;
    height: 22px;
    border-radius: 4px;
    border: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
}

    .templates-root .swatch.primary {
        background: var(--signal);
    }

    .templates-root .swatch.dark {
        background: var(--inverse);
    }

    .templates-root .swatch.contrast {
        background: var(--crit);
    }

.templates-root .theme-swatch {
    text-align: center;
    width: 64px;
}

.templates-root .preview-area {
    background: var(--surface-raised);
    border: 1px solid color-mix(in srgb, var(--ink) 4%, transparent);
}

/* Container boxed variant */
.templates-root .container-boxed {
    max-width: var(--container-max-width);
    margin: 0 auto;
    background: var(--surface-raised);
}

/* Template card tweaks */
.templates-root .template-card img {
    max-height: 140px;
    object-fit: cover;
}

.templates-root .template-card .card-title {
    color: var(--ink);
}

/* Preview area primary button styling */
.templates-root .preview-area .btn-primary {
    background: var(--signal);
    border-color: var(--signal);
}

/* ===================================
   Modal Template Styles
   =================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: none;
    align-items: center;
    justify-content: center;
}

    .modal-overlay.show {
        display: flex;
    }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--ink) 55%, transparent);
    backdrop-filter: blur(2px);
    z-index: 1051;
}

.modal-centered {
    position: relative;
    z-index: 1060;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    width: 100%;
}

.modal-card {
    width: 100%;
    max-width: 720px;
    background: var(--surface-raised);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 30px color-mix(in srgb, var(--ink) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--ink) 6%, transparent);
}

.modal-close button {
    font-size: 1.05rem;
}

/* ===================================
   Gauge Chart Styles
   =================================== */
.gauge-container {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 0 auto;
}

.gauge {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.gauge-bg {
    fill: none;
    stroke: var(--line);
    stroke-width: 10;
}

.gauge-fill {
    fill: none;
    stroke-width: 10;
    stroke-linecap: round;
    transition: stroke-dasharray 0.5s ease-in-out, stroke 0.5s ease-in-out;
}

.gauge-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--ink);
}

/* ===================================
   Responsive Styles
   =================================== */
@media (max-width: 576px) {
    .templates-root {
        padding: 1rem;
    }

    .modal-card {
        max-width: 92%;
    }

    .gauge-container {
        width: 80px;
        height: 80px;
    }

    .gauge-value {
        font-size: 1rem;
    }
}

/* ===================================
   Button Styles
   =================================== */
.btn-save-config {
    color: var(--on-inverse);
    background: linear-gradient(135deg, var(--signal) 0%, var(--signal) 100%);
    border: none;
    padding: 0.5rem 1.25rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-save-config:hover {
    color: var(--on-inverse);
    background: linear-gradient(135deg, var(--signal) 0%, var(--signal) 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--signal) 30%, transparent);
}

.btn-save-config:disabled {
    color: var(--on-inverse);
    background: linear-gradient(135deg, var(--signal) 0%, var(--signal) 100%);
    opacity: 0.65;
    transform: none;
    box-shadow: none;
}

.btn-save-config:focus {
    box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--signal) 25%, transparent);
}

.btn-save-config.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
}

/* ===================================
   Copilot Chatbot Styles
   =================================== */
.copilot-chatbot-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Floating help button */
.copilot-help-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--signal) 0%, var(--inverse) 100%);
    color: var(--on-inverse);
    font-size: 1.5rem;
    cursor: grab;
    box-shadow: 0 4px 16px color-mix(in srgb, var(--signal) 40%, transparent);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    user-select: none;
}

.copilot-help-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px color-mix(in srgb, var(--signal) 50%, transparent);
}

.copilot-help-button:active {
    cursor: grabbing;
}

.copilot-help-button.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0);
}

/* Chat window - positioned relative to container */
.copilot-chat-window {
    position: fixed;
    width: 380px;
    height: 520px;
    background: var(--surface-raised);
    border-radius: 16px;
    box-shadow: 0 8px 32px color-mix(in srgb, var(--ink) 15%, transparent);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
}

/* Position chat window based on container edge */
.copilot-chatbot-container[data-edge="bottom"] .copilot-chat-window,
.copilot-chatbot-container:not([data-edge]) .copilot-chat-window {
    bottom: 70px;
    right: 0;
    left: auto;
    top: auto;
}

.copilot-chatbot-container[data-edge="top"] .copilot-chat-window {
    top: 70px;
    bottom: auto;
    left: auto;
    right: 0;
    transform-origin: top right;
}

.copilot-chatbot-container[data-edge="left"] .copilot-chat-window {
    left: 70px;
    right: auto;
    bottom: 0;
    top: auto;
    transform-origin: bottom left;
}

.copilot-chatbot-container[data-edge="right"] .copilot-chat-window {
    right: 70px;
    left: auto;
    bottom: 0;
    top: auto;
    transform-origin: bottom right;
}

.copilot-chat-window.closed {
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
}

.copilot-chat-window.open {
    opacity: 1;
    transform: scale(1);
}

/* Chat header */
.copilot-chat-header {
    background: linear-gradient(135deg, var(--signal) 0%, var(--inverse) 100%);
    color: var(--on-inverse);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.copilot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.copilot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--on-inverse) 20%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.copilot-header-text {
    display: flex;
    flex-direction: column;
}

.copilot-title {
    font-weight: 600;
    font-size: 1rem;
}

.copilot-status {
    font-size: 0.75rem;
    opacity: 0.9;
}

.copilot-status.online::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--good-night);
    border-radius: 50%;
    margin-right: 6px;
}

.copilot-status.offline::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--warn-night);
    border-radius: 50%;
    margin-right: 6px;
    animation: pulse 1.5s infinite;
}

.copilot-close-button {
    background: color-mix(in srgb, var(--on-inverse) 20%, transparent);
    border: none;
    color: var(--on-inverse);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.copilot-close-button:hover {
    background: color-mix(in srgb, var(--on-inverse) 30%, transparent);
}

/* Messages area */
.copilot-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
    padding: 16px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Welcome message */
.copilot-welcome-message {
    text-align: center;
    padding: 24px;
    color: var(--ink-muted);
}

.copilot-welcome-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--signal) 0%, var(--inverse) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 1.75rem;
    color: var(--on-inverse);
}

.copilot-welcome-message h5 {
    color: var(--ink);
    margin-bottom: 8px;
}

.copilot-welcome-message p {
    font-size: 0.9rem;
    margin: 0;
}

/* Message bubble */
.copilot-message {
    display: flex;
    gap: 8px;
    max-width: 85%;
}

.copilot-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.copilot-message.assistant {
    align-self: flex-start;
}

.copilot-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--signal) 0%, var(--inverse) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--on-inverse);
    font-size: 0.85rem;
    flex-shrink: 0;
}

.copilot-message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    /* Flex item: allow it to shrink below its content width, otherwise a single
       long token (URL, device serial, base64) pushes the bubble out of the panel */
    min-width: 0;
    max-width: 100%;
}

.copilot-message-text {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.copilot-message.user .copilot-message-text {
    background: linear-gradient(135deg, var(--signal) 0%, var(--inverse) 100%);
    color: var(--on-inverse);
    border-bottom-right-radius: 4px;
}

.copilot-message.assistant .copilot-message-text {
    background: var(--surface-raised);
    color: var(--ink);
    border: 1px solid var(--line);
    border-bottom-left-radius: 4px;
}

.copilot-message-time {
    font-size: 0.7rem;
    color: var(--ink-muted);
    padding: 0 4px;
}

.copilot-message.user .copilot-message-time {
    text-align: right;
}

/* Typing indicator */
.copilot-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.copilot-typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--ink-faint);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.copilot-typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.copilot-typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Input area */
.copilot-chat-input {
    padding: 12px 16px 16px;
    background: var(--surface-raised);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}

.copilot-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    transition: border-color 0.2s ease;
}

.copilot-input-wrapper:focus-within {
    border-color: var(--signal);
}

.copilot-input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 0.9rem;
    padding: 8px 0;
    max-height: 120px;
    font-family: inherit;
    line-height: 1.4;
}

.copilot-input-wrapper textarea:focus {
    outline: none;
}

.copilot-input-wrapper textarea::placeholder {
    color: var(--ink-muted);
}

.copilot-send-button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--signal) 0%, var(--inverse) 100%);
    color: var(--on-inverse);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.copilot-send-button:hover:not(:disabled) {
    transform: scale(1.05);
}

.copilot-send-button:disabled {
    background: var(--ink-faint);
    cursor: not-allowed;
}

.copilot-input-footer {
    text-align: center;
    margin-top: 8px;
}

.copilot-input-footer small {
    font-size: 0.7rem;
}

/* ---- Rich content inside assistant bubbles ----
   Replies are markdown rendered to HTML, so the bubble can contain lists, tables,
   code and headings. Everything below keeps that readable inside a narrow panel. */
.copilot-message-text > :first-child {
    margin-top: 0;
}

.copilot-message-text > :last-child {
    margin-bottom: 0;
}

.copilot-message-text p {
    margin: 0 0 8px;
}

.copilot-message-text strong {
    font-weight: 600;
}

.copilot-message-text em {
    font-style: italic;
}

/* Agent headings must not render at browser default size in a 380px bubble */
.copilot-message-text h1,
.copilot-message-text h2,
.copilot-message-text h3,
.copilot-message-text h4,
.copilot-message-text h5,
.copilot-message-text h6 {
    margin: 10px 0 6px;
    font-weight: 600;
    line-height: 1.3;
}

.copilot-message-text h1 {
    font-size: 1.05rem;
}

.copilot-message-text h2 {
    font-size: 1rem;
}

.copilot-message-text h3 {
    font-size: 0.95rem;
}

.copilot-message-text h4,
.copilot-message-text h5,
.copilot-message-text h6 {
    font-size: 0.9rem;
}

.copilot-message-text ul,
.copilot-message-text ol {
    margin: 6px 0 8px;
    padding-left: 20px;
}

.copilot-message-text li {
    margin: 3px 0;
}

.copilot-message-text li > ul,
.copilot-message-text li > ol {
    margin: 3px 0;
    padding-left: 16px;
}

/* The markdown renderer emits a bare table, so the table itself is the scroller.
   Scrolling here instead of on the bubble preserves the padding, the radius and
   the clamp fade, and keeps ordinary paragraphs out of a sideways scroll. */
.copilot-message-text table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 0.8rem;
}

.copilot-message-text th,
.copilot-message-text td {
    border: 1px solid var(--line);
    padding: 5px 8px;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

.copilot-message-text th {
    background: var(--surface);
    font-weight: 600;
    color: var(--ink);
}

.copilot-message-text pre {
    margin: 8px 0;
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.78rem;
    line-height: 1.45;
}

.copilot-message-text pre code {
    background: none;
    border: 0;
    padding: 0;
    white-space: pre;
}

.copilot-message-text code {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 1px 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8rem;
    overflow-wrap: anywhere;
}

.copilot-message-text a {
    color: var(--inverse);
    text-decoration: underline;
    overflow-wrap: anywhere;
}

.copilot-message.user .copilot-message-text a {
    color: var(--on-inverse);
}

.copilot-message-text blockquote {
    margin: 8px 0;
    padding: 2px 0 2px 10px;
    border-left: 3px solid var(--line);
    color: var(--ink-muted);
}

.copilot-message-text hr {
    margin: 10px 0;
    border: 0;
    border-top: 1px solid var(--line);
}

.copilot-message-text img {
    max-width: 100%;
    height: auto;
}

/* User text is plain, not markdown, so keep the line breaks the user typed */
.copilot-message-text.copilot-user-text {
    white-space: pre-wrap;
}

/* ---- Long answer clamp ---- */
.copilot-message-clamped {
    position: relative;
    max-height: 260px;
    overflow: hidden;
}

.copilot-message-clamped::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 48px;
    pointer-events: none;
    background: linear-gradient(to bottom, transparent, var(--surface-raised) 90%);
}

.copilot-show-more {
    align-self: flex-start;
    background: none;
    border: 0;
    padding: 2px 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--inverse);
    cursor: pointer;
}

.copilot-show-more:hover {
    text-decoration: underline;
}

.copilot-show-more:focus-visible,
.copilot-stop-button:focus-visible,
.copilot-retry-button:focus-visible {
    outline: 2px solid var(--signal);
    outline-offset: 2px;
}

/* ---- Stop and retry controls ---- */
.copilot-stop-button,
.copilot-retry-button {
    align-self: flex-start;
    margin-top: 4px;
    padding: 3px 10px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--ink-muted);
    cursor: pointer;
}

.copilot-stop-button:hover,
.copilot-retry-button:hover {
    background: var(--line);
    color: var(--ink);
}

.copilot-stop-button:disabled,
.copilot-retry-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ---- Failed turn ---- */
.copilot-message.error .copilot-message-avatar {
    background: var(--warn-soft);
    color: var(--warn);
}

.copilot-message.error .copilot-message-content .copilot-message-text {
    background: var(--warn-soft);
    border-color: var(--warn-soft);
    color: var(--warn);
}

.copilot-message.error .copilot-message-content .copilot-message-clamped::after {
    background: linear-gradient(to bottom, transparent, var(--warn-soft) 90%);
}

/* ---- Narrow viewports ----
   The panel position is set by attribute plus class selectors, so the mobile
   override has to repeat that shape to win on specificity. */
@media (max-width: 480px) {
    .copilot-chat-window,
    .copilot-chatbot-container:not([data-edge]) .copilot-chat-window,
    .copilot-chatbot-container[data-edge="bottom"] .copilot-chat-window,
    .copilot-chatbot-container[data-edge="top"] .copilot-chat-window,
    .copilot-chatbot-container[data-edge="left"] .copilot-chat-window,
    .copilot-chatbot-container[data-edge="right"] .copilot-chat-window {
        left: 8px;
        right: 8px;
        top: auto;
        bottom: 8px;
        width: auto;
        max-width: none;
        height: 70vh;
        height: 70dvh;
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - 16px);
    }

    .copilot-message {
        max-width: 92%;
    }
}

/* ===================================
   Selection Action Bar - Sidebar Aware
   =================================== */
/* Default: align with expanded sidebar */
.selection-action-bar {
    /* The rail's own width, which also follows its collapsed state. */
    left: var(--rail-width, var(--sidebar-width, 240px)) !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                left 0.25s ease !important;
}

/* When sidebar is collapsed, adjust left position */
.sidebar.collapsed ~ .main .selection-action-bar {
    left: var(--sidebar-collapsed-width, 64px) !important;
}

/* Mobile: sidebar hidden, action bar spans full width */
@media (max-width: 767.98px) {
    .selection-action-bar {
        left: 0 !important;
    }
}

/* Shown by Blazor when the page lost its server session to an error (see App.razor). */
#blazor-error-ui {
    display: none;
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    z-index: 10000;
    max-width: calc(100% - 32px);
    padding: 10px 16px;
    border-radius: 8px;
    background: var(--warn-soft);
    color: var(--ink);
    border: 1px solid var(--warn);
    box-shadow: 0 4px 16px color-mix(in srgb, var(--ink) 12%, transparent);
    font-size: 14px;
}

#blazor-error-ui .reload {
    margin-left: 12px;
    font-weight: 600;
    color: inherit;
    text-decoration: underline;
}

/* A legal text (privacy policy, cookie policy) read without signing in: PolicyFrame. No rail
   and no top bar there, so the page gets its own width and the brand as the way back. */
.policy-public {
    max-width: 1080px;
    margin: 0 auto;
    padding: 24px;
}

.policy-public-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
}
