/* ==========================================
   STRATEGY LMS - COMPLETE STYLE V.15 (TOOLTIP FIXED)
   ✓ Fixed: Tooltip visibility states
   ✓ Smooth transitions
   ✓ Optimized for Window.Print()
   ========================================== */

:root {
    --bg-body: #f5f7fa;
    --bg-sidebar: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --color-brand: #3b82f6;
    --color-brand-light: #60a5fa;
    --color-brand-dark: #2563eb;
    --color-accent: #10b981;
    --color-law: #ef4444;
    --color-acc: #f59e0b;
    
    --sidebar-w: 280px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    
    --font-main: 'Kanit', sans-serif;
    --font-detail: 'Sarabun', sans-serif;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    --transition-fast: 0.15s ease;
    --transition-base: 0.3s ease;
}

/* ==========================================
   BASE STYLES
   ========================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    margin: 0;
    background-color: var(--bg-body);
    font-family: var(--font-main);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    text-decoration: none;
    color: inherit;
    transition: var(--transition-fast);
}

html {
    scroll-behavior: smooth;
}

/* ==========================================
   LAYOUT SYSTEM
   ========================================== */
.layout-container {
    display: flex;
    min-height: 100vh;
}

/* ==========================================
   SIDEBAR
   ========================================== */
.main-sidebar {
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    border-right: 1px solid #e2e8f0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
}

.brand {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--color-brand);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition-base);
}

.brand:hover {
    transform: scale(1.05);
}

.brand i {
    color: var(--color-brand);
}

.brand span {
    color: var(--text-primary);
}

.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e0 transparent;
}

.nav-group {
    margin-bottom: 25px;
}

.nav-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding-left: 12px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    margin-bottom: 4px;
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.95rem;
    transition: all var(--transition-fast);
    position: relative;
}

.nav-link:hover {
    background: #f1f5f9;
    color: var(--color-brand);
    transform: translateX(5px);
}

.nav-link.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--color-brand);
    font-weight: 600;
    border-left: 3px solid var(--color-brand);
}

.unit-icon {
    background: #e0e7ff;
    color: var(--color-brand);
    padding: 4px 8px;
    border-radius: 6px;
    margin-right: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 38px;
    text-align: center;
    transition: all var(--transition-fast);
}

.nav-link:hover .unit-icon,
.nav-link.active .unit-icon {
    background: var(--color-brand);
    color: white;
}

.close-sidebar-btn {
    display: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.5rem;
    transition: color var(--transition-fast);
}

.close-sidebar-btn:hover {
    color: var(--text-primary);
}

/* ==========================================
   MAIN CONTENT AREA
   ========================================== */
.main-content {
    margin-left: var(--sidebar-w);
    width: calc(100% - var(--sidebar-w));
    padding: 40px 5%;
    min-height: 100vh;
    position: relative;
}

/* ==========================================
   DASHBOARD SPECIFIC
   ========================================== */
.dashboard-hero {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 50px 40px;
    border-radius: var(--border-radius);
    margin-bottom: 40px;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.dashboard-hero::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    border-radius: 50%;
    transform: translate(30%, -30%);
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 25px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-base);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.8rem;
}

.stat-info h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.stat-info p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.section-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 30px;
    display: flex;
    align-items: center;
}

.units-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.unit-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 25px;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-base);
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.unit-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--color-brand), var(--color-brand-light));
    transform: scaleX(0);
    transition: transform var(--transition-base);
}

.unit-card:hover::before {
    transform: scaleX(1);
}

.unit-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
    border-color: var(--color-brand);
}

.unit-badge {
    display: inline-block;
    background: #eff6ff;
    color: var(--color-brand);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 15px;
}

.unit-card h3 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 15px;
    line-height: 1.5;
}

.unit-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--color-brand);
    font-weight: 600;
    font-size: 0.9rem;
}

/* ==========================================
   CONTENT HEADER
   ========================================== */
.content-header {
    margin-bottom: 40px;
}

.content-header h1 {
    font-size: 2.8rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
    line-height: 1.3;
}

.subtitle {
    font-size: 1.15rem;
    color: var(--text-secondary);
    font-family: var(--font-detail);
    line-height: 1.6;
}

.pdf-btn {
    background: var(--color-law);
    color: white;
    padding: 12px 24px;
    border-radius: var(--border-radius-sm);
    border: none;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: all var(--transition-fast);
    font-size: 1rem;
    box-shadow: var(--shadow-md);
}

.pdf-btn:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ==========================================
   LONG CONTENT
   ========================================== */
.content-wrapper {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

.long-content-area {
    flex: 1;
    background: white;
    padding: 60px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    max-width: 100%;
}

.long-content {
    font-family: var(--font-detail);
    font-size: 1.125rem;
    line-height: 2;
    color: var(--text-primary);
}

.long-content h2 {
    font-family: var(--font-main);
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-top: 60px;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 3px solid var(--color-brand);
    line-height: 1.4;
}

.long-content h2:first-of-type {
    margin-top: 0;
}

.long-content h3 {
    font-family: var(--font-main);
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--color-brand-dark);
    margin-top: 45px;
    margin-bottom: 20px;
    padding-left: 15px;
    border-left: 5px solid var(--color-brand-light);
    line-height: 1.5;
}

.long-content p {
    margin-bottom: 24px;
    text-align: left;
    color: #334155;
    font-weight: 400;
}

.long-content strong {
    color: #0f172a;
    font-weight: 700;
}

.long-content ul,
.long-content ol {
    margin: 25px 0;
    padding-left: 30px;
}

.long-content li {
    margin-bottom: 12px;
    padding-left: 5px;
}

.long-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 35px 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 0 1px #e2e8f0;
}

.long-content table th {
    background: #f1f5f9;
    font-weight: 700;
    color: var(--text-primary);
    text-align: left;
    padding: 16px;
    font-family: var(--font-main);
}

.long-content table td {
    border-top: 1px solid #e2e8f0;
    padding: 16px;
    vertical-align: top;
}

/* ==========================================
   INSIGHT BOXES
   ========================================== */
.insight-box {
    margin: 30px 0;
    padding: 25px;
    border-radius: var(--border-radius);
    position: relative;
    background: #f8fafc;
    border-left: 5px solid #cbd5e1;
}

.insight-box.law {
    background: linear-gradient(135deg, #fef2f2, #fee2e2);
    border-left-color: var(--color-law);
}

.insight-box.accounting {
    background: linear-gradient(135deg, #fffbeb, #fef3c7);
    border-left-color: var(--color-acc);
}

.insight-label {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 15px;
    color: white;
}

.bg-law {
    background: var(--color-law);
}

.bg-accounting {
    background: var(--color-acc);
}

/* ==========================================
   SMART WORDS & TOOLTIP (FIXED VERSION)
   ========================================== */
.smart-word {
    background: linear-gradient(120deg, #fef3c7 0%, #fcd34d 100%);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    color: #92400e;
    cursor: help;
    position: relative;
    transition: all 0.2s ease;
    border-bottom: 2px dotted #f59e0b;
}

.smart-word:hover {
    background: linear-gradient(120deg, #fde68a 0%, #fbbf24 100%);
    transform: translateY(-1px);
}

/* [CRITICAL FIX] Tooltip Container with Proper States */
#tooltip-container {
    position: fixed;
    background: rgba(15, 23, 42, 0.96);
    color: white;
    padding: 14px 18px;
    border-radius: 10px;
    font-size: 0.95rem;
    line-height: 1.7;
    max-width: 340px;
    z-index: 99999;
    pointer-events: none;
    box-shadow: 0 12px 28px rgba(0,0,0,0.3), 0 0 1px rgba(255,255,255,0.1);
    font-family: var(--font-detail);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(4px);
    
    /* Default: Hidden */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-5px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

/* [FIX] Visible State - ใช้ class แทน pseudo-class */
#tooltip-container.tooltip-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* [FIX] Hidden State - รับประกันว่าซ่อนได้ */
#tooltip-container.tooltip-hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-5px);
}

/* ==========================================
   TOC SIDEBAR
   ========================================== */
.toc-sidebar-area {
    width: 280px;
    position: sticky;
    top: 40px;
    align-self: flex-start;
}

.toc-box {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

.toc-header {
    background: var(--color-brand);
    color: white;
    padding: 18px 20px;
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toc-links {
    padding: 15px;
}

.toc-links a {
    display: block;
    padding: 12px 15px;
    margin-bottom: 4px;
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    transition: all var(--transition-fast);
    font-size: 0.95rem;
    line-height: 1.4;
}

.toc-links a:hover {
    background: #eff6ff;
    color: var(--color-brand);
}

.toc-links a.active {
    background: #eff6ff;
    color: var(--color-brand);
    font-weight: 700;
    border-left: 3px solid var(--color-brand);
}

/* ==========================================
   CHAT SYSTEM
   ========================================== */
.chat-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: var(--color-accent);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    z-index: 900;
    font-size: 1.5rem;
    transition: transform var(--transition-fast);
}

.chat-btn:hover {
    transform: scale(1.1);
}

.chat-box {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 380px;
    height: 550px;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    z-index: 950;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

.chat-header {
    background: var(--color-accent);
    color: white;
    padding: 15px 20px;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.chat-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8fafc;
}

.msg {
    margin-bottom: 12px;
    padding: 10px 14px;
    border-radius: 12px;
    max-width: 85%;
    line-height: 1.5;
    font-size: 0.95rem;
    word-wrap: break-word;
}

.msg.user {
    background: var(--color-brand);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 2px;
}

.msg.bot {
    background: white;
    color: var(--text-primary);
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 2px;
    box-shadow: var(--shadow-sm);
}

.chat-input {
    display: flex;
    gap: 10px;
    padding: 15px;
    border-top: 1px solid #e2e8f0;
    background: white;
}

.chat-input input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    outline: none;
    font-family: var(--font-detail);
}

.chat-input input:focus {
    border-color: var(--color-brand);
}

.chat-input button {
    background: var(--color-brand);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-input button:hover {
    background: var(--color-brand-dark);
}

/* ==========================================
   MOBILE & RESPONSIVE
   ========================================== */
.toc-float-btn {
    display: none;
    position: fixed;
    bottom: 100px;
    right: 25px;
    background: var(--color-brand);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    z-index: 800;
}

.toc-mobile-sheet {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -5px 25px rgba(0, 0, 0, 0.15);
    z-index: 960;
    max-height: 70vh;
    transition: bottom var(--transition-base);
    display: flex;
    flex-direction: column;
}

.toc-mobile-sheet.active {
    bottom: 0;
}

.toc-mobile-sheet .toc-header {
    padding: 20px;
    border-bottom: 1px solid #e2e8f0;
    background: white;
    color: var(--text-primary);
    border-radius: 20px 20px 0 0;
    font-size: 1.1rem;
    justify-content: space-between;
}

.mobile-links {
    overflow-y: auto;
    padding: 15px;
}

.mobile-nav-toggle {
    display: none;
    position: fixed;
    top: 20px;
    left: 20px;
    background: var(--color-brand);
    color: white;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    z-index: 900;
    cursor: pointer;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

@media (max-width: 1024px) {
    .content-wrapper { flex-direction: column; }
    .toc-sidebar-area { display: none; }
    .toc-float-btn { display: flex; }
    .long-content-area { padding: 40px; }
}

@media (max-width: 768px) {
    .mobile-nav-toggle { display: flex; }
    .close-sidebar-btn { display: block; }
    .main-sidebar { transform: translateX(-100%); }
    .main-sidebar.active { transform: translateX(0); }
    .main-content { margin-left: 0; width: 100%; padding: 80px 20px 40px; }
    
    .long-content-area { padding: 25px; }
    .long-content h2 { font-size: 1.6rem; margin-top: 40px; }
    .long-content h3 { font-size: 1.3rem; }
    .content-header h1 { font-size: 2rem; }
    
    .chat-box { width: calc(100% - 40px); right: 20px; }
    .chat-btn { right: 20px; bottom: 20px; }
}

/* ==========================================
   PRINT STYLES
   ========================================== */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        box-shadow: none !important;
    }

    body { background: white !important; font-size: 12pt !important; }
    
    .main-sidebar, .mobile-nav-toggle, .sidebar-overlay,
    .toc-sidebar-area, .toc-float-btn, .toc-mobile-sheet,
    .chat-btn, .chat-box, .no-print, .pdf-btn, #tooltip-container {
        display: none !important;
    }

    .layout-container, .main-content, .content-wrapper, .long-content-area {
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        background: white !important;
    }

    h1 { font-size: 24pt !important; margin-bottom: 10pt !important; color: black !important; }
    h2 { font-size: 18pt !important; margin-top: 20pt !important; border-bottom: 2px solid #000 !important; color: black !important; page-break-after: avoid; }
    h3 { font-size: 14pt !important; margin-top: 15pt !important; color: black !important; border: none !important; padding: 0 !important; page-break-after: avoid; }
    p, li { color: black !important; font-size: 11pt !important; line-height: 1.6 !important; }
    
    a { text-decoration: none !important; color: black !important; }

    .insight-box {
        border: 2px solid #000 !important;
        background: #f4f4f4 !important;
        page-break-inside: avoid;
    }
    .insight-label {
        border: 1px solid #000 !important;
        background: transparent !important;
        color: black !important;
    }
    
    .smart-word {
        background: none !important;
        border-bottom: 1px dotted black !important;
        color: black !important;
    }
}