/* ════════════════════════════════════════════
   DoxMAP — AI Chat Panel Styles
   Frosted glass floating panel + FAB
   ════════════════════════════════════════════ */

/* ── FAB ───────────────────────────────────────────────────────────── */
.ai-fab {
    position: absolute;
    bottom: 80px;
    right: 16px;
    z-index: 900;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--brand, #7C6FFF);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(124, 111, 255, 0.3);
    transition: transform .2s, box-shadow .2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* iOS parity: AI is accessed from the bottom tab bar, not a floating FAB */
.ai-fab {
    display: none !important;
}

.ai-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(124, 111, 255, 0.4);
}

/* ── Panel ─────────────────────────────────────────────────────────── */
.ai-chat-panel {
    position: absolute;
    bottom: 130px;
    right: 16px;
    z-index: 901;
    width: 310px;
    height: 400px;
    border-radius: 18px;
    background: var(--surface, rgba(28, 28, 34, 0.95));
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: ai-panel-in .25s ease-out;
}

/* When mounted in the unified drawer, the container must be flex so the panel fills it */
#ai-chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* When mounted in the unified drawer, use full-width sheet layout */
#ai-chat-container .ai-chat-panel {
    position: relative !important;
    inset: auto !important;
    width: 100% !important;
    height: 100% !important;
    flex: 1 !important;
    min-height: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    animation: none !important;
}

.ai-chat-panel.hidden {
    display: none !important;
}

@keyframes ai-panel-in {
    from {
        opacity: 0;
        transform: scale(.8) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ── Header ────────────────────────────────────────────────────────── */
.ai-chat-header {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    gap: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    flex-shrink: 0;
}

.ai-chat-title {
    font-weight: 700;
    font-size: 14px;
    flex: 1;
    color: var(--text-1, #fff);
}

.ai-chat-clear,
.ai-chat-settings-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 6px;
    opacity: .6;
    transition: opacity .15s;
}

.ai-chat-clear:hover,
.ai-chat-settings-btn:hover {
    opacity: 1;
}

/* ── Messages ──────────────────────────────────────────────────────── */
.ai-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-empty {
    color: var(--text-3, rgba(255, 255, 255, .4));
    font-size: 13px;
    text-align: center;
    padding: 30px 10px;
}

.ai-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}

.ai-bubble-user {
    align-self: flex-end;
    background: var(--brand, #7C6FFF);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ai-bubble-assistant {
    align-self: flex-start;
    background: var(--surface-2, rgba(255, 255, 255, .08));
    color: var(--text-1, #e0e0e0);
    border-bottom-left-radius: 4px;
}

.ai-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 1;
    font-style: normal;
    font-size: 12px;
    color: var(--text-2, rgba(255,255,255,.6));
    padding: 10px 14px;
    position: relative;
}

.ai-cancel-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 50%;
    width: 22px;
    height: 22px;
    color: var(--text-3, rgba(255,255,255,.4));
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
}
.ai-cancel-btn:hover {
    background: rgba(255,60,60,.15);
    border-color: rgba(255,60,60,.4);
    color: #ff4444;
}

/* iOS-style spinner ring */
.ai-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(124, 111, 255, 0.2);
    border-top-color: var(--brand, #7C6FFF);
    border-radius: 50%;
    animation: ai-spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes ai-spin {
    to { transform: rotate(360deg); }
}

/* Status text inside loading bubble */
.ai-loading-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-loading-label {
    font-weight: 600;
    color: var(--text-1, #e0e0e0);
    font-size: 12px;
}

.ai-loading-detail {
    font-size: 11px;
    color: var(--text-3, rgba(255,255,255,.4));
    transition: opacity 0.2s;
}

/* Node applied counter animation */
.ai-loading-count {
    display: inline-block;
    font-variant-numeric: tabular-nums;
    min-width: 1.2em;
    text-align: center;
    font-weight: 700;
    color: var(--brand, #7C6FFF);
}

/* Pulse on the spinner when applying changes */
.ai-loading.ai-applying .ai-spinner {
    border-top-color: #4cd964;
    animation: ai-spin 0.6s linear infinite, ai-pulse 1.2s ease-in-out infinite;
}

@keyframes ai-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(76, 217, 100, 0.3); }
    50% { box-shadow: 0 0 0 6px rgba(76, 217, 100, 0); }
}

/* ── Feedback ──────────────────────────────────────────────────────── */
.ai-feedback {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}

.ai-fb-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 10px;
    opacity: .5;
    transition: opacity .15s, background .15s;
}

.ai-fb-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, .1);
}

.ai-fb-btn.active {
    opacity: 1;
    background: rgba(124, 111, 255, .2);
}

/* ── Input row ─────────────────────────────────────────────────────── */
.ai-chat-input-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid rgba(255, 255, 255, .08);    flex-shrink: 0;}

.ai-chat-input {
    flex: 1;
    background: var(--surface-2, rgba(255, 255, 255, .06));
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 18px;
    padding: 7px 12px;
    font-size: 13px;
    color: var(--text-1, #fff);
    outline: none;
    transition: border-color .2s;
    resize: none;
    min-height: 32px;
    max-height: 120px;
    line-height: 1.4;
    font-family: inherit;
    overflow-y: auto;
}

.ai-chat-input:focus {
    border-color: var(--brand, #7C6FFF);
}

.ai-chat-input::placeholder {
    color: var(--text-3, rgba(255, 255, 255, .35));
}

.ai-chat-send,
.ai-mic-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}

.ai-chat-send {
    background: var(--brand, #7C6FFF);
    color: #fff;
}

.ai-chat-send:hover {
    filter: brightness(1.15);
}

.ai-mic-btn {
    background: rgba(255, 255, 255, .08);
    color: var(--text-2, #bbb);
}

.ai-mic-btn:hover {
    background: rgba(255, 255, 255, .15);
}

.ai-mic-btn.ai-mic-active {
    background: rgba(239, 68, 68, .2);
    color: #EF4444;
    animation: ai-mic-pulse 1s infinite;
}

@keyframes ai-mic-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, .3);
    }

    50% {
        box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);
    }
}

/* ── Settings drawer ───────────────────────────────────────────────── */
.ai-settings-drawer {
    padding: 10px 14px;
    border-top: 1px solid rgba(255, 255, 255, .08);
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;    flex-shrink: 0;}

.ai-settings-drawer.hidden {
    display: none;
}

.ai-settings-drawer label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-2, #aaa);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.ai-settings-drawer select,
.ai-settings-drawer input,
.ai-settings-drawer textarea {
    background: var(--surface-2, rgba(255, 255, 255, .06));
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 12px;
    color: var(--text-1, #fff);
    outline: none;
}

.ai-settings-drawer select:focus,
.ai-settings-drawer input:focus,
.ai-settings-drawer textarea:focus {
    border-color: var(--brand, #7C6FFF);
}

.ai-save-settings {
    background: var(--brand, #7C6FFF);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: filter .15s;
}

.ai-save-settings:hover {
    filter: brightness(1.15);
}

.ai-save-settings.ai-save-success {
    background: #34C759;
    transition: background .2s;
}

.ai-model-input[readonly] {
    opacity: .7;
    cursor: default;
    background: rgba(255, 255, 255, .04);
}

/* ── Light theme overrides ─────────────────────────────────────────── */
[data-theme="light"] .ai-chat-panel {
    background: #ffffff;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .12), 0 0 0 1px rgba(0, 0, 0, .05);
}

/* When inside the unified drawer, force the drawer to white too */
[data-theme="light"] #ai-chat-container .ai-chat-panel {
    background: transparent !important;
}

[data-theme="light"] .ai-chat-header {
    border-bottom-color: rgba(0, 0, 0, .08);
}

[data-theme="light"] .ai-chat-title {
    color: #1a1e2e;
}

[data-theme="light"] .ai-chat-clear,
[data-theme="light"] .ai-chat-settings-btn {
    color: #5a6278;
}

[data-theme="light"] .ai-bubble-assistant {
    background: #f5f6fa;
    color: #222;
}

[data-theme="light"] .ai-bubble-user {
    color: #fff;
}

[data-theme="light"] .ai-chat-input {
    background: #f5f6fa;
    border-color: rgba(0, 0, 0, .12);
    color: #111;
}

[data-theme="light"] .ai-chat-input::placeholder {
    color: rgba(0, 0, 0, .4);
}

[data-theme="light"] .ai-chat-input-row {
    border-top-color: rgba(0, 0, 0, .08);
}

[data-theme="light"] .ai-mic-btn {
    background: rgba(0, 0, 0, .06);
    color: #5a6278;
}

[data-theme="light"] .ai-mic-btn:hover {
    background: rgba(0, 0, 0, .1);
}

[data-theme="light"] .ai-empty {
    color: #9aa2b4;
}

[data-theme="light"] .ai-fb-btn:hover {
    background: rgba(0, 0, 0, .06);
}

/* Settings drawer inside chat — light */
[data-theme="light"] .ai-settings-drawer {
    border-top-color: rgba(0, 0, 0, .08);
}

[data-theme="light"] .ai-settings-drawer label {
    color: #5a6278;
}

[data-theme="light"] .ai-settings-drawer select,
[data-theme="light"] .ai-settings-drawer input {
    background: #f5f6fa;
    border-color: rgba(0, 0, 0, .12);
    color: #111;
}
/* ── BYOK Screen ────────────────────────────────────────────────────── */
.ai-byok-screen {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
    height: 100%;
    overflow-y: auto;
}

.ai-byok-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.ai-byok-icon {
    font-size: 32px;
}

.ai-byok-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--text-1);
}

.ai-byok-card {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: left;
}

.ai-byok-card label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-3);
    letter-spacing: 0.5px;
}

.ai-byok-card select,
.ai-byok-card input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 8px 12px;
    color: #fff;
    font-size: 13px;
    outline: none;
}

.ai-byok-save {
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 4px;
}

.ai-byok-guidance {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    font-size: 11px;
}

.ai-byok-guidance a {
    color: var(--brand);
    text-decoration: none;
    font-weight: 600;
}

.ai-byok-privacy {
    font-size: 10px !important;
    opacity: 0.6;
    margin-top: auto !important;
}

[data-theme="light"] .ai-byok-card {
    background: rgba(0, 0, 0, 0.03);
}

[data-theme="light"] .ai-byok-card select,
[data-theme="light"] .ai-byok-card input {
    background: #fff;
    color: #222;
}

/* ── Tabs ──────────────────────────────────────────────────────────── */
.ai-chat-tabs {
    display: flex;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    margin: 8px 14px 0 14px;
    padding: 2px;
}

.ai-tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-2, rgba(255,255,255,0.6));
    padding: 6px 0;
    font-size: 11px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-tab-btn.active {
    background: var(--brand, #7C6FFF);
    color: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* ── Actions Grid ──────────────────────────────────────────────────── */
.ai-actions-panel {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
}

.ai-actions-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.ai-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--surface-2, rgba(255, 255, 255, 0.08));
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 12px 6px;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-action-btn:hover {
    background: rgba(124, 111, 255, 0.2);
    border-color: rgba(124, 111, 255, 0.4);
    transform: translateY(-2px);
}

.ai-action-btn .icon {
    font-size: 20px;
}

.ai-action-btn .lbl {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-1, #fff);
}

[data-theme="light"] .ai-chat-tabs {
    background: rgba(0,0,0,0.06);
}

[data-theme="light"] .ai-tab-btn {
    color: #5a6278;
}

[data-theme="light"] .ai-tab-btn.active {
    color: #fff;
}

[data-theme="light"] .ai-action-btn {
    background: #f5f6fa;
    border-color: rgba(0,0,0,0.05);
}

[data-theme="light"] .ai-action-btn .lbl {
    color: #222;
}
