/* ── LittoralAI layer ─────────────────────────────────────────
   Assistant widget, AI summary cards, search understanding,
   personalised rails and the reading insights dashboard.
   ---------------------------------------------------------- */

:root {
    --ai-ink: #0f172a;
    --ai-accent: #6d5bd0;
    --ai-accent-soft: rgba(109, 91, 208, .12);
    --ai-border: rgba(15, 23, 42, .1);
    --ai-radius: 18px;
}

/* ── Badges & shared bits ─────────────────────────────────── */
.ai-badge {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .22rem .6rem;
    border-radius: 999px;
    background: var(--ai-accent-soft);
    color: var(--ai-accent);
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: uppercase;
}

.ai-reason {
    display: block;
    margin-top: .35rem;
    font-size: .78rem;
    color: #64748b;
}

/* ── AI summary card (book page) ──────────────────────────── */
.ai-summary-card {
    border: 1px solid var(--ai-border);
    border-radius: var(--ai-radius);
    padding: 1.4rem 1.5rem;
    background: linear-gradient(180deg, rgba(109, 91, 208, .06), rgba(255, 255, 255, 0));
    margin-bottom: 1.75rem;
}

.ai-summary-card h3 {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: 1.05rem;
    margin-bottom: .85rem;
}

.ai-summary-card p {
    margin-bottom: .9rem;
    line-height: 1.7;
}

.ai-summary-points {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
    display: grid;
    gap: .5rem;
}

.ai-summary-points li {
    position: relative;
    padding-left: 1.4rem;
    font-size: .93rem;
    color: #334155;
}

.ai-summary-points li::before {
    content: "";
    position: absolute;
    left: 0;
    top: .55em;
    width: .5rem;
    height: .5rem;
    border-radius: 50%;
    background: var(--ai-accent);
}

.ai-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}

.ai-chip {
    padding: .3rem .7rem;
    border-radius: 999px;
    border: 1px solid var(--ai-border);
    font-size: .78rem;
    color: #475569;
    background: #fff;
}

.ai-feedback {
    display: flex;
    gap: .4rem;
    align-items: center;
    margin-left: auto;
    font-size: .78rem;
    color: #64748b;
}

.ai-feedback button {
    border: 1px solid var(--ai-border);
    background: #fff;
    border-radius: 999px;
    width: 30px;
    height: 30px;
    color: #64748b;
    transition: .18s ease;
}

.ai-feedback button:hover,
.ai-feedback button.is-active {
    color: var(--ai-accent);
    border-color: var(--ai-accent);
    background: var(--ai-accent-soft);
}

.ai-skeleton {
    height: .85rem;
    border-radius: 6px;
    background: linear-gradient(90deg, #eef2f7 25%, #f8fafc 50%, #eef2f7 75%);
    background-size: 200% 100%;
    animation: ai-shimmer 1.3s infinite;
    margin-bottom: .55rem;
}

.ai-skeleton:nth-child(2) { width: 92%; }
.ai-skeleton:nth-child(3) { width: 78%; }

@keyframes ai-shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

/* ── Search understanding block ───────────────────────────── */
.ai-search-panel {
    border: 1px solid var(--ai-border);
    border-radius: var(--ai-radius);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.5rem;
    background: #fff;
}

.ai-search-panel .ai-intent {
    font-size: 1rem;
    color: var(--ai-ink);
    margin: .6rem 0 .8rem;
}

.ai-keyword-list {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.ai-keyword-list a,
.ai-keyword-list span {
    font-size: .78rem;
    padding: .28rem .65rem;
    border-radius: 999px;
    background: #f1f5f9;
    color: #475569;
    text-decoration: none;
}

.ai-keyword-list a:hover {
    background: var(--ai-accent-soft);
    color: var(--ai-accent);
}

/* ── Assistant widget ─────────────────────────────────────── */
.ai-launcher {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1040;
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    padding: .8rem 1.15rem;
    border: none;
    border-radius: 999px;
    background: var(--ai-ink);
    color: #fff;
    font-weight: 600;
    font-size: .9rem;
    box-shadow: 0 18px 40px rgba(15, 23, 42, .28);
    cursor: pointer;
    transition: transform .18s ease, box-shadow .18s ease;
}

.ai-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 22px 48px rgba(15, 23, 42, .34);
}

.ai-launcher i { color: #c7bdff; }

.ai-panel {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1050;
    width: min(390px, calc(100vw - 32px));
    height: min(600px, calc(100vh - 40px));
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 22px;
    border: 1px solid var(--ai-border);
    box-shadow: 0 30px 70px rgba(15, 23, 42, .28);
    overflow: hidden;
    transform: translateY(14px);
    opacity: 0;
    pointer-events: none;
    transition: .22s ease;
}

.ai-panel.is-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.ai-panel-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--ai-border);
    background: linear-gradient(135deg, #14162b, #2b2450);
    color: #fff;
}

.ai-panel-head strong { display: block; font-size: .96rem; }
.ai-panel-head small { color: rgba(255, 255, 255, .7); font-size: .74rem; }

.ai-panel-head .ai-avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, .14);
    color: #d9d2ff;
}

.ai-panel-head-actions {
    margin-left: auto;
    display: flex;
    gap: .35rem;
}

.ai-panel-head-actions button {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    border: none;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    transition: .15s ease;
}

.ai-panel-head-actions button:hover { background: rgba(255, 255, 255, .24); }

.ai-thread {
    flex: 1;
    overflow-y: auto;
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: .85rem;
    background: #f8fafc;
}

.ai-msg {
    max-width: 88%;
    padding: .7rem .9rem;
    border-radius: 14px;
    font-size: .9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-msg-bot {
    background: #fff;
    border: 1px solid var(--ai-border);
    color: #1e293b;
    border-bottom-left-radius: 5px;
}

.ai-msg-user {
    align-self: flex-end;
    background: var(--ai-ink);
    color: #fff;
    border-bottom-right-radius: 5px;
}

.ai-typing {
    display: inline-flex;
    gap: .25rem;
}

.ai-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: ai-bounce 1s infinite;
}

.ai-typing span:nth-child(2) { animation-delay: .15s; }
.ai-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes ai-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.ai-book-list {
    display: grid;
    gap: .5rem;
    margin-top: .1rem;
}

.ai-book {
    display: flex;
    gap: .65rem;
    align-items: center;
    padding: .5rem .6rem;
    border: 1px solid var(--ai-border);
    border-radius: 12px;
    background: #fff;
    text-decoration: none;
    color: inherit;
    transition: .16s ease;
}

.ai-book:hover {
    border-color: var(--ai-accent);
    transform: translateX(2px);
}

.ai-book img {
    width: 34px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.ai-book-meta { min-width: 0; }
.ai-book-meta strong { display: block; font-size: .84rem; line-height: 1.3; }
.ai-book-meta span { font-size: .75rem; color: #64748b; }

.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    padding: .7rem 1rem 0;
    background: #f8fafc;
}

.ai-suggestions button {
    font-size: .78rem;
    padding: .35rem .7rem;
    border-radius: 999px;
    border: 1px solid var(--ai-border);
    background: #fff;
    color: #475569;
    transition: .15s ease;
}

.ai-suggestions button:hover {
    border-color: var(--ai-accent);
    color: var(--ai-accent);
}

.ai-composer {
    display: flex;
    gap: .5rem;
    padding: .85rem 1rem 1rem;
    background: #f8fafc;
    border-top: 1px solid var(--ai-border);
}

.ai-composer input {
    flex: 1;
    border: 1px solid var(--ai-border);
    border-radius: 999px;
    padding: .6rem .95rem;
    font-size: .88rem;
    background: #fff;
}

.ai-composer input:focus {
    outline: none;
    border-color: var(--ai-accent);
    box-shadow: 0 0 0 3px var(--ai-accent-soft);
}

.ai-composer button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--ai-ink);
    color: #fff;
    flex-shrink: 0;
}

.ai-composer button:disabled { opacity: .5; }

.ai-panel-foot {
    font-size: .7rem;
    color: #94a3b8;
    text-align: center;
    padding: 0 1rem .7rem;
    background: #f8fafc;
}

/* ── Insights dashboard ───────────────────────────────────── */
.ai-insight-hero {
    border-radius: 22px;
    padding: 1.6rem 1.8rem;
    background: linear-gradient(135deg, #14162b, #372d63);
    color: #fff;
    margin-bottom: 1.4rem;
}

.ai-insight-hero h1 { font-size: 1.6rem; margin-bottom: .6rem; }
.ai-insight-hero p { color: rgba(255, 255, 255, .82); margin-bottom: 1rem; max-width: 62ch; }

.ai-level-bar {
    height: 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .18);
    overflow: hidden;
    max-width: 420px;
}

.ai-level-bar span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #a78bfa, #f0abfc);
}

.ai-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: .9rem;
    margin-bottom: 1.4rem;
}

.ai-stat {
    background: #fff;
    border: 1px solid var(--ai-border);
    border-radius: 16px;
    padding: 1rem 1.1rem;
}

.ai-stat span { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: #94a3b8; }
.ai-stat strong { display: block; font-size: 1.55rem; line-height: 1.3; color: var(--ai-ink); }
.ai-stat em { font-style: normal; font-size: .78rem; color: #64748b; }

.ai-panel-card {
    background: #fff;
    border: 1px solid var(--ai-border);
    border-radius: 18px;
    padding: 1.25rem 1.4rem;
    margin-bottom: 1.2rem;
}

.ai-panel-card h2 {
    font-size: 1.05rem;
    margin-bottom: .9rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.ai-bar-row {
    display: grid;
    grid-template-columns: 130px 1fr 44px;
    align-items: center;
    gap: .7rem;
    margin-bottom: .55rem;
    font-size: .86rem;
}

.ai-bar {
    height: 8px;
    border-radius: 999px;
    background: #eef2f7;
    overflow: hidden;
}

.ai-bar span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--ai-accent), #a78bfa);
}

.ai-spark {
    display: flex;
    align-items: flex-end;
    gap: 5px;
    height: 90px;
}

.ai-spark div {
    flex: 1;
    min-height: 4px;
    border-radius: 5px 5px 0 0;
    background: linear-gradient(180deg, var(--ai-accent), #c4b5fd);
}

.ai-tip-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }

.ai-tip-list li {
    display: flex;
    gap: .6rem;
    align-items: flex-start;
    font-size: .9rem;
    color: #334155;
}

.ai-tip-list i { color: var(--ai-accent); margin-top: .2rem; }

/* Dark mode (dashboard theme) */
[data-theme="dark"] .ai-panel-card,
[data-theme="dark"] .ai-stat {
    background: #161a2b;
    border-color: rgba(255, 255, 255, .08);
}

[data-theme="dark"] .ai-stat strong,
[data-theme="dark"] .ai-panel-card h2 { color: #f8fafc; }
[data-theme="dark"] .ai-tip-list li { color: #cbd5e1; }
[data-theme="dark"] .ai-bar { background: rgba(255, 255, 255, .1); }

@media (max-width: 575.98px) {
    .ai-launcher span { display: none; }
    .ai-launcher { padding: .85rem; }
    .ai-panel { right: 12px; left: 12px; width: auto; height: min(560px, calc(100vh - 24px)); }
    .ai-bar-row { grid-template-columns: 92px 1fr 38px; }
}
