/* =============================================
   STUDY DASHBOARD - STYLES V2
   Dark Theme with Flip Cards & Conversation
   ============================================= */

:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1e40af;
    --color-primary-light: #3b82f6;
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-surface-light: #334155;
    --color-text: #f1f5f9;
    --color-text-muted: #94a3b8;
    --color-border: #475569;
    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'Cascadia Code', 'Fira Code', monospace;
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-main);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--color-primary-light);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--color-text);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    padding-bottom: 100px;
}

/* ========== HEADER ========== */
.header {
    text-align: center;
    margin-bottom: 1.5rem;
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    border-radius: var(--radius-xl);
}

.header h1 {
    font-size: 1.75rem;
    margin-bottom: 0.25rem;
}

.header p {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* ========== STATS ========== */
.progress-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--color-surface);
    padding: 1rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    text-align: center;
}

.stat-card h3 {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.stat-card .value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--color-primary-light);
}

/* ========== TABS (WRAPPED) ========== */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0.5rem;
}

.tab {
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.2s;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.tab:hover {
    color: var(--color-text);
    background: var(--color-surface);
}

.tab.active {
    color: var(--color-primary-light);
    background: var(--color-surface);
}

/* ========== TAB CONTENT ========== */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== SECTION HEADER ========== */
.section-header {
    background: var(--color-surface);
    padding: 1rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
    border-left: 4px solid var(--color-primary);
}

.section-header h2 {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.section-header p {
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

/* ========== CARDS SECTION ========== */
.cards-section {
    background: var(--color-surface);
    padding: 1rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    margin-bottom: 1rem;
}

.cards-section h3 {
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    color: var(--color-primary-light);
}

/* ========== CALENDAR ========== */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(55px, 1fr));
    gap: 0.4rem;
}

.day-card {
    background: var(--color-surface-light);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.4rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    position: relative;
}

.day-card:hover {
    border-color: var(--color-primary);
    transform: translateY(-2px);
}

.day-card.completed {
    background: var(--color-success);
    border-color: var(--color-success);
}

.day-card .day-number {
    font-size: 0.9rem;
    font-weight: bold;
}

.day-card .day-label {
    font-size: 0.6rem;
    color: var(--color-text-muted);
}

.day-card .checkmark {
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 0.65rem;
}

/* ========== TASK ITEMS ========== */
.task-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--color-surface-light);
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.task-item:hover {
    background: var(--color-border);
}

.task-item.completed {
    opacity: 0.5;
}

.task-item.completed .task-text {
    text-decoration: line-through;
}

.task-checkbox {
    width: 1.1rem;
    height: 1.1rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
}

.task-checkbox.checked {
    background: var(--color-success);
    border-color: var(--color-success);
}

.task-content {
    flex: 1;
}

.task-text {
    font-size: 0.8rem;
    font-weight: 500;
}

.task-duration {
    font-size: 0.7rem;
    color: var(--color-text-muted);
}

/* ========== FLIP FLASHCARDS ========== */
.flashcard-container {
    perspective: 1000px;
    margin-bottom: 1rem;
}

.flashcard-display {
    width: 100%;
    height: 220px;
    position: relative;
    cursor: pointer;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s;
}

.flashcard-display.flipped .flashcard-inner {
    transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
}

.flashcard-back {
    transform: rotateY(180deg);
    background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
    border-color: var(--color-primary);
}

.flashcard-category {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--color-primary-light);
    font-weight: 600;
    margin-bottom: 0.75rem;
    letter-spacing: 1px;
}

.flashcard-back .flashcard-category {
    color: rgba(255, 255, 255, 0.8);
}

.flashcard-text {
    font-size: 1.1rem;
    line-height: 1.6;
    font-weight: 500;
}

.flashcard-hint {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    margin-top: 1rem;
}

.flashcard-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.flashcard-counter {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--color-primary-light);
    min-width: 80px;
    text-align: center;
}

/* ========== RESOURCES ========== */
.resources-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 0.75rem;
}

.resource-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    transition: all 0.2s;
}

.resource-card:hover {
    border-color: var(--color-primary);
    transform: translateY(-2px);
}

.resource-card h3 {
    color: white;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.resource-card p {
    color: var(--color-text-muted);
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
}

.resource-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.65rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.resource-badge.free {
    background: var(--color-success);
}

.resource-badge.paid {
    background: var(--color-warning);
}

.resource-badge.book {
    background: #8b5cf6;
}

/* ========== ROADMAP ========== */
.roadmap-task {
    padding: 0.4rem 0;
    font-size: 0.8rem;
    border-bottom: 1px dashed var(--color-border);
}

.roadmap-task:last-child {
    border-bottom: none;
}

/* ========== PODCAST PLAYER ========== */
.podcast-player {
    background: var(--color-surface);
    padding: 1rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
}

.podcast-player h3 {
    color: var(--color-primary-light);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.podcast-player audio {
    width: 100%;
    margin-bottom: 0.5rem;
}

.podcast-speed {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    justify-content: center;
}

.podcast-speed input[type="range"] {
    width: 100px;
}

.podcast-list {
    display: grid;
    gap: 0.5rem;
}

.podcast-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--color-surface-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.8rem;
}

.podcast-item:hover {
    background: var(--color-border);
}

/* ========== CONVERSATION PRACTICE ========== */
.conversation-area {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.conversation-header {
    background: var(--color-primary);
    padding: 0.75rem 1rem;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversation-messages {
    height: 300px;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.conversation-input-area {
    padding: 0.75rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.conversation-input-area input {
    flex: 1;
    min-width: 150px;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 0.85rem;
}

/* ========== LEETCODE ========== */
.lc-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.lc-problem {
    padding: 1rem;
    background: var(--color-bg);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    min-height: 100px;
    border: 1px solid var(--color-border);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.lc-problem pre {
    background: var(--color-surface-light);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 0.5rem 0;
}

.lc-problem code {
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.lc-solution-area {
    display: none;
}

.lc-code {
    width: 100%;
    min-height: 200px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    color: var(--color-text);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    resize: vertical;
    margin-bottom: 0.75rem;
}

.lc-result {
    padding: 1rem;
    background: var(--color-surface-light);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    min-height: 50px;
}

/* ========== BUTTONS ========== */
.btn {
    padding: 0.4rem 0.75rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--color-primary-dark);
}

.btn-secondary {
    background: var(--color-surface-light);
    color: var(--color-text);
}

.btn-secondary:hover {
    background: var(--color-border);
}

.btn-success {
    background: var(--color-success);
    color: white;
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}

/* ========== TEXTAREA ========== */
.notes-area {
    width: 100%;
    min-height: 150px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    color: var(--color-text);
    font-size: 0.85rem;
    font-family: var(--font-main);
    resize: vertical;
}

.notes-area:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* ========== SELECT ========== */
.select {
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    font-size: 0.8rem;
}

/* ========== AUTH MODAL ========== */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.auth-card {
    background: var(--color-surface);
    padding: 1.5rem;
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 350px;
    text-align: center;
}

.auth-card h2 {
    margin-bottom: 0.75rem;
    font-size: 1.25rem;
}

.auth-input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 1rem;
}

.auth-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    cursor: pointer;
}

.auth-btn:hover {
    background: var(--color-primary-dark);
}

/* ========== CHAT WIDGET ========== */
.chat-fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: var(--color-primary);
    border-radius: 50%;
    box-shadow: 0 6px 15px rgba(59, 130, 246, 0.4);
    z-index: 2000;
    display: grid;
    place-items: center;
    cursor: pointer;
    font-size: 22px;
    transition: all 0.3s;
}

.chat-fab:hover {
    transform: scale(1.1);
}

.chat-window {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 350px;
    height: 450px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    display: none;
    flex-direction: column;
    z-index: 2000;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.chat-window.open {
    display: flex;
}

.chat-header {
    padding: 0.75rem;
    background: var(--color-primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 0.85rem;
}

.chat-close {
    cursor: pointer;
    font-size: 1.1rem;
    opacity: 0.8;
}

.chat-close:hover {
    opacity: 1;
}

.chat-messages {
    flex: 1;
    padding: 0.75rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.message {
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-md);
    max-width: 85%;
    font-size: 0.8rem;
    line-height: 1.4;
}

.message.user {
    background: var(--color-primary);
    align-self: flex-end;
}

.message.ai {
    background: var(--color-surface-light);
    align-self: flex-start;
}

.message .listen-btn {
    background: none;
    border: none;
    cursor: pointer;
    margin-left: 0.4rem;
    font-size: 0.9rem;
}

.chat-input-area {
    padding: 0.75rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.chat-input-area input {
    flex: 1;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 0.85rem;
}

.chat-btn {
    padding: 0.4rem 0.6rem;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
}

.chat-btn.speak {
    background: var(--color-success);
    color: white;
}

.chat-btn.speak.recording {
    background: var(--color-danger);
}

.chat-btn.send {
    background: var(--color-primary);
    color: white;
}

.tts-speed {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    padding: 0 0.75rem;
    justify-content: flex-end;
}

.tts-speed input[type="range"] {
    width: 50px;
}

/* ========== MOBILE ========== */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    .container {
        padding: 1rem;
        padding-bottom: 100px;
    }

    .header {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.25rem;
    }

    .progress-overview {
        grid-template-columns: repeat(2, 1fr);
    }

    .chat-window {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    .chat-fab {
        bottom: 15px;
        right: 15px;
        width: 45px;
        height: 45px;
        font-size: 20px;
    }

    .resources-grid {
        grid-template-columns: 1fr;
    }

    .conversation-messages {
        height: 250px;
    }
}

/* ========== MOBILE ENHANCED ========== */
@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .container {
        padding: 0.75rem;
        padding-bottom: 80px;
    }

    .header {
        padding: 0.75rem;
        border-radius: var(--radius-md);
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .header p {
        font-size: 0.75rem;
    }

    /* Stats mobile */
    .progress-overview {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-card {
        padding: 0.75rem 0.5rem;
    }

    .stat-card h3 {
        font-size: 1.25rem;
    }

    .stat-card p {
        font-size: 0.65rem;
    }

    /* Tabs mobile - scrollable */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 0.5rem;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab {
        font-size: 0.7rem;
        padding: 0.5rem 0.75rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Flashcards mobile - BIGGER */
    .flashcard-container {
        perspective: 1000px;
        margin: 0.5rem 0;
    }

    .flashcard-display {
        height: 220px;
    }

    .flashcard-text {
        font-size: 1rem;
        padding: 0.5rem;
    }

    .flashcard-category {
        font-size: 0.65rem;
    }

    .flashcard-hint {
        font-size: 0.7rem;
    }

    .flashcard-controls {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .flashcard-controls .btn {
        flex: 1;
        min-width: 100px;
        font-size: 0.8rem;
        padding: 0.75rem 0.5rem;
    }

    .flashcard-counter {
        width: 100%;
        text-align: center;
        order: -1;
        margin-bottom: 0.5rem;
    }

    /* Calendar mobile - smaller grid */
    .calendar-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 3px;
    }

    .day-card {
        padding: 0.25rem;
        min-height: 40px;
    }

    .day-number {
        font-size: 0.75rem;
    }

    .day-label {
        font-size: 0.5rem;
    }

    /* Tasks mobile - larger touch targets */
    .task-item {
        padding: 0.75rem;
        min-height: 50px;
    }

    .task-checkbox {
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }

    .task-text {
        font-size: 0.85rem;
    }

    .task-duration {
        font-size: 0.7rem;
    }

    /* Conversation mobile */
    .conversation-messages {
        height: 200px;
    }

    .conversation-input-area {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .conversation-input-area input {
        flex: 1;
        min-width: 150px;
    }

    .conversation-input-area .btn {
        padding: 0.75rem 1rem;
    }

    /* LeetCode mobile */
    .leetcode-arena select {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .leetcode-arena .btn {
        width: 100%;
    }

    #lc-code {
        font-size: 0.8rem;
        height: 150px;
    }

    /* Roadmap mobile */
    .roadmap-week {
        padding: 0.75rem;
    }

    .roadmap-week h4 {
        font-size: 0.9rem;
    }

    .roadmap-week li {
        font-size: 0.8rem;
    }

    /* Podcast mobile */
    .podcast-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .podcast-item .btn {
        width: 100%;
    }

    /* Career mobile */
    .career-grid {
        grid-template-columns: 1fr;
    }

    /* Buttons mobile - larger */
    .btn {
        font-size: 0.85rem;
        padding: 0.75rem 1rem;
        min-height: 44px;
        /* Apple HIG touch target */
    }

    /* Section headers mobile */
    .section-header h2 {
        font-size: 1.1rem;
    }

    .section-header p {
        font-size: 0.75rem;
    }

    .cards-section h3 {
        font-size: 0.95rem;
    }
}

/* ========== UTILITIES ========== */
.text-muted {
    color: var(--color-text-muted);
}

.text-primary {
    color: var(--color-primary-light);
}

.text-success {
    color: var(--color-success);
}

.mt-sm {
    margin-top: 0.5rem;
}

.mt-md {
    margin-top: 0.75rem;
}

.mb-sm {
    margin-bottom: 0.5rem;
}

.mb-md {
    margin-bottom: 0.75rem;
}

.hidden {
    display: none !important;
}

/* ========== PWA / MOBILE SAFE AREAS ========== */
@supports (padding: max(0px)) {
    .container {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-bottom: max(100px, env(safe-area-inset-bottom));
    }
}