/* =========================================
   BASE & THEME VARIABLES
========================================= */
:root {
    --bg: linear-gradient(135deg, #667eea, #764ba2);
    --card: white; 
    --text: #333; 
    --muted: #666; 
    --border: #ccc;
}
body.dark {
    --bg: #121212; 
    --card: #1e1e1e; 
    --text: #eee; 
    --muted: #aaa; 
    --border: #444;
}

html, body {
    /* Use 100dvh so mobile browsers account for the address/nav bars dynamically */
    height: 100%;
    height: 100dvh; 
    margin: 0;
    overflow: hidden;
    font-family: 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background 0.3s;
}

/* =========================================
   LAYOUT & CONTAINERS
========================================= */
.main-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    height: 100dvh;
    padding: 10px; /* Reduced from 15px to save space */
    box-sizing: border-box;
}

.form-container {
    display: flex !important;
    flex-direction: column;
    width: 100%;
    max-width: 800px !important;
    height: 100%;
    max-height: 100%;
    padding: 30px !important;
    box-sizing: border-box;
    /* Modern Glassmorphic Effect */
    background: rgba(255, 255, 255, 0.15) !important;
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px !important;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
}

body.dark .form-container {
    background: rgba(0, 0, 0, 0.35) !important;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}

/* =========================================
   HEADER
========================================= */
.header-area {
    flex-shrink: 0;
    margin-bottom: 15px;
}
.header-area h1 {
    text-align: center;
    width: 100%;
    font-size: 2.0rem;
    font-weight: 800;
    margin: 0 0 10px 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
body.dark .header-area h1 {
    background: linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.header-area p {
    text-align: center;
    width: 100%;
    font-size: 1.1rem;
    color: #a6c6cc;
    margin: 0;
    font-weight: 450;
    letter-spacing: 0.5px;
}
body.dark .header-area p {
    color: #aaa;
}

/* =========================================
   CONTENT & SCROLLBAR
========================================= */
.content-area {
    flex-grow: 1;
    flex-shrink: 1;
    min-height: 0; /* CRITICAL FIX: Allows this div to shrink inside a flexbox so the button at the bottom isn't pushed out! */
    overflow-y: auto;
    margin-bottom: 15px;
    padding-right: 10px;
    display: flex;
    flex-direction: column;
}
.content-area::-webkit-scrollbar {
    width: 6px;
}
.content-area::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.6);
    border-radius: 10px;
}
.phase-title {
    background: linear-gradient(to right, #667eea, #764ba2);
    color: white;
    padding: 8px;
    border-radius: 6px;
    margin: 20px 0 10px;
    font-weight: bold;
}

/* =========================================
   FORM & INPUTS
========================================= */
#curriculumForm {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}
#curriculumForm input,
#curriculumForm select,
#curriculumForm button {
    text-align: center;
    text-align-last: center;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.select-row {
    display: flex;
    gap: 12px;
    width: 100%;
}
.select-row select {
    flex: 1;
    padding: 10px 12px;
    font-size: 0.95rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.4) !important;
    border: 1px solid rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(10px);
    color: #333;
    cursor: pointer;
}
body.dark .select-row select {
    background: rgba(0, 0, 0, 0.4) !important;
    border-color: rgba(255, 255, 255, 0.1);
    color: white;
}
body.dark .select-row select option {
    background: #222;
    color: white;
}

.input-group {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 15px;
}

#stream {
    flex: 1;
    padding: 12px 15px;
    border-radius: 15px;
    font-size: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.4) !important;
    backdrop-filter: blur(10px);
    transition: all 0.3s;
    margin-bottom: 15px;
    box-sizing: border-box;
    color: #333;
}
#stream:focus {
    border-color: #667eea;
    background: rgba(255, 255, 255, 0.7) !important;
    outline: none;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.2);
}
body.dark #stream {
    background: rgba(0, 0, 0, 0.4) !important;
    border-color: rgba(255, 255, 255, 0.1);
    color: white;
    text-align: left;
}
body.dark #stream:focus {
    border-color: #a1c4fd;
    background: rgba(0, 0, 0, 0.6) !important;
}

#micBtn {
    position: static;
    width: 50px;
    height: 48px;
    background: rgba(255, 255, 255, 0.4) !important;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 15px;
    font-size: 1.4rem;
    font-weight: normal;
    cursor: pointer;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    flex-shrink: 0;
    color: #333;
}
body.dark #micBtn {
    background: rgba(0, 0, 0, 0.4) !important;
    border-color: rgba(255, 255, 255, 0.1);
    color: white;
}
#micBtn:hover {
    transform: scale(1.05);
    background: rgba(255, 255, 255, 0.6) !important;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
body.dark #micBtn:hover {
    background: rgba(0, 0, 0, 0.6) !important;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

#curriculumForm button[type="submit"] {
    width: 70%;
    padding: 12px 20px;
    margin-top: 15px;
    border-radius: 12px;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    border: none;
    background: linear-gradient(to right, #667eea, #764ba2);
    color: white;
    font-weight: bold;
    cursor: pointer;
}
#curriculumForm button[type="submit"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

/* =========================================
   NAVIGATION & MENUS
========================================= */
.menu-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
}
.menu-btn {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
    padding: 8px 16px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: opacity 0.3s;
}
.menu-btn:hover {
    opacity: 0.8;
}
.dropdown-content {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
    border-radius: 10px;
    min-width: 120px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
}
.dropdown-content.show {
    display: flex;
}
.dropdown-content a {
    color: white;
    padding: 10px 16px;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: bold;
    transition: background 0.3s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.dropdown-content a:hover {
    background: rgba(255, 255, 255, 0.3);
}

.new-chat-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
    padding: 8px 16px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: opacity 0.3s;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 5px;
}
.new-chat-btn:hover {
    opacity: 0.8;
}

body.dark .menu-btn,
body.dark .dropdown-content,
body.dark .new-chat-btn {
    background: rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.05);
    color: #eee;
}
body.dark .dropdown-content a {
    color: #eee;
    border-bottom-color: rgba(255,255,255,0.05);
}
body.dark .dropdown-content a:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* =========================================
   HISTORY POPUP
========================================= */
.history-popup {
    position: fixed;
    inset: 0;
    display: none;
    justify-content: center;
    align-items: center;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(15px);
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.history-glass {
    width: 95%;
    max-width: 600px;
    max-height: 80vh;
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(25px);
    border-radius: 20px;
    padding: 20px;
    overflow-y: auto;
    color: white;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
body.dark .history-glass {
    background: rgba(0,0,0,0.5);
}
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 15px;
}
.history-header h3 {
    margin: 0;
    font-size: 1.5rem;
    color: white;
    text-shadow: 0 2px 5px rgba(0,0,0,0.3);
    letter-spacing: 1px;
}
#closeHistory {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}
#closeHistory:hover {
    background: rgba(255, 75, 75, 0.8);
    border-color: transparent;
    transform: rotate(90deg) scale(1.1);
    box-shadow: 0 4px 10px rgba(255, 75, 75, 0.4);
}
#historySearch {
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.2);
    color: white;
    margin-bottom: 15px;
    font-size: 1rem;
    box-sizing: border-box;
    outline: none;
    transition: all 0.3s ease;
}
#historySearch::placeholder {
    color: rgba(255, 255, 255, 0.6);
}
#historySearch:focus {
    border-color: #a1c4fd;
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 10px rgba(161, 196, 253, 0.3);
}
.history-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.history-controls button {
    flex: 1;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 10px 5px;
    border-radius: 10px;
    color: white;
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    min-width: 80px;
}
.history-controls button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}
#clearHistory {
    background: rgba(255, 75, 75, 0.2);
    border-color: rgba(255, 75, 75, 0.3);
    color: #ffeaea;
}
#clearHistory:hover {
    background: rgba(255, 75, 75, 0.5);
    border-color: rgba(255, 75, 75, 0.6);
    box-shadow: 0 5px 15px rgba(255, 75, 75, 0.3);
}
.history-item {
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 10px;
    background: rgba(255,255,255,0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: 0.3s;
    cursor: pointer;
}
.history-item:hover {
    transform: scale(1.02);
    background: rgba(255,255,255,0.15);
}
.history-item button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 5px;
    transition: transform 0.2s;
}
.history-item button:hover {
    transform: scale(1.2);
}
.history-item button.del:hover {
    color: #ff4b4b;
}

.undo-box {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 10px 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    z-index: 2500;
}
#undoDelete {
    background: none;
    border: none;
    color: #667eea;
    font-weight: bold;
    cursor: pointer;
    margin-left: 10px;
}
#undoDelete:hover {
    text-decoration: underline;
}

/* =========================================
   📱 MOBILE FIXES (Solves the hidden button issue)
========================================= */
@media (max-width: 600px) {
    .main-container {
        padding: 5px; /* Extremely small padding to maximize space */
    }
    
    .form-container {
        padding: 15px !important; /* Cut padding in half on phones */
        border-radius: 15px !important;
        max-height: calc(100dvh - 10px); /* Strictly fits the screen */
    }
    
    .header-area h1 {
        font-size: 1.6rem;
        margin-bottom: 5px;
    }
    
    .header-area p {
        font-size: 0.95rem;
    }
    
    #stream {
        padding: 10px 15px;
        font-size: 0.95rem;
    }
    
    .select-row {
        gap: 8px; /* Less space between dropdowns */
    }
    
    .select-row select {
        padding: 8px 10px;
        font-size: 0.85rem;
    }
    
    #curriculumForm button[type="submit"] {
        width: 100%; /* Make button full width so it's super easy to tap */
        padding: 12px 20px;
        margin-top: 10px;
    }

    /* Keep top menus inside view */
    .menu-container {
        top: 10px;
        left: 10px;
    }
    .new-chat-btn {
        top: 10px;
        right: 10px;
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}
