/* ══════════════════════════════════════════════════════════════
   PBN69 AI Prompt Generator — Stylesheet
   Mobile-first responsive design
   ══════════════════════════════════════════════════════════════ */

:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface2: #f1f5f9;
    --surface3: #e2e8f0;
    --border: #e2e8f0;
    --border2: #cbd5e1;
    --accent: #6366f1;
    --accent2: #8b5cf6;
    --accent3: #10b981;
    --accent4: #f97316;
    --accent5: #ec4899;
    --accent6: #f59e0b;
    --text: #0f172a;
    --text2: #475569;
    --text3: #64748b;
    --red: #ef4444;
    --sidebar-w: 260px;
    --header-h: auto;
    --radius-sm: 6px;
    --radius-md: 9px;
    --radius-lg: 12px;
    --radius-xl: 20px;
    --radius-full: 28px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 20px rgba(99, 102, 241, 0.05);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.15);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Inter", "IBM Plex Sans Thai", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14.5px;
    line-height: 1.6;
}

/* ── Header ── */
.header {
    background: linear-gradient(135deg, #ffffff 0%, #faf5ff 100%);
    border-bottom: 2px solid #ede9fe;
    padding: 22px 32px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-md);
}

.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 0 18px rgba(99, 102, 241, 0.2);
    flex-shrink: 0;
}

.header-title h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text);
}

.header-title p {
    font-size: 12px;
    color: var(--text2);
    margin-top: 1px;
}

.header-badges {
    margin-left: auto;
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.hbadge {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 20px;
    border: 1px solid var(--border2);
    color: var(--text2);
    background: var(--surface);
    white-space: nowrap;
}

/* ── Layout ── */
.layout {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px 32px;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    gap: 20px;
    align-items: start;
}

/* ── Sidebar ── */
.sidebar {
    position: sticky;
    top: 80px;
}

.cat-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.8px;
    color: var(--text3);
    text-transform: uppercase;
    padding: 0 4px;
    margin-bottom: 8px;
    margin-top: 18px;
}

.cat-label:first-child {
    margin-top: 0;
}

.tab-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    text-align: left;
    margin-bottom: 3px;
    transition: all 0.15s;
    color: var(--text2);
    font-family: inherit;
    font-size: 13px;
}

.tab-btn:hover {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.tab-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.tab-icon {
    font-size: 16px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.tab-sub {
    font-size: 10px;
    color: var(--text3);
    margin-top: 1px;
}

.tab-btn.active .tab-sub {
    color: rgba(255, 255, 255, 0.8);
}

.sidebar-tip {
    margin-top: 18px;
    font-size: 12px;
    color: var(--text2);
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    line-height: 1.7;
}

.sidebar-tip strong {
    color: var(--text);
}

/* ── Sidebar Chat Button ── */
.sidebar-chat-btn {
    margin: 16px 12px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: 12px;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
    transition: all 0.2s;
    width: calc(100% - 24px);
}

.sidebar-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

/* ── Panel ── */
.panel {
    display: none;
}

.panel.active {
    display: block;
}

.panel-hd {
    margin-bottom: 18px;
}

.panel-hd h2 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 3px;
}

.panel-hd p {
    font-size: 13px;
    color: var(--text2);
}

/* ── Card ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 14px;
}

.card-hd {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--text3);
    text-transform: uppercase;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-hd::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── Form ── */
.fg {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.fg label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text2);
}

.fgrid {
    display: grid;
    gap: 12px;
}

.fgrid-2 { grid-template-columns: 1fr 1fr; }
.fgrid-3 { grid-template-columns: 1fr 1fr 1fr; }
.fgrid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.full {
    grid-column: 1 / -1;
}

input[type="text"],
input[type="number"],
select,
textarea {
    background: var(--bg);
    border: 1px solid var(--border2);
    border-radius: 8px;
    padding: 9px 11px;
    font-size: 13px;
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.15s;
    width: 100%;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 142, 247, 0.1);
}

select option {
    background: var(--surface2);
}

textarea {
    resize: vertical;
    min-height: 72px;
    line-height: 1.6;
}

.num-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
    align-items: center;
}

.unit {
    font-size: 12px;
    color: var(--text2);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 9px 10px;
    white-space: nowrap;
}

/* ── Checkboxes ── */
.chk-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}

.chk-item {
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border2);
    border-radius: 8px;
    transition: all 0.15s;
    flex: 1;
    min-width: 180px;
}

.chk-item:has(input:checked) {
    border-color: var(--accent3);
    background: rgba(62, 207, 142, 0.06);
}

.chk-item input {
    display: none;
}

.chk-box {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 2px solid var(--border2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    flex-shrink: 0;
    transition: all 0.15s;
}

.chk-item:has(input:checked) .chk-box {
    background: var(--accent3);
    border-color: var(--accent3);
    color: #000;
}

.chk-text {
    font-size: 13px;
    color: var(--text2);
}

.chk-item:has(input:checked) .chk-text {
    color: var(--text);
}

/* Radio style chips */
.radio-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.radio-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 6px 12px;
    background: var(--bg);
    border: 1px solid var(--border2);
    border-radius: 20px;
    transition: all 0.15s;
    font-size: 12px;
    color: var(--text2);
}

.radio-chip input {
    display: none;
}

.radio-chip:has(input:checked) {
    border-color: var(--accent);
    background: rgba(79, 142, 247, 0.1);
    color: #fff;
}

/* Topics grid */
.topics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.topic-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    transition: all 0.15s;
    font-size: 12px;
    color: var(--text2);
}

.topic-chip:has(input:checked) {
    border-color: var(--accent2);
    background: rgba(124, 92, 252, 0.08);
    color: var(--text);
}

.topic-chip input {
    display: none;
}

.tn {
    font-size: 10px;
    color: var(--text3);
    font-weight: 700;
    min-width: 24px;
}

.topic-chip:has(input:checked) .tn {
    color: var(--accent2);
}

/* ── Button ── */
.btn-gen {
    width: 100%;
    padding: 13px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    border: none;
    border-radius: 10px;
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    box-shadow: 0 4px 18px rgba(79, 142, 247, 0.25);
    margin-top: 4px;
}

.btn-gen:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 22px rgba(79, 142, 247, 0.35);
}

.btn-gen:active {
    transform: translateY(0);
}

/* ── Output ── */
.output {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-top: 14px;
}

.output.show {
    display: block;
}

.out-hd {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
}

.out-hd span {
    font-size: 11px;
    font-weight: 700;
    color: var(--text2);
    letter-spacing: 0.8px;
    text-transform: uppercase;
}

.out-actions {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
}

.btn-copy,
.btn-claude,
.btn-chat {
    padding: 5px 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border2);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.15s;
    font-weight: 500;
}

.btn-copy {
    background: var(--bg);
    color: var(--text2);
}

.btn-copy:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-copy.ok {
    border-color: var(--accent3);
    color: var(--accent3);
}

.btn-claude {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
}

.btn-claude:hover {
    background: #4f46e5;
    border-color: #4f46e5;
}

/* ── Send to Chat Button ── */
.btn-chat {
    background: var(--accent3);
    color: white;
    border-color: var(--accent3);
    font-weight: 600;
}

.btn-chat:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.out-text {
    padding: 18px;
    font-size: 13.5px;
    line-height: 2;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    background: #0f172a;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 20px;
    font-size: 13px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 7px;
    transform: translateY(70px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 200;
    box-shadow: var(--shadow-lg);
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* ── Segment: level selector ── */
.level-toggle {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
}

.lvl-btn {
    flex: 1;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border2);
    background: var(--bg);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    color: var(--text2);
    transition: all 0.15s;
    text-align: center;
    font-weight: 500;
}

.lvl-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* Divider */
.divider {
    height: 1px;
    background: var(--border);
    margin: 14px 0;
}

/* ══════════════════════════════════════════════════════════════
   AI Teaching Assistant Panel
   ══════════════════════════════════════════════════════════════ */

.assistant-welcome {
    background: linear-gradient(135deg, #f0f9ff 0%, #faf5ff 50%, #fdf4ff 100%);
    border: 1px solid #e0e7ff;
    border-radius: 16px;
    padding: 32px 24px;
    text-align: center;
    margin-bottom: 20px;
}

.assistant-welcome-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
}

.assistant-welcome h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
}

.assistant-welcome p {
    font-size: 13.5px;
    color: var(--text2);
    line-height: 1.7;
    max-width: 460px;
    margin: 0 auto;
}

.assistant-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.assistant-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text2);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
}

.assistant-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(99, 102, 241, 0.04);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.1);
}

.assistant-chip:active {
    transform: translateY(0);
}

/* ══════════════════════════════════════════════════════════════
   Gemini Chat UI Styles
   ══════════════════════════════════════════════════════════════ */

@keyframes slideUpChat {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes pulseSparkle {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0px rgba(99, 102, 241, 0)); }
    50% { transform: scale(1.08); filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.3)); }
}

@keyframes geminiShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.gemini-progress-bar {
    height: 4px;
    width: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, #6366f1, #8b5cf6, #ec4899, #f59e0b, #6366f1);
    background-size: 300% 300%;
    animation: geminiShift 2s ease infinite;
    margin-bottom: 8px;
}

.chat-msg-user {
    background: #f1f5f9;
    color: #0f172a;
    border-radius: 18px 18px 0 18px;
    padding: 12px 18px;
    max-width: 75%;
    align-self: flex-end;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    font-size: 13.5px;
    line-height: 1.6;
    word-break: break-word;
}

.chat-msg-ai {
    align-self: flex-start;
    display: flex;
    gap: 12px;
    max-width: 85%;
    margin-top: 6px;
    word-break: break-word;
}

.chat-msg-ai-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.15);
}

.chat-msg-ai-body {
    font-size: 14px;
    line-height: 1.8;
    color: #0f172a;
    white-space: pre-wrap;
}

.chat-thinking-box {
    margin-top: 8px;
    margin-bottom: 12px;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    background: #f8fafc;
    overflow: hidden;
}

.chat-thinking-box summary {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    background: #f1f5f9;
    user-select: none;
}

.chat-thinking-content {
    padding: 12px;
    font-size: 12px;
    color: #475569;
    white-space: pre-wrap;
    font-family: inherit;
    border-left: 3.5px solid #8b5cf6;
    margin: 8px 12px;
}

.btn-ai {
    background: var(--accent3);
    color: white;
    border: 1px solid var(--accent3);
    padding: 5px 13px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
    transition: all 0.15s;
}

.btn-ai:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.btn-export:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* ── AI Spinning Loader bubble CSS ── */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes pulseChatGlow {
    0%, 100% { opacity: 0.85; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.005); }
}

@keyframes bounceDot {
    0%, 100% { transform: translateY(0); opacity: 0.3; }
    50% { transform: translateY(-4px); opacity: 1; }
}

.thinking-spinner-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    margin-right: 6px;
}

.thinking-spinner-dots span {
    width: 6px;
    height: 6px;
    background-color: #8b5cf6;
    border-radius: 50%;
    display: inline-block;
    animation: bounceDot 1.4s infinite ease-in-out both;
}

.thinking-spinner-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.thinking-spinner-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

/* ── Chat Overlay ── */
#gemini-chat-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
    font-family: "Inter", "IBM Plex Sans Thai", sans-serif;
}

.chat-container {
    background: #ffffff;
    width: 100%;
    max-width: 860px;
    height: 90vh;
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.15);
    border: 1px solid #e2e8f0;
    overflow: hidden;
    position: relative;
    animation: slideUpChat 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, #ffffff 0%, #faf5ff 100%);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-info h2 {
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.chat-header-info p {
    font-size: 11px;
    color: #64748b;
    margin: 2px 0 0 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-clear-btn {
    background: #fef2f2;
    border: 1.5px solid #fecaca;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 12px;
    color: #b91c1c;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
    font-family: inherit;
}

.chat-clear-btn:hover {
    background: #fee2e2;
}

.chat-close-btn {
    background: #f1f5f9;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #475569;
    font-weight: 700;
    transition: background 0.2s;
}

.chat-close-btn:hover {
    background: #e2e8f0;
}

#gemini-chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: #fafafa;
}

.chat-welcome-box {
    text-align: center;
    margin: auto;
    max-width: 480px;
    padding: 24px;
    color: #475569;
    background: #ffffff;
    border-radius: var(--radius-xl);
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.05);
    border: 1px solid #e2e8f0;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-welcome-icon {
    font-size: 40px;
    display: block;
    margin-bottom: 12px;
    animation: pulseSparkle 2s infinite;
}

.chat-welcome-box h3 {
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 8px;
}

.chat-welcome-box p {
    font-size: 13px;
    line-height: 1.7;
    margin-bottom: 0;
}

#gemini-chat-loading {
    display: none;
    padding: 16px 24px;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
}

.chat-loading-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: #64748b;
}

.chat-loading-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-loading-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 1.5px solid #6366f1;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#gemini-chat-timer {
    font-family: monospace;
    background: #f1f5f9;
    padding: 1px 6px;
    border-radius: 10px;
}

.chat-input-area {
    padding: 16px 24px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
}

#gemini-input-form {
    display: flex;
    align-items: center;
    background: #f1f5f9;
    border-radius: var(--radius-full);
    padding: 6px 12px 6px 20px;
    border: 1.5px solid transparent;
    transition: all 0.2s;
    gap: 8px;
}

#gemini-chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 13.5px;
    color: #0f172a;
    padding: 8px 0;
    font-family: inherit;
}

#gemini-chat-submit-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #6366f1;
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: transform 0.15s;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.25);
    flex-shrink: 0;
}

#gemini-chat-submit-btn:hover {
    transform: scale(1.05);
}

.token-progress-track {
    display: inline-flex;
    width: 80px;
    height: 5px;
    background: #e2e8f0;
    border-radius: 2.5px;
    overflow: hidden;
    vertical-align: middle;
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
}

#token-progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    transition: width 0.3s ease, background 0.3s ease;
    display: block;
}

/* ══════════════════════════════════════════════════════════════
   Responsive Design — Mobile First
   ══════════════════════════════════════════════════════════════ */

/* ── Mobile sidebar toggle button (hidden on desktop) ── */
.sidebar-mobile-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 16px;
    z-index: 100;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: white;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    line-height: 1;
}
.sidebar-mobile-toggle:active {
    transform: scale(0.92);
}

/* ── Floating AI Chat FAB (mobile only) ── */
.mobile-chat-fab {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 16px;
    z-index: 100;
    padding: 0;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    line-height: 1;
}
.mobile-chat-fab:active {
    transform: scale(0.92);
}

/* ── Mobile sidebar overlay ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 200;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.sidebar-overlay.show {
    display: block;
}

/* ── ≤ 860px — Mobile Layout ── */
@media (max-width: 860px) {
    .layout {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 10px;
    }

    /* --- Mobile Sidebar: slide-in drawer --- */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        z-index: 300;
        background: var(--surface);
        border-right: 1px solid var(--border);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
        display: flex;
        flex-direction: column;
        padding: 16px 12px;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar .cat-label {
        display: block;
    }
    .sidebar .sidebar-tip {
        display: block;
    }
    .sidebar .sidebar-chat-btn {
        margin-top: auto;
        flex-shrink: 0;
    }
    .tab-btn {
        min-width: unset;
        padding: 10px 12px;
        margin-bottom: 2px;
        font-size: 13px;
    }
    .tab-btn .tab-sub {
        display: block;
    }

    /* Mobile toggle + FAB visible */
    .sidebar-mobile-toggle {
        display: flex;
    }
    .mobile-chat-fab {
        display: flex;
    }

    /* Hide sidebar chat button on mobile (replaced by FAB) */
    .sidebar-chat-btn {
        display: none;
    }

    /* Forms */
    .fgrid-2 { grid-template-columns: 1fr 1fr; }
    .fgrid-3 { grid-template-columns: 1fr; }
    .fgrid-4 { grid-template-columns: 1fr 1fr; }
    .topics-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* Header */
    .header {
        padding: 10px 14px;
    }
    .header-badges {
        display: none;
    }
    .header-title h1 {
        font-size: 15px;
    }
    .header-title p {
        font-size: 11px;
    }

    /* Cards */
    .card {
        padding: 14px;
    }
    .panel-hd h2 {
        font-size: 15px;
    }

    /* Add bottom padding so FABs don't cover content */
    body {
        padding-bottom: 80px;
    }
}

/* ── ≤ 540px — Compact mobile ── */
@media (max-width: 540px) {
    .fgrid-2 { grid-template-columns: 1fr; }
    .fgrid-3 { grid-template-columns: 1fr; }
    .fgrid-4 { grid-template-columns: 1fr 1fr; }
    .topics-grid {
        grid-template-columns: 1fr;
    }
    .chk-item {
        min-width: unset;
        flex-basis: calc(50% - 4px);
    }
    .chat-container {
        max-width: 100%;
        height: 100vh;
        border-radius: 0;
    }
    #gemini-chat-overlay {
        padding: 0;
    }
}

/* ── ≤ 480px — Small phones ── */
@media (max-width: 480px) {
    body {
        font-size: 13.5px;
        padding-bottom: 80px;
    }
    .header-inner {
        gap: 8px;
    }
    .logo {
        width: 34px;
        height: 34px;
        font-size: 17px;
        border-radius: 8px;
    }
    .header-title h1 {
        font-size: 14px;
    }
    .header-title p {
        font-size: 10px;
    }
    .btn-gen {
        padding: 12px;
        font-size: 14px;
    }
    .chk-grid {
        gap: 6px;
    }
    .chk-item {
        flex-basis: 100%;
        min-width: unset;
        padding: 8px 10px;
    }
    .fgrid-4 { grid-template-columns: 1fr 1fr; }
    .out-hd {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }
    .out-actions {
        flex-wrap: wrap;
        gap: 4px;
    }
    .out-actions button {
        flex: 1;
        min-width: 0;
        justify-content: center;
        padding: 6px 8px;
        font-size: 11px;
    }
    /* Chat header compact */
    .chat-header {
        padding: 10px 14px;
    }
    .chat-header-info h2 {
        font-size: 14px;
    }
    .chat-header-actions {
        gap: 6px;
    }
    .chat-clear-btn {
        padding: 4px 8px;
        font-size: 11px;
    }
    #gemini-chat-messages {
        padding: 14px;
    }
    .chat-input-area {
        padding: 10px 14px;
    }
    /* Assistant chips stack */
    .assistant-chips {
        flex-direction: column;
    }
    .assistant-chip {
        width: 100%;
        justify-content: center;
    }
}

/* ── ≤ 360px — Very small phones ── */
@media (max-width: 360px) {
    .header {
        padding: 8px 12px;
    }
    .header-title h1 {
        font-size: 13px;
    }
    .layout {
        padding: 10px;
        gap: 10px;
    }
    .fgrid-2,
    .fgrid-3,
    .fgrid-4 {
        grid-template-columns: 1fr;
    }
    .topics-grid {
        grid-template-columns: 1fr;
    }
    .chk-item {
        min-width: unset;
    }
    .out-actions {
        flex-direction: column;
        gap: 4px;
    }
    .out-actions button {
        width: 100%;
        justify-content: center;
    }
    .card {
        padding: 10px;
    }
    .panel-hd h2 {
        font-size: 14px;
    }
    .chat-container {
        border-radius: 0;
        height: 100vh;
    }
}

/* ── ≤ 768px — Tablets ── */
@media (min-width: 541px) and (max-width: 768px) {
    .fgrid-2 { grid-template-columns: 1fr 1fr; }
    .fgrid-3 { grid-template-columns: 1fr 1fr; }
    .fgrid-4 { grid-template-columns: 1fr 1fr; }
    .layout {
        padding: 16px;
        gap: 14px;
    }
    .header {
        padding: 14px;
    }
}

/* ── ≥ 861px — Desktop: restore sidebar ── */
@media (min-width: 861px) {
    .sidebar-mobile-toggle,
    .mobile-chat-fab,
    .sidebar-overlay {
        display: none !important;
    }
    .sidebar-chat-btn {
        display: flex;
    }
    body {
        padding-bottom: 0;
    }
}

/* ≥ 1024px — Desktop */
@media (min-width: 1024px) {
    .layout {
        padding: 24px 32px;
    }
}

/* ≥ 1280px — Large Desktop */
@media (min-width: 1280px) {
    .layout {
        max-width: 1280px;
    }
}
