/* ===== AI assistant widget ===== */

/* ---- Bubble: floats bottom-right ---- */
.ai-bubble {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    z-index: 1300;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--violet), var(--cyan));
    color: #fff;
    font-size: 24px;
    font-weight: 900;
    box-shadow: 0 8px 32px rgba(179, 102, 255, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
    transition: transform 0.2s, box-shadow 0.2s;
    padding-bottom: env(safe-area-inset-bottom);
}
.ai-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 40px rgba(179, 102, 255, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.15) inset;
}
.ai-bubble:active { transform: scale(0.95); }
.ai-bubble::before {
    content: ''; position: absolute; inset: -4px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--violet), var(--cyan));
    opacity: 0.35; filter: blur(10px); z-index: -1;
    animation: ai-bubble-pulse 2.4s ease-in-out infinite;
}
@keyframes ai-bubble-pulse {
    0%, 100% { opacity: 0.25; transform: scale(1); }
    50%       { opacity: 0.55; transform: scale(1.12); }
}
.ai-bubble.unread::after {
    content: ''; position: absolute; top: 4px; right: 4px;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--red);
    box-shadow: 0 0 8px var(--red);
}

/* ---- Panel: slide-up from bottom-right ---- */
.ai-panel {
    position: fixed;
    right: 14px;
    bottom: 14px;
    width: 440px;
    max-width: calc(100vw - 28px);
    height: min(720px, calc(100dvh - 28px));
    background: rgba(12, 12, 20, 0.96);
    border: 1px solid var(--gray2);
    border-radius: 22px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    display: none;
    flex-direction: column;
    z-index: 1290;
    transform: translateY(20px) scale(0.98);
    opacity: 0;
    transition: transform 0.22s ease-out, opacity 0.22s ease-out;
    overscroll-behavior: contain;
}
.ai-panel.open {
    display: flex;
    transform: translateY(0) scale(1);
    opacity: 1;
}

.ai-panel-header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 18px 14px;
    border-bottom: 1px solid var(--gray2);
}
.ai-panel-title-block { flex: 1; min-width: 0; }
.ai-panel-title {
    font-size: 14px; font-weight: 900; color: #fff; letter-spacing: 0.5px;
    display: flex; align-items: center; gap: 8px;
}
.ai-panel-sub {
    font-size: 10px; color: var(--gray); margin-top: 2px;
    letter-spacing: 1px; text-transform: uppercase;
}
.ai-panel-close {
    width: 28px; height: 28px; border-radius: 8px;
    background: var(--gray2); border: none; color: var(--gray);
    font-size: 18px; cursor: pointer; transition: all 0.15s;
}
.ai-panel-close:hover { background: rgba(255, 56, 101, 0.2); color: var(--red); }

.ai-panel-actions {
    padding: 12px 18px;
    border-bottom: 1px solid var(--gray2);
    display: flex; gap: 8px; align-items: center;
}
.ai-analyze-btn {
    flex: 1;
    background: linear-gradient(135deg, var(--violet), var(--cyan));
    color: #fff;
    border: none; border-radius: 10px;
    padding: 12px 16px; font-size: 12px; font-weight: 800; letter-spacing: 1.5px;
    cursor: pointer; transition: transform 0.15s, opacity 0.15s;
    text-transform: uppercase;
}
.ai-analyze-btn:hover { transform: translateY(-1px); }
.ai-analyze-btn:active { transform: scale(0.97); }
.ai-analyze-btn:disabled {
    opacity: 0.5; cursor: not-allowed; transform: none;
    background: var(--gray2); color: var(--gray);
}
.ai-clear-btn {
    background: var(--gray2); color: var(--gray);
    border: none; border-radius: 10px;
    padding: 12px 12px; font-size: 14px;
    cursor: pointer; transition: all 0.15s;
}
.ai-clear-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }

.ai-panel-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 14px;
    display: flex; flex-direction: column; gap: 10px;
}

.ai-empty {
    text-align: center; padding: 40px 24px; color: var(--gray); font-size: 12px;
    line-height: 1.6;
}
.ai-empty-icon {
    font-size: 38px; margin-bottom: 12px; opacity: 0.5;
}
.ai-cta {
    margin-top: 14px;
    background: rgba(0, 212, 255, 0.15); color: var(--cyan);
    border: 1px solid rgba(0, 212, 255, 0.3); border-radius: 8px;
    padding: 8px 14px; font-size: 11px; font-weight: 700; letter-spacing: 1px;
    cursor: pointer; transition: all 0.15s;
}
.ai-cta:hover { background: rgba(0, 212, 255, 0.25); }

.ai-loading {
    display: flex; align-items: center; justify-content: center;
    gap: 10px; padding: 40px 20px; color: var(--gray); font-size: 12px;
}
.ai-spinner {
    width: 18px; height: 18px;
    border: 2px solid var(--gray2);
    border-top-color: var(--cyan);
    border-radius: 50%;
    animation: ai-spin 0.7s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

.ai-error {
    background: rgba(255, 56, 101, 0.1);
    border: 1px solid rgba(255, 56, 101, 0.3);
    border-radius: 10px; padding: 12px 14px;
    color: var(--red); font-size: 12px; line-height: 1.5;
}

/* ---- Analysis summary (top-of-response) ---- */
.ai-analysis-banner {
    background: linear-gradient(135deg, rgba(179, 102, 255, 0.12), rgba(0, 212, 255, 0.12));
    border: 1px solid rgba(179, 102, 255, 0.3);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 12px; line-height: 1.5;
    color: #fff;
}
.ai-analysis-banner-tag {
    display: inline-block; font-size: 9px; font-weight: 800; letter-spacing: 1.5px;
    color: var(--violet); margin-bottom: 6px;
}

/* ---- Generic wireframe card ---- */
.ai-wf {
    background: var(--card); border: 1px solid var(--gray2); border-radius: 12px;
    padding: 12px 14px;
    display: flex; flex-direction: column; gap: 8px;
}
.ai-wf-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ai-wf-title { font-size: 12px; font-weight: 800; color: #fff; flex: 1; min-width: 0; }
.ai-wf-pill {
    font-size: 9px; font-weight: 800; letter-spacing: 1px;
    padding: 2px 7px; border-radius: 6px;
}
.ai-wf-pill.info     { background: rgba(0, 212, 255, 0.15);  color: var(--cyan);   border: 1px solid rgba(0, 212, 255, 0.3); }
.ai-wf-pill.warn     { background: rgba(255, 209, 102, 0.15);color: var(--gold);   border: 1px solid rgba(255, 209, 102, 0.3); }
.ai-wf-pill.critical { background: rgba(255, 56, 101, 0.15); color: var(--red);    border: 1px solid rgba(255, 56, 101, 0.3); }
.ai-wf-text { font-size: 12px; color: rgba(255, 255, 255, 0.8); line-height: 1.5; }
.ai-wf-evidence { display: flex; flex-direction: column; gap: 4px; padding-left: 4px; }
.ai-wf-evidence-item {
    font-size: 11px; color: var(--gray); line-height: 1.5;
    padding-left: 12px; position: relative;
}
.ai-wf-evidence-item::before {
    content: '•'; position: absolute; left: 0; color: var(--cyan);
}

/* Severity left-border accent */
.ai-wf.severity-info     { border-left: 3px solid var(--cyan); }
.ai-wf.severity-warn     { border-left: 3px solid var(--gold); }
.ai-wf.severity-critical { border-left: 3px solid var(--red);  }

/* ---- stat-grid ---- */
.ai-wf-stat-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 6px;
}
.ai-stat-cell {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--gray2);
    border-radius: 8px;
    padding: 8px 10px;
    display: flex; flex-direction: column; gap: 2px;
}
.ai-stat-cell .lab {
    font-size: 9px; color: var(--gray); letter-spacing: 1px; font-weight: 700;
}
.ai-stat-cell .val {
    font-size: 14px; color: #fff; font-weight: 900;
    display: flex; align-items: center; gap: 4px;
}
.ai-stat-cell .trend { font-size: 10px; }
.ai-stat-cell.tone-good .val    { color: var(--green); }
.ai-stat-cell.tone-bad  .val    { color: var(--red); }

/* ---- trade-list ---- */
.ai-wf-trade-list { display: flex; flex-direction: column; gap: 6px; }
.ai-trade-row {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--gray2);
    border-radius: 8px;
    padding: 8px 10px;
    display: flex; flex-direction: column; gap: 4px;
}
.ai-trade-row-head { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.ai-trade-row-sym  { font-weight: 800; color: #fff; }
.ai-trade-row-kol  { color: var(--gray); font-size: 10px; }
.ai-trade-row-pnl.pos  { color: var(--green); font-weight: 800; margin-left: auto; }
.ai-trade-row-pnl.neg  { color: var(--red);   font-weight: 800; margin-left: auto; }
.ai-trade-row-reason { font-size: 10px; color: var(--gray); line-height: 1.4; }

/* ---- kol-analysis ---- */
.ai-wf-kol-head { display: flex; align-items: center; gap: 10px; }
.ai-kol-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--cyan), var(--violet));
    display: flex; align-items: center; justify-content: center;
    color: #000; font-weight: 900; font-size: 14px; flex-shrink: 0;
}
.ai-verdict-pill {
    font-size: 9px; font-weight: 800; letter-spacing: 1px;
    padding: 3px 8px; border-radius: 6px; text-transform: uppercase;
}
.ai-verdict-pill.ban    { background: rgba(255, 56, 101, 0.15); color: var(--red);   border: 1px solid rgba(255, 56, 101, 0.3); }
.ai-verdict-pill.keep   { background: rgba(0, 255, 157, 0.15); color: var(--green); border: 1px solid rgba(0, 255, 157, 0.3); }
.ai-verdict-pill.tune   { background: rgba(255, 209, 102, 0.15); color: var(--gold); border: 1px solid rgba(255, 209, 102, 0.3); }
.ai-verdict-pill.review { background: rgba(0, 212, 255, 0.15); color: var(--cyan); border: 1px solid rgba(0, 212, 255, 0.3); }
.ai-kol-metrics {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 4px; font-size: 10px;
}
.ai-kol-metric {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px; padding: 4px 8px;
    display: flex; justify-content: space-between;
}
.ai-kol-metric .k { color: var(--gray); }
.ai-kol-metric .v { color: #fff; font-weight: 700; }

/* ---- config-change ---- */
.ai-wf-config {
    border-left: 3px solid var(--violet);
}
.ai-config-diff {
    display: flex; align-items: center; gap: 8px;
    background: rgba(179, 102, 255, 0.08);
    border-radius: 8px; padding: 8px 10px;
    font-size: 12px;
}
.ai-config-diff .key { font-weight: 800; color: #fff; flex: 0 0 auto; }
.ai-config-diff .cur { color: var(--red); text-decoration: line-through; }
.ai-config-diff .arrow { color: var(--gray); }
.ai-config-diff .new { color: var(--green); font-weight: 800; }
.ai-config-impact {
    font-size: 11px; color: var(--gray); line-height: 1.5;
    padding-left: 8px; border-left: 2px solid var(--gray2);
}
.ai-config-actions { display: flex; gap: 6px; }
.ai-config-apply, .ai-config-reject {
    flex: 1; border: none; border-radius: 8px;
    padding: 9px 12px; font-size: 11px; font-weight: 800; letter-spacing: 1px;
    cursor: pointer; transition: all 0.15s;
}
.ai-config-apply {
    background: rgba(0, 255, 157, 0.15); color: var(--green);
    border: 1px solid rgba(0, 255, 157, 0.3);
}
.ai-config-apply:hover { background: rgba(0, 255, 157, 0.25); }
.ai-config-apply.applied {
    background: rgba(0, 255, 157, 0.4); color: #000;
    border-color: var(--green); cursor: default;
}
.ai-config-reject {
    background: rgba(255, 56, 101, 0.1); color: var(--red);
    border: 1px solid rgba(255, 56, 101, 0.3);
}
.ai-config-reject:hover { background: rgba(255, 56, 101, 0.2); }
.ai-config-reject.rejected {
    opacity: 0.5; cursor: default;
}

/* ---- log-finding ---- */
.ai-wf-logf-kv { display: flex; flex-direction: column; gap: 4px; }
.ai-wf-logf-kv .row {
    font-size: 11px; line-height: 1.5;
    display: flex; gap: 6px; align-items: baseline;
}
.ai-wf-logf-kv .lab { color: var(--gray); font-weight: 700; min-width: 70px; letter-spacing: 0.5px; text-transform: uppercase; font-size: 9px; }
.ai-wf-logf-kv .val { color: #fff; flex: 1; }
.ai-wf-logf-kv .val.code {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    background: rgba(0, 0, 0, 0.3); border-radius: 4px; padding: 1px 6px; font-size: 10px;
}

/* ---- meta footer ---- */
.ai-meta {
    font-size: 9px; color: var(--gray); letter-spacing: 1px;
    text-align: center; padding: 6px 0 2px;
    text-transform: uppercase;
}

/* ---- Mobile: turn panel into bottom sheet ---- */
@media (max-width: 540px) {
    .ai-panel {
        right: 0; left: 0; bottom: 0;
        width: 100vw; max-width: 100vw;
        height: 86dvh;
        border-radius: 22px 22px 0 0;
    }
    .ai-bubble { right: 14px; bottom: 14px; }
}

/* App-tab section divider (used by the new AI section header) */
.app-config-section-divider {
    margin-top: 24px;
    padding: 8px 0;
    font-size: 11px; font-weight: 900; letter-spacing: 2px;
    color: var(--violet);
    border-top: 1px solid var(--gray2);
}
