/* YEA Payroll Forecast — minimal, clean, brand-aligned */
:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --good: #10b981;
  --bad: #ef4444;
  --actual: #1e293b;
  --confirmed: #4f46e5;
  --estimated: #f59e0b;
  --manual: #ec4899;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

#app { max-width: 1400px; margin: 0 auto; padding: 24px; }

header {
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 24px; margin-bottom: 24px;
}
.brand { display: flex; align-items: center; gap: 16px; }
.logo {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px;
}
header h1 { margin: 0; font-size: 22px; font-weight: 700; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.kpis { display: flex; gap: 12px; flex-wrap: wrap; }
.kpi {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 18px; min-width: 140px;
}
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-value { font-size: 22px; font-weight: 700; margin: 4px 0; }
.kpi-sub { font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab {
  background: transparent; border: none; padding: 10px 16px; cursor: pointer;
  font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.view { display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px;
}
.card h2 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* bar chart */
.bar-chart { display: flex; gap: 12px; align-items: flex-end; height: 220px; padding: 16px 0; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; }
.bar-segs {
  width: 100%; height: 180px; display: flex; flex-direction: column-reverse;
  justify-content: flex-start; align-items: stretch;
  background: var(--bg); border-radius: 6px 6px 0 0; overflow: hidden;
}
.seg { width: 100%; min-height: 1px; }
.bar-label { font-size: 11px; color: var(--muted); margin-top: 6px; }
.bar-value { font-size: 12px; font-weight: 600; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; padding: 8px 0; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* group cards */
.group-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.group-card {
  background: linear-gradient(135deg, #fff 0%, var(--primary-soft) 100%);
}
.group-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.group-total { font-size: 22px; font-weight: 700; margin: 4px 0; color: var(--primary); }
.group-sub { font-size: 12px; color: var(--muted); }
.group-card.intern { background: linear-gradient(135deg, #fff, #f1f5f9); }
.group-card.intern .group-total { color: var(--muted); }

/* dept card */
.dept-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.dept-total .kpi-label { text-align: right; }
.dept-total .kpi-value { font-size: 20px; }
.month-row { display: flex; gap: 8px; padding: 12px 0; border-top: 1px solid var(--border); margin-bottom: 12px; flex-wrap: wrap; }
.month-cell {
  flex: 1; min-width: 100px; padding: 8px 12px;
  background: var(--bg); border-radius: 8px;
}
.m-label { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.m-value { font-size: 15px; font-weight: 600; margin-top: 2px; }

/* tables */
.scroll-x { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); font-weight: 600; background: var(--bg); }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.b { font-weight: 600; }

th.hist, td.hist { background: var(--bg); }
th.fc, td.fc { background: #fef3c7; }

/* cell color by source */
.cell-actual { color: var(--ink); font-weight: 500; }
.cell-confirmed { color: var(--confirmed); }
.cell-estimated { color: var(--estimated); }
.cell-manual { color: var(--manual); font-weight: 600; }
.cell-inactive { color: var(--muted); opacity: 0.5; }

.clickable { cursor: pointer; transition: background 0.1s; }
.clickable:hover { background: var(--primary-soft); }

.dept-row td { font-weight: 500; }
.subtotal-row td { background: var(--primary-soft); font-weight: 600; color: var(--primary); border-top: 2px solid var(--primary); }
.intern-row td { background: #f1f5f9; font-style: italic; }
.total-row td { background: #1e293b; color: #fff; font-weight: 600; }
.grand-total-row td { background: var(--primary); color: #fff; font-weight: 700; font-size: 14px; }

.good { color: var(--good); }
.bad { color: var(--bad); }

/* badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px;
  font-weight: 600; margin-right: 6px;
}
.badge.actual { background: #1e293b; color: #fff; }
.badge.confirmed { background: var(--confirmed); color: #fff; }
.badge.estimated { background: var(--estimated); color: #fff; }
.badge.manual { background: var(--manual); color: #fff; }
.badge.forecast { background: #fef3c7; color: #92400e; }
.cell-legend { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* filter */
.filter-bar { display: flex; gap: 12px; flex-wrap: wrap; }
.filter-bar select, .filter-bar input {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff;
}

/* manage */
.btn {
  padding: 8px 14px; border: 1px solid var(--border); background: #fff; border-radius: 6px;
  cursor: pointer; font-size: 13px; font-weight: 500;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: #4338ca; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: #fee2e2; }

.emp-list { display: flex; flex-direction: column; gap: 8px; }
.emp-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: var(--bg); border-radius: 8px;
}
.emp-row.inactive { opacity: 0.5; }
.emp-name { font-weight: 500; }
.emp-actions { display: flex; gap: 6px; }

/* modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  padding: 20px;
}
.modal {
  background: #fff; border-radius: 12px; padding: 24px;
  max-width: 600px; width: 100%; max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin-top: 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input[type=text], .field input[type=number], .field input[type=month], .field select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.field input[type=checkbox] { width: 16px; height: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.inc-box {
  display: grid; grid-template-columns: 1fr; gap: 6px;
  padding: 8px; background: var(--bg); border-radius: 8px; max-height: 280px; overflow-y: auto;
}
.inc-pick {
  display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px;
  background: #fff; border-radius: 6px; cursor: pointer;
}
.inc-pick:hover { background: var(--primary-soft); }

/* toast */
.toast {
  position: fixed; bottom: 24px; right: 24px; padding: 12px 18px;
  background: var(--ink); color: #fff; border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2); z-index: 2000;
  animation: slideIn 0.2s ease-out;
}
@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

footer { text-align: center; padding: 32px 0 16px; color: var(--muted); font-size: 12px; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* table column overflow guard */
.summary-table { min-width: 900px; }
.emp-table { min-width: 900px; }

/* responsive */
@media (max-width: 720px) {
  #app { padding: 12px; }
  .kpis { gap: 8px; }
  .kpi { min-width: 110px; padding: 10px 12px; }
  .kpi-value { font-size: 16px; }
  header h1 { font-size: 18px; }
}
