/* ============================================================
   Пульт — оформление поверх Fluent UI Blazor.
   Токены (--color*, --shadow*) приходят из Fluent; фолбэки — только
   для первого кадра, пока тема ещё не применена.
   ============================================================ */

:root {
    --pult-header-height: 60px;
    --pult-footer-height: 34px;
    --pult-radius-lg: 18px;
    --pult-radius-md: 14px;
    --pult-bubble-max: 680px;
    --pult-font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --pult-mono: "Cascadia Mono", "SF Mono", ui-monospace, Menlo, monospace;
    --pult-bg: var(--colorNeutralBackground2, #f4f6fb);
    --pult-surface: var(--colorNeutralBackground1, #ffffff);
    --pult-stroke: var(--colorNeutralStroke2, #e3e7ef);
    --pult-text: var(--colorNeutralForeground1, #14181f);
    --pult-text-muted: var(--colorNeutralForeground3, #5c6470);
    --pult-brand: var(--colorBrandBackground, #0f6cbd);
    --pult-brand-soft: var(--colorBrandBackground2, #e5f0fb);
    --pult-danger: var(--colorPaletteRedForeground1, #b10e1c);
    --pult-radius-sm: 10px;
}

html,
body {
    height: 100%;
    margin: 0;
    font-family: var(--pult-font);
    background: var(--pult-bg);
    color: var(--pult-text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

html[data-pult-dark] body {
    background: #0b1220;
    color-scheme: dark;
}

body {
    overflow: hidden;
}

* {
    box-sizing: border-box;
}

::selection {
    background: color-mix(in srgb, var(--pult-brand) 28%, transparent);
}

:focus-visible {
    outline: 2px solid var(--colorStrokeFocus2, #0f6cbd);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- первый кадр / загрузка ---------- */

#app {
    height: 100%;
}

.boot {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background:
        radial-gradient(1200px 620px at 50% -12%, #12335a 0%, #0b1220 58%),
        #0b1220;
    color: #f2f5fa;
}

.boot-mark,
.brand-mark {
    display: inline-grid;
    place-content: center;
    gap: 5px;
    border-radius: 10px;
    background: linear-gradient(145deg, #1a8fe0 0%, #0f5aa8 100%);
    box-shadow: 0 6px 16px rgba(15, 108, 189, 0.35);
}

.boot-mark {
    width: 58px;
    height: 58px;
    border-radius: 18px;
    margin-bottom: 8px;
}

.boot-mark i,
.brand-mark i {
    display: block;
    height: 4px;
    border-radius: 999px;
    background: #fff;
    opacity: 0.94;
}

.boot-mark i:nth-child(1) { width: 26px; }
.boot-mark i:nth-child(2) { width: 18px; margin-left: 8px; }
.boot-mark i:nth-child(3) { width: 22px; margin-left: 3px; }

.boot-title {
    font-size: 24px;
    font-weight: 650;
    letter-spacing: -0.02em;
}

.boot-sub {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #8fa2bd;
}

.boot-bar {
    margin-top: 18px;
    width: 132px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    overflow: hidden;
}

.boot-bar i {
    display: block;
    height: 100%;
    width: 40%;
    border-radius: inherit;
    background: linear-gradient(90deg, #2b9bf0, #7cc4ff);
    animation: boot-slide 1.25s ease-in-out infinite;
}

@keyframes boot-slide {
    0% { transform: translateX(-110%); }
    100% { transform: translateX(360%); }
}

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 2000;
    padding: 14px 20px;
    background: #2b1d1f;
    color: #ffd8dc;
    border-top: 1px solid #6d2b33;
    font-size: 14px;
    box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.35);
}

#blazor-error-ui .reload,
#blazor-error-ui .dismiss {
    color: #fff;
    margin-left: 12px;
}

.noscript {
    padding: 24px;
    font-size: 16px;
    text-align: center;
}

/* ---------- каркас ---------- */

.pult-shell {
    height: 100vh;
    height: 100dvh;
    background: var(--pult-bg);
}

/* FluentLayout красит header/nav/footer своими токенами; для Пулта нужен нейтральный каркас. */
.pult-shell .fluent-layout-item[area="header"] {
    /* FluentLayout красит иконку меню в «foreground on brand» — на нейтральной шапке это белое на белом. */
    --colorNeutralForegroundOnBrand: var(--pult-text);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    background: var(--pult-surface);
    color: var(--pult-text);
    border-bottom: 1px solid var(--pult-stroke);
    box-shadow: 0 1px 0 rgba(16, 24, 40, 0.02);
    z-index: 10;
}

.pult-shell .fluent-layout-item[area="nav"] {
    background: var(--pult-surface);
    border-right: 1px solid var(--pult-stroke);
    padding: 10px 8px;
}

.pult-shell .fluent-layout-item[area="content"] {
    padding: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
}

.pult-shell .fluent-layout-item[area="footer"] {
    background: var(--pult-surface);
    color: var(--pult-text-muted);
    border-top: 1px solid var(--pult-stroke);
    padding: 0 16px;
}

.pult-shell .fluent-layout-item[area="header"] .fluent-layout-hamburger {
    fill: var(--pult-text);
    margin: 0 4px;
}

.pult-shell .fluent-layout-item[area="header"] .fluent-layout-hamburger svg {
    fill: var(--pult-text);
}

.pult-shell .fluent-layout-item[area="header"] .fluent-layout-hamburger:hover {
    background: var(--colorSubtleBackgroundHover, rgba(0, 0, 0, 0.04));
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    padding: 6px 8px;
    border-radius: 10px;
}

.brand:hover {
    background: var(--colorSubtleBackgroundHover, rgba(0, 0, 0, 0.04));
}

.brand-mark {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    gap: 4px;
    border-radius: 9px;
}

.brand-mark i { height: 3px; }
.brand-mark i:nth-child(1) { width: 15px; }
.brand-mark i:nth-child(2) { width: 10px; margin-left: 5px; }
.brand-mark i:nth-child(3) { width: 13px; margin-left: 1px; }

.brand-copy {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.brand-title {
    font-size: 16px;
    font-weight: 680;
    letter-spacing: -0.02em;
}

.brand-sub {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--pult-text-muted);
}

.pult-nav {
    padding: 10px 8px;
    background: var(--pult-surface);
    border-right: 1px solid var(--pult-stroke);
    overflow-y: auto;
}

.pult-navmenu {
    height: 100%;
}

.pult-content {
    padding: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
}

.pult-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    background: var(--pult-surface);
    border-top: 1px solid var(--pult-stroke);
    font-size: 11px;
    color: var(--pult-text-muted);
}

.footer-note {
    white-space: nowrap;
}

.footer-link {
    color: var(--pult-text-muted);
    text-decoration: none;
}

.footer-link:hover {
    color: var(--pult-text);
    text-decoration: underline;
}

.footer-dot {
    opacity: 0.4;
}

/* ---------- шапка: статус связи ---------- */

.connection {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--pult-stroke);
    background: var(--colorNeutralBackground2, #f7f8fb);
    margin-right: 4px;
}

.connection-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--pult-text-muted);
}

.connection-dot.is-online {
    background: #2eaa5f;
    box-shadow: 0 0 0 3px rgba(46, 170, 95, 0.16);
}

.connection-dot.is-offline {
    background: #d97706;
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.16);
}

.connection-text {
    color: var(--pult-text-muted);
    font-size: 11px !important;
}

/* ---------- навигация: чаты ---------- */

.pult-navmenu fluent-nav-item {
    margin-bottom: 2px;
    border-radius: 10px;
}

.nav-chat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    width: 100%;
    position: relative;
}

.nav-chat-top {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.nav-chat-name {
    font-weight: 600;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-chat-time {
    margin-left: auto;
    font-size: 10px;
    color: var(--pult-text-muted);
    white-space: nowrap;
}

.nav-chat-preview {
    font-size: 11px;
    color: var(--pult-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.nav-unread {
    position: absolute;
    right: 0;
    bottom: 2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pult-brand);
    box-shadow: 0 0 0 3px var(--pult-surface);
}

.nav-empty {
    padding: 8px 14px;
}

/* ---------- чат ---------- */

.chat {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    min-height: 0;
    height: 100%;
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--pult-brand-soft) 42%, transparent) 0%, transparent 220px),
        var(--pult-bg);
}

.chat-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--pult-stroke);
    background: var(--pult-surface);
    z-index: 5;
}

.chat-head-copy {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
}

.chat-title {
    font-size: 16px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.chat-sub {
    font-size: 11.5px;
    color: var(--pult-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.banners {
    padding: 10px 20px 0;
}

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scroll-behavior: smooth;
}

.messages::-webkit-scrollbar,
.pult-nav::-webkit-scrollbar {
    width: 10px;
}

.messages::-webkit-scrollbar-thumb,
.pult-nav::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--pult-text-muted) 28%, transparent);
    border: 3px solid transparent;
    border-radius: 999px;
    background-clip: content-box;
}

.day {
    display: flex;
    justify-content: center;
    margin: 14px 0 6px;
}

.day-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--pult-text-muted);
    padding: 4px 12px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--pult-text-muted) 8%, transparent);
}

.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin: 3px 0;
    max-width: 100%;
}

.msg-row.is-own {
    justify-content: flex-end;
}

.msg-row.is-peer {
    justify-content: flex-start;
}

.bubble {
    max-width: min(var(--pult-bubble-max), 80%);
    padding: 10px 14px 8px;
    border-radius: 16px;
    background: var(--pult-surface);
    border: 1px solid var(--pult-stroke);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
    animation: bubble-in 160ms ease-out;
}

@keyframes bubble-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.is-peer .bubble {
    border-bottom-left-radius: 6px;
}

.is-own .bubble {
    background: linear-gradient(170deg, #1683d8 0%, #0f6cbd 100%);
    border-color: transparent;
    color: #fff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 6px 18px rgba(15, 108, 189, 0.22);
}

.bubble.is-failed {
    border-color: color-mix(in srgb, var(--pult-danger) 55%, transparent);
}

.bubble-text {
    font-size: 15px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.bubble-text a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.is-own .bubble-text a {
    color: #eaf4ff;
}

.bubble-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    font-size: 10.5px;
    color: var(--pult-text-muted);
    font-variant-numeric: tabular-nums;
}

.is-own .bubble-meta {
    color: rgba(255, 255, 255, 0.78);
}

.bubble-state {
    opacity: 0.9;
}

.retry-link {
    appearance: none;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
}

.bubble-error {
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--pult-danger);
}

.is-own .bubble-error {
    color: #ffd9dc;
}

.service-row {
    display: flex;
    justify-content: center;
    margin: 8px 0;
}

.service-pill {
    font-size: 11px;
    color: var(--pult-text-muted);
    padding: 4px 12px;
    border-radius: 999px;
    border: 1px dashed color-mix(in srgb, var(--pult-text-muted) 35%, transparent);
}

.messages-empty {
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
    max-width: 420px;
    padding: 40px 20px;
}

/* ---------- скелетоны ---------- */

.skeletons {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 10px 0;
}

.skeleton-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.skeleton-row.right {
    justify-content: flex-end;
}

.skeleton-avatar,
.skeleton-bubble {
    display: block;
    background: color-mix(in srgb, var(--pult-text-muted) 14%, transparent);
    border-radius: 12px;
    animation: pulse 1.4s ease-in-out infinite;
}

.skeleton-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.skeleton-bubble {
    width: 280px;
    height: 54px;
}

.skeleton-bubble.wide { width: 380px; }
.skeleton-bubble.small { width: 190px; height: 44px; }

@keyframes pulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

/* ---------- композер ---------- */

.composer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--pult-stroke);
    background: var(--pult-surface);
}

.composer-field {
    display: block;
    width: 100%;
}

.composer-field fluent-textarea {
    width: 100%;
}

/* Внутренний control FluentTextArea по умолчанию 300px — растягиваем на всю ширину. */
.composer-field fluent-textarea::part(control) {
    width: 100% !important;
}

.composer-field fluent-text-area,
.composer-field::part(control) {
    border-radius: 14px;
}

.composer-bar {
    display: flex;
    align-items: center;
    gap: 12px;
}

.composer-hint,
.composer-count {
    font-size: 11px;
    color: var(--pult-text-muted);
}

.composer-count {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

/* ---------- страницы ---------- */

.page {
    width: min(920px, 100%);
    margin: 0 auto;
    padding: 28px 24px 40px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    height: 100%;
    overflow-y: auto;
}

.page-head {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.page-title {
    margin: 0 0 6px;
    font-size: 26px;
    font-weight: 680;
    letter-spacing: -0.03em;
}

.page-lead {
    margin: 0;
    color: var(--pult-text-muted);
    font-size: 13.5px;
    line-height: 1.55;
    max-width: 640px;
}

.card-title {
    margin: 0;
    font-size: 15px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.settings-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 20px 22px;
}

.settings-card > fluent-button {
    align-self: flex-start;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    font-size: 13.5px;
    padding: 6px 0;
    border-bottom: 1px dashed color-mix(in srgb, var(--pult-stroke) 80%, transparent);
}

.settings-row:last-of-type {
    border-bottom: 0;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.bot-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px 22px;
}

.bot-head {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bot-copy {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.bot-name {
    font-size: 16px;
    font-weight: 650;
}

.bot-sub {
    font-size: 12px;
    color: var(--pult-text-muted);
}

.bot-meta {
    font-size: 11px;
    color: var(--pult-text-muted);
}

.token-card {
    border: 1px solid color-mix(in srgb, var(--colorPaletteDarkOrangeBorderActive, #d97706) 45%, var(--pult-stroke));
    background: color-mix(in srgb, var(--colorPaletteLightYellowBackground2, #fff8e1) 70%, var(--pult-surface));
}

.token {
    display: block;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--colorNeutralBackground3, #f0f2f6);
    border: 1px dashed var(--pult-stroke);
    word-break: break-all;
    font-size: 13px;
    line-height: 1.5;
    user-select: all;
}

.bot-chats {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--pult-stroke);
    text-decoration: none;
    color: inherit;
    background: var(--colorNeutralBackground2, #f7f8fb);
    transition: background 120ms ease, border-color 120ms ease;
}

.chat-row:hover {
    background: var(--colorSubtleBackgroundHover, rgba(0, 0, 0, 0.04));
    border-color: color-mix(in srgb, var(--pult-brand) 35%, var(--pult-stroke));
}

.chat-row-title {
    font-size: 13.5px;
    font-weight: 600;
}

.chat-row-sub {
    margin-left: auto;
    font-size: 11.5px;
    color: var(--pult-text-muted);
}

.chat-row-chevron {
    color: var(--pult-text-muted);
}

/* ---------- пустые состояния, auth, splash ---------- */

.empty-chat,
.splash,
.fatal {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-align: center;
    height: 100%;
    padding: 40px 24px;
}

.brand-mark-lg {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    gap: 5px;
    margin-bottom: 6px;
}

.brand-mark-lg i { height: 5px; }
.brand-mark-lg i:nth-child(1) { width: 24px; }
.brand-mark-lg i:nth-child(2) { width: 16px; margin-left: 7px; }
.brand-mark-lg i:nth-child(3) { width: 20px; margin-left: 2px; }

.brand-mark-xl {
    width: 68px;
    height: 68px;
    border-radius: 20px;
    gap: 6px;
    margin-bottom: 10px;
}

.brand-mark-xl i { height: 6px; }
.brand-mark-xl i:nth-child(1) { width: 30px; }
.brand-mark-xl i:nth-child(2) { width: 20px; margin-left: 9px; }
.brand-mark-xl i:nth-child(3) { width: 25px; margin-left: 3px; }

.auth-screen {
    position: relative;
    height: 100vh;
    height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px;
    overflow: hidden;
    background:
        radial-gradient(900px 520px at 18% 8%, rgba(26, 143, 224, 0.32) 0%, transparent 60%),
        radial-gradient(900px 560px at 88% 92%, rgba(15, 90, 168, 0.28) 0%, transparent 62%),
        #0b1220;
    color: #f2f5fa;
}

.auth-glow {
    position: absolute;
    inset: auto 12% -30% 12%;
    height: 380px;
    background: radial-gradient(closest-side, rgba(124, 196, 255, 0.18), transparent 70%);
    filter: blur(20px);
    pointer-events: none;
}

.auth-card {
    position: relative;
    width: min(430px, 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 44px 34px 36px;
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(20px);
    text-align: center;
}

.auth-title {
    margin: 4px 0 0;
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.035em;
}

.auth-lead {
    margin: 0 0 10px;
    color: #bcc9dc;
    line-height: 1.6;
    font-size: 14px;
    max-width: 330px;
}

.auth-hint {
    margin: 6px 0 0;
    font-size: 11.5px;
    color: #8e9db4;
    max-width: 300px;
}

.auth-card fluent-button {
    min-width: 170px;
}

.splash fluent-spinner {
    margin-bottom: 4px;
}

.fatal {
    gap: 14px;
}

/* ---------- служебное ---------- */

.muted {
    color: var(--pult-text-muted) !important;
}

.small {
    font-size: 12px;
    line-height: 1.55;
}

.mono {
    font-family: var(--pult-mono);
    font-size: 11.5px;
}

/* ---------- адаптив ---------- */

@media (max-width: 900px) {
    .messages {
        padding: 14px 12px 8px;
    }

    .chat-head {
        padding: 10px 12px;
        gap: 10px;
    }

    .bubble {
        max-width: 88%;
    }

    .banners {
        padding: 8px 12px 0;
    }

    .composer {
        padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
    }

    .composer-hint {
        display: none;
    }

    .page {
        padding: 18px 14px 32px;
    }

    .page-title {
        font-size: 22px;
    }

    .brand-sub {
        display: none;
    }

    .connection-text {
        display: none;
    }

    .settings-card,
    .bot-card {
        padding: 16px;
    }

    .chat-row-sub {
        margin-left: auto;
    }
}

@media (max-width: 520px) {
    .bubble {
        max-width: 92%;
    }

    .chat-title {
        font-size: 15px;
    }

    .pult-footer {
        display: none;
    }
}
