/* ==========================================
   STOU/32209 - ULTIMATE COMPACT THEME
   v5.2 (Fixed Header Spacing)
   ========================================== */

:root {
    --bg-body: #f8fafc;
    --bg-paper: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    
    /* Brand Colors */
    --color-brand: #0f766e;       /* Teal 700 */
    --color-brand-dark: #134e4a;  /* Teal 800 */
    --color-brand-light: #ccfbf1; /* Teal 100 */
    
    --color-accent: #d97706;      /* Amber 600 */
    --color-law: #be123c;         
    --color-acc: #15803d;         
    
    --sidebar-w: 280px;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background-color: var(--bg-body);
    font-family: 'Sarabun', sans-serif;
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.8;
}

h1, h2, h3, h4, h5 { font-family: 'Kanit', sans-serif; margin-top: 0; color: var(--text-primary); }
a { text-decoration: none; color: inherit; transition: 0.2s; }

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

/* Sidebar */
.main-sidebar {
    width: var(--sidebar-w);
    background: var(--bg-paper);
    height: 100vh;
    position: fixed;
    top: 0; left: 0;
    border-right: 1px solid #e2e8f0;
    z-index: 1000;
    display: flex; flex-direction: column;
}

.sidebar-header { padding: 20px; border-bottom: 1px solid #e2e8f0; background: #f1f5f9; }
.course-badge { background: var(--color-brand); color: white; padding: 4px 10px; border-radius: 4px; font-size: 0.8rem; font-weight: 700; display: inline-block; margin-bottom: 8px; }
.course-title-menu { font-size: 1.1rem; font-weight: 600; color: #1e293b; line-height: 1.4; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 15px; }
.nav-item { display: flex; align-items: center; padding: 10px 15px; margin-bottom: 5px; border-radius: 8px; color: var(--text-secondary); font-weight: 500; }
.nav-item:hover { background: #f0fdfa; color: var(--color-brand); }
.nav-item.active { background: #ccfbf1; color: var(--color-brand-dark); font-weight: 700; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }

/* Main Content (แก้ไข: ลด Padding บน) */
.main-content {
    margin-left: var(--sidebar-w);
    width: calc(100% - var(--sidebar-w));
    padding: 25px 5% 40px; /* Top reduced from 40px to 25px */
}

/* Content Header (แก้ไข: ลด Padding และ Margin) */
.content-header {
    background: var(--bg-paper);
    padding: 25px 35px; /* Reduced padding */
    border-radius: var(--radius);
    margin-bottom: 30px; /* Reduced margin */
    box-shadow: var(--shadow);
    border-left: 8px solid var(--color-brand);
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

/* Header Typography (แก้ไข: ลด Margin หัวข้อ) */
.content-header h1 { 
    font-size: 2.2rem; 
    color: #0f172a; 
    margin: 5px 0 10px 0; /* Tighten vertical spacing */
    line-height: 1.2;
}
.content-header p { 
    font-size: 1.05rem; 
    color: #64748b; 
    font-weight: 300; 
    margin: 0; 
    max-width: 850px; 
}

/* Badge in Header */
.header-badge {
    background: #e0f2f1; color: #0f766e; 
    padding: 4px 10px; border-radius: 6px; 
    font-size: 0.8rem; font-weight: 700;
    display: inline-block; margin-bottom: 5px;
}

/* PDF Button */
.pdf-btn {
    background: var(--color-law); color: white; border: none;
    padding: 10px 20px; border-radius: 6px; cursor: pointer;
    font-weight: 600; white-space: nowrap;
    display: flex; align-items: center; gap: 8px;
    font-family: 'Kanit', sans-serif;
    transition: transform 0.2s;
    box-shadow: 0 2px 4px rgba(190, 18, 60, 0.2);
}
.pdf-btn:hover { transform: translateY(-2px); background: #9f1239; }

/* Content Wrapper */
.content-wrapper { display: flex; gap: 30px; align-items: flex-start; }
.content-body { flex: 1; min-width: 0; }

/* Long Content Styling */
.long-content {
    background: var(--bg-paper);
    padding: 45px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 1.125rem;
    color: #334155;
}

.long-content p {
    text-align: left;
    margin-bottom: 1.6em;
    letter-spacing: 0.01em;
}

/* Section Header (In-content) */
.section-header {
    margin: 50px 0 25px 0;
    padding-bottom: 10px;
    border-bottom: 3px solid var(--color-brand-light);
}
.section-header h2 {
    font-size: 1.8rem;
    color: var(--color-brand-dark);
    font-weight: 700;
}

/* Sub-topics */
.sub-topic { margin: 35px 0 20px 0; }
.sub-topic h3 {
    font-size: 1.5rem;
    color: #1e293b;
    background: linear-gradient(90deg, #f1f5f9 0%, transparent 100%);
    padding: 8px 15px;
    border-left: 5px solid var(--color-brand);
    border-radius: 0 6px 6px 0;
}

/* Insight Boxes */
.insight-box {
    padding: 25px; margin: 30px 0; border-radius: 10px;
    background: #ffffff; border: 1px solid #e2e8f0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    position: relative;
}
.insight-box.law { border-left: 5px solid var(--color-law); background: #fff1f2; }
.insight-box.accounting { border-left: 5px solid var(--color-acc); background: #f0fdf4; }
.insight-box.example { border-left: 5px solid #2563eb; background: #eff6ff; }

.insight-badge {
    position: absolute; top: -12px; left: 20px;
    padding: 3px 14px; border-radius: 20px;
    font-size: 0.8rem; font-weight: 700; color: white;
    text-transform: uppercase; letter-spacing: 0.5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.insight-box.law .insight-badge { background: var(--color-law); }
.insight-box.accounting .insight-badge { background: var(--color-acc); }
.insight-box.example .insight-badge { background: #2563eb; }

/* Tables */
table { width: 100%; border-collapse: separate; border-spacing: 0; margin: 25px 0; border: 1px solid #cbd5e1; border-radius: 8px; overflow: hidden; }
th { background: #f8fafc; color: #0f172a; padding: 12px; font-weight: 700; border-bottom: 2px solid #e2e8f0; text-align: left; }
td { padding: 12px; border-bottom: 1px solid #e2e8f0; vertical-align: top; background: white; }
tr:last-child td { border-bottom: none; }

/* TOC Sidebar */
.toc-sidebar-area { width: 250px; position: sticky; top: 25px; flex-shrink: 0; }
.toc-box { background: white; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid #e2e8f0; overflow: hidden; }
.toc-header { background: var(--color-brand); color: white; padding: 12px 15px; font-weight: 700; font-size: 0.95rem; }
.toc-links { padding: 10px; max-height: calc(100vh - 120px); overflow-y: auto; }
.toc-links a {
    display: block; padding: 7px 10px; margin-bottom: 3px; border-radius: 6px;
    color: #64748b; font-size: 0.9rem; transition: all 0.2s;
}
.toc-links a:hover { background: #f1f5f9; color: var(--color-brand-dark); }
.toc-links a.active {
    background: var(--color-brand-light); color: var(--color-brand-dark);
    font-weight: 700; border-left: 3px solid var(--color-brand);
}

/* Responsive */
.mobile-nav-toggle, .toc-float-btn { display: none; }

@media (max-width: 1024px) {
    .main-sidebar { transform: translateX(-100%); transition: transform 0.3s; }
    .main-sidebar.active { transform: translateX(0); box-shadow: 0 0 20px rgba(0,0,0,0.2); }
    .main-content { margin-left: 0; width: 100%; padding: 60px 15px; }
    .toc-sidebar-area { display: none; }
    .content-wrapper { flex-direction: column; }
    
    .mobile-nav-toggle {
        display: flex; position: fixed; top: 15px; left: 15px;
        width: 40px; height: 40px; background: white; color: var(--text-primary);
        border-radius: 50%; align-items: center; justify-content: center;
        z-index: 1100; box-shadow: 0 4px 10px rgba(0,0,0,0.1); cursor: pointer;
    }
    .toc-float-btn {
        display: flex; position: fixed; bottom: 30px; right: 20px;
        width: 50px; height: 50px; background: var(--color-brand); color: white;
        border-radius: 50%; align-items: center; justify-content: center;
        z-index: 900; box-shadow: 0 4px 15px rgba(0,0,0,0.2); cursor: pointer; font-size: 1.2rem;
    }
    
    .content-header { padding: 20px; flex-direction: column; align-items: flex-start; }
    .content-header h1 { font-size: 1.8rem; }
    .pdf-btn { width: 100%; justify-content: center; margin-top: 10px; }
    .long-content { padding: 25px; }
}

@media print {
    .no-print, .main-sidebar, .toc-sidebar-area { display: none !important; }
    .main-content { margin: 0; padding: 0; width: 100%; }
    .long-content { box-shadow: none; border: none; padding: 0; }
    .content-header { padding: 0; margin-bottom: 20px; border: none; box-shadow: none; }
    .insight-box { break-inside: avoid; border: 1px solid #000; }
    a { text-decoration: none; color: black; }
}