/* Sams-Soft Attendance System - Mobile-first responsive stylesheet */

:root {
  --primary: #1a237e;
  --primary-light: #3949ab;
  --primary-dark: #0d1456;
  --accent: #5c6bc0;
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --text: #1e2433;
  --muted: #667085;
  --border: #e4e9f2;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0284c7;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 64, 0.06), 0 8px 24px rgba(16, 24, 64, 0.08);
  --sidebar-w: 264px;
  --topbar-h: 64px;
  --tap: 44px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  padding-bottom: env(safe-area-inset-bottom);
}
img { max-width: 100%; height: auto; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-light); }
:focus-visible { outline: 3px solid rgba(57, 73, 171, 0.45); outline-offset: 2px; border-radius: 6px; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 2000;
  background: var(--primary); color: #fff; padding: 10px 16px; border-radius: 0 0 10px 0;
}
.skip-link:focus { left: 0; color: #fff; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; min-height: 100dvh; }
.app-main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: min(var(--sidebar-w), 86vw);
  background: linear-gradient(180deg, #141b5e 0%, var(--primary) 55%, #283593 100%);
  color: #fff; z-index: 1050; display: flex; flex-direction: column;
  transform: translateX(-105%); transition: transform 0.28s ease;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(10, 14, 40, 0.5);
  opacity: 0; pointer-events: none; transition: opacity 0.25s ease; z-index: 1040;
}
.sidebar-overlay.show { opacity: 1; pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.14); }
.brand-mark {
  width: 44px; height: 44px; border-radius: 14px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; color: var(--primary);
  background: linear-gradient(135deg, #fff, #c5cae9);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 17px; letter-spacing: 0.2px; }
.brand-text small { color: rgba(255, 255, 255, 0.72); font-size: 12px; }
.brand-close {
  margin-left: auto; border: 0; border-radius: 10px; width: 40px; height: 40px;
  background: rgba(255, 255, 255, 0.12); color: #fff; font-size: 16px;
}

.nav-menu { overflow-y: auto; padding: 10px 10px 16px; flex: 1; -webkit-overflow-scrolling: touch; }
.nav-section { margin: 14px 8px 6px; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: rgba(255, 255, 255, 0.6); }
.nav-menu .nav-link {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap);
  color: rgba(255, 255, 255, 0.88); padding: 10px 12px; border-radius: 12px; font-weight: 500;
}
.nav-menu .nav-link i { width: 22px; text-align: center; opacity: 0.9; }
.nav-menu .nav-link:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.nav-menu .nav-link.active { background: rgba(255, 255, 255, 0.18); color: #fff; font-weight: 700; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, 0.14); }
.sidebar-foot .logout { color: #ffcdd2; }
.sidebar-foot .version { margin: 8px 4px 0; font-size: 12px; color: rgba(255, 255, 255, 0.6); }

.topbar {
  position: sticky; top: 0; z-index: 1030; min-height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.page-title { margin: 0; font-size: 18px; font-weight: 800; color: var(--primary-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-sub { margin: 0; font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.clock { font-size: 13px; color: var(--muted); }

.icon-btn {
  width: var(--tap); height: var(--tap); border-radius: 12px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--primary);
  font-size: 17px;
}
.icon-btn:hover { background: var(--surface-2); }
.logout-btn { color: var(--danger); border-color: #f3c2c2; }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 999px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: #fff; font-weight: 800;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta strong { font-size: 13px; }
.user-meta small { font-size: 12px; color: var(--muted); }

.content { padding: 14px 14px 96px; width: 100%; max-width: 1280px; margin: 0 auto; }
.footer { text-align: center; padding: 16px 12px 110px; color: var(--muted); font-size: 13px; }

/* Bottom nav (mobile) */
.bottom-nav {
  position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 1045;
  display: flex; background: rgba(255, 255, 255, 0.97); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow); padding: 6px;
}
.bottom-nav a, .bottom-nav button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600; padding: 8px 4px; border-radius: 12px; min-height: 52px;
}
.bottom-nav i { font-size: 18px; }
.bottom-nav .active, .bottom-nav a:hover { color: var(--primary); background: rgba(26, 35, 126, 0.08); }

/* ---------- Page header ---------- */
.page-header {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 14px; box-shadow: var(--shadow);
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
}
.page-header h2 { margin: 0; font-size: 19px; font-weight: 800; color: var(--primary-dark); }
.breadcrumb { margin: 6px 0 0; font-size: 13px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Cards & stats ---------- */
.card { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden; }
.card-header {
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  padding: 12px 14px; font-weight: 700; display: flex; flex-wrap: wrap;
  gap: 10px; align-items: center; justify-content: space-between;
}
.card-body { padding: 14px; }
.card-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }

.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); height: 100%;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.stat-card:hover { transform: translateY(-3px); }
.stat-card .stat-icon {
  width: 46px; height: 46px; border-radius: 14px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; font-size: 20px; color: #fff;
}
.stat-card .stat-value { font-size: 24px; font-weight: 800; }
.stat-card .stat-label { color: var(--muted); font-size: 13px; }
.bg-primary-icon { background: linear-gradient(135deg, #1a237e, #5c6bc0); }
.bg-success-icon { background: linear-gradient(135deg, #15803d, #4ade80); }
.bg-danger-icon { background: linear-gradient(135deg, #b91c1c, #f87171); }
.bg-warning-icon { background: linear-gradient(135deg, #b45309, #fbbf24); }
.bg-info-icon { background: linear-gradient(135deg, #0369a1, #38bdf8); }
.bg-secondary-icon { background: linear-gradient(135deg, #475569, #94a3b8); }

/* ---------- Buttons / forms ---------- */
.btn { border-radius: 12px; font-weight: 600; min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-sm { min-height: 38px; border-radius: 10px; font-size: 13px; }
.action-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.action-btns .btn { flex: 0 0 auto; }

.form-control, .form-select {
  border-radius: 12px; border: 1px solid #cfd7e6; min-height: var(--tap); font-size: 16px;
}
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(26, 35, 126, 0.12); }
.form-label { font-weight: 700; font-size: 14px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.search-bar { position: relative; }
.search-bar i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-bar input { padding-left: 40px; }

/* ---------- Tables -> cards on mobile ---------- */
.table-responsive { border-radius: 0 0 var(--radius) var(--radius); -webkit-overflow-scrolling: touch; }
.table { margin-bottom: 0; font-size: 14px; }
.table thead th {
  background: var(--primary); color: #fff; border: 0; font-weight: 700;
  white-space: nowrap; position: sticky; top: 0;
}
.table tbody td { vertical-align: middle; }
.employee-avatar {
  width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff; font-weight: 700;
}
.badge { padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 12px; }
.badge-success { background: var(--success); }
.badge-danger { background: var(--danger); }
.badge-warning { background: var(--warning); color: #fff; }
.badge-info { background: var(--info); }
.badge-primary { background: var(--primary); }
.badge-secondary { background: #64748b; }

@media (max-width: 767.98px) {
  table.table-cards thead { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }
  table.table-cards, table.table-cards tbody, table.table-cards tr, table.table-cards td { display: block; width: 100%; }
  table.table-cards tbody tr {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin-bottom: 10px; background: #fff; box-shadow: var(--shadow); overflow: hidden;
  }
  table.table-cards tbody td { border: 0; border-bottom: 1px solid var(--border); padding: 10px 12px 10px 46%; position: relative; text-align: left; }
  table.table-cards tbody td:last-child { border-bottom: 0; }
  table.table-cards tbody td::before {
    content: attr(data-label); position: absolute; left: 12px; top: 10px; width: 38%;
    font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
    white-space: normal;
  }
}

/* ---------- Alerts / modals ---------- */
.alert { border-radius: 12px; border: 1px solid transparent; }
.modal-content { border-radius: 18px; border: 0; }
@media (max-width: 575.98px) {
  .modal-dialog { margin: 0; min-height: 100dvh; display: flex; align-items: flex-end; }
  .modal-content { border-radius: 20px 20px 0 0; width: 100%; }
}

/* ---------- Cameras / misc modules ---------- */
.camera-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.camera-card { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #fff; box-shadow: var(--shadow); }
.camera-header { background: var(--surface-2); padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.camera-body { padding: 14px; }
.camera-stream { width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: #fff; }
#cameraStream { width: 100%; aspect-ratio: 16 / 9; max-height: 70vh; background: #000; border-radius: 12px; }
.device-status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.device-status .dot { width: 10px; height: 10px; border-radius: 50%; }
.dot-online { background: var(--success); box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.18); }
.dot-offline { background: var(--danger); box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.15); }
.dot-warning { background: var(--warning); }

.report-filter { background: var(--surface-2); border: 1px solid var(--border); padding: 14px; border-radius: var(--radius); margin-bottom: 14px; }
.payslip-header { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: #fff; padding: 18px; border-radius: var(--radius) var(--radius) 0 0; }
.payslip-details { display: grid; grid-template-columns: 1fr; gap: 12px; }
.payslip-item { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.payslip-total { font-size: 18px; font-weight: 800; border-top: 2px solid var(--primary); padding-top: 12px; margin-top: 8px; }
.leave-approved { color: var(--success); font-weight: 700; }
.leave-rejected { color: var(--danger); font-weight: 700; }
.leave-pending { color: var(--warning); font-weight: 700; }
.user-role { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.role-admin { background: var(--primary); color: #fff; }
.role-employee { background: #64748b; color: #fff; }
.role-supervisor { background: var(--warning); color: #fff; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; min-height: 100dvh; display: flex; }
.login-visual {
  display: none; flex: 1; color: #fff; padding: 48px;
  background: linear-gradient(140deg, #0d1456 0%, #1a237e 45%, #3949ab 100%);
  position: relative; overflow: hidden;
}
.login-visual::after {
  content: ""; position: absolute; width: 480px; height: 480px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.22), transparent 65%);
  right: -140px; top: -140px;
}
.login-visual h1 { font-size: clamp(26px, 3.4vw, 42px); font-weight: 800; margin: 0 0 12px; }
.login-visual p { color: rgba(255,255,255,0.85); max-width: 44ch; }
.login-points { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 12px; }
.login-points li { display: flex; gap: 10px; align-items: center; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.18); border-radius: 12px; padding: 10px 12px; }
.login-panel { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--bg); }
.login-box { background: #fff; border: 1px solid var(--border); border-radius: 22px; padding: 26px 22px; box-shadow: var(--shadow); width: 100%; max-width: 430px; }
.login-box .logo { text-align: center; margin-bottom: 18px; }
.login-box .logo img { max-width: 88px; }
.login-box .logo h2 { color: var(--primary); margin: 10px 0 2px; font-weight: 800; }
.login-box .logo p { color: var(--muted); font-size: 14px; margin: 0; }
.btn-login { background: linear-gradient(135deg, var(--primary), var(--primary-light)); border: 0; padding: 12px; border-radius: 12px; font-size: 16px; font-weight: 700; width: 100%; color: #fff; }
.btn-login:hover { color: #fff; filter: brightness(0.94); }
.password-wrap { position: relative; }
.password-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; width: 44px; height: 44px; color: var(--muted); }

/* ---------- Breakpoints ---------- */
@media (min-width: 576px) {
  .content { padding: 18px 18px 100px; }
  .form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .camera-grid { grid-template-columns: repeat(2, 1fr); }
  .payslip-details { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 992px) {
  .sidebar { transform: none; }
  .brand-close { display: none; }
  .app-main { margin-left: var(--sidebar-w); }
  .bottom-nav { display: none; }
  .content { padding: 24px 24px 40px; }
  .footer { padding-bottom: 24px; }
  .menu-btn { display: none; }
  .page-title { font-size: 22px; }
  .card-grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .card-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .camera-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1200px) {
  .form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  .sidebar, .sidebar-overlay, .topbar, .bottom-nav, .footer, .btn, .page-actions { display: none !important; }
  .app-main { margin-left: 0 !important; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; }
}
