:root {
    --primary: #0066cc;
    --primary-hover: #005bb5;
    --bg-color: #f5f5f7;
    --card-bg: #ffffff;
    --text-main: #1d1d1f;
    --text-muted: #86868b;
    --border-color: #d2d2d7;
    --radius: 12px;
    --shadow: 0 4px 6px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', -apple-system, sans-serif; }
body { background-color: var(--bg-color); color: var(--text-main); line-height: 1.5; font-size: 14px;}

.app-container { max-width: 1200px; margin: 0 auto; padding: 20px; }

/* ==========================================
   GIAO DIỆN ĐĂNG NHẬP (MỚI)
========================================== */
.login-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); backdrop-filter: blur(5px); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.login-box { background: #fff; padding: 40px; border-radius: 16px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); width: 100%; max-width: 400px; text-align: center; }
.login-icon { font-size: 40px; margin-bottom: 10px; }
.login-box h2 { margin-bottom: 8px; color: #111; }
.login-box p { color: var(--text-muted); margin-bottom: 24px; }
.login-box input { width: 100%; padding: 14px; border: 1px solid var(--border-color); border-radius: 8px; font-size: 16px; margin-bottom: 16px; outline: none; text-align: center; letter-spacing: 2px;}
.login-box input:focus { border-color: var(--primary); }
.btn-login { width: 100%; padding: 14px; font-size: 16px; }
.login-error { color: #ff3b30 !important; margin-top: 12px; margin-bottom: 0 !important; font-weight: 500; display: none; }

/* HEADER & SEARCH */
.search-section { background: var(--card-bg); padding: 24px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 24px; }
h1 { font-size: 24px; font-weight: 600; text-align: center; margin-bottom: 24px; }
.home-link { text-decoration: none; color: var(--text-main); transition: color 0.2s;}
.home-link:hover { color: var(--primary); }

.search-bar { display: flex; gap: 12px; margin-bottom: 20px; }
.search-bar input { flex: 1; padding: 12px 16px; border: 1px solid var(--border-color); border-radius: 8px; font-size: 16px; outline: none; transition: border 0.2s;}
.search-bar input:focus { border-color: var(--primary); }
.btn-group { display: flex; gap: 12px; }
button { padding: 12px 24px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; transition: 0.2s; white-space: nowrap;}
button:hover { background: var(--primary-hover); }
.btn-secondary { background: #e5e5ea; color: var(--text-main); }
.btn-secondary:hover { background: #d1d1d6; }
.btn-text { background: transparent; color: #ff3b30; padding: 6px 12px; font-size: 13px; }
.btn-text:hover { background: #ffeceb; }

/* FILTERS */
.filter-bar { display: flex; flex-wrap: wrap; gap: 24px; justify-content: space-between; background: #fafafa; padding: 16px; border-radius: 8px; border: 1px solid var(--border-color);}
.filter-group { display: flex; align-items: center; gap: 12px; font-weight: 500;}
.radio-group, .date-group { display: flex; align-items: center; gap: 12px; font-weight: 400; flex-wrap: wrap;}
input[type="date"] { padding: 8px; border: 1px solid var(--border-color); border-radius: 6px; outline: none; }

/* STATES */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); font-size: 16px; }
.result-header { margin-bottom: 16px; border-bottom: 1px solid var(--border-color); padding-bottom: 12px; }
.history-header { display: flex; justify-content: space-between; align-items: center; }
.history-header h3 { color: #d9534f; }

/* CARD GIAO DIỆN PHẲNG */
.card-grid { display: grid; gap: 24px; }
.doc-card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border-left: 6px solid #ccc;}
.doc-card.den { border-left-color: #ff3b30; } 
.doc-card.di { border-left-color: #34c759; }  

.card-header { padding: 16px; border-bottom: 1px solid var(--border-color); background: #fbfbfd; display: flex; flex-direction: column; gap: 10px; align-items: flex-start;}
.doc-title { font-size: 16px; font-weight: 600; color: var(--primary); line-height: 1.4; width: 100%;}
.doc-type-badge { padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; order: -1; }
.doc-type-badge.den { background: #ffeceb; color: #ff3b30; }
.doc-type-badge.di { background: #e8f8ec; color: #34c759; }

/* YÊU CẦU 2: NÚT MỞ RỘNG TRONG LỊCH SỬ */
.toggle-expand-btn { width: 100%; background: #f0f0f5; color: #555; border-radius: 0; padding: 10px; text-align: center; font-size: 13px; border-bottom: 1px solid var(--border-color); }
.toggle-expand-btn:hover { background: #e2e2e8; }

.card-body { padding: 16px; }
.grid-info { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 24px;}
.info-item { background: #f5f5f7; padding: 12px; border-radius: 8px; font-size: 13px;}
.info-item strong { display: block; color: var(--text-muted); font-size: 11px; text-transform: uppercase; margin-bottom: 4px;}

/* TABLES */
.section-title { font-size: 14px; font-weight: 600; color: #856404; margin-bottom: 8px; text-transform: uppercase;}
.action-box { background: #fffcf0; border: 1px solid #f2e3a1; padding: 16px; border-radius: 8px; margin-bottom: 20px; overflow-x: auto;}
.action-box.dept { background: #f0f7ff; border: 1px solid #cce3ff; }
.action-box.dept .section-title { color: #004085; }

.modern-table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; background: #fff; border-radius: 6px; overflow: hidden; min-width: 600px;}
.modern-table th { background: rgba(0,0,0,0.03); color: #333; font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border-color); }
.modern-table td { padding: 10px 12px; border-bottom: 1px solid #eee; vertical-align: top; color: #444;}
.modern-table tr:last-child td { border-bottom: none; }

/* 4 COLUMNS GRID */
details { background: #fafafa; border: 1px solid var(--border-color); border-radius: 8px; margin-bottom: 16px; overflow: hidden; }
summary { padding: 14px 16px; font-weight: 600; cursor: pointer; user-select: none; outline: none; background: #f5f5f7;}
details div.content { padding: 20px; border-top: 1px solid var(--border-color); }

.meta-group-container { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.meta-group { background: #fff; border: 1px solid #eaeaea; border-radius: 8px; padding: 16px; }
.meta-group h4 { font-size: 13px; color: var(--primary); text-transform: uppercase; margin-bottom: 12px; border-bottom: 1px solid #eee; padding-bottom: 6px; }
.meta-row { display: flex; flex-direction: column; margin-bottom: 10px; font-size: 13px;}
.meta-row:last-child { margin-bottom: 0;}
.meta-row span.lbl { font-size: 11px; color: var(--text-muted); margin-bottom: 2px;}
.meta-row span.val { font-weight: 500; color: #222; word-break: break-word;}

.card-footer { 
    padding: 16px; 
    border-top: 1px solid var(--border-color); 
    background: #fbfbfd; 
    display: flex;
    flex-direction: column; /* Xếp các nút tải file theo chiều dọc */
    gap: 8px; /* Khoảng cách giữa các nút */
}
.download-btn { 
    display: inline-flex; 
    align-items: center; 
    gap: 8px; 
    padding: 10px 20px; 
    background: #e8f1fb; 
    color: var(--primary); 
    text-decoration: none; 
    border-radius: 20px; 
    font-weight: 600; 
    transition: 0.2s;
    width: fit-content; /* Nút chỉ dài bằng nội dung chữ */
}
.download-btn:hover { background: #d0e3f7; }

/* ==========================================
   TỐI ƯU GIAO DIỆN MOBILE
========================================== */
@media (max-width: 768px) {
    .app-container { padding: 10px; }
    h1 { font-size: 18px; }
    
    .search-bar { flex-direction: column; gap: 12px; }
    /* Ép 2 nút tìm kiếm và xóa bộ lọc nằm ngang trên mobile */
    .btn-group { display: flex; flex-direction: row; gap: 10px; width: 100%; }
    .btn-group button { flex: 1; }
    
    .filter-bar { flex-direction: column; align-items: stretch; gap: 16px; }
    .filter-group { flex-direction: column; align-items: flex-start; }
    .radio-group { width: 100%; justify-content: space-between; }
    
    .date-group { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center;}
    .date-group input { width: 100%; }
}