:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-hover: #15803d;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --warning: #f59e0b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #334155;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* HEADER */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
}
.header-left h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--primary);
}
.session-badge {
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.session-badge.admin { background: var(--warning); }
.subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.clock {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.date { font-size: 11px; color: var(--muted); text-align: right; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--surface-2); }

/* TABS */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1;
  min-width: 100px;
  padding: 14px 16px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* CONTENT */
.content {
  flex: 1;
  padding: 16px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* TOOLBAR */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}
.toolbar input { flex: 1; }
.counter { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* FORM ELEMENTS */
input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
label input, label select { margin-top: 4px; }

.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.form-row > * { flex: 1; min-width: 140px; }
.form-row > button { flex: 0 0 auto; min-width: auto; }

/* BUTTONS */
.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: var(--border); }
.btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn.success { background: var(--success); color: white; border-color: var(--success); }
.btn.success:hover { background: var(--success-hover); border-color: var(--success-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}
.card.danger { border-color: var(--danger); }
.card.danger h2 { color: var(--danger); }

.muted { color: var(--muted); font-size: 13px; line-height: 1.5; margin-bottom: 12px; }

/* EMPLOYEE CARDS */
.employee-list { display: flex; flex-direction: column; gap: 10px; }
.employee-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.employee-card.working { border-left: 4px solid var(--success); }
.employee-card.idle { border-left: 4px solid var(--border); }

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.employee-info { flex: 1; min-width: 0; }
.employee-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.employee-role { font-size: 12px; color: var(--muted); margin-top: 2px; }
.employee-status {
  font-size: 12px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.on { background: var(--success); animation: pulse 2s infinite; }
.status-dot.off { background: var(--muted); }
.status-dot.lunch { background: var(--warning); animation: pulse 2s infinite; }

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

.employee-hours {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.action-btn {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
  border: none;
  cursor: pointer;
  color: white;
  transition: transform 0.1s, background 0.15s;
  flex-shrink: 0;
}
.action-btn:active { transform: scale(0.95); }
.action-btn.in { background: var(--success); }
.action-btn.in:hover { background: var(--success-hover); }
.action-btn.out { background: var(--danger); }
.action-btn.out:hover { background: var(--danger-hover); }
.action-btn.lunch { background: var(--warning); }
.action-btn.lunch:hover { background: #d97706; }

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.action-buttons .action-btn { padding: 8px 14px; font-size: 11px; min-width: 100px; }
.action-buttons:has(.action-btn:only-child) .action-btn { padding: 12px 18px; font-size: 13px; }

/* TEAM LIST */
.team-list { display: flex; flex-direction: column; gap: 8px; }
.team-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.team-row .avatar { width: 36px; height: 36px; font-size: 14px; }
.team-row-info { flex: 1; min-width: 0; }
.team-row-info .name { font-size: 14px; font-weight: 500; }
.team-row-info .role { font-size: 12px; color: var(--muted); }
.team-actions { display: flex; gap: 6px; }
.team-actions button {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.team-actions button:hover { background: var(--border); }
.team-actions .delete { color: var(--danger); }

/* SUMMARY & ENTRIES */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.summary-item {
  background: var(--surface-2);
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.summary-item .label { font-size: 12px; color: var(--muted); }
.summary-item .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.entries { display: flex; flex-direction: column; gap: 6px; max-height: 480px; overflow-y: auto; }
.entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.entry:hover { background: var(--border); }
.entry-type {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.entry-type.in { background: rgba(22, 163, 74, 0.15); color: var(--success); }
.entry-type.out { background: rgba(220, 38, 38, 0.15); color: var(--danger); }
.entry-type.lunch_out, .entry-type.lunch_in { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.entry-emp { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-time {
  font-family: "SF Mono", Consolas, monospace;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.empty-hint {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: all 0.3s;
  z-index: 100;
  max-width: 90%;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); color: white; }
.toast.error { background: var(--danger); color: white; }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.modal-content h2 { margin-bottom: 16px; font-size: 17px; }

/* CALENDAR */
.cal-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.cal-toolbar h2 {
  flex: 1;
  text-align: center;
  text-transform: capitalize;
  margin: 0;
  font-size: 16px;
}
.cal-toolbar .icon-btn { font-size: 22px; padding: 4px 12px; line-height: 1; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-header {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 6px 0;
  font-weight: 600;
  text-transform: uppercase;
}
.cal-day {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  min-height: 64px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cal-day.empty { background: transparent; border: none; cursor: default; min-height: 0; }
.cal-day:hover:not(.empty) { border-color: var(--primary); }
.cal-day.today { border-color: var(--primary); background: rgba(37, 99, 235, 0.08); }
.cal-day.has-work { background: rgba(22, 163, 74, 0.08); border-color: rgba(22, 163, 74, 0.3); }
.cal-day.today.has-work { background: rgba(22, 163, 74, 0.12); border-color: var(--primary); }
.cal-day.selected { outline: 2px solid var(--primary); outline-offset: 1px; }
.cal-day-num { font-weight: 600; font-size: 13px; }
.cal-day-hours {
  font-size: 11px;
  color: var(--success);
  font-weight: 700;
  margin-top: auto;
  font-variant-numeric: tabular-nums;
}
.cal-day-count { font-size: 10px; color: var(--muted); }
.cal-day.weekend .cal-day-num { color: var(--muted); }

.cal-legend {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 11px;
  color: var(--muted);
  flex-wrap: wrap;
}
.cal-legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}
.cal-legend .dot.has-work { background: rgba(22, 163, 74, 0.3); border: 1px solid rgba(22, 163, 74, 0.5); }
.cal-legend .dot.today { background: rgba(37, 99, 235, 0.15); border: 1px solid var(--primary); }

.cal-day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.cal-day-header h2 { margin: 0; text-transform: capitalize; }

/* HOLIDAYS & ABSENCES */
.holiday-list, .absence-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  max-height: 320px;
  overflow-y: auto;
}
.holiday-row, .absence-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.holiday-row .date, .absence-row .dates {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
  white-space: nowrap;
}
.holiday-row .name, .absence-row .info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.absence-row .info .note { color: var(--muted); font-size: 12px; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.badge.holiday { background: rgba(220, 38, 38, 0.15); color: var(--danger); }
.badge.vacation { background: rgba(37, 99, 235, 0.15); color: var(--primary); }
.badge.sick { background: rgba(245, 158, 11, 0.18); color: var(--warning); }
.badge.other { background: var(--border); color: var(--text); }
.btn-icon-x {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}
.btn-icon-x:hover { color: var(--danger); }

/* Calendar holiday/absence markers */
.cal-day.holiday { background: rgba(220, 38, 38, 0.10); border-color: rgba(220, 38, 38, 0.35); }
.cal-day.holiday .cal-day-num { color: var(--danger); }
.cal-day-holiday-name {
  font-size: 9px;
  color: var(--danger);
  font-weight: 600;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.cal-day-absences {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin-top: auto;
}
.cal-day-absences .pip {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
}
.cal-day-absences .pip.sick { background: var(--warning); }
.cal-day-absences .pip.other { background: var(--muted); }

/* TASKS, SKILLS, TEMPLATES */
.task-list, .template-list, .skill-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; max-height: 480px; overflow-y: auto; }
.task-row, .template-row, .skill-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.task-row.done { opacity: 0.6; }
.task-row.done .task-title { text-decoration: line-through; }
.task-row .task-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.task-row .task-emp { font-size: 12px; color: var(--muted); white-space: nowrap; }
.task-row .task-due { font-size: 11px; color: var(--muted); font-family: "SF Mono", Consolas, monospace; }
.task-row .task-due.overdue { color: var(--danger); font-weight: 700; }
.task-check { width: 18px; height: 18px; cursor: pointer; }

.template-row .tmpl-meta { font-size: 11px; color: var(--muted); }
.template-row .tmpl-info { flex: 1; min-width: 0; }

.skill-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  margin-top: 12px;
  align-items: center;
}
.skill-grid .sk-name { font-size: 13px; }
.skill-grid .sk-cat { font-size: 11px; color: var(--muted); }
.sk-stars { display: inline-flex; gap: 2px; cursor: pointer; }
.sk-star { font-size: 18px; color: var(--border); user-select: none; }
.sk-star.filled { color: var(--warning); }

.schedule-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.schedule-grid label { font-size: 11px; color: var(--muted); margin: 0; text-align: center; }
.schedule-grid input { padding: 6px 4px; text-align: center; font-size: 13px; }

/* Login modal extras */
#loginModal .modal-content, #pinModal .modal-content { max-width: 360px; }
#loginPin, #pinModalInput { letter-spacing: 8px; text-align: center; font-size: 22px; font-family: "SF Mono", Consolas, monospace; }

.muted h3 { font-weight: 600; }

/* SURVEYS */
.survey-lib, .survey-inbox { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.survey-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.survey-row .info { flex: 1; min-width: 0; }
.survey-row .title { font-weight: 600; }
.survey-row .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.survey-row .actions { display: flex; gap: 4px; }
.survey-row .actions button { padding: 6px 10px; font-size: 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.survey-row .actions button:hover { background: var(--border); }
.survey-row.pending { border-left: 4px solid var(--warning); }
.survey-row.completed { opacity: 0.7; border-left: 4px solid var(--success); }

.survey-q-editor {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 8px;
}
.survey-q-editor .form-row { gap: 6px; }
.survey-q-editor textarea { min-height: 50px; }

.survey-answer-q {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.survey-answer-q:last-child { border-bottom: none; }
.survey-answer-q .q-text { font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.survey-answer-q label { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 13px; }
.survey-answer-q label input { width: auto; margin-right: 6px; }

.rating-input { display: flex; gap: 6px; }
.rating-input .star { font-size: 26px; cursor: pointer; color: var(--border); }
.rating-input .star.filled { color: var(--warning); }

/* CHARTS */
.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap svg { width: 100%; min-width: 300px; height: auto; max-height: 220px; display: block; }
.chart-bar { fill: var(--primary); transition: fill 0.15s; }
.chart-bar:hover { fill: var(--primary-hover); }
.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-label { font-size: 10px; fill: var(--muted); font-family: -apple-system, sans-serif; }
.chart-value { font-size: 10px; fill: var(--text); font-weight: 600; font-family: -apple-system, sans-serif; }
.chart-empty { color: var(--muted); padding: 20px; text-align: center; font-size: 13px; }

/* PRINT */
@media print {
  .app-header, .tabs, #toast, .modal, #installBtn { display: none !important; }
  body { background: white; color: black; }
  .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
  .tab-panel { display: block !important; }
  .tab-panel:not(.active) { display: none !important; }
}

/* MOBILE */
@media (max-width: 600px) {
  .app-header { padding: 12px 16px; }
  .header-left h1 { font-size: 17px; }
  .clock { font-size: 15px; }
  .date { font-size: 10px; }
  .content { padding: 12px; }
  .employee-card { padding: 12px; gap: 10px; }
  .avatar { width: 38px; height: 38px; font-size: 14px; }
  .action-btn { padding: 10px 14px; font-size: 12px; }
  .action-buttons .action-btn { min-width: 90px; padding: 7px 10px; font-size: 10px; }
  .cal-day { min-height: 52px; padding: 4px; }
  .cal-day-num { font-size: 12px; }
  .cal-day-hours { font-size: 10px; }
  .cal-day-count { display: none; }
  .cal-header { font-size: 10px; padding: 4px 0; }
  .form-row { flex-direction: column; }
  .form-row > * { width: 100%; }
  .tab { padding: 12px 8px; font-size: 13px; }
}
