/* ---- BIẾN MÀU & CÀI ĐẶT CHUNG ---- */
:root {
  --primary-color: #007bff;
  --primary-hover: #0056b3;
  --bg-light: #f5f7fb;
  --bg-white: #ffffff;
  --text-dark: #333;
  --text-light: #667;
  --border-color: #e5e9f2;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --item-hover: #f0f2f5;
  --sidebar-bg: #ffffff;
}

/* === DARK MODE VARIABLES === */
body.dark-mode {
  --bg-light: #121212;
  --bg-white: #1e1e1e;
  --text-dark: #e0e0e0;
  --text-light: #a0a0a0;
  --border-color: #333;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --item-hover: #2c2c2c;
  --sidebar-bg: #1e1e1e;
}

/* Fix màu chữ trong Dark Mode cho các vùng đặc biệt */
body.dark-mode .sidebar { background: var(--sidebar-bg); }
body.dark-mode .upload-zone { background: #252525; border-color: #444; }
body.dark-mode .upload-zone.drag-over { background: #1a2634; border-color: var(--primary-color); }
body.dark-mode .search-box input { background: #252525; color: white; }
body.dark-mode .search-box input:focus { background: #2c2c2c; }
body.dark-mode .btn { background: #333; color: #ddd; }
body.dark-mode .btn:hover { background: #444; }
body.dark-mode .btn-primary { background: var(--primary-color); color: white; }
body.dark-mode .grid .item-preview { background: #252525; }
body.dark-mode .list .item-preview { background: #252525; }
body.dark-mode .list .item-preview .file-icon { color: #ccc; }
body.dark-mode .modal-content { background: #252525; color: #eee; }
body.dark-mode #renameExtension { background: #333; border-color: #444; }
body.dark-mode .rename-input-wrapper { border-color: #444; }
body.dark-mode input { background: #252525; color: white; }
body.dark-mode .dropdown-content { background-color: #252525; border: 1px solid #444; }
body.dark-mode .dropdown-content a { color: #ddd; }
body.dark-mode .dropdown-content a:hover { background-color: #333; }
body.dark-mode .context-menu { background: #252525; border-color: #444; color: #eee; }
body.dark-mode .context-menu .menu-item:hover { background: #333; }
body.dark-mode .doc-preview-container { background: #1e1e1e; color: #ddd; }


body {
  font-family: "Segoe UI", Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: var(--bg-light);
  color: var(--text-dark);
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}

/* ---- BỐ CỤC ỨNG DỤNG CHÍNH ---- */
.app-layout {
  display: flex;
  height: 100vh;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg-white);
  border-right: 1px solid var(--border-color);
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  z-index: 10;
  transition: background 0.3s;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--primary-color);
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}
.sidebar-header h2 { margin: 0; font-size: 20px; }
.sidebar-header .fa-cloud { font-size: 24px; }

/* Khu vực Kéo & Thả */
.upload-zone {
  border: 2px dashed var(--border-color);
  border-radius: 12px;
  padding: 25px;
  text-align: center;
  margin-top: 20px;
  background: #fafcff;
  transition: all 0.3s;
}
.upload-zone.drag-over {
  border-color: var(--primary-color);
  background: #f0f7ff;
}
.upload-zone-icon {
  font-size: 32px;
  color: var(--primary-color);
  margin-bottom: 10px;
}
.upload-zone input[type="file"] { display: none; }
.upload-zone label.btn { margin-top: 10px; display: inline-block; }

/* Khu vực File chờ */
.pending-uploads {
  padding: 15px 0;
  border-top: 1px solid var(--border-color);
  margin-top: 20px;
}
.pending-uploads h4 {
  margin: 0 0 10px 0;
  font-size: 16px;
}
.pending-list {
  max-height: 200px;
  overflow-y: auto;
  font-size: 14px;
}
.pending-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border-color); /* Sửa để ăn theo biến màu */
  word-break: break-all;
}
.pending-item:last-child { border-bottom: none; }
.pending-item span {
  flex: 1;
  padding-right: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pending-item button {
  padding: 2px 6px;
  font-size: 10px;
  background: #fbebee;
  color: #dc3545;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* Danh sách tải lên */
.upload-list {
  margin-top: 15px;
  overflow-y: auto;
  flex-grow: 0; 
  max-height: 25%; 
}
.upload-item { 
  margin-bottom: 12px; 
  font-size: 14px;
  word-break: break-all;
}
.progress-container { 
  width: 100%; background: var(--border-color); border-radius: 8px; 
  height: 18px; margin-top: 5px; overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0%; 
  background: linear-gradient(90deg, #4facfe, #00f2fe);
  border-radius: 8px; text-align: center; color: #fff; 
  font-size: 10px; line-height: 18px;
  transition: width 0.3s;
}

/* Thông số mạng */
.network-stats {
  border-top: 1px solid var(--border-color);
  padding-top: 15px;
  margin-top: auto; 
  flex-shrink: 0;
}
.network-stats h3 {
  margin: 0 0 15px 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  margin-bottom: 10px;
}
.status-item strong {
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-item span { color: var(--primary-color); font-weight: bold; }
.status-item .btn-small { padding: 2px 8px; font-size: 12px; }

/* ---- MAIN CONTENT ---- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Thanh công cụ */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 25px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.search-box {
  position: relative;
  width: 300px;
}
.search-box .fa-search {
  position: absolute;
  left: 12px;
  top: 11px;
  color: var(--text-light);
}
.search-box input {
  width: 100%;
  padding: 10px 10px 10px 35px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-light);
  transition: all 0.3s;
  color: var(--text-dark);
}
.search-box input:focus {
  background: var(--bg-white);
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
  outline: none;
}

.toolbar-actions { display: flex; gap: 8px; align-items: center; }
.view-toggle { display: flex; }
.view-toggle .btn {
  border-radius: 0;
  background: var(--bg-light);
  color: var(--text-light);
}
.view-toggle .btn:first-child { border-radius: 6px 0 0 6px; }
.view-toggle .btn:last-child { border-radius: 0 6px 6px 0; }
.view-toggle .btn.active {
  background: var(--primary-color);
  color: #fff;
}

/* DROPDOWN MENU (SẮP XẾP) */
.dropdown {
  position: relative;
  display: inline-block;
}
.dropdown-content {
  display: none;
  position: absolute;
  right: 0;
  background-color: var(--bg-white);
  min-width: 160px;
  box-shadow: var(--shadow-md);
  z-index: 100;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}
.dropdown-content a {
  color: var(--text-dark);
  padding: 10px 16px;
  text-decoration: none;
  display: block;
  font-size: 14px;
}
.dropdown-content a:hover {
  background-color: var(--item-hover);
}
.dropdown.show .dropdown-content {
  display: block;
}


/* Khu vực File */
#fileSection {
  flex: 1;
  overflow-y: auto;
  padding: 25px;
}
.day-group { margin-bottom: 30px; }
.day-title {
  font-weight: bold;
  font-size: 18px;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-dark);
}

/* GRID VIEW */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}
.grid .item {
  background: var(--bg-white);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
  border: 1px solid transparent; /* Chuẩn bị cho hover */
}
.grid .item:hover { 
  transform: translateY(-5px); 
  box-shadow: var(--shadow-md);
  border-color: var(--primary-color);
}
.grid .item-preview {
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f2f5;
  overflow: hidden;
}
.grid .item-preview img, 
.grid .item-preview video {
  width: 100%; height: 100%; object-fit: cover;
}
.grid .item-preview .file-icon {
  font-size: 60px;
  color: var(--text-light);
}
.grid .item-info {
  padding: 12px;
  text-align: center;
}
.grid .item-info .info-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dark);
  word-break: break-all;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Ẩn nút hành động trong Grid, sẽ dùng Context Menu */
.grid .actions { display: none; }


/* LIST VIEW */
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.list .item {
  display: flex;
  align-items: center;
  background: var(--bg-white);
  border-radius: 8px;
  padding: 12px 15px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
}
.list .item:hover {
  background: var(--item-hover);
  box-shadow: 0 2px 8px rgba(0,123,255,0.15);
}
.list .item-preview {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-light);
  border-radius: 6px;
  margin-right: 15px;
}
.list .item-preview img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 6px;
}
.list .item-preview .file-icon {
  font-size: 20px;
  color: var(--text-dark);
}

.list .item-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 0; 
}
.list .item-info .info-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-dark);
}
.list .file-meta {
  display: flex;
  flex-shrink: 0;
  color: var(--text-light);
  font-size: 14px;
  white-space: nowrap;
  margin-left: 20px;
  gap: 20px; 
}
.list .file-meta-ext { width: 80px; }
.list .file-meta-size { width: 120px; }
.list .file-meta-date { width: 150px; margin-left: 0; }
.list .file-meta strong { color: var(--text-dark); margin-right: 5px; }

/* Ẩn nút hành động trong List để dùng Context Menu (hoặc giữ lại nếu muốn) */
/* .list .actions { display: none; } */


/* ---- NÚT CHUNG ---- */
.btn {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  background: #e4e6eb;
  color: var(--text-dark);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none; 
}
.btn:hover { background: #d0d2d6; }

.btn-primary, .upload-btn, .share-btn {
  background: var(--primary-color);
  color: #fff;
}
.btn-primary:hover, .upload-btn:hover, .share-btn:hover {
  background: var(--primary-hover);
}
.actions .btn {
  padding: 4px 10px;
  font-size: 12px;
}

.delete-btn { background: #fbebee; color: #dc3545; }
.delete-btn:hover { background: #dc3545; color: #fff; }

.download-btn { background: #e6f7ee; color: #28a745; }
.download-btn:hover { background: #28a745; color: #fff; }

.rename-btn { background: #fff8e6; color: #ff9800; }
.rename-btn:hover { background: #ff9800; color: #fff; }

.share-btn { background: #e6f2ff; color: #007bff; }
.share-btn:hover { background: #007bff; color: #fff; }

/* ---- MODAL ĐỔI TÊN ---- */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
}
.modal-content {
  background: var(--bg-white);
  padding: 25px;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 450px;
}
.modal-content h4 {
  margin-top: 0;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dark);
}
.modal-content p { font-size: 14px; color: var(--text-light); }

.rename-input-wrapper {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  margin-top: 10px;
  overflow: hidden;
}
.rename-input-wrapper:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
}

.modal-content input {
  flex: 1;
  width: auto;
  padding: 10px;
  border: none;
  margin-top: 0;
  box-sizing: border-box;
  outline: none;
  color: var(--text-dark);
}
#renameExtension {
  padding: 10px;
  background: var(--bg-light);
  border-left: 1px solid var(--border-color);
  color: var(--text-light);
  font-size: 14px;
  white-space: nowrap;
}
.modal-actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---- FILTER GROUP ---- */
.filter-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.filter-btn {
  background: var(--bg-light);
  color: var(--text-light);
}
.filter-btn.active {
  background: var(--primary-color);
  color: #fff;
  font-weight: bold;
}

/* ---- LIGHTBOX ---- */
.lightbox-content {
  background: rgba(0,0,0,0.8);
  padding: 10px;
  width: 90vw;
  max-width: 1200px;
  height: 90vh;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
}
.lightbox-close {
  position: absolute;
  top: 10px;
  right: 25px;
  color: #fff;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  z-index: 1001;
}

#lightbox-media {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}

#lightbox-media img,
#lightbox-media video,
#lightbox-media iframe {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  border: none;
}

/* PREVIEW TEXT/DOC */
.lightbox-loading {
    color: white;
    font-size: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}
.doc-preview-container {
    width: 100%;
    height: 100%;
    background: var(--bg-white);
    color: var(--text-dark);
    border-radius: 8px;
    overflow-y: auto;
    padding: 30px;
    box-sizing: border-box;
    text-align: left;
    font-size: 15px;
}
.doc-preview-container pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: Consolas, "Courier New", monospace;
    font-size: 14px;
}

.item-preview { position: relative; }
.play-icon {
  position: absolute;
  font-size: 32px;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(0, 0, 0, 0.4);
  border-radius: 50%;
  padding: 12px 15px 12px 18px;
  pointer-events: none;
  transition: all 0.2s;
}
.item:hover .play-icon { transform: scale(1.1); }

/* FOOTER & BUTTONS */
.app-footer {
  flex-shrink: 0;
  padding: 15px 25px;
  background: var(--bg-white);
  border-top: 1px solid var(--border-color);
  text-align: center;
  font-size: 13px;
  color: var(--text-light);
}

.btn-stats-sidebar {
  padding: 2px 8px;
  font-size: 12px;
  background: #e6f7ee;
  color: #28a745;
}
.btn-stats-sidebar:hover {
  background: #28a745;
  color: #fff;
}
.btn-stats-sidebar .fa-solid {
  font-size: 11px;
  margin-right: 4px;
}

/* ==== TÍNH NĂNG MỚI ==== */

/* 1. TOAST NOTIFICATION */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  min-width: 250px;
  background: var(--bg-white);
  color: var(--text-dark);
  padding: 15px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideInLeft 0.3s ease;
  border-left: 4px solid #ccc;
  font-size: 14px;
}
.toast.success { border-left-color: #28a745; }
.toast.success i { color: #28a745; }
.toast.error { border-left-color: #dc3545; }
.toast.error i { color: #dc3545; }
.toast.info { border-left-color: #007bff; }
.toast.info i { color: #007bff; }

@keyframes slideInLeft {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
  to { opacity: 0; transform: translateY(-20px); }
}

/* 2. CONTEXT MENU */
.context-menu {
  position: absolute;
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  border-radius: 6px;
  width: 180px;
  z-index: 5000;
  display: none;
  padding: 5px 0;
  font-size: 14px;
}
.context-menu .menu-item {
  padding: 8px 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dark);
}
.context-menu .menu-item i { width: 16px; text-align: center; color: var(--text-light); }
.context-menu .menu-item:hover {
  background: var(--item-hover);
}
.context-menu hr {
  margin: 5px 0;
  border: 0;
  border-top: 1px solid var(--border-color);
}
.context-menu .menu-item.delete:hover {
  background: #fbebee;
  color: #dc3545;
}
.context-menu .menu-item.delete:hover i { color: #dc3545; }


/* ==== LOADING SCREEN (GIỮ NGUYÊN) ==== */
#loading-screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-color: var(--bg-white);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
#loading-screen.hidden {
  opacity: 0; visibility: hidden; pointer-events: none;
}
.loader-content { text-align: center; animation: fadeIn 0.5s ease; }
.cloud-icon-wrapper { position: relative; display: inline-block; margin-bottom: 15px; }
.cloud-icon-wrapper .fa-cloud { font-size: 80px; color: var(--primary-color); }
.cloud-icon-wrapper .loading-spinner {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 30px; color: #fff;
}
.loader-content h2 { color: var(--primary-color); font-size: 24px; margin: 10px 0; }
.loader-content p { color: var(--text-light); font-size: 16px; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (max-width: 992px) {
  .sidebar { width: 280px; }
  .search-box { width: 200px; }
  .list .file-meta-ext, .list .file-meta-date { display: none; }
  .list .file-meta-size { width: auto; }
}

@media (max-width: 768px) {
  body { overflow: auto; }
  .app-layout { flex-direction: column; height: auto; }
  .sidebar { width: 100%; max-height: 60vh; border-right: none; border-bottom: 1px solid var(--border-color); }
  .upload-list { max-height: 200px; }
  .toolbar { flex-direction: column; gap: 15px; align-items: stretch; position: sticky; top: 0; z-index: 20; }
  .search-box { width: 100%; }
  .toolbar-actions, .filter-group { justify-content: center; flex-wrap: wrap; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  #fileSection { padding: 15px; }
  .app-footer { padding: 10px 15px; }
  .list .file-meta { display: none; }
  
  /* Ẩn context menu trên mobile, dùng nút bình thường */
  .context-menu { display: none !important; }
  /* Hiện lại nút actions trong list trên mobile để thao tác */
  .list .actions { display: flex; margin-left: auto; } 
  .grid .actions { display: flex; }
}
