/* ==========================================================================
   AI Tutor page (public/ai-tutor.php): full-height chat, sidebar of saved chats,
   readable answers and editor-style code blocks.
   ========================================================================== */

.aip {
    --aip-bg: #080c16;
    --aip-side: #0a0f1d;
    --aip-surface: #0f172a;
    --aip-surface-2: #131c31;
    --aip-border: rgba(255, 255, 255, 0.08);
    --aip-text: #e2e8f0;
    --aip-muted: #94a3b8;
    --aip-faint: #64748b;
    --aip-accent: #38bdf8;
    --aip-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, SFMono-Regular, Consolas, Menlo, monospace;
    position: relative;
    display: flex;
    flex: 1 1 auto;
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px);
    min-height: 480px;
    overflow: hidden;
    background:
        radial-gradient(ellipse 70% 40% at 60% -10%, rgba(37, 99, 235, 0.14), transparent 70%),
        var(--aip-bg);
    color: var(--aip-text);
}

/* ---------- Sidebar ---------- */
.aip-side {
    width: 284px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--aip-side);
    border-right: 1px solid var(--aip-border);
    z-index: 30;
}
.aip-side-top { padding: 14px 14px 8px; }
.aip-new {
    width: 100%;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px 14px;
    border-radius: 12px;
    border: 1px solid rgba(56, 189, 248, 0.35);
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.22), rgba(99, 102, 241, 0.16));
    color: #e0f2fe; font-weight: 700; font-size: 14px; cursor: pointer;
    transition: background .2s, transform .1s;
}
.aip-new:hover { background: linear-gradient(135deg, rgba(37, 99, 235, 0.35), rgba(99, 102, 241, 0.28)); }
.aip-new:active { transform: scale(0.98); }
.aip-label { padding: 14px 18px 6px; font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--aip-faint); }
.aip-hist { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.aip-hist::-webkit-scrollbar, .aip-scroll::-webkit-scrollbar, .aip .code-block pre::-webkit-scrollbar { width: 8px; height: 8px; }
.aip-hist::-webkit-scrollbar-thumb, .aip-scroll::-webkit-scrollbar-thumb, .aip .code-block pre::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.25); border-radius: 8px; }
.aip-item {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px; margin: 2px 0;
    border-radius: 10px; cursor: pointer;
    color: var(--aip-muted); font-size: 13.5px;
    border: 1px solid transparent;
}
.aip-item:hover { background: rgba(255, 255, 255, 0.05); color: #fff; }
.aip-item.active { background: rgba(56, 189, 248, 0.1); border-color: rgba(56, 189, 248, 0.25); color: #fff; }
.aip-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aip-item .del { opacity: 0; background: none; border: 0; color: var(--aip-faint); cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.aip-item:hover .del, .aip-item.active .del { opacity: 1; }
.aip-item .del:hover { color: #fb7185; background: rgba(244, 63, 94, 0.12); }
.aip-empty-hist { padding: 10px 18px; font-size: 13px; color: var(--aip-faint); }

.aip-side-foot { padding: 12px 14px 16px; border-top: 1px solid var(--aip-border); }
.aip-quota { padding: 12px 14px; border-radius: 12px; background: var(--aip-surface); border: 1px solid var(--aip-border); }
.aip-quota .row { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; color: var(--aip-muted); }
.aip-quota .row b { font-size: 15px; color: #fff; }
.aip-bar { height: 6px; margin-top: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.aip-bar span { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #38bdf8, #6366f1); transition: width .4s ease; }
.aip-bar.low span { background: linear-gradient(90deg, #f59e0b, #f97316); }
.aip-bar.out span { background: #f43f5e; }
.aip-quota a { color: var(--aip-accent); font-weight: 700; text-decoration: none; }
.aip-quota a:hover { text-decoration: underline; }
.aip-note { margin: 10px 2px 0; font-size: 11px; line-height: 1.5; color: var(--aip-faint); }

/* ---------- Main column ---------- */
.aip-main { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; }
.aip-top {
    height: 54px; flex-shrink: 0;
    display: flex; align-items: center; gap: 10px;
    padding: 0 16px;
    border-bottom: 1px solid var(--aip-border);
    background: rgba(8, 12, 22, 0.7);
    backdrop-filter: blur(12px);
}
.aip-top .title { font-weight: 700; font-size: 14.5px; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aip-top .model { font-size: 11px; font-weight: 700; color: var(--aip-accent); background: rgba(56, 189, 248, 0.1); border: 1px solid rgba(56, 189, 248, 0.25); padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.aip-top .sp { flex: 1; }
.aip-icon-btn {
    width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px; border: 1px solid var(--aip-border); background: rgba(255, 255, 255, 0.04);
    color: var(--aip-muted); cursor: pointer; font-size: 14px;
}
.aip-icon-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.09); }
.aip-menu-btn { display: none; }
.aip-top-counter { font-size: 12px; font-weight: 600; color: var(--aip-muted); white-space: nowrap; }
.aip-top-counter.low { color: #fbbf24; }
.aip-top-counter.out { color: #fb7185; }

.aip-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.aip-thread { width: 100%; max-width: 860px; margin: 0 auto; padding: 8px 22px 28px; }

/* ---------- Empty state ---------- */
.aip-hero { max-width: 760px; margin: 0 auto; padding: min(9vh, 70px) 22px 20px; text-align: center; }
.aip-hero .logo {
    width: 68px; height: 68px; margin: 0 auto 18px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 22px; font-size: 28px; color: #fff;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    box-shadow: 0 18px 50px -12px rgba(79, 70, 229, 0.7);
}
.aip-hero h1 { margin: 0; font-size: clamp(1.6rem, 3.6vw, 2.3rem); font-weight: 800; letter-spacing: -0.02em; color: #fff; }
.aip-hero p { margin: 10px auto 0; max-width: 560px; color: var(--aip-muted); font-size: 15.5px; line-height: 1.65; }
.aip-suggest { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 30px; text-align: left; }
.aip-card {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 14px 16px; border-radius: 14px;
    background: var(--aip-surface); border: 1px solid var(--aip-border);
    color: var(--aip-text); font-size: 14px; line-height: 1.5; cursor: pointer; text-align: left;
    transition: border-color .2s, transform .15s, background .2s;
}
.aip-card:hover { border-color: rgba(56, 189, 248, 0.45); background: var(--aip-surface-2); transform: translateY(-2px); }
.aip-card i { margin-top: 3px; color: var(--aip-accent); font-size: 15px; }
.aip-card small { display: block; margin-top: 2px; color: var(--aip-faint); font-size: 12px; }

/* ---------- Messages ---------- */
.aip-msg { display: flex; gap: 14px; margin: 24px 0; }
.aip-msg.user { justify-content: flex-end; }
.aip-bubble {
    max-width: min(82%, 640px);
    padding: 11px 16px;
    border-radius: 18px 18px 4px 18px;
    background: linear-gradient(135deg, #1d4ed8, #4f46e5);
    color: #fff; font-size: 15px; line-height: 1.6;
    white-space: pre-wrap; overflow-wrap: anywhere;
    box-shadow: 0 8px 24px -10px rgba(37, 99, 235, 0.6);
}
.aip-avatar {
    width: 34px; height: 34px; flex-shrink: 0; margin-top: 2px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 11px; font-size: 14px; color: #fff;
    background: linear-gradient(135deg, #0ea5e9, #6366f1);
}
.aip-body { flex: 1; min-width: 0; }
.aip-name { font-size: 13px; font-weight: 700; color: #fff; margin-bottom: 4px; }
.aip-name span { margin-left: 6px; font-weight: 600; color: var(--aip-faint); font-size: 11.5px; }

/* answer typography */
.aip-md { font-size: 15.5px; line-height: 1.78; color: var(--aip-text); overflow-wrap: anywhere; }
.aip-md > :first-child { margin-top: 0; }
.aip-md > :last-child { margin-bottom: 0; }
.aip-md p { margin: 0 0 14px; }
.aip-md h1, .aip-md h2, .aip-md h3, .aip-md h4 { margin: 22px 0 10px; font-weight: 700; color: #fff; line-height: 1.35; }
.aip-md h1 { font-size: 1.4rem; } .aip-md h2 { font-size: 1.22rem; } .aip-md h3 { font-size: 1.08rem; } .aip-md h4 { font-size: 1rem; }
.aip-md ul, .aip-md ol { margin: 0 0 14px; padding-left: 1.5rem; }
.aip-md ul { list-style: disc; } .aip-md ol { list-style: decimal; }
.aip-md li { margin: 5px 0; }
.aip-md li::marker { color: var(--aip-accent); }
.aip-md a { color: #7dd3fc; text-decoration: underline; text-underline-offset: 3px; }
.aip-md strong { color: #fff; font-weight: 700; }
.aip-md blockquote { margin: 0 0 14px; padding: 8px 16px; border-left: 3px solid #6366f1; background: rgba(99, 102, 241, 0.08); border-radius: 0 10px 10px 0; color: #cbd5e1; }
.aip-md hr { border: 0; border-top: 1px solid var(--aip-border); margin: 20px 0; }
.aip-md table { width: 100%; border-collapse: collapse; margin: 0 0 16px; font-size: 14px; display: block; overflow-x: auto; }
.aip-md th, .aip-md td { padding: 8px 12px; border: 1px solid var(--aip-border); text-align: left; }
.aip-md th { background: rgba(255, 255, 255, 0.05); color: #fff; }
.aip-md :not(pre) > code {
    font-family: var(--aip-mono); font-size: 0.86em;
    padding: 2px 7px; border-radius: 7px; font-variant-ligatures: none;
    background: rgba(56, 189, 248, 0.12); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.18);
}

/* code blocks */
.aip .code-block {
    margin: 16px 0;
    border-radius: 14px;
    border: 1px solid #263041;
    background: #0d1117;
    overflow: hidden;
    box-shadow: 0 10px 30px -14px rgba(0, 0, 0, 0.8);
}
.aip .code-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 8px 10px 8px 14px;
    background: #151b27; border-bottom: 1px solid #263041;
    font-size: 12px; color: #8b98a9;
}
.aip .code-dots { display: inline-flex; gap: 6px; margin-right: 10px; vertical-align: middle; }
.aip .code-dots i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.aip .code-lang { font-family: var(--aip-mono); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: #9fb0c6; }
.aip .code-copy {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px; border-radius: 8px;
    background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.1);
    color: #c3cedd; font-size: 12px; font-weight: 600; cursor: pointer;
}
.aip .code-copy:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.aip .code-copy.done { color: #34d399; border-color: rgba(52, 211, 153, 0.4); }
.aip .code-block pre { margin: 0; padding: 16px 18px; overflow-x: auto; background: transparent; tab-size: 4; }
.aip .code-block pre code {
    display: block; padding: 0; background: transparent; border: 0; color: #e6edf3;
    font-family: var(--aip-mono); font-size: 13.5px; line-height: 1.7; white-space: pre;
    font-variant-ligatures: none; font-feature-settings: 'liga' 0, 'calt' 0;   /* show <= and === as typed, not as symbols */
}
.aip .code-block pre code.hljs { background: transparent; padding: 0; }

/* message actions */
.aip-actions { display: flex; gap: 6px; margin-top: 10px; opacity: 0; transition: opacity .15s; }
.aip-msg:hover .aip-actions, .aip-msg:last-child .aip-actions, .aip-actions:focus-within { opacity: 1; }
.aip-act {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px; border-radius: 8px; background: transparent;
    border: 1px solid var(--aip-border); color: var(--aip-muted); font-size: 12px; font-weight: 600; cursor: pointer;
}
.aip-act:hover { color: #fff; background: rgba(255, 255, 255, 0.07); }
.aip-act.done { color: #34d399; }

/* streaming state */
.aip-dots { display: inline-flex; gap: 5px; padding: 10px 0; }
.aip-dots span { width: 8px; height: 8px; border-radius: 50%; background: #64748b; animation: aipDot 1.2s infinite ease-in-out; }
.aip-dots span:nth-child(2) { animation-delay: 0.15s; } .aip-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes aipDot { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }
.aip-msg.streaming .aip-md > :last-child:not(.code-block)::after {
    content: ""; display: inline-block; width: 8px; height: 1.05em; margin-left: 3px; vertical-align: text-bottom;
    background: var(--aip-accent); border-radius: 2px; animation: aipCaret 0.9s steps(2) infinite;
}
@keyframes aipCaret { 0% { opacity: 1; } 100% { opacity: 0; } }

.aip-error {
    padding: 12px 16px; border-radius: 14px; font-size: 14px; line-height: 1.55;
    background: rgba(244, 63, 94, 0.1); border: 1px solid rgba(244, 63, 94, 0.3); color: #fecdd3;
}
.aip-error a { color: #fff; font-weight: 700; text-decoration: underline; }

.aip-jump {
    position: absolute; left: 50%; bottom: 118px; transform: translateX(-50%);
    display: none; align-items: center; gap: 6px;
    padding: 7px 14px; border-radius: 999px; z-index: 10;
    background: #1e293b; border: 1px solid rgba(255, 255, 255, 0.15); color: #e2e8f0;
    font-size: 12px; font-weight: 700; cursor: pointer; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.aip-jump.show { display: inline-flex; }

/* ---------- Composer ---------- */
.aip-composer { flex-shrink: 0; padding: 8px 22px calc(14px + env(safe-area-inset-bottom, 0px)); background: linear-gradient(to top, var(--aip-bg) 65%, transparent); }
.aip-box {
    max-width: 860px; margin: 0 auto;
    display: flex; align-items: flex-end; gap: 10px;
    padding: 10px 10px 10px 18px;
    border-radius: 20px;
    background: var(--aip-surface); border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 16px 40px -18px rgba(0, 0, 0, 0.8);
    transition: border-color .2s, box-shadow .2s;
}
.aip-box:focus-within { border-color: rgba(56, 189, 248, 0.6); box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.1), 0 16px 40px -18px rgba(0, 0, 0, 0.8); }
.aip-box textarea {
    flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent;
    color: #fff; font: inherit; font-size: 15.5px; line-height: 1.6;
    padding: 6px 0; max-height: 200px; min-height: 28px;
}
.aip-box textarea::placeholder { color: var(--aip-faint); }
.aip-send {
    width: 42px; height: 42px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 14px; border: 0; cursor: pointer; color: #fff; font-size: 15px;
    background: linear-gradient(135deg, #2563eb, #6366f1);
    box-shadow: 0 8px 20px -8px rgba(79, 70, 229, 0.8);
    transition: transform .1s, filter .15s, opacity .2s;
}
.aip-send:hover { filter: brightness(1.12); }
.aip-send:active { transform: scale(0.94); }
.aip-send:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }
.aip-send.stop { background: #334155; box-shadow: none; }
.aip-foot-note { max-width: 860px; margin: 8px auto 0; display: flex; justify-content: space-between; gap: 12px; font-size: 11.5px; color: var(--aip-faint); }
.aip-foot-note .len.warn { color: #fbbf24; }

/* ---------- Responsive ---------- */
.aip-backdrop { display: none; }
@media (max-width: 900px) {
    .aip-side { position: absolute; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .25s ease; width: min(86vw, 320px); box-shadow: 20px 0 50px rgba(0, 0, 0, 0.6); }
    .aip.side-open .aip-side { transform: none; }
    .aip.side-open .aip-backdrop { display: block; position: absolute; inset: 0; background: rgba(2, 6, 23, 0.6); z-index: 20; }
    .aip-menu-btn { display: inline-flex; }
    .aip-top .model { display: none; }
}
@media (max-width: 640px) {
    .aip-thread { padding: 4px 14px 24px; }
    .aip-composer { padding: 6px 12px calc(10px + env(safe-area-inset-bottom, 0px)); }
    .aip-suggest { grid-template-columns: 1fr; }
    .aip-msg { gap: 10px; margin: 20px 0; }
    .aip-avatar { width: 30px; height: 30px; font-size: 12px; border-radius: 10px; }
    .aip-bubble { max-width: 90%; }
    .aip-md { font-size: 15px; }
    .aip .code-block { margin: 14px -6px; border-radius: 12px; }
    .aip .code-block pre code { font-size: 12.5px; }
    .aip-actions { opacity: 1; }
    .aip-foot-note .hint { display: none; }
    .aip-hero { padding-top: 40px; }
    .aip-jump { bottom: 104px; }
}
@media (prefers-reduced-motion: reduce) { .aip-dots span, .aip-msg.streaming .aip-md > :last-child::after { animation: none; } }

/* The install banner would sit on top of the composer */
#installBanner { display: none !important; }

/* ---------- Sensitive-data warning (passwords, API keys, PINs, bank details) ---------- */
.aip-warn {
    max-width: 860px; margin: 0 auto 10px;
    display: flex; gap: 12px; align-items: flex-start;
    padding: 12px 16px; border-radius: 14px;
    background: rgba(245, 158, 11, 0.1); border: 1px solid rgba(245, 158, 11, 0.4); color: #fde68a;
    font-size: 13.5px; line-height: 1.55;
}
.aip-warn[hidden] { display: none; }
.aip-warn > i { margin-top: 3px; font-size: 18px; color: #fbbf24; flex-shrink: 0; }
.aip-warn b { display: block; margin-bottom: 4px; color: #fff; font-size: 14px; }
.aip-warn span { display: block; white-space: pre-line; color: #fde68a; }
