/**
 * ============================================
 * PROJECTS.CSS — Styles cho trang Quản lý Dự án
 * ============================================
 * Bao gồm: toolbar, bảng, pagination, modal, inline-edit,
 * skeleton loading, empty state, badges.
 */

/* ============================================
   LAYOUT TRANG PROJECTS
   ============================================ */

.projects-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
}


/* ============================================
   TOOLBAR: FILTER BAR + NÚT TẠO MỚI
   ============================================ */

.projects-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

/* Dropdown filter */
.filter-select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  min-width: 140px;
  transition: border-color .2s;
}

.filter-select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Search box */
.search-wrapper {
  position: relative;
  flex: 1;
  min-width: 180px;
  max-width: 280px;
}

.search-icon {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  pointer-events: none;
}

.filter-search {
  width: 100%;
  height: 36px;
  padding: 0 10px 0 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  transition: border-color .2s;
  box-sizing: border-box;
}

.filter-search:focus {
  outline: none;
  border-color: var(--primary);
}

/* Nút xóa bộ lọc */
.btn-clear-filter {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
}

.btn-clear-filter:hover {
  background: var(--danger-light, #fee2e2);
  border-color: var(--danger, #ef4444);
  color: var(--danger, #ef4444);
}


/* ============================================
   BẢNG DỰ ÁN
   ============================================ */

.table-wrapper {
  background: var(--bg-card);
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow-x: auto;          /* Horizontal scroll trên mobile */
  -webkit-overflow-scrolling: touch;
}

.projects-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;          /* Đảm bảo không bị vỡ layout */
  font-size: 13px;
}

/* Header */
.projects-table thead {
  background: var(--bg-sidebar, #f8fafc);
  border-bottom: 2px solid var(--border);
}

.projects-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  user-select: none;
}

/* Cột có thể sort */
.projects-table th.sortable {
  cursor: pointer;
}

.projects-table th.sortable:hover {
  background: var(--bg-hover, rgba(99,102,241,.06));
  color: var(--primary);
}

.projects-table th.active-sort {
  color: var(--primary);
}

.sort-icon {
  font-size: 11px;
  opacity: .6;
  margin-left: 4px;
}

/* Rows */
.projects-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}

.projects-table tbody tr:last-child {
  border-bottom: none;
}

.projects-table tbody tr:hover {
  background: var(--bg-hover, rgba(99,102,241,.04));
}

.projects-table td {
  padding: 10px 12px;
  color: var(--text-primary);
  vertical-align: middle;
}

/* Cột cụ thể */
.col-id {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.col-name {
  min-width: 160px;
  max-width: 240px;
}

.project-name-link {
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.project-name-link:hover {
  text-decoration: underline;
}

.col-deadline.overdue {
  color: var(--danger, #ef4444);
  font-weight: 600;
}


/* ============================================
   STATUS BADGE
   ============================================ */

.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  cursor: default;
}

/* Phase badge */
.phase-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-hover, rgba(99,102,241,.1));
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  cursor: default;
}

/* Eval result badges */
.eval-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.eval-pass {
  background: #dcfce7;
  color: #16a34a;
}

.eval-fail {
  background: #fee2e2;
  color: #dc2626;
}

.eval-pending {
  background: #fef9c3;
  color: #ca8a04;
}


/* ============================================
   PROGRESS BAR MINI
   ============================================ */

.progress-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 80px;
}

.progress-bar-mini {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width .4s;
}

.progress-text {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 28px;
}


/* ============================================
   ACTION BUTTONS (trong bảng)
   ============================================ */

.col-actions {
  white-space: nowrap;
}

.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
  opacity: .7;
  transition: all .15s;
}

.action-btn:hover {
  opacity: 1;
  background: var(--bg-hover, rgba(0,0,0,.06));
}

.edit-btn:hover  { background: rgba(99,102,241,.1); }
.delete-btn:hover { background: rgba(239,68,68,.1); }


/* ============================================
   SKELETON LOADING
   ============================================ */

.skeleton-row td {
  padding: 12px;
}

.skeleton-cell {
  height: 14px;
  width: 100px;
  background: linear-gradient(90deg, var(--border) 25%, var(--bg-hover,#f0f0f0) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s infinite;
  border-radius: 4px;
}

@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


/* ============================================
   EMPTY STATE
   ============================================ */

.empty-cell {
  padding: 60px 20px !important;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: .5;
}

.empty-state h3 {
  font-size: 16px;
  margin: 0 0 6px;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 13px;
  margin: 0;
}


/* ============================================
   PAGINATION
   ============================================ */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 4px 0;
}

.pagination-info {
  font-size: 13px;
  color: var(--text-secondary);
}

.page-btn {
  height: 34px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}

.page-btn:hover:not(:disabled) {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.page-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}


/* ============================================
   INLINE EDIT — Double-click Status / Phase
   ============================================ */

/* Ô có thể inline-edit — hiện dấu bút khi hover */
[data-inline] {
  cursor: default;
  position: relative;
}

[data-inline]:hover::after {
  content: '✏️';
  font-size: 10px;
  position: absolute;
  top: 6px;
  right: 4px;
  opacity: .5;
}

/* Dropdown hiện khi inline edit */
.inline-select {
  width: 100%;
  min-width: 110px;
  height: 28px;
  padding: 0 6px;
  border: 2px solid var(--primary);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 12px;
  cursor: pointer;
  outline: none;
}

/* Spinner nhỏ khi đang lưu inline */
.saving-indicator {
  font-size: 14px;
  animation: spin 1s linear infinite;
  display: inline-block;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}


/* ============================================
   MODAL TẠO / SỬA DỰ ÁN
   ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(2px);
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in .2s ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(.96) translateY(-8px); }
  to   { opacity: 1; transform: scale(1)  translateY(0);     }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
  transition: all .15s;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text-primary);
}

/* Form grid 2 cột */
.modal-form {
  padding: 20px 24px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

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

.required {
  color: var(--danger, #ef4444);
}

/* Input / Select / Textarea trong modal */
.modal-form .form-control {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-main, #f9fafb);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  transition: border-color .2s;
  box-sizing: border-box;
  width: 100%;
}

.modal-form textarea.form-control {
  height: auto;
  padding: 8px 10px;
  resize: vertical;
}

.modal-form .form-control:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-card);
}

/* Validation error */
.modal-form .form-control.error {
  border-color: var(--danger, #ef4444);
  background: #fff5f5;
}

.field-error {
  font-size: 11px;
  color: var(--danger, #ef4444);
  margin-top: 2px;
}

/* Nút hành động modal */
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.btn-secondary {
  height: 38px;
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}

.btn-secondary:hover {
  background: var(--border);
}


/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .projects-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar {
    flex-wrap: wrap;
  }

  .search-wrapper {
    max-width: 100%;
  }

  /* Modal toàn màn hình trên mobile */
  .modal-box {
    max-height: 100vh;
    border-radius: 0;
    margin: 0;
  }

  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  /* Form 1 cột trên mobile */
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-group.full-width {
    grid-column: 1;
  }
}
