/* ============================================================
   EMS / Attendance System - Modern Theme
   Built on Bootstrap 5.3 + Bootstrap Icons
   ============================================================ */

:root {
  --bs-primary: #4f46e5;
  --bs-primary-rgb: 79, 70, 229;
  --brand-grad: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --surface: #ffffff;
  --surface-2: #f6f7fb;
  --border-soft: #eceef3;
  --text-muted: #6b7280;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
  --radius: 14px;
}

* { -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
  background: var(--surface-2);
  color: #111827;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Navbar ---------- */
.app-navbar {
  background: var(--brand-grad);
  box-shadow: var(--shadow-md);
  padding: .5rem 1rem;
}
.app-navbar .navbar-brand {
  font-weight: 700;
  letter-spacing: .2px;
  display: flex;
  align-items: center;
  gap: .5rem;
  white-space: nowrap;
}
.app-navbar .navbar-brand .brand-dot {
  width: 30px; height: 30px;
  background: rgba(255,255,255,.18);
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 1.05rem;
}
/* Allow the nav list to WRAP to multiple rows on desktop so all items stay
   visible instead of overflowing off-screen. */
.app-navbar .navbar-nav {
  flex-wrap: wrap;
  row-gap: 2px;
}
.app-navbar .nav-link {
  color: rgba(255,255,255,.85) !important;
  border-radius: 8px;
  padding: .4rem .65rem !important;
  margin: 1px 1px;
  font-weight: 500;
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: .4rem;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.app-navbar .nav-link:hover { background: rgba(255,255,255,.14); color: #fff !important; }
.app-navbar .nav-link.active { background: rgba(255,255,255,.22); color: #fff !important; }
.app-navbar .nav-link i { font-size: 1rem; }

.app-navbar .navbar-toggler {
  border-color: rgba(255,255,255,.35);
  padding: .35rem .55rem;
}
.app-navbar .navbar-toggler:focus { box-shadow: 0 0 0 3px rgba(255,255,255,.25); }

/* Make sure the right-side user chip aligns with the brand row, not the
   wrapping nav. Push it to its own line on small desktops if needed. */
.app-navbar .navbar-collapse { align-items: flex-end; }

.user-chip {
  display: flex; align-items: center; gap: .5rem;
  background: rgba(255,255,255,.16);
  padding: .3rem .7rem .3rem .35rem;
  border-radius: 999px;
  color: #fff;
  font-weight: 500;
  font-size: .9rem;
}
.user-chip .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: grid; place-items: center;
  font-weight: 700; font-size: .8rem;
}

/* ---------- Layout ---------- */
.app-container { max-width: 1200px; margin: 0 auto; padding: 1.1rem; }
.page-head { margin-bottom: 1.1rem; }
.page-head h1, .page-head h3 {
  margin: 0; font-weight: 700; font-size: 1.4rem;
  display: flex; align-items: center; gap: .5rem;
}
.page-head .sub { color: var(--text-muted); font-size: .9rem; margin-top: .2rem; }

/* ---------- Cards ---------- */
.card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}
.card-header {
  background: #fff;
  border-bottom: 1px solid var(--border-soft);
  font-weight: 600;
  border-radius: var(--radius) var(--radius) 0 0 !important;
  padding: .85rem 1.1rem;
}
.card-body { padding: 1.1rem; }

/* ---------- Stat cards ---------- */
.stat-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; gap: 1rem;
  height: 100%;
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card .ico {
  width: 50px; height: 50px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.4rem; color: #fff;
  flex-shrink: 0;
}
.stat-card .num { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-card .lbl { color: var(--text-muted); font-size: .82rem; margin-top: .25rem; }
.ico-indigo { background: linear-gradient(135deg,#4f46e5,#7c3aed); }
.ico-green   { background: linear-gradient(135deg,#10b981,#059669); }
.ico-rose    { background: linear-gradient(135deg,#f43f5e,#e11d48); }
.ico-amber   { background: linear-gradient(135deg,#f59e0b,#d97706); }
.ico-sky     { background: linear-gradient(135deg,#0ea5e9,#2563eb); }
.ico-slate   { background: linear-gradient(135deg,#64748b,#334155); }
.ico-violet  { background: linear-gradient(135deg,#a855f7,#7c3aed); }

/* ---------- Buttons ---------- */
.btn { border-radius: 10px; font-weight: 600; }
.btn-lg { border-radius: 12px; }
.btn-primary { background: var(--bs-primary); border-color: var(--bs-primary); }
.btn-primary:hover { background: #4338ca; border-color: #4338ca; }
.btn-soft { background: #eef2ff; color: #4338ca; border: 1px solid #e0e7ff; }
.btn-soft:hover { background: #e0e7ff; color: #3730a3; }

/* ---------- Punch UI ---------- */
.punch-stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #111827;
  aspect-ratio: 3/4;
  max-height: 60vh;
  width: 100%;
  margin: 0 auto;
  box-shadow: var(--shadow-lg);
}
.punch-stage video, .punch-stage canvas {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.punch-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 1rem;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,0,0,.45) 0%, rgba(0,0,0,0) 25%, rgba(0,0,0,0) 70%, rgba(0,0,0,.55) 100%);
  color: #fff;
}
.punch-tag {
  align-self: flex-start;
  background: rgba(0,0,0,.45);
  border: 1px solid rgba(255,255,255,.2);
  padding: .3rem .7rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600;
  display: flex; align-items: center; gap: .4rem;
  backdrop-filter: blur(4px);
}
.gps-pill {
  align-self: flex-start;
  background: rgba(0,0,0,.45);
  border: 1px solid rgba(255,255,255,.2);
  padding: .35rem .7rem; border-radius: 999px;
  font-size: .76rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: .4rem;
  backdrop-filter: blur(4px);
}
.gps-dot { width: 9px; height: 9px; border-radius: 50%; background: #f59e0b; box-shadow: 0 0 0 0 rgba(245,158,11,.6); animation: gpspulse 1.4s infinite; }
.gps-dot.ok { background: #22c55e; animation: none; }
.gps-dot.err { background: #ef4444; animation: none; }
@keyframes gpspulse { 0%{box-shadow:0 0 0 0 rgba(245,158,11,.5)} 70%{box-shadow:0 0 0 8px rgba(245,158,11,0)} 100%{box-shadow:0 0 0 0 rgba(245,158,11,0)} }

.punch-capture-btn {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  width: 74px; height: 74px; border-radius: 50%;
  background: #fff; border: 4px solid rgba(255,255,255,.85);
  box-shadow: 0 0 0 4px rgba(255,255,255,.25), var(--shadow-lg);
  display: grid; place-items: center; color: #111827; font-size: 1.6rem;
  cursor: pointer; pointer-events: auto;
  transition: transform .1s;
}
.punch-capture-btn:active { transform: translateX(-50%) scale(.94); }
.punch-capture-btn:disabled { opacity: .5; cursor: not-allowed; }

.punch-switch {
  position: absolute; top: 14px; right: 14px;
  background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.25);
  color: #fff; border-radius: 10px; padding: .4rem .55rem;
  font-size: 1.1rem; pointer-events: auto; cursor: pointer; backdrop-filter: blur(4px);
}

.punch-big {
  width: 100%; border-radius: 16px; padding: 1.1rem;
  font-size: 1.15rem; font-weight: 700; letter-spacing: .3px;
  display: flex; align-items: center; justify-content: center; gap: .6rem;
  box-shadow: var(--shadow-md);
  border: none; transition: transform .08s, box-shadow .15s;
}
.punch-big:active { transform: scale(.98); }
.punch-big.in  { background: linear-gradient(135deg,#10b981,#059669); color: #fff; }
.punch-big.out { background: linear-gradient(135deg,#f43f5e,#e11d48); color: #fff; }
.punch-big:disabled { opacity: .6; }

/* timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: .8rem; padding: .6rem 0; border-bottom: 1px solid var(--border-soft); }
.timeline li:last-child { border-bottom: none; }
.timeline .tl-dot {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; color: #fff; font-size: .95rem;
}
.tl-in  { background: linear-gradient(135deg,#10b981,#059669); }
.tl-out { background: linear-gradient(135deg,#f43f5e,#e11d48); }
.timeline .tl-main { font-weight: 600; line-height: 1.2; }
.timeline .tl-sub { color: var(--text-muted); font-size: .82rem; }

/* ---------- Tables ---------- */
.table { margin-bottom: 0; vertical-align: middle; }
.table thead th {
  font-size: .76rem; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); font-weight: 700;
  border-bottom: 1px solid var(--border-soft);
  background: #fbfbfe;
}
.table td { border-color: var(--border-soft); padding: .7rem .8rem; }
.table-striped > tbody > tr:nth-of-type(odd) > * { background: #fafbff; }

.badge-soft-success { background:#d1fae5; color:#065f46; }
.badge-soft-danger  { background:#ffe4e6; color:#9f1239; }
.badge-soft-warning { background:#fef3c7; color:#92400e; }
.badge-soft-info    { background:#e0f2fe; color:#075985; }
.badge-soft-secondary { background:#eef2f7; color:#374151; }

/* ---------- Forms ---------- */
.form-label { font-weight: 600; font-size: .85rem; margin-bottom: .35rem; }
.form-control, .form-select { border-radius: 10px; border-color: #d8dbe5; padding: .6rem .8rem; }
.form-control:focus, .form-select:focus { border-color: var(--bs-primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }

/* ---------- Misc ---------- */
.text-muted-2 { color: var(--text-muted) !important; }
.cursor-pointer { cursor: pointer; }
.divider { height: 1px; background: var(--border-soft); margin: 1rem 0; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 2.6rem; opacity: .5; display: block; margin-bottom: .5rem; }

@media (max-width: 575.98px) {
  .app-container { padding: .8rem; }
  .page-head h1, .page-head h3 { font-size: 1.2rem; }
  .app-navbar .nav-link { margin: 2px 0; }
  .stat-card .num { font-size: 1.35rem; }
}

/* When the collapsed mobile menu opens, stack items full-width with labels */
@media (max-width: 991.98px) {
  .app-navbar .navbar-nav { flex-direction: column; width: 100%; }
  .app-navbar .nav-link { width: 100%; }
  .app-navbar .navbar-collapse { align-items: stretch; }
}

/* ---------- Attendance Calendar ---------- */
.cal-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-legend-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap !important;
  padding-bottom: 4px;
}
.cal-dow {
  text-align: center;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  padding: .3rem 0;
}
.cal-cell {
  position: relative;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: .35rem .4rem .4rem;
  min-height: 90px;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cal-cell.cal-empty { background: #f9fafb; border-color: transparent; min-height: 0; }
.cal-today {
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 2px rgba(var(--bs-primary-rgb), .2);
}
.cal-clickable { cursor: pointer; transition: transform .1s, box-shadow .15s; }
.cal-clickable:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); z-index: 2; }

.cal-bar {
  height: 4px;
  border-radius: 999px;
  background: var(--cal-bar, #e5e7eb);
  margin-bottom: .25rem;
  flex-shrink: 0;
}
.cal-daynum {
  font-weight: 700;
  font-size: .85rem;
  line-height: 1;
  color: #111827;
}
.cal-status {
  font-size: .65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .3px;
  margin-top: .1rem;
}
.cal-time {
  font-size: .68rem;
  color: #374151;
  line-height: 1.25;
  margin-top: .1rem;
}
.cal-time i { font-size: .62rem; opacity: .6; }
.cal-worked {
  font-size: .68rem;
  font-weight: 600;
  color: #059669;
  margin-top: .1rem;
}
.cal-ot {
  font-size: .65rem;
  font-weight: 600;
  color: #d97706;
}

/* Legend */
.cal-legend { font-size: .78rem; color: #374151; }
.cal-leg { display: inline-flex; align-items: center; gap: .35rem; }
.cal-leg-dot {
  width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.08);
}

/* Compact calendar on tablet — show bar + day number + status only */
@media (max-width: 767.98px) {
  .cal-grid { gap: 4px; }
  .cal-cell { min-height: 58px; padding: .25rem .3rem; }
  .cal-daynum { font-size: .8rem; }
  .cal-status { font-size: .55rem; margin-top: .15rem; }
  /* Hide the detailed text on tablet — popup has it all */
  .cal-time, .cal-worked, .cal-ot { display: none; }
  /* Make the color bar more prominent */
  .cal-bar { height: 5px; margin-bottom: .2rem; }
}

/* Phone — pure visual mini-calendar: big color bar + day number only */
@media (max-width: 420px) {
  .cal-grid { gap: 3px; }
  .cal-cell {
    min-height: 52px;
    padding: .15rem .2rem;
    /* Tint the whole cell background with the status color for visibility */
    background: color-mix(in srgb, var(--cal-bar, #e5e7eb) 14%, #fff);
  }
  .cal-cell.cal-empty { background: #f9fafb; }
  .cal-bar { height: 6px; margin-bottom: .2rem; border-radius: 6px; }
  .cal-daynum { font-size: .78rem; }
  .cal-status { display: none; }
  .cal-time, .cal-worked, .cal-ot { display: none; }
  .cal-dow { font-size: .62rem; padding: .2rem 0; }
}

/* Very small phones — keep readable, allow horizontal scroll as last resort */
@media (max-width: 360px) {
  .cal-grid { gap: 2px; }
  .cal-cell { min-height: 46px; padding: .12rem .15rem; }
  .cal-daynum { font-size: .72rem; }
  .cal-dow { font-size: .55rem; }
}

/* ============================================================
   Mobile Bottom Navigation Bar
   ============================================================ */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 1040;
  display: flex;
  align-items: stretch;
  background: #fff;
  border-top: 1px solid var(--border-soft);
  box-shadow: 0 -2px 10px rgba(16, 24, 40, .08);
  padding: .3rem 0 calc(.3rem + env(safe-area-inset-bottom, 0px));
  height: auto;
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .15rem;
  padding: .35rem .2rem .2rem;
  text-decoration: none;
  color: var(--text-muted);
  font-size: .62rem;
  font-weight: 600;
  letter-spacing: .2px;
  text-transform: uppercase;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.bottom-nav-item i {
  font-size: 1.25rem;
  line-height: 1;
  transition: transform .15s;
}
.bottom-nav-item.active {
  color: var(--bs-primary);
}
.bottom-nav-item.active i {
  transform: scale(1.1);
}
.bottom-nav-item.active::before {
  content: '';
  position: absolute;
  top: 0; left: 20%; right: 20%;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--bs-primary);
}
.bottom-nav-item:active i {
  transform: scale(.9);
}

/* Push main content above the bottom nav on mobile */
@media (max-width: 991.98px) {
  main.app-container {
    padding-bottom: 4.2rem !important;
  }
}

/* When print, hide bottom nav */
@media print {
  .bottom-nav { display: none !important; }
}
