/* assets/css/global.css */

:root {
    --primary-color: #0d6efd;
    --secondary-color: #6c757d;
    --success-color: #198754;
    --bg-body: #f4f6f9; /* Màu nền xám xanh hiện đại */
    --bg-sidebar: #ffffff;
    --border-color: #e9ecef;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --sidebar-width: 300px;
}

body {
    background-color: var(--bg-body);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #333;
}

/* --- Card Styling --- */
.card {
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    border-radius: 8px;
    background: #fff;
    margin-bottom: 1.5rem;
}

.card-header {
    background-color: #fff;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

/* --- Sidebar Styling --- */
/* Override class cũ .sidebar-card để trông chuyên nghiệp hơn */
.sidebar-card {
    background-color: var(--bg-sidebar);
    border-left: 4px solid var(--primary-color); /* Điểm nhấn bên trái */
}

/* --- Navigation Tabs --- */
.nav-tabs {
    border-bottom: 1px solid var(--border-color);
}

.nav-tabs .nav-link {
    color: var(--secondary-color);
    border: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
    font-weight: 500;
}

.nav-tabs .nav-link:hover {
    color: var(--primary-color);
    isolation: isolate; /* Fix lỗi render border */
}

.nav-tabs .nav-link.active {
    color: var(--primary-color);
    background: none;
    border-bottom: 2px solid var(--primary-color);
}

/* --- Tables & Inputs (Engineering Focus) --- */
/* Container cuộn cho bảng dài */
.table-scroll-container {
    max-height: 450px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.table-scroll-container thead th {
    position: sticky;
    top: 0;
    background-color: #f8f9fa; /* Màu nền header bảng */
    z-index: 10;
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}

/* Input trong bảng nhìn gọn gàng hơn */
td input[type="number"], 
td input[type="text"] {
    width: 100%;
    border: 1px solid #dee2e6;
    padding: 4px 8px;
    border-radius: 4px;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    font-size: 0.9rem;
}

td input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.15);
}

/* Căn giữa nội dung cột STT và Thao tác */
table td.text-center, 
table th.text-center {
    vertical-align: middle;
}

/* --- Loading Overlay (WASM Loader) --- */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.85); /* Nền trắng mờ hiện đại hơn đen */
    backdrop-filter: blur(5px); /* Hiệu ứng mờ nền phía sau */
    display: none; /* Mặc định ẩn, JS sẽ bật lên khi cần (display: flex) */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

#loading-overlay .spinner {
    width: 60px;
    height: 60px;
    border: 5px solid #e9ecef;
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#loading-overlay .loading-text {
    color: var(--primary-color);
    font-size: 1.2rem;
    margin-top: 20px;
    font-weight: 500;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Utility Classes --- */
.cursor-pointer { cursor: pointer; }
.fw-medium { font-weight: 500; }

/* Ẩn spinner trong nút khi chưa chạy */
.btn .spinner-border { display: none; }
.btn.loading .spinner-border { display: inline-block; }
.btn.loading i { display: none; }

/* --- MODERN CODE BLOCK STYLING --- */

/* 1. Khung bao quanh code */
div.highlighter-rouge {
  background: #282c34; /* Màu nền tối giống VS Code */
  border-radius: 8px;
  margin-bottom: 1.5em;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  position: relative;
  padding-top: 30px; /* Chừa chỗ cho thanh header giả */
  overflow: hidden;
}

/* 2. Thanh Header giả lập cửa sổ (Mac Style) */
div.highlighter-rouge:before {
  content: "";
  position: absolute;
  top: 12px;
  left: 15px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ff5f56; /* Nút đỏ */
  box-shadow: 20px 0 0 #ffbd2e, 40px 0 0 #27c93f; /* Nút vàng và xanh */
  z-index: 2;
}

/* 3. Hiển thị Label ngôn ngữ (VBA, APDL, C++) */
div.highlighter-rouge:after {
  content: attr(class); /* Fallback */
  position: absolute;
  top: 5px;
  right: 15px;
  font-family: sans-serif;
  font-size: 0.75rem;
  font-weight: bold;
  color: #abb2bf;
  text-transform: uppercase;
}
/* --- JULIA CODE BLOCK STYLING --- */

/* Label cho ngôn ngữ Julia */
.language-julia.highlighter-rouge:after { 
  content: "Julia Language"; 
  color: #9558b2; /* Màu tím đặc trưng của Julia */
  font-weight: 800;
}

/* Tùy chỉnh highlight cho các từ khóa Julia phổ biến */
.highlight .kn { color: #9558b2; font-weight: bold; } /* Import/Using */
.highlight .nf { color: #389826; } /* Functions */
.highlight .mi { color: #cb3c33; } /* Numbers */
.highlight .kt { color: #4163ad; } /* Types */

/* Đảm bảo khung code có độ bo góc và bóng đổ giống mẫu dầm bê tông */
.language-julia.highlighter-rouge {
  border-left: 4px solid #9558b2;
  background: #1e1e1e; /* Màu nền tối hơn một chút cho code */
}

/* Định nghĩa Label cụ thể cho từng ngôn ngữ */
.language-vba.highlighter-rouge:after { content: "VBA (Excel)"; color: #207245; }
.language-apdl.highlighter-rouge:after { content: "ANSYS APDL"; color: #ffb700; }
.language-cpp.highlighter-rouge:after { content: "C++ / WASM"; color: #00599C; }
.language-js.highlighter-rouge:after { content: "JavaScript"; color: #f7df1e; }

/* 4. Tinh chỉnh nội dung code */
div.highlighter-rouge pre.highlight {
  margin: 0;
  padding: 15px;
  background: transparent; /* Để lộ màu nền của div cha */
  color: #abb2bf; /* Màu chữ chính */
  font-family: "Consolas", "Monaco", monospace;
  font-size: 0.9em;
  line-height: 1.5;
  overflow-x: auto;
}

/* 5. Highlight màu (Nếu theme chưa hỗ trợ tốt Rouge) */
/* Comment màu xám xanh */
.highlight .c, .highlight .cm, .highlight .c1 { color: #7f848e; font-style: italic; }
/* String màu xanh lá */
.highlight .s, .highlight .s1, .highlight .s2 { color: #98c379; }
/* Keyword màu tím */
.highlight .k, .highlight .kd, .highlight .kp { color: #c678dd; font-weight: bold; }

/* Nút CTA chuẩn hiện đại */
.btn-cta-primary {
  display: inline-block;
  padding: 12px 24px;
  background: linear-gradient(135deg, #0d6efd 0%, #0056b3 100%);
  color: white !important;
  font-weight: 600;
  text-decoration: none;
  border-radius: 50px; /* Bo tròn hoàn toàn */
  box-shadow: 0 4px 15px rgba(13, 110, 253, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
  text-align: center;
  margin-top: 20px;
}

.btn-cta-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(13, 110, 253, 0.4);
}

.btn-cta-primary i {
  margin-right: 8px;
}

/* =====================================================================
   MODERN POST LAYOUT - CSS GRID (20:60:20) with STICKY LEFT SIDEBAR
   Applied to: _layouts/single.html
   ===================================================================== */
.img-zoom-125 img {
  width: 125%;
  max-width: none;
  display: block;
  margin: 0 auto;
}

/* Grid Container for Single Post Layout */
.post-grid-container {
  display: grid;
  grid-template-columns: 20% 60% 20%;
  gap: 1.5rem;
  align-items: start; /* Prevent equal height stretching */
  margin: 0 auto;
  max-width: 100%;
  padding: 1rem;
}

/* LEFT SIDEBAR - Sticky positioning */
.post-grid-sidebar-left {
  position: sticky;
  top: 2em; /* Offset for masthead/header */
  align-self: start; /* Prevents stretching to match tallest column */
  max-height: calc(100vh - 4em); /* Prevent sidebar from being taller than viewport */
  overflow-y: auto; /* Allow scrolling if content is too long */
}

/* MAIN ARTICLE - Center column */
.post-grid-article {
  /* Article flows naturally, scrolls with page */
  min-width: 0; /* Prevent grid blowout from long content */
}

/* RIGHT SIDEBAR - Scrollable with content */
.post-grid-sidebar-right {
  /* Flows naturally with the main article content */
  align-self: start;
}

/* Styling for sidebars (clean, modern appearance) */
.left-sidebar,
.right-sidebar {
  background: var(--bg-sidebar);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: var(--card-shadow);
}

.left-sidebar .sidebar-module,
.right-sidebar .sidebar-module {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.left-sidebar .sidebar-module:last-child,
.right-sidebar .sidebar-module:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.sidebar-heading {
  font-size: 1rem;
  font-weight: 700;
  color: #333;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-heading.header-highlight {
  color: var(--primary-color);
  border-bottom: 2px solid var(--primary-color);
  padding-bottom: 0.5rem;
}

/* Share/Recommendation Lists */
.share-list,
.rec-list,
.latest-posts-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.share-item,
.rec-item,
.latest-post-item {
  margin-bottom: 0.5rem;
}

.share-link,
.rec-link {
  color: #333;
  text-decoration: none;
  display: flex;
  align-items: center;
  padding: 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
}

.share-link:hover,
.rec-link:hover {
  background-color: var(--bg-body);
  color: var(--primary-color);
}

.share-link i,
.rec-link i {
  margin-right: 0.5rem;
  width: 20px;
  text-align: center;
}

/* Latest Posts Styling (Right Sidebar) */
.latest-post-item {
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.latest-post-item:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.lp-date {
  font-size: 0.75rem;
  color: var(--secondary-color);
  font-weight: 500;
}

.lp-title {
  font-size: 0.95rem;
  margin: 0.25rem 0 0.5rem 0;
  font-weight: 600;
}

.lp-title a {
  color: #333;
  text-decoration: none;
  transition: color 0.2s;
}

.lp-title a:hover {
  color: var(--primary-color);
}

.lp-excerpt {
  font-size: 0.85rem;
  color: #666;
  line-height: 1.4;
}

/* =====================================================================
   RESPONSIVE DESIGN - Mobile & Tablet
   ===================================================================== */

/* Tablet (below 1024px) - 2 columns: Content + Right Sidebar */
@media (max-width: 1024px) {
  .post-grid-container {
    grid-template-columns: 70% 30%;
    gap: 1rem;
  }

  /* Hide left sidebar on tablets */
  .post-grid-sidebar-left {
    display: none;
  }

  .post-grid-article {
    grid-column: 1;
  }

  .post-grid-sidebar-right {
    grid-column: 2;
  }
}

/* Mobile (below 768px) - Single column, stack everything */
@media (max-width: 768px) {
  .post-grid-container {
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 0.5rem;
  }

  /* Hide both sidebars on mobile for clean reading experience */
  .post-grid-sidebar-left,
  .post-grid-sidebar-right {
    display: none;
  }

  .post-grid-article {
    grid-column: 1;
  }
}

/* Alternative: Show sidebars stacked below content on mobile */
@media (max-width: 768px) {
  /* Uncomment below if you want sidebars to appear below content on mobile
  .post-grid-sidebar-left,
  .post-grid-sidebar-right {
    display: block;
    position: relative;
    top: auto;
    max-height: none;
  }
  */
}