/* ═══════════════════════════════════════════════════════════
   MNN Learning — AI Sensei Beta
   ai-sensei.css — Phase 1
   Tidak mengubah styles.css utama
   ═══════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────
   PAGE WRAPPER
───────────────────────────────────────────── */
#page-ai-sensei {
    display: none;
    flex-direction: column;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    background: var(--bg, #0f0f13);
    position: relative;
}
#page-ai-sensei.active {
    display: flex;
}

/* ─────────────────────────────────────────────
   HEADER
───────────────────────────────────────────── */
.ais-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    background: var(--bg, #0f0f13);
    gap: 10px;
}

.ais-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.ais-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6c63ff 0%, #48cfad 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.ais-header-info {
    min-width: 0;
}
.ais-header-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text, #f0f0f5);
    line-height: 1.2;
    white-space: nowrap;
}
.ais-header-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #6c63ff;
    background: rgba(108,99,255,0.15);
    border: 1px solid rgba(108,99,255,0.35);
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 4px;
    vertical-align: middle;
}

/* Kredit bar header */
.ais-credit-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}
.ais-credit-label {
    font-size: 11px;
    color: var(--text-muted, #888);
    white-space: nowrap;
}
#ais-credit-remaining {
    font-size: 11px;
    font-weight: 600;
    color: var(--text, #f0f0f5);
}
.ais-credit-track {
    width: 80px;
    height: 4px;
    background: rgba(255,255,255,0.1);
    border-radius: 99px;
    overflow: hidden;
}
.ais-credit-bar-fill {
    height: 100%;
    background: #48cfad;
    border-radius: 99px;
    transition: width 0.5s ease;
}
.ais-credit-bar-fill.ais-credit-mid { background: #ffc107; }
.ais-credit-bar-fill.ais-credit-low { background: #ff6b6b; }

/* Tombol new chat */
#ais-new-chat-btn {
    flex-shrink: 0;
    background: rgba(108,99,255,0.12);
    border: 1px solid rgba(108,99,255,0.3);
    color: #9d97ff;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 11px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}
#ais-new-chat-btn:hover { background: rgba(108,99,255,0.22); }

/* ─────────────────────────────────────────────
   QUICK QUESTIONS
───────────────────────────────────────────── */
.ais-quick-wrap {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    padding: 10px 16px 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.ais-quick-wrap::-webkit-scrollbar { display: none; }
.ais-quick-btn {
    flex-shrink: 0;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text, #f0f0f5);
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 99px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}
.ais-quick-btn:hover {
    background: rgba(108,99,255,0.15);
    border-color: rgba(108,99,255,0.4);
}

/* ─────────────────────────────────────────────
   MESSAGES AREA
───────────────────────────────────────────── */
#ais-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
#ais-messages::-webkit-scrollbar { width: 4px; }
#ais-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 99px; }

/* ── Welcome ── */
.ais-welcome {
    text-align: center;
    padding: 28px 16px;
    margin: auto;
    max-width: 300px;
}
.ais-welcome-icon {
    font-size: 48px;
    margin-bottom: 12px;
    animation: ais-float 3s ease-in-out infinite;
}
@keyframes ais-float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-6px); }
}
.ais-welcome-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text, #f0f0f5);
    margin-bottom: 8px;
}
.ais-welcome-sub {
    font-size: 13px;
    color: var(--text-muted, #888);
    line-height: 1.6;
}

/* ── Bubbles ── */
.ais-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.65;
    word-break: break-word;
}
.ais-bubble-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #6c63ff 0%, #7c72ff 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ais-bubble-ai {
    align-self: flex-start;
    background: rgba(255,255,255,0.06);
    color: var(--text, #f0f0f5);
    border: 1px solid rgba(255,255,255,0.08);
    border-bottom-left-radius: 4px;
}
.ais-bubble-ai p {
    margin: 0 0 8px;
}
.ais-bubble-ai p:last-child { margin-bottom: 0; }
.ais-bubble-ai ul {
    margin: 4px 0;
    padding-left: 18px;
}
.ais-bubble-ai li {
    margin-bottom: 4px;
}
.ais-bubble-ai strong { color: #9d97ff; }
.ais-bubble-ai em { color: #48cfad; font-style: normal; }

.ais-bubble-error {
    align-self: stretch;
    background: rgba(255,107,107,0.1);
    border: 1px solid rgba(255,107,107,0.25);
    color: #ff9a9a;
    border-radius: 12px;
    font-size: 13px;
    text-align: center;
    white-space: pre-line;
}
.ais-error-icon { margin-right: 4px; }

/* ── Loading dots ── */
.ais-loading {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
    width: fit-content;
}
.ais-loading span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(255,255,255,0.4);
    animation: ais-dot 1.2s ease-in-out infinite;
}
.ais-loading span:nth-child(2) { animation-delay: 0.2s; }
.ais-loading span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ais-dot {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
    40%           { transform: scale(1.1); opacity: 1; }
}

/* ─────────────────────────────────────────────
   INPUT AREA
───────────────────────────────────────────── */
.ais-input-wrap {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 10px 16px 16px;
    border-top: 1px solid rgba(255,255,255,0.07);
    background: var(--bg, #0f0f13);
}

#ais-input {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 14px;
    color: var(--text, #f0f0f5);
    font-size: 14px;
    line-height: 1.5;
    padding: 10px 14px;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    overflow-y: auto;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
}
#ais-input::placeholder { color: var(--text-muted, #666); }
#ais-input:focus {
    border-color: rgba(108,99,255,0.5);
    background: rgba(255,255,255,0.08);
}
#ais-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#ais-send-btn {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #6c63ff 0%, #48cfad 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s, transform 0.1s;
    color: #fff;
}
#ais-send-btn:active { transform: scale(0.93); }
#ais-send-btn:disabled,
#ais-send-btn.ais-btn-loading {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}
#ais-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* ─────────────────────────────────────────────
   NAV ITEM — ai-sensei (ditambah di bottom-nav)
───────────────────────────────────────────── */
.nav-item[data-page="ai-sensei"] .nav-icon {
    font-size: 20px;
}
.nav-item[data-page="ai-sensei"].active .nav-label {
    color: #6c63ff;
}
.nav-item[data-page="ai-sensei"].active .nav-icon::after {
    background: #6c63ff;
}

/* ─────────────────────────────────────────────
   RESPONSIVE — safe area bottom
───────────────────────────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .ais-input-wrap {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

/* ═══════════════════════════════════════════════════════════
   AI CREDIT PAGE — ai-sensei-credit.js styles
   ═══════════════════════════════════════════════════════════ */

/* Page wrapper */
#page-ai-credit {
    display: none;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg, #0f0f13);
}
#page-ai-credit.active { display: flex; }

/* Back button */
.aic-back-btn {
    background: none;
    border: none;
    color: var(--text, #f0f0f5);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

/* Header balance */
.aic-header-balance {
    font-size: 13px;
    font-weight: 700;
    color: #6c63ff;
    background: rgba(108,99,255,0.12);
    border: 1px solid rgba(108,99,255,0.3);
    padding: 5px 12px;
    border-radius: 99px;
    flex-shrink: 0;
}

/* Scroll container */
.aic-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 96px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.08) transparent;
}

/* Cards */
.aic-card {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px;
    padding: 18px;
}
.aic-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted, #888);
    margin-bottom: 14px;
}

/* Balance card */
.aic-balance-card {
    background: linear-gradient(135deg, rgba(108,99,255,0.15) 0%, rgba(72,207,173,0.1) 100%);
    border-color: rgba(108,99,255,0.2);
    text-align: center;
}
.aic-balance-num {
    font-size: 52px;
    font-weight: 800;
    line-height: 1;
    color: var(--text, #f0f0f5);
    margin-bottom: 4px;
}
.aic-balance-label {
    font-size: 13px;
    color: var(--text-muted, #888);
    margin-bottom: 16px;
}
.aic-balance-track {
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 12px;
}
.aic-balance-meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted, #888);
}

/* Bonus card */
.aic-bonus-card { border-color: rgba(72,207,173,0.2); }
.aic-bonus-row {
    display: flex;
    align-items: center;
    gap: 12px;
}
.aic-bonus-icon { font-size: 28px; flex-shrink: 0; }
.aic-bonus-name { font-size: 14px; font-weight: 600; color: var(--text, #f0f0f5); }
.aic-bonus-sub  { font-size: 12px; color: var(--text-muted, #888); margin-top: 2px; }
.aic-bonus-badge {
    margin-left: auto;
    font-size: 11px;
    font-weight: 700;
    color: #48cfad;
    background: rgba(72,207,173,0.12);
    border: 1px solid rgba(72,207,173,0.3);
    padding: 3px 9px;
    border-radius: 99px;
    flex-shrink: 0;
}

/* Usage log */
.aic-log-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.aic-log-row:last-child { border-bottom: none; }
.aic-log-icon { font-size: 22px; flex-shrink: 0; }
.aic-log-feature { font-size: 13px; font-weight: 600; color: var(--text, #f0f0f5); }
.aic-log-date   { font-size: 11px; color: var(--text-muted, #888); margin-top: 2px; }
.aic-log-cost   {
    margin-left: auto;
    font-size: 13px;
    font-weight: 700;
    color: #ff9a9a;
    flex-shrink: 0;
}
.aic-empty {
    text-align: center;
    color: var(--text-muted, #888);
    font-size: 13px;
    padding: 16px 0;
}

/* Top up packages */
.aic-pkg-note {
    font-size: 12px;
    color: var(--text-muted, #888);
    margin-bottom: 14px;
}
.aic-pkg-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.aic-pkg-card {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 14px 10px;
    text-align: center;
    position: relative;
}
.aic-pkg-tag {
    position: absolute;
    top: -9px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #6c63ff;
    color: #fff;
    padding: 2px 8px;
    border-radius: 99px;
    white-space: nowrap;
}
.aic-pkg-credits {
    font-size: 26px;
    font-weight: 800;
    color: var(--text, #f0f0f5);
    line-height: 1;
}
.aic-pkg-label {
    font-size: 11px;
    color: var(--text-muted, #888);
    margin-bottom: 8px;
}
.aic-pkg-price {
    font-size: 13px;
    font-weight: 700;
    color: #48cfad;
    margin-bottom: 10px;
}
.aic-pkg-btn {
    width: 100%;
    background: rgba(108,99,255,0.15);
    border: 1px solid rgba(108,99,255,0.3);
    color: #9d97ff;
    font-size: 11px;
    font-weight: 600;
    padding: 7px 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}
.aic-pkg-btn:hover { background: rgba(108,99,255,0.28); }

/* Admin tools */
.aic-admin-card { border-color: rgba(255,193,7,0.2); }
.aic-admin-mode-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}
.aic-mode-btn {
    flex: 1;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid rgba(255,193,7,0.3);
    background: transparent;
    color: rgba(255,193,7,0.5);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.aic-mode-btn.aic-mode-active {
    background: rgba(255,193,7,0.15);
    border-color: rgba(255,193,7,0.6);
    color: #ffc107;
}
.aic-admin-label {
    font-size: 13px;
    color: var(--text-muted, #888);
    margin-bottom: 10px;
}
.aic-admin-input {
    width: 100%;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    color: var(--text, #f0f0f5);
    font-size: 13px;
    padding: 10px 12px;
    outline: none;
    margin-bottom: 10px;
    font-family: inherit;
    box-sizing: border-box;
}
.aic-admin-input:focus { border-color: rgba(255,193,7,0.5); }
.aic-admin-btn {
    width: 100%;
    background: rgba(255,193,7,0.15);
    border: 1px solid rgba(255,193,7,0.3);
    color: #ffc107;
    font-size: 13px;
    font-weight: 700;
    padding: 11px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
}
.aic-admin-btn:hover { background: rgba(255,193,7,0.25); }
.aic-admin-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.aic-admin-result { font-size: 12px; margin-top: 10px; text-align: center; }
.aic-admin-ok  { color: #48cfad; }
.aic-admin-err { color: #ff9a9a; }

/* ─────────────────────────────────────────────────────────
   ADMIN ANALYTICS DASHBOARD
───────────────────────────────────────────────────────── */
.aic-analytics-card { border-color: rgba(99,179,237,0.3); }
.aic-analytics-empty { font-size: 13px; color: rgba(255,255,255,0.4); text-align: center; padding: 16px 0; }
.aic-analytics-subtitle {
    font-size: 11px; font-weight: 600; letter-spacing: 1px;
    color: rgba(255,255,255,0.4); margin: 16px 0 8px;
    text-transform: uppercase;
}

/* Stat grid */
.aic-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 4px;
}
.aic-stat-box {
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    padding: 10px 12px;
    border: 1px solid rgba(255,255,255,0.07);
}
.aic-stat-highlight {
    background: rgba(99,179,237,0.1);
    border-color: rgba(99,179,237,0.25);
}
.aic-stat-num {
    font-size: 18px; font-weight: 700; color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aic-stat-lbl { font-size: 10px; color: rgba(255,255,255,0.45); margin-top: 2px; }

/* Feature bar chart */
.aic-feat-chart { display: flex; flex-direction: column; gap: 6px; }
.aic-feat-row { display: flex; align-items: center; gap: 8px; }
.aic-feat-label { font-size: 11px; color: rgba(255,255,255,0.6); width: 110px; flex-shrink: 0; }
.aic-feat-bar-wrap { flex: 1; background: rgba(255,255,255,0.07); border-radius: 4px; height: 8px; overflow: hidden; }
.aic-feat-bar { height: 100%; background: #63b3ed; border-radius: 4px; transition: width 0.4s ease; }
.aic-feat-count { font-size: 11px; color: rgba(255,255,255,0.5); width: 30px; text-align: right; }

/* Top users table */
.aic-table-wrap { overflow-x: auto; margin-top: 4px; }
.aic-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.aic-table th {
    text-align: left; padding: 6px 8px;
    color: rgba(255,255,255,0.4); border-bottom: 1px solid rgba(255,255,255,0.08);
    font-weight: 600;
}
.aic-table td { padding: 6px 8px; color: rgba(255,255,255,0.75); border-bottom: 1px solid rgba(255,255,255,0.05); }
.aic-uid-cell { font-family: monospace; font-size: 10px; }
.aic-refresh-btn {
    font-size: 10px; background: transparent; border: 1px solid rgba(99,179,237,0.4);
    color: #63b3ed; border-radius: 6px; padding: 2px 8px; cursor: pointer; margin-left: 8px;
}
.aic-refresh-btn:hover { background: rgba(99,179,237,0.1); }

/* Light mode overrides */
[data-theme="light"] .aic-stat-box { background: rgba(0,0,0,0.03); border-color: rgba(0,0,0,0.08); }
[data-theme="light"] .aic-stat-num { color: #1a1a2e; }
[data-theme="light"] .aic-stat-lbl { color: rgba(0,0,0,0.45); }
[data-theme="light"] .aic-feat-label { color: rgba(0,0,0,0.6); }
[data-theme="light"] .aic-feat-bar-wrap { background: rgba(0,0,0,0.07); }
[data-theme="light"] .aic-feat-bar { background: #3c3489; }
[data-theme="light"] .aic-feat-count { color: rgba(0,0,0,0.5); }
[data-theme="light"] .aic-table th { color: rgba(0,0,0,0.4); border-color: rgba(0,0,0,0.1); }
[data-theme="light"] .aic-table td { color: rgba(0,0,0,0.75); border-color: rgba(0,0,0,0.05); }
[data-theme="light"] .aic-analytics-empty { color: rgba(0,0,0,0.4); }
[data-theme="light"] .aic-analytics-subtitle { color: rgba(0,0,0,0.35); }

/* Loading spinner */
.aic-loading-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
}
.aic-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255,255,255,0.08);
    border-top-color: #6c63ff;
    border-radius: 50%;
    animation: aic-spin 0.8s linear infinite;
}
@keyframes aic-spin { to { transform: rotate(360deg); } }

/* Credit popup */
#ais-credit-popup, #aic-topup-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    padding: 24px;
}
.ais-popup-box {
    background: #1a1a24;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 28px 24px;
    max-width: 340px;
    width: 100%;
    text-align: center;
}
.ais-popup-icon  { font-size: 40px; margin-bottom: 12px; }
.ais-popup-title { font-size: 17px; font-weight: 700; color: var(--text,#f0f0f5); margin-bottom: 12px; }
.ais-popup-body  { font-size: 14px; color: var(--text-muted,#aaa); line-height: 1.7; margin-bottom: 8px; }
.ais-popup-sub   { font-size: 12px; color: var(--text-muted,#666); margin-bottom: 20px; }
.ais-popup-actions { display: flex; gap: 10px; }
.ais-popup-btn-secondary {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-muted,#aaa);
    font-size: 14px;
    font-weight: 600;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
}
.ais-popup-btn-primary {
    flex: 1;
    background: linear-gradient(135deg, #6c63ff, #48cfad);
    border: none;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
}

/* Cost badge */
.ais-cost-badge {
    align-self: center;
    font-size: 11px;
    color: var(--text-muted,#666);
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 99px;
    padding: 3px 10px;
}

/* Welcome bonus toast */
.ais-bonus-toast {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: linear-gradient(135deg, rgba(72,207,173,0.95), rgba(108,99,255,0.95));
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 12px 20px;
    border-radius: 99px;
    z-index: 9999;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}
.ais-bonus-icon { font-size: 18px; }

/* Tombol credit di header AI Sensei */
.aic-header-link {
    flex-shrink: 0;
    background: rgba(108,99,255,0.1);
    border: 1px solid rgba(108,99,255,0.25);
    border-radius: 10px;
    font-size: 18px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.aic-header-link:hover { background: rgba(108,99,255,0.22); }

/* ─── Top Up QRIS Modal ─── */
.aic-topup-box {
    max-width: 360px;
    padding: 24px 20px 20px;
    position: relative;
    text-align: center;
    max-height: 90dvh;
    overflow-y: auto;
}
.aic-topup-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: rgba(255,255,255,0.06);
    border: none;
    color: var(--text-muted, #aaa);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.aic-topup-price {
    font-size: 22px;
    font-weight: 800;
    color: #48cfad;
    margin: 4px 0 16px;
}
.aic-qris-label {
    font-size: 12px;
    color: var(--text-muted, #888);
    margin-bottom: 10px;
}
.aic-qris-wrap {
    background: #fff;
    border-radius: 14px;
    padding: 12px;
    margin-bottom: 12px;
    display: inline-block;
    width: 100%;
    box-sizing: border-box;
}
.aic-qris-img {
    width: 100%;
    max-width: 240px;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 8px;
}
.aic-qris-err {
    color: #999;
    font-size: 13px;
    padding: 20px;
}
.aic-topup-memberid {
    font-size: 12px;
    color: var(--text-muted, #888);
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 12px;
    word-break: break-all;
}
.aic-topup-note {
    font-size: 12px;
    color: var(--text-muted, #777);
    margin-bottom: 4px;
    line-height: 1.5;
}
.aic-wa-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    background: #25D366;
    border: none;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    padding: 14px 16px;
    border-radius: 12px;
    cursor: pointer;
    text-decoration: none;
    box-sizing: border-box;
    transition: background 0.15s;
}
.aic-wa-btn:hover { background: #1ebe59; }

/* ─── Quick Buttons — Roleplay highlight ─── */
.ais-quick-btn.ais-quick-roleplay {
    background: rgba(108,99,255,0.12);
    border-color: rgba(108,99,255,0.3);
    color: #c4c0ff;
}
.ais-quick-btn.ais-quick-roleplay:hover {
    background: rgba(108,99,255,0.25);
}

/* ─── QRIS Zoom Overlay ─── */
#aic-qris-zoom {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 16px;
}
.aic-qris-zoom-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 400px;
    width: 100%;
}
.aic-qris-zoom-img {
    width: 100%;
    height: auto;
    border-radius: 16px;
    background: #fff;
    padding: 16px;
    box-sizing: border-box;
    /* Pinch zoom di mobile */
    touch-action: pinch-zoom;
}
.aic-qris-zoom-close {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 28px;
    border-radius: 99px;
    cursor: pointer;
}

/* ════════════════════════════════════════════════════════
   UI FIX — Layout In-flow + Light Mode + Scroll UX
   Tidak pakai position:fixed agar tidak overlap header/sidebar.
   Page mengisi container alaminya di dalam <main>.
   ════════════════════════════════════════════════════════ */

/* ══════════════════════════════════════════════════════════
   CORE LAYOUT FIX
   Rantai height harus terdefinisi agar flex children
   bisa scroll dengan benar di mobile.
   ══════════════════════════════════════════════════════════

   #app (min-height: 100dvh → dikunci jadi height: 100dvh)
    └── main.main-content (flex:1 → padding:0, overflow:hidden)
         └── #page-ai-sensei (flex:1, min-height:0)
              ├── .ais-header (flex-shrink:0)
              ├── .ais-quick-wrap (flex-shrink:0)
              ├── #ais-messages (flex:1, min-height:0, overflow-y:auto) ← HANYA ini scroll
              └── .ais-input-wrap (flex-shrink:0) ← selalu di bawah
   ══════════════════════════════════════════════════════════ */

/* ── 0. Kunci #app ke 100dvh saat halaman AI aktif ──
   Tanpa ini, #app hanya min-height sehingga height:100%
   pada main/page tidak bisa resolve dengan benar di mobile. */
#app.ais-app-lock {
    height: 100dvh !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

/* FIX: .app-main-col harus jadi flex container di mobile agar
   rantai flex #app → .app-main-col → main → page bisa bekerja.
   Tanpa ini, main.ais-page-active { flex:1 } tidak ada efeknya
   karena parent (.app-main-col) bukan flex container di mobile.
   MOBILE ONLY — desktop sudah punya rule sendiri di styles.css @media(min-width:960px) */
@media (max-width: 959px) {
    #app.ais-app-lock > .app-main-col {
        flex: 1 !important;
        min-height: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }
}

/* ── 1. main: buang padding, jadikan flex column ── */
main.ais-page-active {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    min-height: 0 !important;
    overflow: hidden !important;
    padding: 0 !important;
    gap: 0 !important;
    height: auto !important; /* biarkan flex tentukan tinggi */
}

/* ── 2. Page wrapper: flex:1 dengan min-height:0 ── */
#page-ai-sensei {
    background: var(--bg-base, #0f0f13) !important;
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* KRITIS: tanpa ini flex child tidak bisa scroll */
    height: auto !important;    /* FIX: override height:100dvh dari blok awal */
    max-height: none !important; /* FIX: override max-height:100dvh dari blok awal */
    overflow: hidden;
    position: relative !important;
    top: auto !important; left: auto !important;
    right: auto !important; bottom: auto !important;
}
#page-ai-sensei.active {
    display: flex;
    gap: 0 !important;
    animation: none !important;
}

/* ── 3. Header: tetap di atas ── */
.ais-header {
    background: var(--bg-base, #0f0f13) !important;
    border-bottom: 1px solid var(--border, rgba(255,255,255,0.07)) !important;
    flex-shrink: 0;
    position: relative;
    z-index: 5;
}

/* ── 4. Quick wrap: tidak ikut scroll ── */
.ais-quick-wrap {
    flex-shrink: 0;
    background: var(--bg-base, #0f0f13);
}

/* ── 5. Messages: HANYA ini yang scroll ──
   flex:1 + min-height:0 = mengisi sisa ruang dan bisa scroll. */
#ais-messages {
    flex: 1;
    min-height: 0; /* KRITIS */
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* ── 6. Input wrap: selalu menempel di bawah ── */
.ais-input-wrap {
    background: var(--bg-base, #0f0f13) !important;
    border-top: 1px solid var(--border, rgba(255,255,255,0.07)) !important;
    flex-shrink: 0 !important;
    position: relative;
    z-index: 95; /* FIX: di atas bottom-nav (z-index:90) agar tidak tertutup */
    padding: 10px 16px !important;
    padding-bottom: max(16px, env(safe-area-inset-bottom)) !important;
}

/* ── 6. Scroll Buttons — floating di atas #ais-messages ──
   Keduanya absolute di dalam #page-ai-sensei (position:relative).
   Disejajarkan secara vertikal (flex column) di kanan tengah. */
#ais-scroll-top,
#ais-scroll-bottom {
    position: absolute;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-elevated, #23232f);
    border: 1px solid var(--border-strong, rgba(255,255,255,0.14));
    color: var(--text-primary, #f0f0f5);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 20;
}
/* Scroll-up: mepet di bawah quick-wrap + header */
#ais-scroll-top {
    top: auto;
    /* Dihitung dari #ais-messages via JS, tapi fallback CSS pakai positioning */
    bottom: calc(72px + 100px); /* input-wrap + gap + scroll-down height */
}
/* Scroll-down: tepat di atas input bar */
#ais-scroll-bottom {
    bottom: calc(72px + 56px); /* input-wrap ~72px + margin cukup lapang */
}
#ais-scroll-top.visible,
#ais-scroll-bottom.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

/* ════════════════════════════════════════════════════════
   LIGHT MODE — semua komponen AI Sensei
   Selector: [data-theme="light"] (sesuai app)
   ════════════════════════════════════════════════════════ */
[data-theme="light"] #page-ai-sensei,
[data-theme="light"] .ais-header,
[data-theme="light"] .ais-quick-wrap,
[data-theme="light"] .ais-input-wrap {
    background: var(--bg-base, #f5f5f7) !important;
}

[data-theme="light"] .ais-header {
    border-bottom-color: var(--border, rgba(0,0,0,0.07)) !important;
}

[data-theme="light"] .ais-header-title {
    color: var(--text-primary, #1a1a2e);
}

[data-theme="light"] #ais-credit-remaining {
    color: var(--text-primary, #1a1a2e);
}

[data-theme="light"] .ais-credit-track {
    background: rgba(0,0,0,0.08);
}

[data-theme="light"] #ais-new-chat-btn,
[data-theme="light"] .aic-header-link {
    background: rgba(108,99,255,0.08);
    color: #5a54e0;
    border-color: rgba(108,99,255,0.2);
}

[data-theme="light"] .ais-quick-btn {
    background: var(--bg-surface, #ffffff);
    border-color: var(--border-strong, rgba(0,0,0,0.13));
    color: var(--text-primary, #1a1a2e);
}

[data-theme="light"] .ais-quick-btn.ais-quick-roleplay {
    background: rgba(108,99,255,0.06);
    border-color: rgba(108,99,255,0.2);
    color: #5a54e0;
}

[data-theme="light"] #ais-messages {
    background: var(--bg-base, #f5f5f7);
}

[data-theme="light"] .ais-welcome-title {
    color: var(--text-primary, #1a1a2e);
}

[data-theme="light"] .ais-welcome-sub {
    color: var(--text-secondary, #5a5a7a);
}

[data-theme="light"] .ais-bubble-user {
    background: linear-gradient(135deg, #5a54e0 0%, #6c63ff 100%);
    color: #fff;
}

[data-theme="light"] .ais-bubble-ai {
    background: var(--bg-surface, #ffffff);
    border-color: var(--border, rgba(0,0,0,0.07));
    color: var(--text-primary, #1a1a2e);
}

[data-theme="light"] .ais-bubble-ai strong { color: #5a54e0; }
[data-theme="light"] .ais-bubble-ai em     { color: #2a8f6f; }

[data-theme="light"] .ais-bubble-error {
    background: rgba(220,50,50,0.06);
    border-color: rgba(220,50,50,0.15);
    color: #b32020;
}

[data-theme="light"] .ais-loading span {
    background: rgba(0,0,0,0.2);
}

[data-theme="light"] .ais-cost-badge {
    background: var(--bg-card, #ffffff);
    border-color: var(--border, rgba(0,0,0,0.07));
    color: var(--text-secondary, #5a5a7a);
}

[data-theme="light"] #ais-input {
    background: var(--bg-surface, #ffffff);
    border-color: var(--border-strong, rgba(0,0,0,0.13));
    color: var(--text-primary, #1a1a2e);
}

[data-theme="light"] #ais-input::placeholder {
    color: var(--text-secondary, #9898b4);
}

[data-theme="light"] #ais-input:focus {
    border-color: rgba(108,99,255,0.4);
    background: #fff;
}

/* AI Credit page — light mode */
[data-theme="light"] #page-ai-credit {
    background: var(--bg-base, #f5f5f7) !important;
}

[data-theme="light"] .ais-header {
    background: var(--bg-base, #f5f5f7) !important;
}

[data-theme="light"] .aic-scroll {
    background: var(--bg-base, #f5f5f7);
}

[data-theme="light"] .aic-card {
    background: var(--bg-surface, #ffffff);
    border-color: var(--border, rgba(0,0,0,0.07));
}

[data-theme="light"] .aic-section-title {
    color: var(--text-secondary, #5a5a7a);
}

[data-theme="light"] .aic-balance-num,
[data-theme="light"] .aic-balance-label,
[data-theme="light"] .aic-balance-meta,
[data-theme="light"] .aic-log-feature {
    color: var(--text-primary, #1a1a2e);
}

[data-theme="light"] .aic-log-date,
[data-theme="light"] .aic-bonus-sub,
[data-theme="light"] .aic-pkg-note {
    color: var(--text-secondary, #5a5a7a);
}

[data-theme="light"] .aic-log-row {
    border-bottom-color: var(--border, rgba(0,0,0,0.06));
}

[data-theme="light"] .aic-balance-track {
    background: rgba(0,0,0,0.08);
}

[data-theme="light"] .aic-pkg-card {
    background: var(--bg-surface, #fff);
    border-color: var(--border-strong, rgba(0,0,0,0.13));
}

[data-theme="light"] .aic-pkg-credits { color: var(--text-primary, #1a1a2e); }

[data-theme="light"] .aic-admin-input {
    background: var(--bg-surface, #fff);
    border-color: var(--border-strong, rgba(0,0,0,0.13));
    color: var(--text-primary, #1a1a2e);
}

[data-theme="light"] .ais-popup-box {
    background: var(--bg-surface, #ffffff);
    border-color: var(--border, rgba(0,0,0,0.07));
}

[data-theme="light"] .ais-popup-title { color: var(--text-primary, #1a1a2e); }
[data-theme="light"] .ais-popup-body  { color: var(--text-secondary, #5a5a7a); }
[data-theme="light"] .ais-popup-sub   { color: var(--text-secondary, #9898b4); }

[data-theme="light"] .ais-popup-btn-secondary {
    background: rgba(0,0,0,0.04);
    border-color: var(--border, rgba(0,0,0,0.1));
    color: var(--text-secondary, #5a5a7a);
}

[data-theme="light"] #ais-scroll-top {
    background: var(--bg-surface, #fff);
    border-color: var(--border-strong, rgba(0,0,0,0.13));
    color: var(--text-primary, #1a1a2e);
}

/* ── Scroll to Bottom Button ── */
/* #ais-scroll-bottom sudah didefinisikan di blok scroll buttons di atas */
[data-theme="light"] #ais-scroll-bottom {
    background: var(--bg-surface, #fff);
    border-color: var(--border-strong, rgba(0,0,0,0.13));
    color: var(--text-primary, #1a1a2e);
}

/* ── AI Credit page: sama seperti ai-sensei, gunakan flex layout ── */
#page-ai-credit {
    position: relative !important;
    top: auto !important; left: auto !important;
    flex: 1 !important;
    min-height: 0 !important;
    height: auto !important;      /* FIX: override height:100dvh dari blok awal */
    max-height: none !important;
    overflow: hidden !important;
}
#page-ai-credit.active {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
    animation: none !important;
}
.aic-scroll {
    flex: 1 !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* ════════════════════════════════════════════════════════
   CHAT HISTORY DRAWER
   ════════════════════════════════════════════════════════ */

/* Overlay */
.aish-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.aish-overlay.open {
    display: block;
    opacity: 1;
}

/* Drawer */
.aish-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 300px;
    max-width: 85vw;
    height: 100dvh;
    background: var(--bg-surface, #1a1a24);
    border-left: 1px solid var(--border, rgba(255,255,255,0.08));
    display: flex;
    flex-direction: column;
    z-index: 201;
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(.4,0,.2,1);
    box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}
.aish-drawer.open { transform: translateX(0); }

.aish-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px;
    border-bottom: 1px solid var(--border, rgba(255,255,255,0.07));
    flex-shrink: 0;
}
.aish-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary, #f0f0f5);
}
.aish-close {
    background: none;
    border: none;
    color: var(--text-secondary, #888);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.aish-close:hover { background: rgba(255,255,255,0.06); }

.aish-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.aish-item {
    position: relative;
    padding: 10px 40px 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid transparent;
}
.aish-item:hover { background: rgba(255,255,255,0.05); }
.aish-item-active {
    background: rgba(108,99,255,0.1);
    border-color: rgba(108,99,255,0.25);
}

.aish-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #f0f0f5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}
.aish-item-date {
    font-size: 11px;
    color: var(--text-muted, #666);
}
.aish-item-del {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted, #666);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}
.aish-item:hover .aish-item-del { opacity: 1; }
.aish-item-del:hover { color: #ff6b6b; }

.aish-loading, .aish-empty {
    text-align: center;
    color: var(--text-muted, #888);
    font-size: 13px;
    padding: 32px 16px;
}

/* Light mode drawer */
[data-theme="light"] .aish-drawer {
    background: var(--bg-surface, #fff);
    border-color: var(--border, rgba(0,0,0,0.07));
}
[data-theme="light"] .aish-title { color: var(--text-primary, #1a1a2e); }
[data-theme="light"] .aish-item:hover { background: var(--bg-base, #f5f5f7); }
[data-theme="light"] .aish-item-active {
    background: rgba(108,99,255,0.06);
    border-color: rgba(108,99,255,0.2);
}
[data-theme="light"] .aish-item-title { color: var(--text-primary, #1a1a2e); }


/* ═══════════════════════════════════════════════════════════════
   BUG FIX — 2026-06-22
   1. Double input bar (mobile)
   2. Desktop panel blank
   ═══════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────
   FIX 1 — MOBILE: input bar dobel
   Masalah: main.ais-page-active { padding:0 } menghapus
   padding-bottom 100px yang biasanya mencegah konten
   masuk di balik bottom-nav (position:fixed; bottom:0).
   Akibatnya page mencapai bawah viewport, ais-input-wrap
   harus z-index:95 agar muncul di atas nav → tampak dobel.

   Fix: kembalikan padding-bottom setara tinggi nav,
        reset z-index input-wrap ke normal.
───────────────────────────────────────────── */
@media (max-width: 1023px) {
    main.ais-page-active {
        /* nav height ≈ 68px + safe area inset */
        padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)) !important;
    }
    /* Tidak perlu lagi lebih tinggi dari nav */
    .ais-input-wrap {
        z-index: 5 !important;
    }
}

/* ─────────────────────────────────────────────
   FIX 2 — DESKTOP (≥1024px): panel AI blank
   Masalah: #app.ais-app-lock set flex-direction:column
   yang merusak layout desktop (sidebar row + content).
   main.ais-page-active juga dapat max-width:760px dari
   desktop style yang bikin panel sempit & konten hilang.

   Fix: pertahankan flex-direction:row di desktop,
        pasang height chain pada .app-main-col,
        hapus max-width + margin dari main AI.
───────────────────────────────────────────── */
@media (min-width: 1024px) {
    /* Pertahankan layout sidebar + kolom konten */
    #app.ais-app-lock {
        flex-direction: row !important;
        height: 100dvh !important;
        overflow: hidden !important;
        align-items: stretch !important;
    }

    /* Kolom kanan harus full-height flex column */
    #app.ais-app-lock > .app-main-col {
        flex: 1 !important;
        min-width: 0 !important;
        min-height: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        height: 100dvh !important;
    }

    /* main.ais-page-active: full width, tanpa padding */
    main.ais-page-active {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        height: 100% !important;
        flex: 1 !important;
        min-height: 0 !important;
    }
}

/* ─────────────────────────────────────────────
   FIX 3 (CSS) — Collapsible usage history
   Toggle button + animasi untuk expand/collapse list
───────────────────────────────────────────── */
.aic-history-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    background: none;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    color: var(--text-muted, #888);
    font-size: 12px;
    font-weight: 600;
    padding: 9px 14px;
    margin-top: 10px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    font-family: inherit;
}
.aic-history-toggle:hover {
    background: rgba(108,99,255,0.08);
    border-color: rgba(108,99,255,0.3);
    color: #9d97ff;
}
.aic-history-toggle-icon {
    font-size: 10px;
    transition: transform 0.2s ease;
    display: inline-block;
}
.aic-history-toggle.expanded .aic-history-toggle-icon {
    transform: rotate(180deg);
}
.aic-log-hidden {
    display: none !important;
}
[data-theme="light"] .aic-history-toggle {
    border-color: rgba(0,0,0,0.1);
    color: var(--text-secondary, #5a5a7a);
}
[data-theme="light"] .aic-history-toggle:hover {
    background: rgba(108,99,255,0.05);
    border-color: rgba(108,99,255,0.2);
    color: #5a54e0;
}
