/* ========================================
   财务部核算业务工作负荷分析模型 - Stylesheet
   ======================================== */

/* ----- CSS Variables ----- */
:root {
  /* Backgrounds */
  --bg-page: #eef1f6;
  --bg-card: #ffffff;
  --bg-card-hover: #f8f9fb;
  --bg-pool: #f0f2f7;

  /* Primary colors */
  --c-primary: #1a3a5f;
  --c-primary-light: #2c5282;
  --c-accent: #c9a227;

  /* Text */
  --c-text: #1a202c;
  --c-text-secondary: #64748b;
  --c-text-muted: #94a3b8;

  /* Borders */
  --c-border: #e2e8f0;
  --c-border-light: #f1f5f9;

  /* Status colors */
  --c-success: #10b981;
  --c-warning: #f59e0b;
  --c-danger: #ef4444;
  --c-info: #3b82f6;

  /* Stat bar colors (RPG style) */
  --c-ability: #3b82f6;
  --c-ability-bg: linear-gradient(90deg, #2563eb, #60a5fa);
  --c-efficiency: #10b981;
  --c-efficiency-bg: linear-gradient(90deg, #059669, #34d399);
  --c-experience: #8b5cf6;
  --c-experience-bg: linear-gradient(90deg, #7c3aed, #a78bfa);

  /* Difficulty colors */
  --c-diff-1: #10b981;
  --c-diff-2: #22c55e;
  --c-diff-3: #84cc16;
  --c-diff-4: #eab308;
  --c-diff-5: #f59e0b;
  --c-diff-6: #f97316;
  --c-diff-7: #ef4444;
  --c-diff-8: #dc2626;
  --c-diff-9: #b91c1c;
  --c-diff-10: #991b1b;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.08), 0 4px 8px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 48px rgba(0,0,0,0.12), 0 8px 16px rgba(0,0,0,0.06);

  /* Radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 24px;

  /* Transitions */
  --t-fast: 0.15s ease;
  --t-normal: 0.25s ease;
  --t-slow: 0.4s ease;
}

/* ----- Reset ----- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  background: var(--bg-page);
  color: var(--c-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ----- Header ----- */
.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1600px;
  margin: 0 auto;
  padding: 18px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}

.header-title h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--c-primary);
  letter-spacing: 0.5px;
}

.header-title .subtitle {
  font-size: 12px;
  color: var(--c-text-muted);
  letter-spacing: 1px;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* Right-side container: work actions + admin actions, visually separated */
.header-right {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-admin {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 18px;
  border-left: 1px solid var(--c-border-light);
  flex-wrap: wrap;
}

/* --- Admin badge & login button --- */
.admin-badge {
  font-size: 11px;
  color: var(--c-text-muted);
  background: var(--bg-pool);
  border: 1px solid var(--c-border-light);
  padding: 3px 10px;
  border-radius: 999px;
  line-height: 1.5;
  white-space: nowrap;
}

.admin-badge.on {
  color: #065f46;
  background: #d1fae5;
  border-color: #a7f3d0;
}

.btn-admin-on {
  color: #065f46 !important;
  border-color: #a7f3d0 !important;
  background: #d1fae5 !important;
}

.btn-change-pwd {
  color: var(--c-info) !important;
  border-color: #bfdbfe !important;
  background: #eff6ff !important;
}

/* View-only mode: dim operation controls (clicking still prompts login) */
body.view-only .tag-action,
body.view-only .tag-remove,
body.view-only .emp-edit-btn {
  opacity: 0.35;
}

/* ----- Buttons ----- */
.btn {
  padding: 8px 18px;
  border: none;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
}

.btn-primary {
  background: var(--c-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--c-primary-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-outline {
  background: transparent;
  color: var(--c-primary);
  border: 1px solid var(--c-border);
}
.btn-outline:hover {
  background: var(--bg-card-hover);
  border-color: var(--c-primary);
}

.btn-danger-outline {
  background: transparent;
  color: var(--c-danger);
  border: 1px solid var(--c-border);
}
.btn-danger-outline:hover {
  background: #fef2f2;
  border-color: var(--c-danger);
}

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

.btn-block {
  width: 100%;
  margin-top: 4px;
}

/* ----- Dashboard ----- */
.dashboard {
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  padding: 24px 32px 8px;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr 1fr;
  gap: 16px;
}

.dashboard-card {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  padding: 18px 22px;
  box-shadow: var(--shadow-md);
  transition: all var(--t-normal);
  position: relative;
  overflow: hidden;
}

.dashboard-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--c-primary);
  opacity: 0.15;
}

.highlight-card::before { background: var(--c-primary); opacity: 0.6; }
.alert-card::before { background: var(--c-danger); opacity: 0.5; }

.card-label {
  font-size: 12px;
  color: var(--c-text-secondary);
  font-weight: 500;
  margin-bottom: 8px;
}

.card-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--c-text);
  line-height: 1.2;
}

.card-value .unit {
  font-size: 14px;
  font-weight: 400;
  color: var(--c-text-muted);
  margin-left: 4px;
}

.highlight-card .card-value { color: var(--c-primary); }
.alert-card .card-value { color: var(--c-danger); }

.card-bar {
  height: 6px;
  background: var(--c-border-light);
  border-radius: 3px;
  margin-top: 10px;
  overflow: hidden;
}

.card-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease, background 0.3s ease;
  width: 0%;
}

.card-sub {
  font-size: 11px;
  color: var(--c-text-muted);
  margin-top: 8px;
}

/* ----- Pool Section ----- */
.pool-section {
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  padding: 16px 32px;
}

.section-title-bar {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title-bar h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--c-text);
}

.hint-text {
  font-size: 12px;
  color: var(--c-text-muted);
}

.pool-block {
  margin-bottom: 14px;
}

.pool-block:last-child {
  margin-bottom: 0;
}

.pool-block-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.pool-block-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text);
  padding-left: 8px;
  border-left: 3px solid var(--c-primary);
  line-height: 1.4;
}

.pool-block-count {
  font-size: 11px;
  color: var(--c-text-muted);
  background: var(--bg-pool);
  border: 1px solid var(--c-border-light);
  padding: 0 8px;
  border-radius: 999px;
  line-height: 1.6;
}

.pool {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  padding: 14px;
  min-height: 72px;
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--c-border-light);
  transition: all var(--t-normal);
}

/* Financial work pool: 7 cards per row */
.pool-financial {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

/* Fixed work pool: 6 cards per row */
.pool-fixed {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.pool.drag-active {
  border-color: var(--c-info);
  background: #f0f7ff;
}

.pool:empty::after {
  content: '暂无未分配工作';
  color: var(--c-text-muted);
  font-size: 13px;
  padding: 8px;
}

/* ----- Work Tags ----- */
.work-tag {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 8px 10px 9px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border-radius: var(--r-md);
  font-size: 13px;
  cursor: grab;
  transition: all var(--t-fast);
  background: var(--bg-card);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  user-select: none;
  position: relative;
}

/* In the top work pool: cards stretch to their grid column */
.pool .work-tag {
  width: 100%;
  min-width: 0;
}

.work-tag:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.work-tag:active { cursor: grabbing; }

.work-tag.selected {
  border-color: var(--c-info);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
  background: #eff6ff;
}

.work-tag .tag-header {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.work-tag .tag-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--c-border-light);
  flex-wrap: wrap;
}

.work-tag .tag-name {
  flex: 1;
  min-width: 0;
  font-weight: 500;
  color: var(--c-text);
  line-height: 1.3;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

.work-tag .tag-params {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.tag-param {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  color: var(--c-text-secondary);
}

.tag-param .param-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tag-param .param-label {
  color: var(--c-text-muted);
  font-weight: 400;
  font-size: 10px;
}

.tag-param .param-value {
  font-weight: 600;
}

.work-tag .tag-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  color: var(--c-text-muted);
  transition: all var(--t-fast);
  padding: 0;
  margin-left: 2px;
}

.tag-remove:hover {
  background: #fee2e2;
  color: var(--c-danger);
}

/* ----- Tag Actions (edit / delete for pool tags) ----- */
.work-tag .tag-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 2px;
  visibility: hidden;
  opacity: 0;
  transition: opacity var(--t-fast);
}

.work-tag:hover .tag-actions {
  visibility: visible;
  opacity: 1;
}

.tag-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--c-text-muted);
  transition: all var(--t-fast);
  padding: 0;
}

.tag-action-edit:hover {
  background: #dbeafe;
  color: var(--c-info);
}

.tag-action-del:hover {
  background: #fee2e2;
  color: var(--c-danger);
}

.work-tag.assigned {
  padding-right: 10px;
}

.work-tag.warning {
  border-color: var(--c-warning);
  background: #fffbeb;
}

.work-tag.warning .tag-name {
  color: #92400e;
}

.work-tag .warning-icon {
  color: var(--c-warning);
  font-size: 14px;
}

/* ----- Tag Metrics (base score & cost) ----- */
/* Stack base-cost and work-cost on two lines so long labels never overflow */
.work-tag .tag-metrics {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  flex-shrink: 0;
  min-width: 0;
  max-width: 100%;
}

.tag-metric {
  font-size: 10px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  background: var(--bg-pool);
  color: var(--c-text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag-metric-base {
  background: var(--bg-pool);
  color: var(--c-text-secondary);
}

.tag-metric-cost {
  background: #eef4ff;
  color: var(--c-info);
  font-weight: 600;
}

.tag-metric-cost.busy {
  background: #fffbeb;
  color: #b45309;
}

.tag-metric-cost.hot {
  background: #fef2f2;
  color: var(--c-danger);
}

/* ----- Cost Tooltip (calculation details) ----- */
#globalTooltip {
  position: fixed;
  z-index: 9999;
  width: 320px;
  background: var(--bg-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xl);
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.75;
  color: var(--c-text);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
  pointer-events: none;
  text-align: left;
}

#globalTooltip .tt-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--c-text);
}

#globalTooltip .tt-title span {
  font-weight: 400;
  color: var(--c-text-muted);
  font-size: 11px;
  margin-left: 6px;
}

#globalTooltip .tt-line {
  color: var(--c-text-secondary);
  font-size: 11px;
  font-family: ui-monospace, 'SF Mono', Consolas, 'Microsoft YaHei', monospace;
}

#globalTooltip .tt-result {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--c-border);
  font-weight: 600;
  color: var(--c-info);
  font-size: 12px;
}

/* ----- Grid Section ----- */
.grid-section {
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  padding: 8px 32px 32px;
  flex: 1;
}

.grid-head {
  display: grid;
  grid-template-columns: 260px minmax(0, 1.6fr) minmax(400px, 1fr) 190px;
  gap: 12px;
  margin-bottom: 12px;
}

.gh {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-secondary);
  padding: 8px 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.grid-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ----- Employee Row ----- */
.emp-row {
  display: grid;
  grid-template-columns: 260px minmax(0, 1.6fr) minmax(400px, 1fr) 190px;
  gap: 12px;
  background: var(--bg-card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: box-shadow var(--t-normal);
}

.emp-row:hover {
  box-shadow: var(--shadow-lg);
}

/* --- Employee Info Cell --- */
.emp-info {
  padding: 18px 16px;
  border-right: 1px solid var(--c-border-light);
}

.emp-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}

.emp-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.emp-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--c-text);
}

.emp-title {
  font-size: 11px;
  color: var(--c-text-muted);
  background: var(--bg-pool);
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 2px;
  display: inline-block;
}

.emp-edit-btn {
  background: none;
  border: none;
  color: var(--c-text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  border-radius: 4px;
  transition: all var(--t-fast);
}
.emp-edit-btn:hover {
  color: var(--c-primary);
  background: var(--bg-card-hover);
}

.emp-actions {
  display: flex;
  gap: 4px;
}

/* --- Employee drag handle (reorder) --- */
.emp-drag-handle {
  cursor: grab;
  color: var(--c-text-muted);
  font-size: 16px;
  line-height: 1;
  padding: 9px 11px;
  border-radius: 6px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  display: inline-flex;
  align-items: center;
  border: 1px dashed transparent;
}
.emp-drag-handle:hover {
  color: var(--c-primary);
  background: var(--bg-card-hover);
  border-color: var(--c-primary);
}
.emp-drag-handle:active {
  cursor: grabbing;
}
.emp-row.emp-dragging {
  opacity: 0.45;
  box-shadow: var(--shadow-md);
}
.emp-row.drag-insert-before {
  box-shadow: 0 -4px 0 0 var(--c-primary), var(--shadow-md);
}
.emp-row.drag-insert-after {
  box-shadow: 0 4px 0 0 var(--c-primary), var(--shadow-md);
}

/* --- Custom pointer-drag: ghost + dragging state --- */
body.dragging {
  user-select: none;
  -webkit-user-select: none;
  cursor: grabbing;
}
body.dragging #globalTooltip {
  display: none;
}
.drag-ghost {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.9;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  border-radius: 8px;
  transform: rotate(2deg);
  background: var(--bg-card);
  cursor: grabbing;
}
.drag-ghost .tag-remove,
.drag-ghost .tag-actions {
  display: none;
}
.emp-ghost {
  padding: 10px 16px;
  font-size: 14px;
  color: var(--c-text);
  border: 1px solid var(--c-primary);
  white-space: nowrap;
}

/* --- Stat Bars (RPG style) --- */
.stat-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-bar-label {
  font-size: 11px;
  color: var(--c-text-secondary);
  width: 42px;
  flex-shrink: 0;
  text-align: right;
}

.stat-bar-track {
  flex: 1;
  height: 14px;
  background: var(--c-border-light);
  border-radius: 7px;
  overflow: hidden;
  position: relative;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 7px;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.stat-bar-fill::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.3), rgba(255,255,255,0));
  border-radius: 7px;
}

.stat-bar-fill.ability { background: var(--c-ability-bg); }
.stat-bar-fill.efficiency { background: var(--c-efficiency-bg); }
.stat-bar-fill.experience { background: var(--c-experience-bg); }

.stat-bar-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--c-text);
  width: 24px;
  text-align: right;
  flex-shrink: 0;
}

.emp-capacity {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--c-border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.emp-capacity-label {
  font-size: 11px;
  color: var(--c-text-muted);
}

.emp-capacity-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--c-primary);
}

/* --- Drop Zone Cell --- */
.drop-zone {
  padding: 12px;
  min-height: 180px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-content: start;
  border-right: 1px solid var(--c-border-light);
  transition: all var(--t-normal);
  position: relative;
}

.drop-zone:last-child { border-right: none; }

.drop-zone.drag-over {
  background: #eff6ff;
  box-shadow: inset 0 0 0 2px var(--c-info);
}

/* Drag-reorder insertion indicator */
.work-tag.drag-insert-before {
  box-shadow: 0 -3px 0 0 var(--c-primary);
}
.work-tag.drag-insert-after {
  box-shadow: 0 3px 0 0 var(--c-primary);
}

.drop-zone:empty::after {
  content: '拖拽工作项到此处';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--c-text-muted);
  font-size: 12px;
}

/* --- Load Cell --- */
.load-cell {
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-left: 1px solid var(--c-border-light);
}

.load-gauge {
  position: relative;
  width: 90px;
  height: 90px;
}

.load-gauge svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.load-gauge-bg {
  fill: none;
  stroke: var(--c-border-light);
  stroke-width: 8;
}

.load-gauge-fill {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s ease, stroke 0.3s ease;
}

.load-gauge-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.load-gauge-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}

.load-gauge-label {
  font-size: 10px;
  color: var(--c-text-muted);
  margin-top: 2px;
}

.load-status {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 12px;
  text-align: center;
}

.load-status.ok {
  background: #d1fae5;
  color: #065f46;
}

.load-status.busy {
  background: #fef3c7;
  color: #92400e;
}

.load-status.warning {
  background: #ffedd5;
  color: #9a3412;
}

.load-status.overload {
  background: #fee2e2;
  color: #991b1b;
  animation: pulse 1.5s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.load-detail {
  font-size: 11px;
  color: var(--c-text-muted);
  text-align: center;
}

.load-warnings {
  font-size: 11px;
  color: var(--c-danger);
  text-align: center;
  margin-top: 4px;
}

/* ----- Modals ----- */
.modal-bg {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.2s ease;
}

.modal-bg.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  width: 440px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.25s ease;
}

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

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

.modal-head h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--c-text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--c-text-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color var(--t-fast);
}
.modal-close:hover { color: var(--c-text); }

.modal-body {
  padding: 24px;
}

.form-row {
  margin-bottom: 20px;
}

.form-row label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--c-text-secondary);
  margin-bottom: 8px;
}

.form-row input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: 14px;
  color: var(--c-text);
  transition: border-color var(--t-fast);
  font-family: inherit;
}

.form-row input[type="text"]:focus {
  outline: none;
  border-color: var(--c-info);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* --- Sliders --- */
.slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: 999px;
  background: var(--c-border-light);
  outline: none;
  cursor: pointer;
}

/* Gradient ruler per slider: track shows the level color scale */
.slider.slider-wl   { background: linear-gradient(90deg, #3b82f6, #8b5cf6, #ec4899); }
.slider.slider-diff { background: linear-gradient(90deg, #10b981, #eab308 33%, #f97316 66%, #991b1b); }
.slider.slider-urg  { background: linear-gradient(90deg, #10b981, #f59e0b, #ef4444); }
.slider.slider-emp  { background: linear-gradient(90deg, #3b82f6, #8b5cf6); }

.slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: inherit;
}
.slider::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: inherit;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--thumb-color, var(--c-primary));
  cursor: pointer;
  box-shadow: 0 0 0 3px #fff, var(--shadow-sm);
  transition: transform var(--t-fast);
}
.slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--thumb-color, var(--c-primary));
  cursor: pointer;
  border: none;
  box-shadow: 0 0 0 3px #fff, var(--shadow-sm);
}

.slider-val {
  float: right;
  font-size: 16px;
  font-weight: 700;
  color: var(--c-primary);
}

.weight-note {
  float: right;
  margin-right: 56px;
  font-size: 11px;
  font-weight: 400;
  color: var(--c-text-muted);
  background: var(--bg-pool);
  border: 1px solid var(--c-border-light);
  padding: 1px 8px;
  border-radius: 999px;
  line-height: 1.6;
}

.radio-group {
  display: flex;
  gap: 18px;
  align-items: center;
}

.radio-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--c-text);
  cursor: pointer;
  user-select: none;
}

.radio-item input[type="radio"] {
  accent-color: var(--c-primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.form-note {
  margin-top: 4px;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  background: var(--bg-pool);
  border: 1px dashed var(--c-border);
  font-size: 12px;
  color: var(--c-text-secondary);
  line-height: 1.6;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--c-text-muted);
  margin-top: 6px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--c-border);
}

/* ----- Archive Modal ----- */
.modal-archive {
  width: 560px;
  max-width: 94vw;
}

.archive-list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 18px 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text);
}

.archive-count {
  font-size: 11px;
  font-weight: 400;
  color: var(--c-text-muted);
  background: var(--bg-pool);
  border: 1px solid var(--c-border-light);
  padding: 1px 8px;
  border-radius: 999px;
}

.archive-list {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.archive-empty {
  font-size: 12px;
  color: var(--c-text-muted);
  background: var(--bg-pool);
  border: 1px dashed var(--c-border-light);
  border-radius: var(--r-sm);
  padding: 14px;
  text-align: center;
}

.archive-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--c-border-light);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  transition: all var(--t-fast);
}

.archive-item:hover {
  border-color: var(--c-primary);
  box-shadow: var(--shadow-sm);
}

.archive-item-main {
  min-width: 0;
  flex: 1;
}

.archive-time {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text);
  font-variant-numeric: tabular-nums;
}

.archive-meta {
  font-size: 11px;
  color: var(--c-text-muted);
  margin-top: 2px;
}

.archive-note {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--c-info);
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 1px 8px;
  border-radius: 999px;
}

.archive-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ----- Footer ----- */
.app-footer {
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  padding: 16px 32px 24px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 24px;
}

/* --- Load Scale (footer) --- */
.load-scale-block {
  grid-column: 1 / -1;
  background: var(--bg-card);
  border: 1px solid var(--c-border-light);
  border-radius: var(--r-md);
  padding: 14px 18px 16px;
  box-shadow: var(--shadow-sm);
}

.load-scale-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.load-scale-note {
  font-size: 11px;
  color: var(--c-text-muted);
}

.load-scale-bar {
  display: flex;
  height: 38px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.load-scale-seg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  min-width: 0;
  gap: 1px;
}

.load-scale-seg .seg-name {
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
}

.load-scale-seg .seg-range {
  font-size: 9px;
  opacity: 0.92;
  line-height: 1.25;
  white-space: nowrap;
}

.load-scale-seg.ok { background: var(--c-success); }
.load-scale-seg.busy { background: var(--c-warning); }
.load-scale-seg.warning { background: #f97316; }
.load-scale-seg.overload { background: var(--c-danger); }

.load-scale-items {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.load-scale-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-pool);
  border: 1px solid var(--c-border-light);
  border-radius: var(--r-sm);
}

.load-scale-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.load-scale-item.ok .load-scale-dot { background: var(--c-success); }
.load-scale-item.busy .load-scale-dot { background: var(--c-warning); }
.load-scale-item.warning .load-scale-dot { background: #f97316; }
.load-scale-item.overload .load-scale-dot { background: var(--c-danger); }

.load-scale-item .item-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.load-scale-item .item-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text);
}

.load-scale-item .item-range {
  font-size: 10px;
  color: var(--c-text-secondary);
  font-family: 'SF Mono', 'Cascadia Mono', Consolas, monospace;
}

.load-scale-item .item-desc {
  font-size: 10px;
  color: var(--c-text-muted);
  line-height: 1.55;
  margin-top: 2px;
}

/* ----- Work Parameter Scale (工作量 / 难度 / 时效) ----- */
.param-scale-rows {
  display: grid;
  gap: 10px;
}

.param-scale-row {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  grid-template-areas:
    "info track"
    "info ticks";
  align-items: center;
  gap: 4px 16px;
  padding: 10px 14px;
  background: var(--bg-pool);
  border: 1px solid var(--c-border-light);
  border-radius: var(--r-sm);
}

.param-scale-info {
  grid-area: info;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.param-scale-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text);
}

.param-scale-desc {
  font-size: 11px;
  color: var(--c-text-muted);
}

.param-scale-track {
  grid-area: track;
  height: 12px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}

.param-scale-track.wl   { background: linear-gradient(90deg, #3b82f6, #8b5cf6, #ec4899); }
.param-scale-track.diff { background: linear-gradient(90deg, #10b981, #eab308 33%, #f97316 66%, #991b1b); }
.param-scale-track.urg  { background: linear-gradient(90deg, #10b981, #f59e0b, #ef4444); }

.param-scale-ticks {
  grid-area: ticks;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--c-text-muted);
  flex-wrap: wrap;
}

.param-scale-ticks .tick {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.tick-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.formula-block {
  font-size: 11px;
  color: var(--c-text-muted);
  background: var(--bg-pool);
  border: 1px solid var(--c-border-light);
  border-radius: var(--r-sm);
  padding: 10px 14px;
}

.formula-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.formula-expr {
  font-family: 'SF Mono', 'Cascadia Mono', Consolas, monospace;
  color: var(--c-text);
  font-weight: 500;
  font-size: 12px;
}

.formula-desc {
  margin: 6px 0 0;
  line-height: 1.6;
  color: var(--c-text-muted);
}

.formula-tag {
  background: var(--c-primary);
  color: #fff;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 10px;
  flex-shrink: 0;
}

/* ----- Toast ----- */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--c-text);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--r-md);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  opacity: 0;
  transition: all var(--t-normal);
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ----- Scrollbar ----- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--c-border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--c-text-muted);
}

/* ----- Responsive ----- */
@media (max-width: 1200px) {
  .dashboard {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .grid-head, .emp-row {
    grid-template-columns: 220px minmax(0, 1.5fr) minmax(380px, 1fr) 170px;
  }
}

/* Narrow screens: work columns fall back to single-card rows */
@media (max-width: 1180px) {
  .grid-head, .emp-row {
    grid-template-columns: 200px minmax(0, 1fr) minmax(0, 1fr) 160px;
  }
  .drop-zone {
    grid-template-columns: 1fr;
  }
  .pool-financial {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .pool-fixed {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .load-scale-items {
    grid-template-columns: repeat(2, 1fr);
  }
  .pool-financial {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .pool-fixed {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  /* Collapse the 4-column employee grid into stacked blocks (tablet portrait / phone) */
  .grid-head { display: none; }
  .emp-row {
    grid-template-columns: 1fr;
  }
  .emp-info { border-right: none; border-bottom: 1px solid var(--c-border-light); }
  .drop-zone { border-right: none; border-bottom: 1px solid var(--c-border-light); min-height: 100px; }
  .load-cell { border-left: none; border-top: 1px solid var(--c-border-light); flex-direction: row; }
  .emp-info::before,
  .drop-zone::before,
  .load-cell::before {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    color: var(--c-text-secondary);
    background: var(--bg-pool);
    border: 1px solid var(--c-border-light);
    border-radius: 999px;
    padding: 5px 10px;
    margin-bottom: 10px;
    align-self: flex-start;
  }
  .emp-info::before { content: '人员配置'; }
  .drop-zone::before { grid-column: 1 / -1; }
  .drop-zone[data-category="financial"]::before { content: '财务工作'; }
  .drop-zone[data-category="fixed"]::before { content: '固定工作'; }
  .load-cell::before { content: '负荷分析'; }
}

@media (max-width: 560px) {
  .header-content { padding: 12px; }
  .header-title h1 { font-size: 17px; }
  .header-title .subtitle { font-size: 10px; }
  .header-actions, .header-admin { gap: 6px; }
  .header-actions .btn, .header-admin .btn { padding: 7px 11px; font-size: 12px; }
  .admin-badge { font-size: 10px; }
  .dashboard { grid-template-columns: 1fr; gap: 10px; padding: 12px; }
  .pool-section, .grid-section { padding: 10px 12px; }
  .pool { padding: 10px; }
  .pool-financial {
    grid-template-columns: 1fr;
  }
  .pool-fixed {
    grid-template-columns: 1fr;
  }
  .drop-zone { padding: 10px; min-height: 80px; }
  .emp-info, .load-cell { padding: 14px 12px; }
  .load-scale-items { grid-template-columns: 1fr; }
  .load-scale-block { padding: 12px; }
  .param-scale-row {
    grid-template-columns: 1fr;
    grid-template-areas: "info" "track" "ticks";
    gap: 8px;
  }
  .app-footer { padding: 10px 12px; }
  .formula-block { padding: 8px 12px; }
  .modal-body { padding: 18px 16px; }
  .modal-foot { padding: 12px 16px; }
  .modal { max-width: 94vw; }
}

@media (max-width: 768px) {
  .header-content {
    padding: 14px 16px;
    flex-direction: column;
    align-items: flex-start;
  }
  .dashboard {
    grid-template-columns: 1fr 1fr;
    padding: 16px;
  }
  .pool-section, .grid-section {
    padding: 12px 16px;
  }
  .emp-info { border-right: none; border-bottom: 1px solid var(--c-border-light); }
  .drop-zone { border-right: none; border-bottom: 1px solid var(--c-border-light); min-height: 100px; }
  .load-cell { border-left: none; border-top: 1px solid var(--c-border-light); flex-direction: row; }
  .app-footer { grid-template-columns: 1fr; padding: 12px 16px; }
}

/* ========================================
   Print / PDF Export (WYSIWYG)
   Keep the page exactly as it looks on screen:
   nothing is hidden, spacing/layout unchanged.
   ======================================== */
@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  body {
    background: #fff !important;
  }
  /* Only pagination nicety: rows/cards never split across pages */
  .work-tag,
  .dashboard-card,
  .load-scale-block,
  .formula-block,
  .emp-row {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .load-gauge-fill { transition: none !important; }
}

/* ----- Sync Status Badge (footer) ----- */
.sync-badge-row {
  display: flex;
  justify-content: center;
  padding: 2px 0 14px;
}
.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #64748b;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 4px 14px;
}
.sync-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
}
.sync-badge.on {
  color: #0f6e56;
  background: #e1f5ee;
  border-color: #9fe1cb;
}
.sync-badge.on::before {
  background: #1d9e75;
}
@media print {
  .sync-badge-row { display: none; }
}
