/* ==================== CSS 变量 ==================== */
:root {
  --primary: #2563eb;
  --primary-light: #eef2ff;
  --danger: #b91c1c;
  --border: #e2e8f0;
  --bg: #f5f7fb;
  --card-bg: #fff;
  --text: #1e293b;
  --text-secondary: #475569;
  --shadow: 0 8px 20px rgba(0,0,0,0.04);
  --radius: 16px;
}

/* ==================== 基础样式 ==================== */
* { box-sizing: border-box; margin: 0; font-family: 'Microsoft YaHei', 'Segoe UI', Roboto, sans-serif; }

body {
  background: var(--bg);
  padding: 20px;
  min-width: 320px;
}

/* ==================== 主容器 ==================== */
.app-container {
  max-width: 100%;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  transition: all 0.2s;
}

/* ==================== 标题区域 ==================== */
.title-section {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

h1 { font-size: 26px; font-weight: 500; color: var(--text); letter-spacing: 1px; }

.year-month-badge {
  font-size: 22px;
  font-weight: 400;
  color: var(--primary);
  background: var(--primary-light);
  padding: 4px 16px;
  border-radius: 40px;
}

/* ==================== 统计区域 ==================== */
.stats-row {
  display: flex;
  gap: 30px;
  background: #f8fafc;
  padding: 16px 24px;
  border-radius: 20px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.stat-item { display: flex; align-items: baseline; gap: 8px; }
.stat-label { color: var(--text-secondary); font-weight: 500; }
.stat-number { font-size: 28px; font-weight: 700; color: #0f172a; }
.stat-unit { color: #64748b; font-size: 14px; margin-left: 4px; }

/* ==================== 图表区域 ==================== */
.chart-container {
  background: #ffffff;
  border-radius: 20px;
  padding: 16px 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.chart-container h3 {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

canvas { max-height: 220px; width: 100%; }

/* ==================== 工具栏 ==================== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-bottom: 20px;
  background: white;
  padding: 8px 0;
}

.tool-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ==================== 按钮样式 ==================== */
button, .month-picker, .search-box {
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 30px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

button:hover { background: #f1f5f9; border-color: #94a3b8; }
button.primary { background: var(--primary); border-color: var(--primary); color: white; }
button.primary:hover { background: #1d4ed8; }
button.danger { color: var(--danger); border-color: #fecaca; }
button.danger:hover { background: #fee2e2; }

.search-box { width: 220px; outline: none; }
.search-box:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.month-picker { padding: 7px 12px; }

/* ==================== 表格区域 ==================== */
.table-wrapper {
  overflow-x: auto;
  margin-top: 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
  max-height: 600px;
  overflow-y: auto;
  position: relative;
}

table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 14px;
  table-layout: auto;
  white-space: nowrap;
}

thead tr { position: sticky; top: 0; background: #f1f5f9; z-index: 10; }

th {
  padding: 10px 8px;
  text-align: center;
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid #cbd5e1;
  border-right: 1px solid #d1d5db;
  background: #f1f5f9;
}

td {
  padding: 8px 6px;
  text-align: center;
  border-right: 1px solid #e9eef3;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

/* 固定列样式 */
th.sticky-left, td.sticky-left {
  position: sticky;
  left: 0;
  background: #f8fafc;
  z-index: 5;
  box-shadow: 2px 0 5px -2px rgba(0,0,0,0.05);
}

td.sticky-left { background: white; }

th.sticky-right, td.sticky-right {
  position: sticky;
  right: 0;
  background: #f8fafc;
  z-index: 5;
  box-shadow: -2px 0 5px -2px rgba(0,0,0,0.05);
}

td.sticky-right { background: white; }

/* ==================== 特殊单元格样式 ==================== */
.weekend-day { color: #dc2626 !important; font-weight: 500; }
.today-cell { background: #fef9c3 !important; font-weight: 600; }
.checked-meal { background: #dbeafe !important; }

/* 可编辑单元格 */
td[contenteditable="true"] {
  background: #fffbeb;
  cursor: text;
  outline: 2px solid #fbbf24;
  outline-offset: -1px;
}

td[contenteditable="true"]:hover { background: #fef3c7; }

/* 统计行 */
.stat-row td {
  background: #f1f5f9;
  font-weight: 500;
  color: #0b3b5c;
  border-top: 2px solid #94a3b8;
}

/* 删除按钮 */
.delete-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-weight: bold;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 20px;
}

.delete-btn:hover { background: #fee2e2; }

/* 页脚提示 */
.footer-note { margin-top: 16px; color: #64748b; font-size: 13px; }

/* ==================== 打印样式 ==================== */
@media print {
  @page {
    size: landscape;
    margin: 0.5cm;
  }
  
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  body { 
    background: white; 
    padding: 0; 
    margin: 0;
    font-size: 12px;
  }
  
  .app-container { 
    box-shadow: none; 
    padding: 10px; 
    max-width: 100%;
  }
  
  .toolbar, .stats-row, .chart-container, .no-print, .footer-note { 
    display: none !important; 
  }
  
  .title-section {
    margin-bottom: 10px;
  }
  
  .title-section h1 {
    font-size: 18px;
  }
  
  .year-month-badge {
    font-size: 16px;
  }
  
  .table-wrapper { 
    overflow: visible; 
    border: 1px solid #ccc; 
    max-height: none;
    max-width: 100%;
  }
  
  table { 
    width: 100%; 
    border-collapse: collapse;
    font-size: 10px;
  }
  
  th, td { 
    border: 1px solid #666; 
    padding: 4px 2px;
    font-size: 9px;
  }
  
  th { 
    background: #f0f0f0 !important;
    font-weight: bold;
  }
  
  .sticky-left, .sticky-right {
    position: static !important;
    box-shadow: none !important;
  }
  
  .sticky-right { 
    display: none; 
  }
  
  /* 隐藏固定列阴影效果 */
  td.sticky-left, th.sticky-left {
    background: white !important;
  }
}

/* ==================== 内联输入样式 ==================== */
.inline-input {
  width: 100%;
  border: 2px solid var(--primary);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  outline: none;
  background: #fffbeb;
}

.name-input { min-width: 80px; }
.dept-input { min-width: 100px; }

.new-person-row {
  background: #fffbeb !important;
}

.new-person-row td { background: #fffbeb; }

.confirm-add-btn, .cancel-add-btn {
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 14px;
  cursor: pointer;
}

.confirm-add-btn { color: #16a34a; }
.confirm-add-btn:hover { background: #dcfce7; border-color: #16a34a; }

.cancel-add-btn { color: var(--danger); }
.cancel-add-btn:hover { background: #fee2e2; border-color: var(--danger); }

/* ==================== 节假日面板样式 ==================== */
.holiday-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  z-index: 1000;
  min-width: 400px;
  max-width: 90vw;
}

.holiday-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--primary);
  color: white;
  border-radius: 16px 16px 0 0;
  font-weight: 600;
}

.holiday-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
}

.holiday-content {
  padding: 20px;
}

.holiday-tip {
  color: #64748b;
  font-size: 14px;
  margin-bottom: 16px;
}

.holiday-days {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.holiday-day {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: white;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}

.holiday-day:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.holiday-day.weekend {
  color: #dc2626;
}

.holiday-day.skipped {
  background: #fee2e2;
  border-color: #dc2626;
  color: #dc2626;
  text-decoration: line-through;
}

.holiday-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  justify-content: center;
}

.holiday-save-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 30px;
  cursor: pointer;
  font-weight: 500;
}

.holiday-clear-btn {
  background: white;
  border: 1px solid #cbd5e1;
  padding: 10px 24px;
  border-radius: 30px;
  cursor: pointer;
}

/* ==================== 复制月份选择器样式 ==================== */
.copy-month-selector {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
}

.copy-month-selector select {
  padding: 10px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  background: white;
  cursor: pointer;
  min-width: 100px;
}

.copy-month-selector select:focus {
  outline: none;
  border-color: var(--primary);
}
