:root {
  --primary: #4a6cf7;
  --primary-light: #eef1ff;
  --danger: #e74c3c;
  --success: #27ae60;
  --warning: #f39c12;
  --gray: #95a5a6;
  --gray-light: #f8f9fa;
  --border: #dfe4ea;
  --text: #2d3436;
  --text-light: #636e72;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  color: var(--text);
  background: #f5f6fa;
  line-height: 1.6;
}
.container { max-width: 1400px; margin: 0 auto; padding: 20px; }

/* Header */
.header {
  text-align: center;
  padding: 40px 20px 30px;
  background: linear-gradient(135deg, #4a6cf7 0%, #6c5ce7 100%);
  color: #fff;
  border-radius: 12px;
  margin-bottom: 24px;
}
.header h1 { font-size: 28px; font-weight: 600; margin-bottom: 8px; }
.header p { opacity: .85; font-size: 14px; }

/* Upload Area */
.upload-area {
  background: #fff;
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  margin-bottom: 24px;
  position: relative;
}
.upload-area:hover,
.upload-area.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.upload-area .icon { font-size: 40px; margin-bottom: 12px; }
.upload-area .hint { color: var(--text-light); font-size: 14px; }
.upload-area .filename {
  display: none;
  margin-top: 12px;
  padding: 8px 16px;
  background: var(--primary-light);
  border-radius: 8px;
  color: var(--primary);
  font-size: 14px;
}
.upload-area.has-file { border-style: solid; border-color: var(--success); }
.upload-area.has-file .filename { display: inline-block; }
.upload-area input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}

/* Controls */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.controls .info { font-size: 14px; color: var(--text-light); }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #3b5de7; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #219a52; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--gray-light); }
.btn-outline-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}
.btn-outline-danger:hover { background: #fdf0ef; }

/* Table */
.table-wrap {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  overflow-x: auto;
  margin-bottom: 24px;
}
table {
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}
thead { background: #f8f9fc; }
thead th {
  position: sticky; top: 0;
  background: #f8f9fc;
  padding: 12px 10px;
  font-weight: 600;
  text-align: left;
  border-bottom: 2px solid var(--border);
  z-index: 2;
}
.th-name { z-index: 3; background: #f8f9fc; }
.td-name { position: sticky; left: 0; background: #fff; }
tbody tr:hover .td-name { background: #fafbfc; }
.dept-col { min-width: 180px; white-space: normal; word-break: break-all; }
tbody td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: none; }

.employee-name { font-weight: 600; }
.employee-dept { color: var(--text-light); font-size: 12px; }

.salary-input {
  width: 100px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  text-align: right;
}
.salary-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74,108,247,.15); }

.rate-input {
  width: 60px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  text-align: right;
}
.rate-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(74,108,247,.15); }

.stat-value { font-weight: 500; }
.stat-negative { color: var(--danger); }
.stat-money { font-weight: 600; }
.stat-final {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  text-shadow: 0 1px 2px rgba(74,108,247,0.2);
}

/* Daily Calendar — 7-column grid */
.daily-grid {
  display: grid;
  grid-template-columns: repeat(7, 18px);
  gap: 2px;
}
.day-cell {
  width: 18px; height: 18px;
  border-radius: 3px;
  font-size: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  position: relative;
}
.day-cell.wd { background: none; color: var(--text-light); font-size: 7px; height: 14px; cursor: default; border-radius: 0; pointer-events: none; }
.day-cell.normal { background: #d4edda; color: #155724; }
.day-cell.rest { background: #e9ecef; color: #6c757d; }
.day-cell.miss { background: #fff3cd; color: #856404; }
.day-cell.entry { background: #cce5ff; color: #004085; }
.day-cell.overtime { background: #cce5ff; color: #004085; }
.day-cell.absent { background: #f8d7da; color: #721c24; }
.day-cell.comp { background: #d1ecf1; color: #0c5460; }
.day-cell.none { background: #f8f9fa; }

.day-cell:hover::after {
  content: attr(title);
  position: absolute;
  bottom: 120%;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 10px;
  white-space: nowrap;
  z-index: 10;
}

/* Summary */
.summary-wrap {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  padding: 20px;
  margin-bottom: 24px;
}
.summary-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.summary-card {
  background: var(--gray-light);
  border-radius: 8px;
  padding: 14px 16px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.summary-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.summary-card .label { font-size: 12px; color: var(--text-light); margin-bottom: 4px; }
.summary-card .value { font-size: 18px; font-weight: 700; }
.summary-card .value.primary { color: var(--primary); }
.summary-card .value.danger { color: var(--danger); }
.summary-card .value.success { color: var(--success); }

/* Rules Panel */
.rules-wrap {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  margin-bottom: 20px;
  overflow: hidden;
  transition: all 0.3s ease;
}
.rules-wrap:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.rules-title-static {
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.rules-body-static {
  display: block !important;
  padding: 16px 20px 20px;
}
.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.rule-item {
  background: var(--gray-light);
  border-radius: 8px;
  padding: 12px 14px;
}
.rule-name { font-size: 12px; color: var(--primary); font-weight: 600; margin-bottom: 4px; }
.rule-formula { font-size: 13px; color: var(--text); }
.rule-formula small { color: var(--text-light); font-size: 11px; }

/* Footer */
.footer {
  text-align: center;
  padding: 20px;
  color: var(--text-light);
  font-size: 13px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 15px; }

/* Print */
@media print {
  body { background: #fff; }
  .header { background: #4a6cf7 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .upload-area, .controls, .no-print { display: none !important; }
  .table-wrap { box-shadow: none; border: 1px solid #ddd; border-radius: 0; }
  .day-cell { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .day-cell.normal { background: #d4edda !important; }
  .day-cell.rest { background: #e9ecef !important; }
  .day-cell.miss { background: #fff3cd !important; }
  .day-cell.entry { background: #cce5ff !important; }
  .day-cell.overtime { background: #cce5ff !important; }
  .day-cell.absent { background: #f8d7da !important; }
  .day-cell.comp { background: #d1ecf1 !important; }
}

/* Responsive */
@media (max-width: 768px) {
  .container { padding: 12px; }
  .header { padding: 24px 16px; }
  .header h1 { font-size: 22px; }
  .salary-input { width: 80px; }
  .leave-input { width: 60px; }
}

/* Scrollbar styling */
.table-wrap::-webkit-scrollbar {
  height: 8px;
}
.table-wrap::-webkit-scrollbar-track {
  background: var(--gray-light);
  border-radius: 4px;
}
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--gray);
  border-radius: 4px;
}
.table-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--text-light);
}

/* Input focus states */
input[type="number"]:focus {
  outline: none;
}

/* Static rules (always visible at bottom) */
.rules-static {
  margin-top: 24px;
}
.rules-title-static {
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.rules-body-static {
  display: block !important;
  padding: 16px 20px 20px;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}
.modal-overlay.active {
  display: flex;
}
.modal-content {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 680px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-light);
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 20px 24px 24px;
}
.settings-group {
  margin-bottom: 24px;
}
.settings-group:last-child {
  margin-bottom: 0;
}
.settings-group-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
