/* ============================================
   Shorthand Pro — Main Stylesheet
   ============================================ */

:root {
    --primary: #4f46e5;
    --secondary: #7c3aed;
    --sidebar-width: 260px;
    --topbar-height: 54px;
    --border-radius: 12px;
}

/* ---- Base ---- */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f8fafc;
    color: #1e293b;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width) !important;
    height: 100vh;
    position: fixed;
    top: 0; left: 0;
    z-index: 1040;
    padding: 0;
    background: linear-gradient(160deg, var(--primary) 0%, var(--secondary) 100%);
    box-shadow: 4px 0 20px rgba(79,70,229,0.15);
    transition: width 0.28s cubic-bezier(.4,0,.2,1), transform 0.3s ease;
    overflow: hidden;           /* sidebar itself doesn't scroll */
    display: flex;
    flex-direction: column;
}
/* The nav inside scrolls */
.sidebar > nav {
    flex: 1 1 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.25) transparent;
}
.sidebar > nav::-webkit-scrollbar { width: 4px; }
.sidebar > nav::-webkit-scrollbar-track { background: transparent; }
.sidebar > nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.25); border-radius: 2px; }

.sidebar .nav-link {
    color: rgba(255,255,255,0.85);
    border-radius: 8px;
    padding: 0.6rem 1rem;
    transition: background 0.15s, color 0.15s, padding 0.2s, font-size 0.1s;
    font-size: 0.9rem;
    font-weight: 500;
    min-height: 44px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    background: rgba(255,255,255,0.18);
    color: #fff;
}

.sidebar .nav-link i {
    width: 20px;
    flex-shrink: 0;
    text-align: center;
    transition: margin 0.2s;
}

/* sidebar close button – mobile only */
.sidebar-close-btn {
    display: none !important;   /* hidden on desktop always */
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    z-index: 10;
    align-items: center;
    justify-content: center;
}

/* ---- Desktop sidebar collapse toggle (in topbar) ---- */
#desktopSidebarToggle {
    min-width: 36px;
    min-height: 36px;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

/* ---- Desktop collapsed sidebar ---- */
body.sidebar-collapsed .sidebar {
    width: 68px !important;
    box-shadow: 2px 0 10px rgba(79,70,229,0.1);
}
/* Icon-only: hide text nodes via font-size trick */
body.sidebar-collapsed .sidebar .nav-link,
body.sidebar-collapsed .sidebar span.nav-link {
    font-size: 0 !important;
    justify-content: center !important;
    padding: 0.55rem 0.4rem !important;
}
body.sidebar-collapsed .sidebar .nav-link i,
body.sidebar-collapsed .sidebar span.nav-link i {
    font-size: 1.15rem !important;
    margin: 0 !important;
    width: auto !important;
}
body.sidebar-collapsed .sidebar .nav-link .badge,
body.sidebar-collapsed .sidebar .bi-lock-fill { display: none !important; }
body.sidebar-collapsed .sidebar .sidebar-brand-text { display: none !important; }
body.sidebar-collapsed .sidebar .sidebar-brand-sub  { display: none !important; }
body.sidebar-collapsed .sidebar .sidebar-user-section  { display: none !important; }
body.sidebar-collapsed .sidebar .sidebar-refer-section { display: none !important; }
body.sidebar-collapsed .sidebar .sidebar-brand {
    justify-content: center !important;
    padding: 1rem 0.4rem !important;
}

/* Hover to expand while collapsed — sidebar overlays content */
body.sidebar-collapsed .sidebar:hover {
    width: var(--sidebar-width) !important;
    box-shadow: 6px 0 28px rgba(79,70,229,0.28);
    z-index: 1045;
    overflow: hidden;
}
body.sidebar-collapsed .sidebar:hover > nav {
    overflow-y: auto;
}
body.sidebar-collapsed .sidebar:hover .nav-link,
body.sidebar-collapsed .sidebar:hover span.nav-link {
    font-size: 0.9rem !important;
    justify-content: flex-start !important;
    padding: 0.6rem 1rem !important;
}
body.sidebar-collapsed .sidebar:hover .nav-link i,
body.sidebar-collapsed .sidebar:hover span.nav-link i {
    font-size: 0.9rem !important;
    margin-right: 0.5rem !important;
    width: 20px !important;
}
body.sidebar-collapsed .sidebar:hover .nav-link .badge { display: inline-block !important; }
body.sidebar-collapsed .sidebar:hover .bi-lock-fill   { display: inline !important; font-size: 11px !important; }
body.sidebar-collapsed .sidebar:hover .sidebar-brand-text { display: inline !important; }
body.sidebar-collapsed .sidebar:hover .sidebar-brand-sub  { display: block  !important; }
body.sidebar-collapsed .sidebar:hover .sidebar-user-section  { display: block !important; }
body.sidebar-collapsed .sidebar:hover .sidebar-refer-section { display: block !important; }
body.sidebar-collapsed .sidebar:hover .sidebar-brand {
    justify-content: flex-start !important;
    padding: 0.75rem 1rem !important;
}

/* Collapse toggle icon – CSS handles the flip so JS doesn't fight it */
#desktopSidebarToggle i {
    display: inline-block;
    transition: transform 0.28s cubic-bezier(.4,0,.2,1);
}
body.sidebar-collapsed #desktopSidebarToggle i { transform: rotate(180deg); }

/* ---- Sidebar overlay (mobile) ---- */
#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1039;
    backdrop-filter: blur(2px);
}
#sidebarOverlay.show { display: block; }

/* ---- Cards ---- */
.card {
    border-radius: var(--border-radius) !important;
    border: 1px solid rgba(0,0,0,0.05) !important;
}
.card.shadow-sm {
    box-shadow: 0 2px 12px rgba(0,0,0,0.06) !important;
}

/* ---- Buttons ---- */
.btn { min-height: 36px; }
.btn-primary {
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border: none;
    min-height: 40px;
}
.btn-primary:hover {
    background: linear-gradient(90deg, var(--secondary), var(--primary));
    border: none;
}
.btn-primary:active, .btn-primary:focus {
    background: var(--secondary) !important;
    border: none !important;
    box-shadow: 0 0 0 0.25rem rgba(79,70,229,0.3) !important;
}

/* ---- Forms ---- */
.form-control, .form-select { min-height: 44px; }
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(79,70,229,0.15);
}

/* ---- Tables ---- */
.table > :not(caption) > * > * {
    padding: 0.85rem 1rem;
    vertical-align: middle;
}
.table tbody tr:hover { background: rgba(79,70,229,0.03); }

/* ---- Badges ---- */
.badge { font-weight: 500; letter-spacing: 0.02em; }

/* ---- Assignment Cards ---- */
.assignment-card { transition: transform 0.2s ease, box-shadow 0.2s ease; }
.assignment-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(79,70,229,0.12) !important;
}

/* ---- Audio Player ---- */
.audio-player-wrapper { background: linear-gradient(135deg, var(--primary), var(--secondary)); }
#progressBar { cursor: pointer; background: rgba(255,255,255,0.3); border-radius: 100px; }
#progressFill { border-radius: 100px; background: rgba(255,255,255,0.9); transition: width 0.1s linear; }

/* ---- Timer Ring ---- */
.timer-ring circle { transition: stroke-dashoffset 1s linear, stroke 0.5s; }

/* ---- Typing Area ---- */
#typingArea {
    font-family: 'Courier New', monospace;
    line-height: 2;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    transition: border-color 0.2s;
}
#typingArea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

/* ---- Phase Steps ---- */
.phase-step .badge { transition: all 0.3s ease; font-size: 0.85rem; }

/* ---- Progress Bars ---- */
.progress { border-radius: 100px; overflow: hidden; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(79,70,229,0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(79,70,229,0.5); }

/* ---- Stats Bar cells ---- */
.stats-bar-cell {
    text-align: center;
    padding: 10px 12px;
    flex: 1 1 90px;
    border-right: 1px solid #e5e7eb;
    min-width: 80px;
}
.stats-bar-cell:last-child { border-right: none; }

/* ---- Topbar hamburger ---- */
#sidebarToggle {
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   RESPONSIVE — Tablet (≤ 991px)
   ============================================ */
@media (max-width: 991px) {
    /* Mobile: slide-in drawer */
    .sidebar { transform: translateX(-100%); width: var(--sidebar-width) !important; }
    .sidebar.show { transform: translateX(0); z-index: 1040; }
    /* Show X close button on mobile only */
    .sidebar-close-btn { display: flex !important; }
    /* Hide desktop collapse toggle on mobile */
    #desktopSidebarToggle { display: none !important; }
    /* Reset any desktop-collapse body class on mobile */
    body.sidebar-collapsed .sidebar {
        width: var(--sidebar-width) !important;
    }
    body.sidebar-collapsed .sidebar .nav-link,
    body.sidebar-collapsed .sidebar span.nav-link {
        font-size: 0.9rem !important;
        justify-content: flex-start !important;
        padding: 0.6rem 1rem !important;
    }
    body.sidebar-collapsed .sidebar .nav-link i { font-size: 0.9rem !important; margin-right: 0.5rem !important; width: 20px !important; }
    body.sidebar-collapsed .sidebar .nav-link .badge { display: inline-block !important; }
    body.sidebar-collapsed .sidebar .bi-lock-fill { display: inline !important; }
    body.sidebar-collapsed .sidebar .sidebar-brand-text,
    body.sidebar-collapsed .sidebar .sidebar-brand-sub,
    body.sidebar-collapsed .sidebar .sidebar-user-section,
    body.sidebar-collapsed .sidebar .sidebar-refer-section { display: block !important; }
    body.sidebar-collapsed .sidebar .sidebar-brand { justify-content: flex-start !important; padding: 0.75rem 1rem !important; }

    [style*="margin-left:var(--sidebar-width)"],
    [style*="margin-left: var(--sidebar-width)"] {
        margin-left: 0 !important;
    }

    body.sidebar-open { overflow: hidden; }
}

/* ============================================
   RESPONSIVE — Mobile (≤ 767px)
   ============================================ */
@media (max-width: 767px) {
    .card-body   { padding: 1rem !important; }
    .card-header { padding: 0.75rem 1rem !important; }

    /* Stats bar: 3-col grid */
    .stats-bar-flex {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
    }
    .stats-bar-cell {
        flex: none !important;
        min-width: unset !important;
        border-bottom: 1px solid #e5e7eb;
    }

    /* Tables: horizontal scroll */
    .table-responsive-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-responsive-wrap .table { min-width: 500px; }

    /* Page padding */
    .p-4 { padding: 0.75rem !important; }

    /* Topbar title */
    .topbar-page-title {
        max-width: 150px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: inline-block;
    }

    /* Typing / editor areas */
    .ql-container.ql-snow, #typingArea { height: 280px !important; font-size: 14px !important; }
    .orig-text-box                     { height: 280px !important; font-size: 14px !important; }

    /* Grid cols become full width */
    .row.g-3 > [class*="col-md"] { width: 100%; }

    /* Phase stepper */
    .phase-step .badge { font-size: 0.72rem; }
    .phase-step .small { font-size: 10px; }

    /* TTS player */
    .tts-card .d-flex { flex-wrap: wrap !important; }

    /* Action buttons */
    .d-flex.gap-2.flex-wrap { gap: 6px !important; }
    .d-flex.gap-2.flex-wrap .btn { font-size: 13px; padding: 6px 10px; }
}

/* ============================================
   RESPONSIVE — Small phones (≤ 480px)
   ============================================ */
@media (max-width: 480px) {
    /* Stats bar: 2-col */
    .stats-bar-flex { grid-template-columns: repeat(2, 1fr) !important; }

    .assignment-card .card-body { padding: 0.75rem !important; }
    .stat-card .display-4 { font-size: 2rem !important; }

    /* Tables: tighter */
    .table > :not(caption) > * > * { padding: 0.5rem 0.6rem; font-size: 13px; }

    /* Hide secondary info in topbar */
    .topbar-username { display: none !important; }
}

/* ---- Dark mode overrides ---- */
[data-bs-theme="dark"] body   { background: #0f172a; color: #e2e8f0; }
[data-bs-theme="dark"] .card  { background: #1e293b; border-color: rgba(255,255,255,0.05) !important; }
[data-bs-theme="dark"] .table-light { background: #1e293b; }
[data-bs-theme="dark"] .bg-light    { background: #334155 !important; }

/* ---- Result diff colours ---- */
.diff-correct { color: #16a34a; }
.diff-typo    { color: #d97706; }
.diff-wrong   { color: #dc2626; }
.diff-missed  { color: #dc2626; text-decoration: line-through; opacity: 0.6; }

/* ---- Auth pages ---- */
.auth-card { border-radius: 20px; overflow: hidden; }

/* ---- Toast ---- */
.toast-timer {
    position: fixed;
    top: 20px; right: 20px;
    z-index: 9999;
    min-width: 300px;
    max-width: calc(100vw - 40px);
}

/* ---- Plan cards ---- */
.plan-card { transition: transform 0.2s ease, box-shadow 0.2s ease; }
.plan-card:hover { transform: translateY(-6px); box-shadow: 0 20px 40px rgba(0,0,0,0.12) !important; }

/* ---- Ready countdown ---- */
#readyCountdown { display: inline-block; transition: transform 0.3s ease; line-height: 1; }

/* ---- Timer urgency ---- */
@keyframes timerUrgent { 0%,100%{opacity:1} 50%{opacity:0.5} }
.timer-urgent { animation: timerUrgent 0.6s infinite; }

/* ---- Animations ---- */
@keyframes fadeInUp { from{opacity:0;transform:translateY(20px)} to{opacity:1;transform:translateY(0)} }
.fade-in-up { animation: fadeInUp 0.4s ease forwards; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.5} }
.pulse { animation: pulse 2s infinite; }
