/* static/css/style.css — Layout System
   Phụ thuộc: design-system.css phải được load trước
*/

/* Ghi đè Bootstrap text-muted để đủ tương phản trên mobile */
.text-muted { color: var(--color-text-muted) !important; }
.small, small { color: inherit; }
@media (max-width: 768px) {
  body { color: var(--color-text-primary); }
  .text-muted { color: var(--color-text-secondary) !important; }
  td, th, label, .form-label, .form-text { color: var(--color-text-primary); }
}

/* ═══════════════════════════════════════════════════════
   1. SIDEBAR
═══════════════════════════════════════════════════════ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--color-primary);
  display: flex; flex-direction: column;
  z-index: var(--z-sidebar);
  overflow-y: auto;
  overflow-x: hidden;
  transition: left var(--transition-base), width var(--transition-base);
}

/* Thanh cuộn sidebar mỏng */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 2px; }

/* Brand / Logo */
.sidebar-brand {
  display: flex; flex-direction: column; align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid rgba(255,255,255,.1);
  text-decoration: none; flex-shrink: 0; text-align: center;
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand-logo {
  width: 52px; height: 52px; flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,.3);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

/* Mobile: sidebar dạng ngang, logo nhỏ hơn */
@media (max-width: 992px) {
  .sidebar-brand {
    flex-direction: row;
    text-align: left;
    padding: var(--space-2) var(--space-4);
    gap: var(--space-3);
  }
  .sidebar-brand-logo {
    width: 32px; height: 32px;
  }
}
/* Điện thoại nhỏ */
@media (max-width: 576px) {
  .sidebar-brand-logo {
    width: 24px; height: 24px;
  }
}
.sidebar-brand-icon {
  width: 36px; height: 36px; flex-shrink: 0;
  background: var(--color-accent);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: #fff;
}
.sidebar-brand-text {
  color: #fff; font-weight: var(--font-weight-bold);
  font-size: var(--font-size-xs); line-height: 1.3;
}
.sidebar-brand-sub { color: rgba(255,255,255,.5); font-size: 0.68rem; }

/* Navigation sections */
.sidebar-section {
  padding: var(--space-3) var(--space-3) var(--space-2);
  flex: 1;
}
.sidebar-section-label {
  padding: var(--space-4) var(--space-3) var(--space-1);
  color: rgba(255,255,255,.35);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: var(--font-weight-semibold);
}

/* Nhóm có thể thu gọn */
.sidebar-group-toggle {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-3) var(--space-1);
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,.35);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: var(--font-weight-semibold);
}
.sidebar-group-toggle:hover { color: rgba(255,255,255,.6); }
.sidebar-chevron {
  font-size: 10px;
  transition: transform .25s ease;
}
.sidebar-group-toggle.open .sidebar-chevron { transform: rotate(180deg); }

.sidebar-group {
  overflow: hidden;
  max-height: 0;
  transition: max-height .3s ease;
}
.sidebar-group.open { max-height: 400px; }

/* Nav links */
.sidebar-link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  color: rgba(255,255,255,.7);
  border-radius: var(--radius-md);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  transition: all var(--transition-fast);
  margin-bottom: 2px;
  white-space: nowrap;
}
.sidebar-link:hover {
  background: rgba(255,255,255,.1);
  color: #fff; text-decoration: none;
}
.sidebar-link.active {
  background: rgba(255,255,255,.18);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--color-accent);
}
.sidebar-link-icon {
  width: 20px; text-align: center; flex-shrink: 0;
  font-size: var(--font-size-base);
}
.sidebar-badge {
  margin-left: auto;
  background: var(--color-accent);
  color: #fff;
  font-size: 10px;
  font-weight: var(--font-weight-bold);
  padding: 1px 6px;
  border-radius: var(--radius-full);
}

/* User info bottom */
.sidebar-user {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; gap: var(--space-3);
  flex-shrink: 0;
}
.sidebar-user-avatar {
  width: 36px; height: 36px; border-radius: var(--radius-full);
  background: linear-gradient(135deg, #f59e0b, #e8a020);
  color: #1a3a5c;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--font-size-sm); font-weight: var(--font-weight-bold);
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.25);
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  letter-spacing: 0;
}
.sidebar-user-name  { color: #fff; font-size: var(--font-size-sm); font-weight: var(--font-weight-medium); }
.sidebar-user-role  { color: rgba(255,255,255,.5); font-size: var(--font-size-xs); }
.sidebar-user-logout {
  margin-left: auto; color: rgba(255,255,255,.5);
  text-decoration: none; font-size: var(--font-size-lg);
  transition: color var(--transition-fast);
}
.sidebar-user-logout:hover { color: #fff; }
.sidebar-version {
  text-align: center;
  font-size: 10px;
  color: rgba(255,255,255,.2);
  padding: var(--space-1) 0 var(--space-2);
  letter-spacing: .05em;
}

/* Desktop toggle — ẩn sidebar (giữ nguyên UX hiện tại) */
.sidebar.hidden { left: calc(-1 * var(--sidebar-width)); }

/* ═══════════════════════════════════════════════════════
   2. TOPBAR
═══════════════════════════════════════════════════════ */
.topbar {
  position: sticky; top: 0;
  height: var(--topbar-height);
  background: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  z-index: var(--z-topbar);
  margin-bottom: var(--space-6);
  box-shadow: var(--shadow-xs);
}
.topbar-left {
  display: flex; align-items: center; gap: var(--space-3);
  flex: 1;
}
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }

/* Nút toggle sidebar */
.btn-toggle-sidebar {
  background: none; border: none;
  color: var(--color-text-secondary);
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer; font-size: 1.2rem;
  transition: background var(--transition-fast), color var(--transition-fast);
  display: flex; align-items: center;
}
.btn-toggle-sidebar:hover {
  background: var(--color-bg-page);
  color: var(--color-text-primary);
}

/* ═══════════════════════════════════════════════════════
   3. MAIN LAYOUT
═══════════════════════════════════════════════════════ */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex; flex-direction: column;
  transition: margin-left var(--transition-base);
}
.main-content.expanded { margin-left: 0; }

.page-body {
  flex: 1;
  padding: 0 var(--space-6) var(--space-8);
  max-width: var(--content-max-width);
  width: 100%;
}

/* Page header */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.page-title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  margin: 0 0 var(--space-1);
  line-height: var(--line-height-tight);
}
.page-subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin: 0;
}
.page-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; }

/* ═══════════════════════════════════════════════════════
   4. GRID SYSTEM
═══════════════════════════════════════════════════════ */
.grid { display: grid; gap: var(--space-6); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-stat { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* ═══════════════════════════════════════════════════════
   5. RESPONSIVE — Mobile & Tablet
═══════════════════════════════════════════════════════ */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 992px) {
  .sidebar {
    transform: translateX(-100%);
    left: 0;
    z-index: 1000;
  }
  .sidebar.hidden { transform: translateX(-100%); left: 0; }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }
  .main-content { margin-left: 0; }
  .main-content.expanded { margin-left: 0; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar-toggle-btn { display: flex !important; }
}

@media (max-width: 768px) {
  .page-body { padding: 0 var(--space-4) var(--space-6); }
  .topbar    { padding: 0 var(--space-4); }
  .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .grid-stat { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; align-items: stretch; }
  .table-responsive-gt { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .col-hidden-mobile { display: none; }
}

@media (max-width: 480px) {
  .grid-stat { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════
   6. OVERLAY (khi sidebar mở trên mobile)
═══════════════════════════════════════════════════════ */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 999;
  opacity: 0; transition: opacity var(--transition-base);
}
.sidebar-overlay.visible { display: block; opacity: 1; }

/* ═══════════════════════════════════════════════════════
   7. ANIMATIONS
═══════════════════════════════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.animate-fade-in { animation: fadeIn var(--transition-base) both; }

/* Stagger children */
.stagger > * { animation: fadeIn var(--transition-base) both; }
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 60ms; }
.stagger > *:nth-child(3) { animation-delay: 120ms; }
.stagger > *:nth-child(4) { animation-delay: 180ms; }

/* ═══════════════════════════════════════════════════════
   8. LOADING / SKELETON
═══════════════════════════════════════════════════════ */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-loading {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ═══════════════════════════════════════════════════════
   9. PRINT
═══════════════════════════════════════════════════════ */
@media print {
  .sidebar, .topbar, .page-actions,
  .btn-gt, .btn-toggle-sidebar { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .page-body { padding: 0 !important; }
  .card-gt { box-shadow: none !important; border: 1px solid #ccc; }
}
