/* css/styles.css */
/* ==================== 1. DESIGN SYSTEM & VARIABLES ==================== */

:root {
  /* HSL Color Palette - Premium & Elegant Slate Theme */
  --primary-hue: 220;
  --accent-hue: 142; /* Emerald Green */
  
  --primary: hsl(var(--primary-hue), 85%, 57%);     /* #2563eb (Royal Blue) */
  --primary-hover: hsl(var(--primary-hue), 85%, 47%);
  --primary-light: rgba(37, 99, 235, 0.1);
  
  --accent: rgb(16, 185, 129);                     /* #10b981 (Emerald) */
  --accent-hover: rgb(5, 150, 105);
  
  /* Trạng thái và các nút màu sắc khác */
  --rose: hsl(342, 75%, 50%);                       /* Reset button */
  --rose-hover: hsl(342, 75%, 40%);
  --info: hsl(190, 80%, 45%);                       /* Print button */
  --info-hover: hsl(190, 80%, 35%);
  --warning: hsl(35, 90%, 55%);                     /* Orange/Yellow */
  
  /* Font Families */
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-title: 'Outfit', 'Inter', system-ui, sans-serif;
}

/* Light Theme Variables */
body.theme-light {
  --bg-app: #f8fafc;
  --bg-sidebar: #0f172a; /* Sidebar luôn giữ màu tối lịch lãm */
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-input: #ffffff;
  
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --text-white: #ffffff;
  
  --border-color: rgba(226, 232, 240, 0.8);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.06), 0 4px 6px -2px rgba(15, 23, 42, 0.04);
  --glass-effect: backdrop-filter: blur(10px);
  --header-bg: rgba(248, 250, 252, 0.8);
  
  --table-header-bg: #f1f5f9;
  --table-row-hover: #f8fafc;
  --table-stripe: #f8fafc;
}

/* Dark Theme Variables */
body.theme-dark {
  --bg-app: #090d16;
  --bg-sidebar: #05080e;
  --bg-card: rgba(15, 23, 42, 0.85);
  --bg-input: #1e293b;
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --text-white: #ffffff;
  
  --border-color: rgba(51, 65, 85, 0.5);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  --glass-effect: backdrop-filter: blur(12px);
  --header-bg: rgba(9, 13, 22, 0.8);
  
  --table-header-bg: #1e293b;
  --table-row-hover: rgba(30, 41, 59, 0.6);
  --table-stripe: rgba(30, 41, 59, 0.3);
}

/* ==================== 2. GLOBAL RESET & BASE ==================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-title);
  font-weight: 600;
}

a {
  color: var(--primary);
  text-decoration: none;
}

/* ==================== 3. APP LAYOUT STRUCTURE ==================== */

.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* Sidebar bên trái (PC) */
.app-sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  color: var(--text-white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-brand {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: white;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.brand-info h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand-info span {
  font-size: 11px;
  color: var(--text-light);
  text-transform: uppercase;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.sidebar-nav {
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 500;
  font-size: 14px;
  transition: all 0.2s ease;
}

.nav-item i {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-white);
}

.nav-item.active {
  background-color: var(--primary);
  color: var(--text-white);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.app-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-indicator.online {
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.status-indicator.offline {
  background-color: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}

/* Khung nội dung chính */
.app-content {
  flex: 1;
  margin-left: 260px; /* Nhường chỗ cho sidebar */
  padding: 24px 32px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Bottom Navigation (Điện thoại) */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background-color: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  z-index: 99;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.05);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  flex: 1;
  padding: 8px 0;
}

.mobile-nav-item i {
  font-size: 18px;
  transition: transform 0.2s;
}

.mobile-nav-item.active {
  color: var(--primary);
}

.mobile-nav-item.active i {
  transform: translateY(-2px);
}

/* ==================== 4. HEADER COMPONENTS ==================== */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background-color: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.main-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.5px;
}

.subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-install {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(16, 185, 129, 0.15);
  animation: pulse-green 2s infinite;
}

.btn-theme-toggle {
  background: var(--primary-light);
  color: var(--primary);
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
}

.btn-theme-toggle:hover {
  background-color: var(--primary);
  color: white;
}

/* ==================== 5. COMMON UI - CARD ==================== */

.card {
  background-color: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.card-header-gradient {
  padding: 14px 20px;
  background: linear-gradient(90deg, var(--primary-light), transparent);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-header-gradient i {
  color: var(--primary);
  font-size: 16px;
}

.card-header-gradient h3 {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-main);
}

.card-body {
  padding: 20px;
}

/* ==================== 6. BỘ LỌC & TÌM KIẾM (FILTERS) ==================== */

.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Dropdown styling */
.select-wrapper {
  position: relative;
}

.select-wrapper::after {
  content: '\f107';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 12px;
}

select {
  width: 100%;
  padding: 10px 32px 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 13px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  outline: none;
}

select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
}

/* ==================== 7. BUTTON SYSTEM ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2);
}

.btn-secondary {
  background-color: var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background-color: rgba(148, 163, 184, 0.2);
}

.btn-reset {
  background-color: var(--rose);
  color: white;
}

.btn-reset:hover {
  background-color: var(--rose-hover);
  box-shadow: 0 4px 10px rgba(244, 63, 94, 0.2);
}

.btn-export {
  background-color: var(--accent);
  color: white;
}

.btn-export:hover {
  background-color: var(--accent-hover);
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.2);
}

.btn-info {
  background-color: var(--info);
  color: white;
}

.btn-info:hover {
  background-color: var(--info-hover);
  box-shadow: 0 4px 10px rgba(6, 182, 212, 0.2);
}

/* ==================== 8. ACTION BAR & SEARCH ==================== */

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.action-left {
  display: flex;
  gap: 10px;
}

.search-box {
  position: relative;
  width: 320px;
}

.search-box i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
}

.search-box input {
  width: 100%;
  padding: 10px 16px 10px 38px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  color: var(--text-main);
  font-size: 13px;
  outline: none;
}

.search-box input:focus {
  border-color: var(--primary);
  background-color: var(--bg-input);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* ==================== 9. DATA TABLE (PC VIEW) ==================== */

.data-card {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status-badge {
  background-color: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(37, 99, 235, 0.15);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th {
  background-color: var(--table-header-bg);
  color: var(--text-muted);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tbody tr {
  background-color: var(--bg-card);
}

.data-table tbody tr:nth-child(even) {
  background-color: var(--table-stripe);
}

.data-table tbody tr:hover {
  background-color: var(--table-row-hover);
}

/* Kiểu cột đặc biệt */
.td-doc-type {
  font-weight: 600;
}

.td-doc-number {
  font-family: monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background-color: var(--primary-light);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
}

.td-doc-content {
  max-width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.td-doc-note {
  color: var(--text-muted);
  font-style: italic;
}

/* Nút tệp đính kèm trong bảng */
.btn-table-file {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background-color: var(--primary-light);
  color: var(--primary);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-table-file:hover {
  background-color: var(--primary);
  color: white;
}

.btn-table-file.no-file {
  background-color: rgba(148, 163, 184, 0.08);
  color: var(--text-light);
  cursor: not-allowed;
}

/* Nút sửa/xóa trong bảng */
.table-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.btn-action {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
}

.btn-action.btn-edit {
  background-color: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
}

.btn-action.btn-edit:hover {
  background-color: #3b82f6;
  color: white;
}

.btn-action.btn-delete {
  background-color: rgba(244, 63, 94, 0.1);
  color: var(--rose);
}

.btn-action.btn-delete:hover {
  background-color: var(--rose);
  color: white;
}

/* ==================== 10. MOBILE CARD LIST (MOBILE VIEW) ==================== */

.mobile-card-grid {
  display: none;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 16px;
}

.mobile-doc-card {
  background-color: var(--bg-card);
  border-radius: 10px;
  border: 1px solid var(--border-color);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

.card-mobile-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 8px;
}

.card-mobile-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
}

.card-mobile-num {
  font-family: monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
}

.card-mobile-content {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  word-break: break-word;
}

.card-mobile-details {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.detail-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.detail-item i {
  color: var(--primary);
  width: 14px;
}

.card-mobile-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px dashed var(--border-color);
  padding-top: 10px;
  margin-top: 4px;
}

.card-mobile-note {
  font-size: 11px;
  font-style: italic;
  color: var(--text-light);
}

.card-mobile-actions {
  display: flex;
  gap: 8px;
}

/* ==================== 11. MODAL DIALOG COMPONENT ==================== */

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.active {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal-dialog {
  width: 100%;
  max-width: 600px;
  background-color: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  animation: scaleUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-dialog.modal-lg {
  max-width: 800px;
}

.modal-content {
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--table-header-bg);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  max-height: 75vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* ==================== 12. CUSTOM FORM CONTROLS ==================== */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-group label.required::after {
  content: ' *';
  color: var(--rose);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

input[type="text"], input[type="date"], textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 13px;
  outline: none;
}

input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

/* Ô chọn nhập văn bản có thể chỉnh sửa tự do (Select & Editable Textbox) */
.select-editable-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Vùng Kéo thả tệp tin đính kèm (Drag and Drop Upload Zone) */
.drag-drop-area {
  border: 2px dashed var(--primary);
  background-color: var(--primary-light);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.drag-drop-area.dragover {
  background-color: rgba(37, 99, 235, 0.15);
  transform: scale(1.02);
}

.drag-drop-area i {
  font-size: 32px;
  color: var(--primary);
  margin-bottom: 10px;
}

.drag-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
}

.drag-text span {
  color: var(--primary);
  text-decoration: underline;
  font-weight: 600;
}

.file-limits {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  margin-top: 4px;
}

/* Khung hiển thị tệp tin đã chọn */
.selected-file-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: var(--bg-input);
  margin-top: 10px;
}

.file-icon-box {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background-color: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.selected-file-details {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.selected-file-details .file-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  max-width: 350px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-file-details .file-size {
  font-size: 10px;
  color: var(--text-light);
}

.btn-remove-file {
  background: none;
  border: none;
  color: var(--rose);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
}

/* ==================== 13. DOCUMENT VIEWER IN-APP ==================== */

.doc-viewer-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.doc-meta-panel {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 14px;
  background-color: var(--table-header-bg);
  border-radius: 8px;
  font-size: 13px;
}

.meta-row {
  display: flex;
  gap: 8px;
}

.meta-row.full-width {
  grid-column: span 2;
  flex-direction: column;
  gap: 4px;
}

.meta-label {
  font-weight: 600;
  color: var(--text-muted);
}

.meta-val {
  color: var(--text-main);
}

.meta-val.content-text {
  background-color: var(--bg-input);
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.viewer-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.viewer-container h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  border-left: 3px solid var(--primary);
  padding-left: 8px;
}

.viewer-placeholder {
  height: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  color: var(--text-muted);
}

.viewer-placeholder i {
  font-size: 48px;
  color: var(--text-light);
}

/* ==================== 14. TAB SYSTEM & STATS ==================== */

.tab-pane {
  display: none;
  flex-direction: column;
  gap: 24px;
}

.tab-pane.active {
  display: flex;
}

/* Dashboard Thống kê */
.stats-overview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-box {
  border-radius: 10px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  color: white;
}

.stat-box.blue {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
}

.stat-box.purple {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
}

.stat-box.green {
  background: linear-gradient(135deg, #10b981, #047857);
}

.stat-box i {
  font-size: 32px;
  opacity: 0.8;
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-number {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.stat-label {
  font-size: 12px;
  opacity: 0.8;
}

.stats-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.chart-card {
  background-color: var(--bg-input);
  border-radius: 8px;
  padding: 16px;
  border: 1px solid var(--border-color);
}

.chart-card h4 {
  font-size: 13px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
  color: var(--primary);
  text-transform: uppercase;
}

.stats-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}

.stats-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stats-item-name {
  font-weight: 500;
}

.stats-item-bar-wrapper {
  flex: 1;
  margin: 0 16px;
  height: 8px;
  background-color: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
}

.stats-item-bar {
  height: 100%;
  background-color: var(--primary);
  border-radius: 4px;
}

.stats-item-count {
  font-weight: 600;
  color: var(--primary);
  background-color: var(--primary-light);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Hướng dẫn PWA */
.tutorial-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.tutorial-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tutorial-section h4 {
  font-size: 14px;
  color: var(--primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
}

.device-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.device-tab {
  padding: 8px 14px;
  border-radius: 6px;
  background-color: var(--table-header-bg);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.device-tab.active {
  background-color: var(--primary);
  color: white;
}

.tutor-step {
  display: none;
  background-color: var(--table-stripe);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
}

.tutor-step.active {
  display: block;
}

.tutor-step p {
  margin-bottom: 6px;
}

/* ==================== 15. KEYFRAME ANIMATIONS ==================== */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleUp {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes pulse-green {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  70% { transform: scale(1.02); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* ==================== 16. RESPONSIVE DESIGN (MEDIA QUERIES) ==================== */

/* Tối ưu hóa iPad / Tablet và Mobile rộng (Dưới 992px) */
@media (max-width: 991px) {
  .app-sidebar {
    display: none; /* Ẩn sidebar trên điện thoại */
  }

  .app-content {
    margin-left: 0; /* Nội dung chính phủ kín màn hình */
    padding: 16px 16px 80px 16px; /* Cách đáy 80px để nhường chỗ cho Bottom Navigation */
    gap: 16px;
  }
  
  .app-header {
    padding: 10px 16px;
  }
  
  .main-title {
    font-size: 14px;
  }
  
  .subtitle {
    font-size: 10px;
  }

  /* Ẩn bảng dữ liệu cồng kềnh */
  .table-responsive {
    display: none;
  }
  
  /* Hiện danh sách Card di động */
  .mobile-card-grid {
    display: grid;
  }
  
  .mobile-bottom-nav {
    display: flex; /* Hiện bottom menu */
  }
  
  .stats-overview-grid {
    grid-template-columns: 1fr;
  }
  
  .stats-detail-grid {
    grid-template-columns: 1fr;
  }

  .filter-grid {
    grid-template-columns: repeat(2, 1fr); /* Chia 2 cột bộ lọc trên di động */
  }
  
  .action-bar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .action-left {
    justify-content: space-between;
  }
  
  .search-box {
    width: 100%; /* Hộp tìm kiếm co giãn 100% */
  }

  .modal-dialog {
    max-height: 90vh;
  }
  
  .form-row {
    grid-template-columns: 1fr; /* Form đổi sang 1 dòng */
    gap: 0;
  }
  
  .doc-meta-panel {
    grid-template-columns: 1fr;
  }
  
  .meta-row.full-width {
    grid-column: span 1;
  }
}

/* Tối ưu hóa điện thoại nhỏ (Dưới 576px) */
@media (max-width: 575px) {
  .filter-grid {
    grid-template-columns: 1fr; /* Bộ lọc đổi sang 1 dòng */
  }
  
  .action-left {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  
  .btn-install span {
    display: none; /* Chỉ hiện icon tải app trên điện thoại quá nhỏ */
  }
  
  .btn-install {
    padding: 8px 12px;
  }
}

/* ==================== 17. CHẾ ĐỘ IN ẤN CHUYÊN NGHIỆP (CSS PRINT) ==================== */

@media print {
  /* Khai báo A4 */
  @page {
    size: A4 landscape; /* In ngang để vừa vặn bảng */
    margin: 1.5cm;
  }
  
  /* Ẩn toàn bộ các phần điều khiển và đồ họa thừa */
  .no-print,
  .app-sidebar,
  .app-header,
  .filter-card,
  .action-bar,
  .card-header,
  .mobile-bottom-nav,
  .mobile-card-grid,
  th.no-print,
  td.no-print {
    display: none !important;
  }
  
  /* Tối ưu hóa khung chứa chính */
  body, .app-container, .app-content {
    background-color: white !important;
    color: black !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    display: block !important;
  }
  
  /* Tiêu đề trang in trang trọng */
  .app-content::before {
    content: "BÁO CÁO HỆ THỐNG QUẢN LÝ VĂN BẢN PHÁP LÝ & DỊCH VỤ CÔNG";
    display: block;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 24px;
    color: black;
    font-family: 'Inter', sans-serif;
  }

  /* Định dạng lại bảng in */
  .card.data-card {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    width: 100% !important;
  }
  
  .table-responsive {
    display: block !important;
    width: 100% !important;
    overflow: visible !important;
  }

  .data-table {
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: 12px !important;
  }

  .data-table th, .data-table td {
    border: 1px solid #000000 !important;
    padding: 6px 8px !important;
    color: #000000 !important;
    background: transparent !important;
    white-space: normal !important; /* Cho phép text tự động xuống dòng trong ô in */
  }

  .data-table th {
    font-weight: 700 !important;
    text-transform: uppercase !important;
    font-size: 11px !important;
  }
  
  .td-doc-number {
    background: transparent !important;
    color: black !important;
    font-weight: 700 !important;
    padding: 0 !important;
    border-radius: 0 !important;
  }
  
  .td-doc-content {
    max-width: none !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }
}

/* ==================== 18. LOGIN SYSTEM & ROLE ACCESS ==================== */

.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: var(--bg-app);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease, visibility 0.5s;
}

.login-overlay:not(.active) {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  padding: 40px 30px;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  text-align: center;
  margin: 20px;
}

.login-header {
  margin-bottom: 30px;
}

.login-logo {
  width: 64px;
  height: 64px;
  font-size: 28px;
  margin: 0 auto 16px;
}

.login-header h2 {
  font-size: 22px;
  color: var(--primary);
  margin-bottom: 4px;
}

.login-header p {
  font-size: 13px;
  color: var(--text-muted);
}

.login-body {
  text-align: left;
}

.input-with-icon {
  position: relative;
}

.input-with-icon i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.input-with-icon input {
  padding-left: 40px;
}

.btn-login {
  width: 100%;
  padding: 12px;
  justify-content: center;
  font-size: 14px;
  margin-top: 10px;
}

/* Role Based Access Control */
/* Ẩn các thao tác Admin nếu không phải admin (cấp 2) */
body.role-user .admin-only {
  display: none !important;
}

/* Ẩn nội dung chính khi chưa login */
body:not(.logged-in) .app-container,
body:not(.logged-in) .mobile-bottom-nav {
  display: none !important;
}

/* ==================== 19. MULTI-PROJECT & ADVANCED RBAC ==================== */
body.role-user .admin-only {
  display: none !important;
}
body.role-user .manager-up {
  display: none !important;
}
body.role-manager .admin-only {
  display: none !important;
}

/* Ẩn option admin trong select role nếu không phải admin */
body:not(.role-admin) .admin-only-option {
  display: none !important;
}

/* Project Selector Styles */
.project-selector-wrapper {
  margin-left: 2rem;
  display: inline-flex;
  align-items: center;
}

.project-selector {
  width: auto;
  min-width: 250px;
  background-color: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.project-selector:focus {
  background-color: var(--bg-card);
  color: var(--text-color);
}

.theme-light .project-selector option {
  color: #333;
}
.theme-dark .project-selector option {
  color: #fff;
  background: var(--bg-card);
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 5px 0;
  font-weight: normal;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

@media (max-width: 768px) {
  .project-selector-wrapper {
    margin-left: 0;
    margin-top: 10px;
    width: 100%;
  }
  .header-left {
    flex-direction: column;
    align-items: flex-start;
  }
}

