/* =========================================================================
   DaCure.org - SAGE (Multidisciplinary Expert AI) Stylesheet
   File: css/sage.css
   ========================================================================= */

:root {
    --sage-primary: #2d3748;
    --sage-accent: #2b6cb0;
    --sage-accent-hover: #2c5282;
    --sage-bg: #f7fafc;
    --sage-card-bg: #ffffff;
    --sage-border: #e2e8f0;
    --sage-text: #2d3748;
    --sage-text-muted: #718096;
    --sage-user-bubble: #ebf8ff;
    --sage-user-border: #bee3f8;
    --sage-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --sage-radius: 12px;
}

/* --- Container & Layout --- */
.sage-root {
    width: 100%;
    max-width: 1350px;
    margin: 0 auto;
    padding: 10px 15px 30px;
    box-sizing: border-box;
}

/* --- Guest Hero Section --- */
.sage-guest-hero {
    max-width: 900px;
    margin: 40px auto;
    padding: 30px 20px;
}

.sage-guest-card {
    background: var(--sage-card-bg);
    border: 1px solid var(--sage-border);
    border-radius: var(--sage-radius);
    padding: 40px 30px;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

.sage-badge-pill {
    display: inline-block;
    padding: 5px 14px;
    background: #e6fffa;
    color: #234e52;
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 20px;
    margin-bottom: 15px;
}

.sage-lead {
    font-size: 1.15rem;
    color: var(--sage-text-muted);
    max-width: 680px;
    margin: 15px auto 30px;
    line-height: 1.6;
}

.sage-perspectives-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin: 30px 0;
    text-align: left;
}

.sage-perspective-item {
    background: #f8fafc;
    border: 1px solid #edf2f7;
    border-radius: 10px;
    padding: 16px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sage-perspective-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--sage-shadow);
}

.sage-perspective-item.sage-p-full {
    grid-column: 1 / -1;
}

.sage-p-icon {
    font-size: 1.6rem;
    margin-bottom: 8px;
}

.sage-perspective-item h3 {
    margin: 0 0 6px 0;
    font-size: 1rem;
    color: #1a202c;
}

.sage-perspective-item p {
    margin: 0;
    font-size: 0.85rem;
    color: #4a5568;
    line-height: 1.45;
}

.sage-guest-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin: 35px 0 20px;
    flex-wrap: wrap;
}

.sage-disclaimer-note {
    font-size: 0.8rem;
    color: #a0aec0;
    margin-top: 25px;
}

/* --- Workspace Split Layout --- */
.sage-workspace {
    display: flex;
    gap: 20px;
    height: calc(100vh - 140px);
    min-height: 620px;
    position: relative;
}

/* --- Sidebar --- */
.sage-sidebar {
    width: 290px;
    flex-shrink: 0;
    background: #ffffff;
    border: 1px solid var(--sage-border);
    border-radius: var(--sage-radius);
    display: flex;
    flex-direction: column;
    box-shadow: var(--sage-shadow);
    overflow: hidden;
}

.sage-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--sage-border);
    display: flex;
    gap: 8px;
    align-items: center;
}

.sage-btn-new-chat {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
}

.sage-sidebar-close-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #718096;
}

.sage-threads-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 12px;
}

.sage-threads-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: #a0aec0;
    margin: 0 0 10px 8px;
}

.sage-threads-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sage-thread-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 5px;
    cursor: pointer;
    font-size: 0.88rem;
    color: #4a5568;
    transition: background 0.15s ease;
}

.sage-thread-item:hover {
    background: #edf2f7;
    color: #1a202c;
}

.sage-thread-item.active {
    background: #ebf8ff;
    color: #2b6cb0;
    font-weight: 600;
    border-left: 3px solid #3182ce;
}

.sage-thread-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-grow: 1;
}

.sage-thread-del-btn {
    background: none;
    border: none;
    color: #a0aec0;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.sage-thread-item:hover .sage-thread-del-btn {
    opacity: 1;
}

.sage-thread-del-btn:hover {
    color: #e53e3e;
    background: #fed7d7;
}

.sage-sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--sage-border);
    background: #fafafa;
}

.sage-user-credits-widget {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.sage-credits-label {
    font-size: 0.85rem;
    color: #718096;
}

.sage-credits-badge {
    background: #ebf8ff;
    color: #2b6cb0;
    border: 1px solid #bee3f8;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
}

.sage-btn-buy-modal {
    width: 100%;
    margin-bottom: 8px;
    font-size: 0.88rem;
}

.sage-footer-links {
    text-align: center;
    font-size: 0.75rem;
    margin-top: 6px;
}

.sage-footer-links a {
    color: #718096;
    text-decoration: underline;
}

/* --- Main Panel --- */
.sage-main-panel {
    flex-grow: 1;
    min-width: 0;
    min-height: 0;
    background: #ffffff;
    border: 1px solid var(--sage-border);
    border-radius: var(--sage-radius);
    display: flex;
    flex-direction: column;
    box-shadow: var(--sage-shadow);
    overflow: hidden;
    position: relative;
}

/* --- Control Bar --- */
.sage-control-bar {
    padding: 12px 20px;
    border-bottom: 1px solid var(--sage-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #ffffff;
    z-index: 10;
    flex-wrap: wrap;
}

.sage-mobile-menu-btn {
    display: none;
    background: none;
    border: 1px solid var(--sage-border);
    border-radius: 6px;
    font-size: 1.2rem;
    padding: 4px 10px;
    cursor: pointer;
}

.sage-title-wrapper h2 {
    margin: 0;
    font-size: 1.25rem;
    color: #1a202c;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sage-subtitle-tag {
    font-size: 0.72rem;
    font-weight: 600;
    color: #4a5568;
    background: #edf2f7;
    padding: 2px 8px;
    border-radius: 10px;
}

.sage-model-picker-wrapper {
    flex-grow: 1;
    max-width: 380px;
}

.sage-model-select {
    width: 100%;
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid var(--sage-border);
    background: #f8fafc;
    font-size: 0.88rem;
    color: #2d3748;
    font-weight: 500;
    cursor: pointer;
}

.sage-model-select:focus {
    outline: none;
    border-color: var(--sage-accent);
}

.sage-quick-credits {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #edf2f7;
    padding: 4px 10px;
    border-radius: 20px;
}

.sage-qc-count {
    font-size: 0.85rem;
    font-weight: 700;
    color: #2d3748;
}

.sage-qc-plus {
    background: #3182ce;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* --- High-Cost Model Warning Banner --- */
.sage-cost-warning {
    background: #fffaf0;
    border-bottom: 1px solid #feebc8;
    padding: 9px 20px;
    color: #c05621;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

.sage-cost-warning-icon {
    font-size: 1.1rem;
}

/* --- Messages Scroll Area --- */
.sage-messages-scroll {
    flex-grow: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: #fbfbfb;
}

/* Message Cards */
.sage-message-card {
    max-width: 860px;
    width: 100%;
    border-radius: 12px;
    padding: 18px 22px;
    line-height: 1.6;
    font-size: 0.95rem;
    box-sizing: border-box;
    animation: fadeIn 0.25s ease;
}

.sage-msg-user {
    align-self: flex-end;
    background: var(--sage-user-bubble);
    border: 1px solid var(--sage-user-border);
    color: #1a365d;
    max-width: 650px;
}

.sage-msg-assistant {
    align-self: flex-start;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    color: #2d3748;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.sage-msg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 0.85rem;
}

.sage-avatar {
    font-size: 1.2rem;
}

.sage-author-name {
    font-weight: 700;
    color: #2d3748;
}

.sage-source-badge {
    background: #e2e8f0;
    color: #4a5568;
    font-size: 0.72rem;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.sage-source-cache {
    background: #e6fffa;
    color: #234e52;
}

.sage-msg-time {
    margin-left: auto;
    color: #a0aec0;
    font-size: 0.78rem;
}

/* Welcome Card */
.sage-welcome-card {
    background: #ffffff;
    border: 1px dashed #cbd5e0;
}

.sage-prompt-hints {
    margin-top: 15px;
    background: #f7fafc;
    border-left: 3px solid #3182ce;
    padding: 12px 16px;
    border-radius: 4px;
    font-size: 0.88rem;
}

.sage-prompt-hints ul {
    margin: 8px 0 0 18px;
    padding: 0;
}

.sage-prompt-hints li {
    margin-bottom: 4px;
    color: #4a5568;
}

/* Explanation Prose */
.sage-explanation-text {
    margin-bottom: 18px;
    font-size: 0.96rem;
    line-height: 1.65;
    color: #2d3748;
}

/* --- THE THREE GAUGES CONTAINER --- */
.sage-gauges-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
    margin: 20px 0;
    background: #f8fafc;
    border: 1px solid #edf2f7;
    border-radius: 10px;
    padding: 16px 14px;
}

.sage-gauge-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 8px;
}

.sage-gauge-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #718096;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.sage-gauge-svg {
    width: 130px;
    height: 75px;
}

.sage-gauge-bg-arc {
    fill: none;
    stroke: #e2e8f0;
    stroke-width: 9;
    stroke-linecap: round;
}

.sage-gauge-value-arc {
    fill: none;
    stroke-width: 9;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.9s ease-out;
}

.sage-gauge-num {
    font-size: 1.4rem;
    font-weight: 800;
    margin-top: -15px;
    color: #1a202c;
}

.sage-gauge-badge {
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 4px;
    padding: 2px 8px;
    border-radius: 8px;
}

/* Gauge Color Themes */
.gauge-confidence .sage-gauge-value-arc { stroke: #319795; }
.gauge-confidence .sage-gauge-num { color: #234e52; }
.gauge-confidence .sage-gauge-badge { background: #e6fffa; color: #234e52; }

.gauge-experimental .sage-gauge-value-arc { stroke: #805ad5; }
.gauge-experimental .sage-gauge-num { color: #44337a; }
.gauge-experimental .sage-gauge-badge { background: #faf5ff; color: #553c9a; }

.gauge-community.positive .sage-gauge-value-arc { stroke: #38a169; }
.gauge-community.positive .sage-gauge-badge { background: #f0fff4; color: #22543d; }

.gauge-community.neutral .sage-gauge-value-arc { stroke: #d69e2e; }
.gauge-community.neutral .sage-gauge-badge { background: #fffff0; color: #744210; }

.gauge-community.negative .sage-gauge-value-arc { stroke: #e53e3e; }
.gauge-community.negative .sage-gauge-badge { background: #fff5f5; color: #742a2a; }

.gauge-community.no-reviews .sage-gauge-value-arc { stroke: #cbd5e0; }
.gauge-community.no-reviews .sage-gauge-badge { background: #edf2f7; color: #718096; }

/* --- 7 PERSPECTIVES ACCORDION / TABS --- */
.sage-perspectives-accordion {
    margin: 20px 0;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}

.sage-accordion-header {
    background: #edf2f7;
    padding: 10px 14px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #4a5568;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sage-perspectives-tabs {
    display: flex;
    flex-wrap: wrap;
    border-bottom: 1px solid #edf2f7;
    background: #f8fafc;
}

.sage-persp-tab-btn {
    padding: 8px 14px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 0.83rem;
    font-weight: 600;
    color: #718096;
    cursor: pointer;
    transition: all 0.15s ease;
}

.sage-persp-tab-btn:hover {
    color: #2b6cb0;
}

.sage-persp-tab-btn.active {
    color: #2b6cb0;
    border-bottom-color: #2b6cb0;
    background: #ffffff;
}

.sage-persp-content-box {
    padding: 16px;
    background: #ffffff;
    font-size: 0.92rem;
    line-height: 1.6;
    color: #4a5568;
    min-height: 60px;
}

/* Referenced Entities Section */
.sage-referenced-section {
    margin: 16px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.85rem;
}

.sage-ref-label {
    font-weight: 600;
    color: #718096;
}

.sage-entity-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #edf2f7;
    color: #2b6cb0;
    padding: 4px 10px;
    border-radius: 14px;
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    border: 1px solid #e2e8f0;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.sage-entity-chip:hover {
    background: #ebf8ff;
    border-color: #bee3f8;
}

/* Safety Flags Card */
.sage-safety-box {
    background: #fffaf0;
    border-left: 4px solid #dd6b20;
    padding: 12px 16px;
    border-radius: 4px;
    margin: 16px 0;
    font-size: 0.88rem;
    color: #9c4221;
}

.sage-safety-box strong {
    display: block;
    margin-bottom: 4px;
}

.sage-safety-box ul {
    margin: 4px 0 0 16px;
    padding: 0;
}

/* Medical Disclaimer Footer */
.sage-disclaimer-footer {
    border-top: 1px solid #edf2f7;
    padding-top: 10px;
    margin-top: 16px;
    font-size: 0.78rem;
    color: #a0aec0;
    font-style: italic;
}

/* Generated Image Container */
.sage-image-container {
    margin: 18px 0;
    text-align: center;
}

.sage-generated-img {
    max-width: 100%;
    max-height: 480px;
    border-radius: 8px;
    border: 1px solid #cbd5e0;
    box-shadow: var(--sage-shadow);
}

/* --- Typing Indicator --- */
.sage-typing-indicator {
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: #718096;
    background: #f8fafc;
    border-top: 1px solid #edf2f7;
}

.sage-typing-dots {
    display: flex;
    gap: 4px;
}

.sage-typing-dots span {
    width: 6px;
    height: 6px;
    background: #a0aec0;
    border-radius: 50%;
    animation: typingBounce 1.2s infinite ease-in-out;
}

.sage-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.sage-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* --- Composer Bar --- */
.sage-composer-bar {
    padding: 14px 20px;
    border-top: 1px solid var(--sage-border);
    background: #ffffff;
}

.sage-chat-form {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.sage-input-container {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
}

.sage-input-box {
    width: 100%;
    min-height: 58px;
    padding: 12px 14px 28px 14px;
    border: 1px solid var(--sage-border);
    border-radius: 10px;
    font-size: 0.94rem;
    line-height: 1.45;
    resize: none;
    box-sizing: border-box;
    font-family: inherit;
    transition: border-color 0.15s ease;
}

.sage-input-box:focus {
    outline: none;
    border-color: var(--sage-accent);
}

.sage-input-meta {
    position: absolute;
    bottom: 6px;
    right: 12px;
    font-size: 0.72rem;
    color: #718096;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.92);
    padding: 1px 6px;
    border-radius: 4px;
}

.sage-send-btn {
    padding: 12px 22px;
    border-radius: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    height: 48px;
}

.sage-composer-disclaimer {
    font-size: 0.74rem;
    color: #a0aec0;
    text-align: center;
    margin-top: 8px;
}

/* --- Purchase Modal Styles --- */
.sage-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 15px;
    box-sizing: border-box;
}

.sage-modal-card {
    background: #ffffff;
    border-radius: 14px;
    max-width: 650px;
    width: 100%;
    max-height: calc(100vh - 30px);
    max-height: calc(100dvh - 30px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    animation: scaleIn 0.2s ease;
}

.sage-modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid #edf2f7;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    background: #ffffff;
}

.sage-modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #1a202c;
}

.sage-modal-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    padding: 4px 8px;
    cursor: pointer;
    color: #718096;
}

.sage-modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.sage-modal-desc {
    font-size: 0.92rem;
    color: #4a5568;
    margin-top: 0;
    margin-bottom: 20px;
}

.sage-packages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 15px;
}

.sage-pkg-card {
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px 14px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.sage-pkg-card:hover {
    border-color: var(--sage-accent);
    transform: translateY(-2px);
    box-shadow: var(--sage-shadow);
}

.sage-pkg-card.highlight {
    border-color: #3182ce;
    background: #f7fafc;
}

.sage-pkg-credits {
    font-size: 1.8rem;
    font-weight: 800;
    color: #2b6cb0;
}

.sage-pkg-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 8px 0;
    color: #2d3748;
}

.sage-pkg-price {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1a202c;
    margin-bottom: 14px;
}

.sage-modal-error {
    color: #e53e3e;
    background: #fff5f5;
    padding: 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-top: 15px;
}

.sage-modal-footer {
    padding: 14px 24px;
    background: #f7fafc;
    border-top: 1px solid #edf2f7;
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* --- Mobile Responsiveness --- */
@media (max-width: 900px) {
    .sage-root {
        padding: 6px 8px 16px;
    }
    .sage-workspace {
        height: auto;
        min-height: auto;
    }
    .sage-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: -320px;
        z-index: 999;
        transition: left 0.3s ease;
        box-shadow: 2px 0 16px rgba(0,0,0,0.2);
    }
    .sage-sidebar.open {
        left: 0;
    }
    .sage-sidebar-close-btn {
        display: block;
    }
    .sage-mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    /* Decouple from fixed viewport height trapping when mobile keyboard opens */
    .sage-main-panel {
        height: auto;
        min-height: calc(100vh - 110px);
        min-height: calc(100dvh - 110px);
        overflow: visible;
    }
    .sage-messages-scroll {
        padding: 14px 12px;
        gap: 14px;
    }
    /* Sticky bottom composer so input and send button stay above mobile keyboard */
    .sage-composer-bar {
        position: sticky;
        bottom: 0;
        z-index: 25;
        background: #ffffff;
        border-radius: 0 0 var(--sage-radius) var(--sage-radius);
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
    }

    /* Control Bar Responsive Wrap */
    .sage-control-bar {
        padding: 10px 14px;
        gap: 8px 12px;
        flex-wrap: wrap;
        border-radius: var(--sage-radius) var(--sage-radius) 0 0;
    }
    .sage-title-wrapper {
        display: flex;
        align-items: center;
        min-width: 0;
    }
    .sage-title-wrapper h2 {
        font-size: 1.15rem;
    }
    .sage-quick-credits {
        margin-left: auto;
        flex-shrink: 0;
    }
    .sage-model-picker-wrapper {
        width: 100%;
        max-width: 100%;
        order: 4; /* Wraps model picker cleanly to full-width row under title & credits */
        margin-top: 2px;
    }
    .sage-model-select {
        padding: 8px 10px;
        font-size: 0.86rem;
    }
}

@media (max-width: 640px) {
    .sage-control-bar {
        padding: 8px 12px;
        gap: 6px 10px;
    }
    .sage-subtitle-tag {
        display: none; /* Hide subtitle tag on small phone screens so title & credits stay cleanly on row 1 */
    }
    .sage-composer-bar {
        padding: 10px 10px;
    }
    /* Compact mode when mobile keyboard is open */
    .sage-composer-bar:focus-within,
    .sage-root.sage-keyboard-open .sage-composer-bar {
        padding: 8px 10px;
    }
    .sage-composer-bar:focus-within .sage-composer-disclaimer,
    .sage-root.sage-keyboard-open .sage-composer-disclaimer {
        display: none;
    }
    .sage-chat-form {
        gap: 8px;
        align-items: flex-end;
    }
    /* Expanded input box height to prevent placeholder overlap + 16px font to prevent iOS auto-zoom */
    .sage-input-box {
        min-height: 66px;
        max-height: 140px;
        overflow-y: auto;
        padding: 10px 12px 26px 12px;
        font-size: 16px;
        line-height: 1.4;
    }
    .sage-input-meta {
        bottom: 4px;
        right: 8px;
        font-size: 0.7rem;
        background: rgba(255, 255, 255, 0.95);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    }
    .sage-send-btn {
        height: 46px;
        padding: 0 14px;
        font-size: 0.9rem;
        align-self: flex-end;
        flex-shrink: 0;
    }

    /* Mobile-Friendly Credit Purchase Modal */
    .sage-modal-overlay {
        padding: 10px;
    }
    .sage-modal-card {
        max-height: calc(100vh - 20px);
        max-height: calc(100dvh - 20px);
        border-radius: 12px;
    }
    .sage-modal-header {
        padding: 12px 16px;
    }
    .sage-modal-header h3 {
        font-size: 1.02rem;
    }
    .sage-modal-body {
        padding: 12px 14px;
    }
    .sage-modal-desc {
        font-size: 0.84rem;
        margin-bottom: 12px;
        line-height: 1.4;
    }
    .sage-packages-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    /* Convert tall vertical package cards into compact horizontal rows on mobile */
    .sage-pkg-card {
        display: grid;
        grid-template-columns: 58px 1fr auto;
        grid-template-rows: auto auto;
        align-items: center;
        gap: 2px 12px;
        padding: 10px 12px;
        text-align: left;
    }
    .sage-pkg-credits {
        grid-column: 1;
        grid-row: 1 / 3;
        font-size: 1.35rem;
        text-align: center;
        background: #ebf8ff;
        border-radius: 8px;
        padding: 6px 4px;
        line-height: 1.1;
    }
    .sage-pkg-title {
        grid-column: 2;
        grid-row: 1;
        margin: 0;
        font-size: 0.9rem;
    }
    .sage-pkg-price {
        grid-column: 2;
        grid-row: 2;
        margin: 0;
        font-size: 1.05rem;
    }
    .sage-pkg-card .btn {
        grid-column: 3;
        grid-row: 1 / 3;
        width: auto;
        padding: 8px 14px;
        font-size: 0.88rem;
        white-space: nowrap;
    }
    .sage-modal-footer {
        padding: 10px 16px;
    }
}
