/*
 * AI-чат (ADR-016, Phase 1 MVP) — FAB + drawer 420px справа
 * Дизайн: Swiss minimal v07.04.2026 + Figma «ХП — AI-чат UX».
 * Палитра тянется из существующих CSS-vars в style.css; дублируем
 * только то, чего там нет. Намеренно без external CDN — CSP self-only.
 */

/* ─────────────────────────────────────────────────
   Tokens (если style.css не определил — дефолты)
   ───────────────────────────────────────────────── */
:root {
    --chat-fab-size: 56px;
    --chat-drawer-w: 420px;
    --chat-bg: #FAFAFA;
    --chat-surface: #FFFFFF;
    --chat-ink: #0A0A0A;
    --chat-ink-2: #1A1A1A;
    --chat-muted: #737373;
    --chat-border: #E5E5E5;
    --chat-hover: #F5F5F5;
    --chat-accent: #171717;
    --chat-ai-bg: #F5F5F5;
    --chat-user-bg: #1A1A1A;
    --chat-shadow-fab: 0 4px 16px rgba(0, 0, 0, 0.18);
    --chat-shadow-drawer: -8px 0 24px rgba(0, 0, 0, 0.10);
    --chat-radius-card: 8px;
    --chat-radius-input: 24px;
    --chat-radius-pill: 14px;
    /* z-index выбран так, чтобы:
       — FAB (8900) был ПОД другими drawer'ами на странице (calendar.css =
         9000/9001) — иначе он бы перекрывал их UI. Когда они закрыты,
         FAB виден.
       — Свой drawer чата (9300) был ВЫШЕ календарного drawer'а (9001),
         но НИЖЕ exec-report-overlay (9999) — отчёт важнее чата. */
    --chat-z-fab: 8900;
    --chat-z-overlay: 9200;
    --chat-z-drawer: 9300;
}

/* ─────────────────────────────────────────────────
   FAB (Floating Action Button)
   ───────────────────────────────────────────────── */
.hp-chat-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: var(--chat-fab-size);
    height: var(--chat-fab-size);
    border-radius: 50%;
    background: var(--chat-accent);
    color: var(--chat-surface);
    border: none;
    cursor: pointer;
    z-index: var(--chat-z-fab);
    display: none; /* JS активирует через .hp-chat-fab--ready */
    align-items: center;
    justify-content: center;
    font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.4px;
    box-shadow: var(--chat-shadow-fab);
    transition: transform 120ms ease, box-shadow 120ms ease, width 180ms ease;
    overflow: hidden;
}
.hp-chat-fab--ready { display: flex; }
.hp-chat-fab:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
    width: 140px;
    border-radius: 28px;
    justify-content: flex-start;
    padding-left: 18px;
}
.hp-chat-fab__label {
    margin-left: 10px;
    opacity: 0;
    white-space: nowrap;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-weight: 500;
    transition: opacity 120ms ease 60ms;
    letter-spacing: 0;
}
.hp-chat-fab:hover .hp-chat-fab__label { opacity: 1; }

.hp-chat-fab--open {
    /* при открытом drawer FAB прячем — иначе перекрывает input */
    transform: scale(0.8);
    opacity: 0;
    pointer-events: none;
}

/* ─────────────────────────────────────────────────
   Overlay (затемнение под drawer)
   ───────────────────────────────────────────────── */
.hp-chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: var(--chat-z-overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
}
.hp-chat-overlay--open {
    opacity: 1;
    pointer-events: auto;
}

/* ─────────────────────────────────────────────────
   Drawer 420px справа
   ───────────────────────────────────────────────── */
.hp-chat-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--chat-drawer-w);
    max-width: 100vw;
    height: 100vh;
    background: var(--chat-surface);
    border-left: 1px solid var(--chat-border);
    box-shadow: var(--chat-shadow-drawer);
    z-index: var(--chat-z-drawer);
    transform: translateX(100%);
    transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.hp-chat-drawer--open { transform: translateX(0); }

.hp-chat-drawer__header {
    padding: 20px 24px 12px;
    border-bottom: 1px solid var(--chat-border);
    flex: 0 0 auto;
}
.hp-chat-drawer__title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.hp-chat-drawer__title {
    margin: 0;
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 16px;
    font-weight: 600;
    color: var(--chat-ink);
    letter-spacing: -0.2px;
}
.hp-chat-drawer__close {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background: transparent;
    border: 0;
    color: var(--chat-muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}
.hp-chat-drawer__close:hover { background: var(--chat-hover); color: var(--chat-ink); }

.hp-chat-pill {
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: var(--chat-radius-pill);
    background: var(--chat-hover);
    border: 1px solid var(--chat-border);
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11px;
    color: var(--chat-ink);
    line-height: 1;
}
.hp-chat-pill__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    margin-right: 8px;
    opacity: 0.6;
}

/* ─────────────────────────────────────────────────
   Список сообщений
   ───────────────────────────────────────────────── */
.hp-chat-thread {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px 24px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.hp-chat-msg {
    max-width: 92%;
    border-radius: var(--chat-radius-card);
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.45;
    color: var(--chat-ink);
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.hp-chat-msg--ai {
    align-self: flex-start;
    background: var(--chat-ai-bg);
}
.hp-chat-msg--user {
    align-self: flex-end;
    background: var(--chat-user-bg);
    color: var(--chat-surface);
}
.hp-chat-msg--blocked {
    background: #FEF3C7;
    color: #92400E;
    border: 1px solid #FCD34D;
}
.hp-chat-msg__role {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.8px;
    color: var(--chat-muted);
    text-transform: uppercase;
    margin-bottom: 6px;
    display: block;
}
.hp-chat-msg--user .hp-chat-msg__role { color: rgba(255, 255, 255, 0.6); }
.hp-chat-msg__body {
    white-space: pre-wrap;
}
.hp-chat-msg__cite {
    margin-top: 10px;
    padding: 8px 10px;
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 4px;
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 10px;
    color: var(--chat-muted);
    letter-spacing: 0.2px;
}
.hp-chat-msg__truncated {
    margin-top: 6px;
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 10px;
    color: #B91C1C;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

/* «AI печатает …» индикатор */
.hp-chat-typing {
    align-self: flex-start;
    padding: 12px 16px;
    border-radius: var(--chat-radius-card);
    background: var(--chat-ai-bg);
    color: var(--chat-muted);
    font-size: 18px;
    line-height: 1;
    letter-spacing: 4px;
}

/* ─────────────────────────────────────────────────
   Шорткаты (предложения вопросов)
   ───────────────────────────────────────────────── */
.hp-chat-shortcuts {
    padding: 8px 24px 12px;
    border-top: 1px solid var(--chat-border);
    flex: 0 0 auto;
}
.hp-chat-shortcuts__label {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 9px;
    font-weight: 600;
    color: var(--chat-muted);
    letter-spacing: 1.2px;
    margin: 0 0 8px;
    text-transform: uppercase;
}
.hp-chat-shortcuts__list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.hp-chat-chip {
    appearance: none;
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 14px;
    padding: 6px 12px;
    font-size: 11px;
    color: var(--chat-ink);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
}
.hp-chat-chip:hover {
    background: var(--chat-hover);
    border-color: var(--chat-ink);
}

/* ─────────────────────────────────────────────────
   Input
   ───────────────────────────────────────────────── */
.hp-chat-input-wrap {
    padding: 12px 24px 24px;
    border-top: 1px solid var(--chat-border);
    flex: 0 0 auto;
}
.hp-chat-input {
    position: relative;
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius-input);
    padding: 12px 56px 12px 18px;
    transition: border-color 120ms ease;
}
.hp-chat-input:focus-within { border-color: var(--chat-ink); }
.hp-chat-input__field {
    appearance: none;
    border: 0;
    background: transparent;
    width: 100%;
    font-size: 13px;
    color: var(--chat-ink);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    outline: 0;
    resize: none;
    min-height: 22px;
    max-height: 150px;
}
.hp-chat-input__send {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--chat-accent);
    color: var(--chat-surface);
    border: 0;
    font-size: 16px;
    cursor: pointer;
    transition: opacity 120ms ease;
}
.hp-chat-input__send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ─────────────────────────────────────────────────
   Mobile (≤767px) — drawer на полный экран
   ───────────────────────────────────────────────── */
@media (max-width: 767px) {
    .hp-chat-drawer {
        width: 100vw;
    }
    .hp-chat-fab {
        right: 16px;
        bottom: 16px;
    }
}

/* ─────────────────────────────────────────────────
   Уважаем reduce-motion
   ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .hp-chat-drawer,
    .hp-chat-overlay,
    .hp-chat-fab {
        transition: none !important;
    }
}
