/* CSS Variables for Dark Mode Glassmorphism */
:root {
    --bg-color: #0d1117;
    --text-main: #e6edf3;
    --text-muted: #8b949e;
    --glass-bg: rgba(22, 27, 34, 0.72);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --primary: #58a6ff;
    --primary-hover: #3182ce;
    --secondary: #238636;
    --secondary-hover: #2ea043;
    --magic: linear-gradient(135deg, #a371f7, #58a6ff);
    --magic-hover: linear-gradient(135deg, #b388ff, #79b8ff);
    --danger: #f85149;
    --border-radius: 14px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    position: relative;
    overflow-x: hidden;
}

/* Animated Background Glows */
.background-elements {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.glow {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 20s infinite ease-in-out alternate;
}

.glow-1 {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: radial-gradient(circle, rgba(88, 166, 255, 0.2) 0%, rgba(13, 17, 23, 0) 70%);
}

.glow-2 {
    bottom: -20%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, rgba(163, 113, 247, 0.15) 0%, rgba(13, 17, 23, 0) 70%);
    animation-delay: -5s;
}

.glow-3 {
    top: 40%;
    left: 40%;
    width: 30vw;
    height: 30vw;
    background: radial-gradient(circle, rgba(35, 134, 54, 0.1) 0%, rgba(13, 17, 23, 0) 70%);
    animation-delay: -10s;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(5%, 10%) scale(1.1);
    }
}

/* ===== Layout ===== */
.app-container {
    width: 100%;
    max-width: 1140px;
    /* wider */
    padding: 2rem 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: relative;
    z-index: 1;
}

header {
    text-align: center;
    margin-bottom: 0.5rem;
}

h1 {
    font-size: 2.6rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 0.5rem;
}

.gradient-text {
    background: var(--magic);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.05rem;
}

/* ===== Cards & Glassmorphism ===== */
.card,
.tab-content {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    box-shadow: var(--glass-shadow);
}

.card {
    padding: 1.5rem 2rem;
    transition: border-color 0.3s ease;
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.18);
}

/* ===== Tab Navigation ===== */
.tab-nav {
    display: flex;
    align-items: center;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 0.75rem 1.25rem;
    gap: 0;
    box-shadow: var(--glass-shadow);
    overflow-x: auto;
}

.tab-nav::-webkit-scrollbar {
    height: 4px;
}

.tab-nav::-webkit-scrollbar-track {
    background: transparent;
}

.tab-nav::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 2px;
}

.tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 0.65rem 1.1rem;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.tab-btn:not(:disabled):hover {
    background: rgba(88, 166, 255, 0.1);
    color: var(--text-main);
}

.tab-btn.active {
    background: rgba(88, 166, 255, 0.15);
    color: var(--primary);
    box-shadow: 0 0 0 1px rgba(88, 166, 255, 0.35);
}

.tab-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

.tab-num {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.07);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 700;
    transition: background 0.2s;
}

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

.tab-btn.done .tab-num {
    background: var(--secondary);
    color: #fff;
}

.tab-btn.done {
    color: #7ee787;
}

.tab-connector {
    flex: 1;
    height: 2px;
    background: var(--glass-border);
    min-width: 16px;
    max-width: 60px;
}

/* ===== Tab Content Panes ===== */
.tab-content {
    padding: 2rem 2.5rem;
    min-height: 360px;
}

.tab-pane {
    display: none;
    animation: fadeIn 0.25s ease;
}

.tab-pane.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-title {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: #fff;
}

/* ===== Form Elements ===== */
.input-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

input[type="text"],
input[type="password"],
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(1, 4, 9, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s ease;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.18);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:not(:disabled):hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--secondary);
    color: #fff;
}

.btn-secondary:not(:disabled):hover {
    background: var(--secondary-hover);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    margin: 0.5rem 0;
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-magic {
    background: var(--magic);
    color: #fff;
    box-shadow: 0 4px 15px rgba(163, 113, 247, 0.3);
}

.btn-magic:not(:disabled):hover {
    background: var(--magic-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(163, 113, 247, 0.4);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

/* ===== Utilities ===== */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

/* ===== Loading State ===== */
.loading-container {
    text-align: center;
    padding: 2rem;
    background: var(--glass-bg);
    border-radius: var(--border-radius);
    border: 1px solid var(--glass-border);
    margin-top: -0.5rem;
}

.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 1rem;
    border: 3px solid rgba(88, 166, 255, 0.2);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

.progress-bar-container {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin-top: 1rem;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--magic);
    width: 0%;
    transition: width 0.3s ease;
}

/* ===== Results Section ===== */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

/* ===== Markdown Body ===== */
.markdown-body {
    font-size: 0.95rem;
    color: var(--text-main);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
    color: #fff;
}

.markdown-body p {
    margin-bottom: 1rem;
}

.markdown-body strong {
    color: var(--primary);
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    overflow: hidden;
    font-size: 0.9rem;
}

.markdown-body th,
.markdown-body td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--glass-border);
    text-align: left;
}

.markdown-body th {
    background: rgba(88, 166, 255, 0.1);
    font-weight: 600;
    color: #fff;
}

.markdown-body tr:last-child td {
    border-bottom: none;
}

.markdown-body a {
    color: var(--primary);
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

/* ===== PubMed direct link button ===== */
.pubmed-link-btn {
    display: inline-block;
    padding: 0.28rem 0.6rem;
    background: rgba(88, 166, 255, 0.12);
    color: var(--primary);
    border: 1px solid rgba(88, 166, 255, 0.35);
    border-radius: 4px;
    font-size: 0.78rem;
    text-decoration: none !important;
    transition: all 0.2s;
    font-weight: 500;
}

.pubmed-link-btn:hover {
    background: var(--primary);
    color: #fff;
}

/* ===== AI Chat Bubble ===== */
.ai-chat-bubble {
    background: rgba(163, 113, 247, 0.08);
    border-left: 4px solid #a371f7;
    padding: 1.5rem;
    border-radius: 0 8px 8px 0;
    margin-top: 0.5rem;
}

/* ===== Info Box ===== */
.info-box {
    background: rgba(88, 166, 255, 0.06);
    border: 1px solid rgba(88, 166, 255, 0.2);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    font-size: 0.9rem;
}

.query-display {
    margin-top: 0.5rem;
    font-family: monospace;
    font-size: 0.88rem;
    color: var(--primary);
    word-break: break-all;
    line-height: 1.6;
}

/* ===== Step 5: Research Draft Sections ===== */
.draft-section {
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    margin-bottom: 1rem;
    overflow: hidden;
    transition: border-color 0.2s ease;
}

.draft-section:hover {
    border-color: rgba(88, 166, 255, 0.35);
}

.draft-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1.25rem;
    background: rgba(88, 166, 255, 0.08);
    border-bottom: 1px solid var(--glass-border);
    font-weight: 600;
    font-size: 1rem;
    color: var(--primary);
    letter-spacing: 0.3px;
}

.draft-section-body {
    padding: 1.5rem 1.75rem;
    font-size: 0.94rem;
    line-height: 1.85;
    background: rgba(0, 0, 0, 0.12);
    color: var(--text-main);
}

.draft-section-body p {
    margin-bottom: 0.95rem;
}

.draft-section-body a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.draft-section-body a:hover {
    text-decoration: underline;
}

.copy-btn {
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
    border-color: rgba(88, 166, 255, 0.4);
    color: var(--text-muted);
    transition: all 0.2s;
    margin: 0;
}

.copy-btn:hover {
    background: rgba(88, 166, 255, 0.15);
    color: var(--primary);
    border-color: var(--primary);
}

/* ===== Global Settings ===== */
.global-settings {
    background: rgba(13, 17, 23, 0.5);
}

/* ===== Footer ===== */
footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    padding-bottom: 2rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .app-container {
        padding: 1rem 1rem;
    }

    .tab-content {
        padding: 1.5rem 1.25rem;
    }

    h1 {
        font-size: 1.9rem;
    }

    .tab-label {
        font-size: 0.72rem;
    }

    .tab-connector {
        min-width: 8px;
    }
}