/* ==========================================================================
   Document Hub — Components CSS Styles
   Cards, Modals, Forms, Buttons, Dropdowns, Grid Views, Toasts
   ========================================================================== */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  text-decoration: none;
}

.btn-outline {
  background-color: var(--bg-surface);
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover {
  background-color: var(--bg-subtle);
  border-color: #cbd5e1;
  text-decoration: none;
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}
.btn-danger:hover {
  background-color: var(--danger-hover);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  cursor: pointer;
}
.btn-icon:hover {
  background: var(--bg-subtle);
}

.btn-icon-subtle {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
}
.btn-icon-subtle:hover, .btn-icon-subtle.active {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Badges & Chips */
.doc-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-docs {
  background: var(--color-docs-subtle);
  color: var(--color-docs);
}
.badge-sheets {
  background: var(--color-sheets-subtle);
  color: var(--color-sheets);
}
.badge-slides {
  background: var(--color-slides-subtle);
  color: #b45309;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
}
.chip-success {
  background: var(--success-subtle);
  color: var(--success);
}
.chip-warning {
  background: var(--warning-subtle);
  color: var(--warning);
}

/* User Pill Topbar */
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  cursor: pointer;
}
.user-pill:hover {
  background: var(--bg-subtle);
}
.user-pill-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  overflow: hidden;
}
.user-pill-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.user-pill-name {
  font-size: 13px;
  font-weight: 500;
}
.user-pill-arrow {
  font-size: 10px;
  color: var(--text-muted);
}

/* Dropdown */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  padding: 6px 0;
  z-index: 50;
  display: none;
}
.dropdown-menu.show {
  display: block;
}

.user-menu {
  right: 0;
  left: auto;
  min-width: 220px;
}

.user-menu-header {
  padding: 10px 16px;
}
.user-menu-name {
  font-weight: 600;
  font-size: 13px;
}
.user-menu-email {
  font-size: 11px;
  color: var(--text-muted);
}

.dropdown-divider {
  border: 0;
  border-top: 1px solid var(--border-color);
  margin: 6px 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 16px;
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
}
.dropdown-item:hover {
  background-color: var(--bg-hover);
}

/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.bg-blue-subtle { background: var(--primary-subtle); color: var(--primary); }
.bg-blue { background: var(--color-docs-subtle); color: var(--color-docs); }
.bg-green { background: var(--color-sheets-subtle); color: var(--color-sheets); }
.bg-amber { background: var(--color-slides-subtle); color: #b45309; }

.stat-count {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

@media (max-width: 960px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Quick Create Cards */
.quick-create-section {
  margin-bottom: 32px;
}

.quick-create-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.quick-create-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  flex-direction: column;
}
.quick-create-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-docs:hover { border-color: var(--color-docs); }
.card-sheets:hover { border-color: var(--color-sheets); }
.card-slides:hover { border-color: var(--color-slides); }

.qc-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 12px;
}
.card-docs .qc-badge { background: var(--color-docs-subtle); color: var(--color-docs); }
.card-sheets .qc-badge { background: var(--color-sheets-subtle); color: var(--color-sheets); }
.card-slides .qc-badge { background: var(--color-slides-subtle); color: #b45309; }

.quick-create-card h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.quick-create-card p {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  flex: 1;
}

.qc-action {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
}

@media (max-width: 768px) {
  .quick-create-grid {
    grid-template-columns: 1fr;
  }
}

/* Toolbar & Filter */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-pills {
  display: flex;
  align-items: center;
  background: var(--bg-subtle);
  padding: 2px;
  border-radius: var(--radius-sm);
}

.filter-pill {
  border: none;
  background: transparent;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}
.filter-pill.active {
  background: var(--bg-surface);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.btn-filter-fav.active {
  background: #fef08a;
  border-color: #facc15;
  color: #854d0e;
  font-weight: 600;
}

.view-mode-group {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
  background: var(--bg-surface);
}

/* Document Grid & Cards */
.documents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.doc-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: all var(--transition-fast);
  position: relative;
}
.doc-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.doc-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.doc-card-type-icon {
  font-size: 24px;
}

.doc-card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-fav {
  background: transparent;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: #cbd5e1;
  transition: transform 0.1s ease;
}
.btn-fav.active {
  color: #f59e0b;
}
.btn-fav:hover {
  transform: scale(1.15);
}

.doc-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  word-break: break-word;
}
.doc-card-title a {
  color: inherit;
}
.doc-card-title a:hover {
  color: var(--primary);
}

.doc-card-meta {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.doc-card-folder {
  background: var(--bg-subtle);
  padding: 2px 6px;
  border-radius: 4px;
  max-width: 110px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-card-footer {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.doc-card-footer .btn {
  flex: 1;
}

/* Dạng danh sách (List View) */
.documents-grid.list-view {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.documents-grid.list-view .doc-card {
  flex-direction: row;
  align-items: center;
  padding: 10px 16px;
  gap: 16px;
}

.documents-grid.list-view .doc-card-top {
  margin-bottom: 0;
  gap: 12px;
}

.documents-grid.list-view .doc-card-title {
  margin-bottom: 0;
  flex: 2;
  -webkit-line-clamp: 1;
}

.documents-grid.list-view .doc-card-meta {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  flex: 1;
  justify-content: flex-end;
  gap: 16px;
}

.documents-grid.list-view .doc-card-footer {
  margin-top: 0;
  flex: none;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  background: var(--bg-surface);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-lg);
  margin-top: 20px;
}
.empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
}
.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
}
.empty-state p {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 400px;
  margin: 0 auto 20px auto;
}

/* Settings View Components */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 16px;
}

.settings-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

.card-title {
  font-size: 15px;
  font-weight: 600;
}

.card-body {
  padding: 20px;
}

.card-footer {
  padding: 12px 20px;
  background: #fafbfc;
  border-top: 1px solid var(--border-color);
}

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

.user-detail-row {
  display: flex;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 13px;
}
.user-detail-row:last-child {
  border-bottom: none;
}
.detail-label {
  width: 180px;
  font-weight: 500;
  color: var(--text-secondary);
}
.detail-value {
  flex: 1;
  color: var(--text-main);
  word-break: break-all;
}

.prose ul {
  padding-left: 20px;
  list-style: disc;
}
.prose li {
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Health status rows */
.health-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 13px;
}
.health-item:last-child {
  border-bottom: none;
}

/* Form Controls */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-main);
}
.required { color: var(--danger); }

.form-control, .form-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  font-size: 13px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-control:focus, .form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.select-sm {
  padding: 6px 10px;
  font-size: 12px;
  height: 34px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Type selector radio buttons in modal */
.type-selector-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.type-option input {
  display: none;
}

.type-option-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.type-option-card:hover {
  background: var(--bg-subtle);
}

.type-option input:checked + .type-option-card {
  border-color: var(--primary);
  background: var(--primary-subtle);
  font-weight: 600;
}

.type-icon {
  font-size: 20px;
}
.type-name {
  font-size: 12px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-dialog {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  animation: modalEnter 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-dialog-sm {
  max-width: 400px;
}

@keyframes modalEnter {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(-8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}
.modal-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 12px 20px;
  background: #fafbfc;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.fallback-action-container {
  margin-top: 16px;
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  margin-bottom: 20px;
}
.alert-danger {
  background: var(--danger-subtle);
  border: 1px solid #fecaca;
  color: #b91c1c;
}

/* Toast Container */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 380px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: #1e293b;
  color: #ffffff;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  animation: toastIn 0.25s ease;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-error { border-left: 4px solid var(--danger); }
.toast.toast-info { border-left: 4px solid var(--primary); }

.toast-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 14px;
}
.toast-close:hover {
  color: #fff;
}
