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

:root {
  --bg:        #0b0f1a;
  --surface:   #111827;
  --surface2:  #1a2235;
  --border:    rgba(255,255,255,0.07);
  --accent:    #00d4b4;
  --accent2:   #0ea5e9;
  --danger:    #f43f5e;
  --warn:      #f59e0b;
  --success:   #10b981;
  --text:      #f0f4ff;
  --muted:     #6b7a99;
  --font-disp: 'Syne', sans-serif;
  --font-body: 'DM Sans', sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(0,212,180,0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 90% 110%, rgba(14,165,233,0.07) 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(255,255,255,0.02) 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(255,255,255,0.02) 40px);
}

/* ── TOPBAR ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 32px; height: 64px;
  background: rgba(17,24,39,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.brand-name {
  font-family: var(--font-disp); font-size: 17px; font-weight: 700;
  background: linear-gradient(90deg, #fff 60%, var(--accent));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-date { font-size: 13px; color: var(--muted); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: var(--bg);
}

/* ── LAYOUT ── */
.app-layout { display: flex; min-height: calc(100vh - 64px); }

/* ── SIDEBAR ── */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: rgba(17,24,39,0.6);
  border-right: 1px solid var(--border);
  padding: 24px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.sidebar-section {
  font-size: 10px; font-weight: 600; letter-spacing: 1.2px;
  color: var(--muted); text-transform: uppercase;
  padding: 0 10px; margin: 8px 0 6px;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  font-family: var(--font-body); font-size: 14px; font-weight: 500;
  color: var(--muted); background: transparent; border: none; cursor: pointer;
  transition: all 0.18s; width: 100%; text-align: left;
}
.nav-btn:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.nav-btn.tab-active {
  background: rgba(0,212,180,0.12); color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

/* ── MAIN ── */
.main-content { flex: 1; padding: 32px 36px; overflow-y: auto; }

/* ── PAGE HEADER ── */
.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 28px;
}
.page-title { font-family: var(--font-disp); font-size: 26px; font-weight: 700; }
.page-subtitle { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ── CONTROLS BAR ── */
.controls-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 20px; margin-bottom: 24px;
}
.ctrl-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.ctrl-spacer { flex: 1; }

/* ── INPUTS ── */
input[type="date"], input[type="number"], select, .ctrl-input {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 8px 12px; border-radius: 7px;
  font-family: var(--font-body); font-size: 14px;
  outline: none; transition: border-color 0.2s;
}
input[type="date"]:focus, input[type="number"]:focus, select:focus {
  border-color: var(--accent);
}

/* ── BUTTONS ── */
button {
  font-family: var(--font-body); cursor: pointer;
  transition: all 0.2s; border: none;
}
.btn-primary {
  padding: 9px 20px; border-radius: 7px;
  font-size: 14px; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: var(--bg);
}
.btn-primary:hover { opacity: 0.85; transform: translateY(-1px); }
.btn-ghost {
  padding: 9px 18px; border-radius: 7px;
  font-size: 14px; font-weight: 500;
  background: transparent; border: 1px solid var(--border); color: var(--text);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger {
  padding: 9px 18px; border-radius: 7px;
  font-size: 14px; font-weight: 500;
  background: transparent; border: 1px solid rgba(244,63,94,0.3); color: var(--danger);
}
.btn-danger:hover { background: rgba(244,63,94,0.1); }

/* ── CARD ── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden; margin-bottom: 20px;
}

/* ── TABLE ── */
table { width: 100%; border-collapse: collapse; }
thead tr { background: var(--surface2); }
th {
  font-family: var(--font-disp); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px; color: var(--muted);
  padding: 14px 20px; text-align: left;
}
td { padding: 13px 20px; font-size: 14px; border-top: 1px solid var(--border); }
tbody tr { transition: background 0.15s; }
tbody tr:hover td { background: rgba(255,255,255,0.025); }

/* row status colours */
tr.present td:first-child { border-left: 3px solid var(--success); }
tr.absent  td:first-child { border-left: 3px solid var(--danger); }
tr.leave   td:first-child { border-left: 3px solid var(--warn); }
tr.wfh     td:first-child { border-left: 3px solid var(--accent2); }
tr.awol    td:first-child { border-left: 3px solid #a855f7; }

/* select inside table */
td select {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 6px 10px; border-radius: 6px;
  font-size: 13px; min-width: 130px;
}

/* ── KPI GRID ── */
.kpi-container {
  display: grid; grid-template-columns: repeat(4,1fr); gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px 24px; position: relative; overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
#kpiPresent::before { background: var(--success); }
#kpiAbsent::before  { background: var(--danger); }
#kpiLeave::before   { background: var(--warn); }
#kpiRate::before    { background: linear-gradient(90deg, var(--accent), var(--accent2)); }

.kpi-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--muted); margin-bottom: 8px;
}
.kpi-value {
  font-family: var(--font-disp); font-size: 36px; font-weight: 800; line-height: 1;
}
#kpiPresent .kpi-value { color: var(--success); }
#kpiAbsent  .kpi-value { color: var(--danger); }
#kpiLeave   .kpi-value { color: var(--warn); }
#kpiRate    .kpi-value {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

/* ── CHARTS ── */
.charts-row { display: grid; grid-template-columns: 1fr 2fr; gap: 16px; }
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px 24px;
}
.chart-title {
  font-family: var(--font-disp); font-size: 14px; font-weight: 700;
  margin-bottom: 16px; color: var(--text);
}
#attendanceChart, #trendChart { max-height: 240px; }

/* ── CALENDAR ── */
#calendar {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 8px; margin-top: 16px;
}
.day {
  aspect-ratio: 1; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid transparent; color: var(--text); width: auto; height: auto;
  line-height: normal;
}
.day:hover { transform: scale(1.1); box-shadow: 0 4px 16px rgba(0,0,0,0.4); }

/* override inline bg colours from JS with themed versions */
.day[style*="#28a745"] { background: rgba(16,185,129,0.18) !important; color: #10b981 !important; border-color: rgba(16,185,129,0.3) !important; }
.day[style*="#ffc107"] { background: rgba(245,158,11,0.18) !important; color: #f59e0b !important; border-color: rgba(245,158,11,0.3) !important; }
.day[style*="#dc3545"] { background: rgba(244,63,94,0.18)  !important; color: #f43f5e !important; border-color: rgba(244,63,94,0.3)  !important; }
.day[style*="#e0e0e0"] { background: var(--surface2) !important; color: var(--muted) !important; }

/* ── LEGEND ── */
.legend-box {
  margin-top: 20px; padding: 16px 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; display: inline-flex; gap: 24px; flex-wrap: wrap;
}
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.green  { background: var(--success); }
.yellow { background: var(--warn); }
.red    { background: var(--danger); }
.grey   { background: var(--muted); }

/* ── SUMMARY TABLE ── */
#summaryResults table { border-radius: 14px; overflow: hidden; }
#summaryResults th { background: var(--surface2); }
#summaryResults td { border-top: 1px solid var(--border); }

/* ── TAB CONTENT ── */
.tab-content { display: none; animation: fadeUp 0.3s ease both; }

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

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── DAY DETAILS ── */
#dayDetails {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 20px; margin-bottom: 20px;
  font-size: 14px; color: var(--muted);
}
#dayDetails table th { background: var(--surface2); }
#dayDetails strong { color: var(--accent); }

/* ── FILTER ROW ── */
.filter-row {
  display: flex; align-items: center; gap: 12px;
  margin-top: 20px;
}

/* ── TREND BOX ── */
#trendBox { margin-bottom: 8px; }

.staff-link {
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  transition: color 0.2s ease;
}

.staff-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.person-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.person-stat {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.person-stat-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.8px;
}

.person-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.person-history-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

.person-history-table th,
.person-history-table td {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  text-align: left;
}

.person-history-table th {
  background: var(--surface2);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

@media (max-width: 900px) {
  .person-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .person-stats {
    grid-template-columns: 1fr;
  }
}
