:root {
    --bg-gradient: linear-gradient(135deg, #0a1628 0%, #0d2a45 50%, #0a1f35 100%);
    --glass-bg: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --accent-color: #10b981;
    --accent-hover: #059669;
    --text-main: #f0f4f8;
    --text-muted: #94a3b8;
    --text-secondary: #64748b;
    --error: #ef4444;
    --success: #10b981;
    --bot-msg-bg: rgba(37, 99, 235, 0.15);
    --user-msg-bg: rgba(255, 255, 255, 0.08);
    --card-bg: rgba(255, 255, 255, 0.04);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

h1, h2, h3 {
    font-family: 'Outfit', sans-serif;
}

.app-container {
    width: 100%;
    max-width: 960px;
    height: 92vh;
    position: relative;
    padding: 20px;
}

/* ── Glassmorphism Panel ── */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 40px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.6),
                0 0 0 1px rgba(255,255,255,0.03) inset;
    position: absolute;
    top: 20px; left: 20px; right: 20px; bottom: 20px;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass-panel.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.hidden { display: none !important; }

/* ── Auth Section ── */
#auth-section {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.civic-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    display: block;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-8px); }
}

.brand-title {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(to right, #60a5fa, #34d399);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 40px;
}

.auth-form {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ── Inputs ── */
input[type="email"],
input[type="password"],
input[type="text"],
input[type="file"] {
    width: 100%;
    padding: 14px 20px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.25);
    color: var(--text-main);
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.2);
}

/* ── Select dropdown ── */
select {
    flex: 1;
    padding: 14px 20px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.25);
    color: var(--text-main);
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.2);
}

select option {
    background: #0d2a45;
    color: var(--text-main);
}

textarea {
    width: 100%;
    padding: 14px 20px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.25);
    color: var(--text-main);
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    outline: none;
    resize: none;
    min-height: 60px;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.2);
}

/* ── Buttons ── */
button {
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    padding: 14px 24px;
    border-radius: 12px;
    cursor: pointer;
    border: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

button:focus-visible {
    box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.5);
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary-color), #3b82f6);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(37,99,235,0.4);
}

.primary-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(37,99,235,0.45);
}

.primary-btn:active:not(:disabled) { transform: translateY(0); }

.secondary-btn {
    background: rgba(16, 185, 129, 0.1);
    border: 2px solid var(--accent-color);
    color: #34d399; /* Higher contrast green */
}

.secondary-btn:hover:not(:disabled) {
    background: rgba(16,185,129,0.2);
    transform: translateY(-1px);
}

.text-btn { background: transparent; color: var(--text-muted); padding: 8px 16px; border-radius: 8px; }
.text-btn:hover { color: var(--text-main); background: rgba(255,255,255,0.05); }

.icon-btn { 
    background: rgba(255,255,255,0.08); 
    color: var(--text-main); 
    padding: 10px 18px; 
    border-radius: 10px; 
}
.icon-btn:hover { background: rgba(255,255,255,0.16); }

.error-msg  { color: var(--error);  font-size: 0.875rem; min-height: 20px; }

.status-msg {
    font-size: 0.875rem;
    min-height: 20px;
    margin-top: 8px;
    font-weight: 500;
    transition: color 0.3s ease;
}

/* ── Dashboard ── */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--glass-border);
    flex-shrink: 0;
}

.app-header h2 { font-size: 1.4rem; }
.app-header h2 span { color: #60a5fa; }

.dashboard-content {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
    overflow-y: auto;
    padding-right: 4px;
}

.dashboard-content::-webkit-scrollbar { width: 4px; }
.dashboard-content::-webkit-scrollbar-track { background: transparent; }
.dashboard-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 10px; }

.card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 22px 24px;
    transition: border-color 0.3s ease;
}

.card:hover { border-color: rgba(255,255,255,0.18); }
.card h3 { margin-bottom: 6px; font-size: 1.05rem; color: var(--text-main); }
.card p  { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 14px; }

.topic-input-group { display: flex; gap: 10px; align-items: stretch; }

.document-upload input[type="file"] {
    background: rgba(0,0,0,0.15);
    border: 1px dashed var(--glass-border);
    cursor: pointer;
    padding: 10px 16px;
    margin-bottom: 10px;
}

.document-upload input[type="file"]:hover { border-color: var(--accent-color); }

.stats-grid { display: flex; gap: 30px; flex-wrap: wrap; }
.stat-item  { display: flex; flex-direction: column; gap: 2px; }

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: #60a5fa;
    font-family: 'Outfit', sans-serif;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Learning Session ── */
#learning-section { padding: 20px 40px 30px; }

.level-indicator {
    background: linear-gradient(135deg, var(--accent-color), #059669);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: white;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding-right: 8px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 16px;
}

.chat-container::-webkit-scrollbar { width: 5px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 10px; }

.message {
    max-width: 82%;
    padding: 14px 18px;
    border-radius: 16px;
    line-height: 1.6;
    font-size: 0.95rem;
    animation: fadeIn 0.3s ease forwards;
}

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

.message.bot {
    align-self: flex-start;
    background: var(--bot-msg-bg);
    border: 1px solid rgba(37,99,235,0.2);
    border-bottom-left-radius: 4px;
}

.message.user {
    align-self: flex-end;
    background: var(--user-msg-bg);
    border: 1px solid var(--glass-border);
    border-bottom-right-radius: 4px;
}

.message strong { color: #60a5fa; font-weight: 700; }
.message em { color: #f0f4f8; font-style: italic; opacity: 0.9; }
.message p { margin-bottom: 10px; }
.message p:last-child { margin-bottom: 0; }
.message ul, .message ol { margin-left: 24px; margin-bottom: 12px; }
.message li { margin-bottom: 6px; }

.inline-code {
    background: rgba(0, 0, 0, 0.3);
    color: #60a5fa;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9em;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.input-area { display: flex; gap: 12px; align-items: flex-end; flex-shrink: 0; }
.input-area button { height: 58px; padding: 0 28px; white-space: nowrap; }

/* ── Typing Indicator ── */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 14px 18px;
    background: var(--bot-msg-bg);
    border: 1px solid rgba(37,99,235,0.2);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    width: fit-content;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #60a5fa;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}

/* ── Markdown headings inside messages ── */
.message h1, .message h2, .message h3 {
    margin-top: 10px;
    margin-bottom: 6px;
    color: #60a5fa;
}

/* ── Toast Notification ── */
.toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    padding: 14px 22px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    color: white;
    z-index: 9999;
    animation: toastIn 0.3s ease forwards;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    max-width: 320px;
}

.toast.success { background: linear-gradient(135deg, #059669, #10b981); }
.toast.error   { background: linear-gradient(135deg, #dc2626, #ef4444); }
.toast.info    { background: linear-gradient(135deg, #1d4ed8, #2563eb); }

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

/* ── Responsive ── */
@media (max-width: 640px) {
    .glass-panel { padding: 24px 20px; border-radius: 16px; }
    .brand-title { font-size: 2.4rem; }
    .topic-input-group { flex-direction: column; }
    .input-area { gap: 8px; }
    .input-area button { height: 50px; padding: 0 18px; }
    #learning-section { padding: 16px 20px 20px; }
    .app-container { height: 100vh; padding: 0; }
    .glass-panel { border-radius: 0; top: 0; left: 0; right: 0; bottom: 0; }
}
