/* ========== Departments Management ========== */

/* --- Page Layout --- */
.dm-content { display: flex; flex-direction: column; height: 100%; }
.dm-main { flex: 1; padding: 20px 24px; overflow: auto; }

/* --- Breadcrumb --- */
.dm-breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted-foreground); margin-bottom: 12px; }
.dm-breadcrumb a { color: var(--muted-foreground); transition: color 0.2s; }
.dm-breadcrumb a:hover { color: var(--primary); }
.dm-breadcrumb span { user-select: none; }

/* --- Page Header --- */
.dm-page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.dm-page-title { font-size: 20px; font-weight: 700; color: var(--foreground); }
.dm-page-desc { font-size: 13px; color: var(--muted-foreground); margin-top: 4px; }

/* --- Buttons (dm-) --- */
.dm-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px; border-radius: 8px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border); background: var(--background); color: var(--foreground);
  cursor: pointer; transition: all 0.2s; white-space: nowrap; line-height: 1.4;
}
.dm-btn:hover { background: var(--muted); }
.dm-btn-primary { background: var(--primary); color: var(--primary-foreground); border-color: var(--primary); }
.dm-btn-primary:hover { background: var(--primary-hover); }

/* --- Stats --- */
.dm-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.dm-stat-card { display: flex; align-items: center; gap: 14px; padding: 18px 20px; background: var(--background); border-radius: 12px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.dm-stat-icon { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0; }
.dm-stat-icon svg { width: 20px; height: 20px; }
.dm-stat-icon.blue { background: #eff6ff; color: #2563eb; }
.dm-stat-icon.green { background: #f0fdf4; color: #16a34a; }
.dm-stat-icon.orange { background: #fff7ed; color: #ea580c; }
.dm-stat-icon.red { background: #fef2f2; color: #dc2626; }
.dm-stat-info { display: flex; flex-direction: column; }
.dm-stat-value { font-size: 24px; font-weight: 700; color: var(--foreground); line-height: 1.2; }
.dm-stat-label { font-size: 13px; color: var(--muted-foreground); margin-top: 2px; }

/* --- Body: Tree + Table --- */
.dm-body { display: grid; grid-template-columns: 280px 1fr; gap: 16px; min-height: 0; }

/* --- Tree Panel --- */
.dm-tree-panel { display: flex; flex-direction: column; background: var(--background); border-radius: 12px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); overflow: hidden; max-height: calc(100vh - 260px); }
.dm-tree-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.dm-tree-header-title { font-size: 14px; font-weight: 600; }
.dm-tree-header-actions { display: flex; gap: 4px; }
.dm-tree-btn { display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 6px; color: var(--muted-foreground); cursor: pointer; transition: all 0.2s; background: none; border: none; }
.dm-tree-btn:hover { background: var(--muted); color: var(--foreground); }
.dm-tree-btn svg { width: 16px; height: 16px; }
.dm-tree-search { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.dm-tree-search input { width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; outline: none; transition: border-color 0.2s; background: var(--background); }
.dm-tree-search input:focus { border-color: var(--primary); }
.dm-tree { flex: 1; overflow-y: auto; padding: 6px 0; }

/* Tree Node */
.dm-tree-node { }
.dm-tree-row { display: flex; align-items: center; gap: 4px; padding: 6px 12px; cursor: pointer; transition: background 0.15s; font-size: 13px; }
.dm-tree-row:hover { background: var(--muted); }
.dm-tree-row.active { background: #eff6ff; color: #2563eb; font-weight: 500; }
.dm-tree-row.active .dm-tree-label { color: #2563eb; }
.dm-tree-toggle { display: flex; align-items: center; justify-content: center; width: 20px; height: 20px; flex-shrink: 0; cursor: pointer; border-radius: 4px; transition: transform 0.2s, background 0.15s; color: var(--muted-foreground); }
.dm-tree-toggle:hover { background: var(--border); }
.dm-tree-toggle svg { width: 14px; height: 14px; transition: transform 0.2s; }
.dm-tree-toggle.expanded svg { transform: rotate(90deg); }
.dm-tree-toggle.empty { visibility: hidden; }
.dm-tree-folder { display: flex; align-items: center; flex-shrink: 0; width: 18px; height: 18px; }
.dm-tree-folder svg { width: 18px; height: 18px; }
.dm-tree-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-tree-count { margin-left: auto; font-size: 11px; color: var(--muted-foreground); background: var(--muted); padding: 1px 7px; border-radius: 10px; flex-shrink: 0; }
.dm-tree-children { display: none; }
.dm-tree-children.show { display: block; }

/* --- Table Panel --- */
.dm-table-panel { min-width: 0; }
.dm-card { background: var(--background); border-radius: 12px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); overflow: hidden; }
.dm-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.dm-toolbar-left { display: flex; align-items: center; gap: 12px; }
.dm-current-dept { font-size: 14px; color: var(--foreground); }
.dm-current-dept span { font-weight: 600; }
.dm-toolbar-right { display: flex; gap: 8px; }

/* Table */
.dm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dm-table thead { background: var(--muted); }
.dm-table th { padding: 10px 16px; text-align: left; font-weight: 500; color: var(--muted-foreground); font-size: 12px; text-transform: none; border-bottom: 1px solid var(--border); }
.dm-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.dm-table tbody tr:hover { background: #fafbfc; }

/* Dept Cell */
.dm-dept-cell { display: flex; align-items: center; gap: 10px; }
.dm-dept-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--muted-foreground); }
.dm-dept-dot.level-0 { background: var(--primary); width: 10px; height: 10px; }
.dm-dept-dot.level-1 { background: #2563eb; }
.dm-dept-dot.level-2 { background: #6366f1; }
.dm-dept-name { font-weight: 500; }
.dm-dept-path { font-size: 11px; color: var(--muted-foreground); margin-top: 2px; }

/* Leader */
.dm-leader { display: flex; align-items: center; gap: 8px; }
.dm-leader-avatar { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: #fff; flex-shrink: 0; }
.dm-leader-avatar.c0 { background: #6366f1; }
.dm-leader-avatar.c1 { background: #3b82f6; }
.dm-leader-avatar.c2 { background: #10b981; }
.dm-leader-avatar.c3 { background: #f59e0b; }
.dm-leader-avatar.c4 { background: #ef4444; }
.dm-leader-avatar.c5 { background: #8b5cf6; }
.dm-leader-avatar.c6 { background: #ec4899; }
.dm-leader-avatar.c7 { background: #14b8a6; }
.dm-leader-name { font-size: 13px; }

/* Status */
.dm-status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.dm-status-dot { width: 6px; height: 6px; border-radius: 50%; }
.dm-status-dot.green { background: #22c55e; }
.dm-status-dot.orange { background: #f59e0b; }
.dm-status-dot.red { background: #ef4444; }

/* Actions */
.dm-action-link { color: var(--primary); cursor: pointer; font-size: 13px; transition: opacity 0.15s; text-decoration: none; }
.dm-action-link:hover { opacity: 0.8; }
.dm-action-sep { color: var(--border); margin: 0 4px; font-size: 12px; user-select: none; }

/* --- Pagination --- */
.dm-pagination { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-top: 1px solid var(--border); }
.dm-pagination-info { font-size: 13px; color: var(--muted-foreground); }
.dm-pagination-pages { display: flex; gap: 4px; }
.dm-page-btn { width: 32px; height: 32px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 13px; border: 1px solid var(--border); background: var(--background); cursor: pointer; transition: all 0.15s; }
.dm-page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.dm-page-btn.active { background: var(--primary); color: var(--primary-foreground); border-color: var(--primary); }
.dm-page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- Modal --- */
.dm-modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; }
.dm-modal-overlay.show { display: flex; }
.dm-modal { background: var(--background); border-radius: 12px; box-shadow: var(--shadow-lg); width: 520px; max-width: 90vw; max-height: 85vh; display: flex; flex-direction: column; }
.dm-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid var(--border); }
.dm-modal-title { font-size: 16px; font-weight: 600; }
.dm-modal-close { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 6px; cursor: pointer; color: var(--muted-foreground); transition: all 0.15s; background: none; border: none; }
.dm-modal-close:hover { background: var(--muted); color: var(--foreground); }
.dm-modal-close svg { width: 18px; height: 18px; }
.dm-modal-body { padding: 24px; overflow-y: auto; }
.dm-modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); }

/* --- Form --- */
.dm-form-group { margin-bottom: 16px; display: flex; flex-direction: column; }
.dm-form-label { font-size: 13px; font-weight: 500; color: var(--foreground); margin-bottom: 6px; }
.dm-form-label .required { color: #ef4444; margin-left: 2px; }
.dm-form-input, .dm-form-select { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; outline: none; transition: border-color 0.2s; background: var(--background); color: var(--foreground); }
.dm-form-input:focus, .dm-form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,26,46,0.08); }
.dm-form-input.error { border-color: #ef4444; }
.dm-form-error { display: none; color: #ef4444; font-size: 12px; margin-top: 4px; }
.dm-form-hint { font-size: 12px; color: var(--muted-foreground); margin-top: 4px; }
.dm-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dm-form-textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; outline: none; resize: vertical; min-height: 80px; font-family: inherit; transition: border-color 0.2s; background: var(--background); color: var(--foreground); }
.dm-form-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,26,46,0.08); }

/* Switch */
.dm-switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.dm-switch-track { width: 44px; height: 24px; border-radius: 12px; background: var(--border); position: relative; transition: background 0.2s; }
.dm-switch-track.on { background: #22c55e; }
.dm-switch-thumb { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.15); transition: left 0.2s; }
.dm-switch-track.on .dm-switch-thumb { left: 22px; }
.dm-switch-label { font-size: 13px; color: var(--foreground); }

/* --- Confirm Dialog --- */
.dm-confirm-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1100; align-items: center; justify-content: center; }
.dm-confirm-overlay.show { display: flex; }
.dm-confirm { background: var(--background); border-radius: 12px; box-shadow: var(--shadow-lg); width: 400px; max-width: 90vw; padding: 28px; text-align: center; }
.dm-confirm-icon { display: flex; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 50%; background: #fef2f2; color: #ef4444; margin: 0 auto 16px; }
.dm-confirm-icon svg { width: 24px; height: 24px; }
.dm-confirm-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.dm-confirm-desc { font-size: 13px; color: var(--muted-foreground); margin-bottom: 24px; line-height: 1.5; }
.dm-confirm-actions { display: flex; justify-content: center; gap: 10px; }

/* --- Toast --- */
.dm-toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 9999; padding: 10px 24px; border-radius: 8px; font-size: 14px; font-weight: 500; background: var(--foreground); color: #fff; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity 0.3s; pointer-events: none; }
.dm-toast.show { opacity: 1; }
.dm-toast.success { background: #16a34a; }
.dm-toast.error { background: #ef4444; }

/* Empty State */
.dm-empty { text-align: center; padding: 48px 20px; color: var(--muted-foreground); }
.dm-empty p { margin-bottom: 8px; }
.dm-empty a { color: var(--primary); }

/* --- Responsive --- */
@media (max-width: 1024px) {
  .dm-body { grid-template-columns: 1fr; }
  .dm-tree-panel { max-height: 300px; }
  .dm-stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .dm-main { padding: 12px 16px; }
  .dm-stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .dm-stat-card { padding: 12px 14px; }
  .dm-stat-value { font-size: 20px; }
  .dm-form-row { grid-template-columns: 1fr; }
  .dm-toolbar { flex-direction: column; gap: 10px; align-items: flex-start; }
}
