:root {
  --primary: #0f766e;
  --primary-dark: #0b534d;
  --primary-light: #14b8a6;
  --primary-bg: #f0fdfa;
  --primary-border: #99f6e4;
  --secondary: #0284c7;
  --gradient-primary: linear-gradient(135deg, #0b534d 0%, #0f766e 55%, #14b8a6 100%);
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #0284c7;
  --info-bg: #e0f2fe;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ---------- Auth Screens ---------- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: radial-gradient(circle at top right, var(--primary-bg), var(--bg) 60%);
}

.auth-container {
  width: 100%;
  max-width: 460px;
}

.auth-container.wide {
  max-width: 580px;
}

.auth-brand-head {
  text-align: center;
  margin-bottom: 20px;
}

.auth-logo {
  width: 82px;
  height: 82px;
  border-radius: 20px;
  object-fit: cover;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.14);
  background: #fff;
  padding: 4px;
}

.auth-title {
  margin: 12px 0 4px;
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
}

.auth-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.env-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.env-pill.uat { background: var(--warning-bg); color: #92400e; border: 1px solid #fcd34d; }
.env-pill.prod { background: var(--success-bg); color: #166534; border: 1px solid #86efac; }
.env-pill-top { background: rgba(255,255,255,0.2); color: #fff; border: 1px solid rgba(255,255,255,0.35); }

.turnstile-wrap {
  margin-bottom: 14px;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}
.turnstile-wrap.hidden {
  display: none;
}
.turnstile-wrap > div {
  width: 100%;
  display: flex;
  justify-content: center;
}

/* ---------- Layout & Topbar ---------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--gradient-primary);
  color: #fff;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 3px 14px rgba(15, 23, 42, 0.14);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.mobile-menu-btn {
  display: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-logo-img {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  object-fit: cover;
  background: #fff;
  padding: 2px;
  flex-shrink: 0;
}

.brand-titles {
  min-width: 0;
}

.brand-app-name {
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 11px;
  opacity: 0.85;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.ws-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.ws-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
}
.ws-dot.polling { background: #fbbf24; }
.ws-dot.offline { background: #f87171; }

.branch-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--primary-dark);
  border: none;
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  max-width: 210px;
}

.branch-pill-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shell-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ---------- Sidebar & Mobile Drawer ---------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 65;
}

.drawer-mobile-head {
  display: none;
}

.sidebar {
  width: 256px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  flex-shrink: 0;
}

.sidebar-nav-scroll {
  overflow-y: auto;
  flex: 1;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 10px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 4px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: var(--primary-bg);
  color: var(--primary-dark);
}

.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  border-left: 3px solid var(--primary);
  font-weight: 700;
}

.sidebar-footer {
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-card-mini {
  background: var(--primary-bg);
  border: 1px solid var(--primary-border);
  border-radius: 12px;
  padding: 10px 12px;
}

.user-card-mini .u-name {
  font-weight: 800;
  font-size: 13.5px;
  color: var(--primary-dark);
}

.user-card-mini .u-email {
  font-size: 11.5px;
  color: var(--muted);
  word-break: break-all;
}

.attendance-pill-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
}

.attendance-pill-btn.in { background: var(--success-bg); color: #166534; border-color: #86efac; }
.attendance-pill-btn.out { background: var(--info-bg); color: #075985; border-color: #7dd3fc; }
.attendance-pill-btn.none { background: var(--warning-bg); color: #92400e; border-color: #fcd34d; }

/* ---------- Main Content ---------- */
.main-content {
  flex: 1;
  padding: 20px;
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
  overflow-x: hidden;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.page-title {
  margin: 0;
  font-size: 21px;
  font-weight: 800;
  color: var(--text);
}

.page-subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Cards, Grids, KPIs ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 700; }
.kpi-value { font-size: 26px; font-weight: 800; color: var(--primary); margin-top: 6px; }
.kpi-hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }

/* ---------- Forms & Buttons ---------- */
.form-group { margin-bottom: 14px; }
label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: #334155;
  margin-bottom: 5px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 9px 15px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  min-height: 38px;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: var(--primary-bg); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: #f1f5f9; color: #334155; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; min-height: 32px; }
.btn-lg { padding: 12px 20px; font-size: 15px; min-height: 46px; }
.w-full { width: 100%; }

/* ---------- Badges & Chips ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}
.badge-primary { background: var(--primary-bg); color: var(--primary-dark); border: 1px solid var(--primary-border); }
.badge-success { background: var(--success-bg); color: #166534; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-danger { background: var(--danger-bg); color: #991b1b; }
.badge-info { background: var(--info-bg); color: #075985; }
.badge-neutral { background: #e2e8f0; color: #334155; }

.online-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.22);
}
.offline-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  background: #94a3b8;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.chip.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ---------- Tables & Responsive Mobile Cards ---------- */
.table-wrap,
.desktop-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.mobile-cards-list {
  display: none;
}

.m-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.m-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.m-card-title {
  font-weight: 800;
  font-size: 14.5px;
  color: var(--text);
}

.m-card-sub {
  font-size: 12px;
  color: var(--muted);
  word-break: break-word;
}

.m-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  font-size: 12.5px;
  background: #f8fafc;
  padding: 9px 10px;
  border-radius: 10px;
}

.m-card-kv {
  min-width: 0;
}

.m-card-k {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}

.m-card-v {
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

.m-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.m-card-actions .btn {
  flex: 1;
  min-width: 110px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th, td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f8fafc;
  color: #475569;
  font-weight: 800;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

tr:hover td { background: #fafcff; }

/* ---------- Branch Branding Cards & Live Preview ---------- */
.branch-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.branch-card-banner {
  height: 10px;
}

.branch-card-body {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.branch-logo-thumb {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #fff;
  padding: 2px;
}

.swatch-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.swatch-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1.5px #cbd5e1;
  cursor: pointer;
}
.swatch-btn.active {
  box-shadow: 0 0 0 2.5px var(--text);
  transform: scale(1.08);
}

.brand-preview-box {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f8fafc;
}

.brand-preview-header {
  padding: 12px 14px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- Toolbar & Tabs ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}
.toolbar > * { min-width: 145px; }
.toolbar .grow { flex: 1; min-width: 190px; }

.subtabs {
  display: inline-flex;
  background: #e2e8f0;
  padding: 4px;
  border-radius: 12px;
  gap: 4px;
  margin-bottom: 16px;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.subtab-btn {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 13px;
  color: #475569;
  cursor: pointer;
  white-space: nowrap;
}
.subtab-btn.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-panel {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-title { margin: 0; font-size: 17px; font-weight: 800; }
.modal-close {
  border: none;
  background: #f1f5f9;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}
.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

/* ---------- Toast ---------- */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}

.toast {
  padding: 12px 16px;
  border-radius: 12px;
  color: #fff;
  font-weight: 700;
  font-size: 13.5px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.22);
}
.toast.success { background: #15803d; }
.toast.error { background: #b91c1c; }
.toast.warning { background: #b45309; }
.toast.info { background: #0369a1; }

/* ---------- Switch ---------- */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}

/* ---------- Bottom Nav ---------- */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  z-index: 45;
  justify-content: space-around;
  padding: 6px 4px max(6px, env(safe-area-inset-bottom));
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.06);
}

.bottom-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: transparent;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  min-height: 44px;
  min-width: 56px;
}
.bottom-nav-btn.active { color: var(--primary); }

/* ---------- Print Header (Reports PDF) ---------- */
.print-only-header {
  display: none;
}

/* ---------- Tablet & Mobile Responsive Rules ---------- */
@media (max-width: 900px) {
  .topbar {
    height: 56px;
    padding: 8px 12px;
    gap: 8px;
  }
  .brand-logo-img {
    width: 32px;
    height: 32px;
  }
  .brand-sub,
  #envPillTop,
  #wsStatusLabel,
  .top-logout-btn {
    display: none;
  }
  .ws-pill {
    padding: 8px;
  }
  .branch-pill {
    max-width: 155px;
    padding: 6px 10px;
    font-size: 12px;
  }
  .mobile-menu-btn { display: inline-flex; }
  .drawer-mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 12px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 282px;
    max-width: 85vw;
    z-index: 70;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 28px rgba(15, 23, 42, 0.22);
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { padding: 14px 12px 92px; }
  .bottom-nav { display: flex; }
  .toast-stack { bottom: 76px; right: 12px; left: 12px; max-width: none; }
}

@media (max-width: 768px) {
  .desktop-table-wrap { display: none; }
  .mobile-cards-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .toolbar > * {
    width: 100%;
    min-width: 0;
  }
  .page-title { font-size: 18.5px; }
}

@media (max-width: 640px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .kpi-card { padding: 12px; }
  .kpi-value { font-size: 21px; }
  .card { padding: 14px 12px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  select,
  textarea {
    font-size: 16px;
    min-height: 44px;
  }

  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; padding: 6px 12px; }

  /* Bottom-sheet modal on mobile */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .modal-panel {
    max-width: 100% !important;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
  }
  .modal-header { padding: 14px 16px; }
  .modal-body { padding: 14px 16px; }
  .modal-footer {
    padding: 12px 16px max(14px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 430px) {
  .branch-pill { max-width: 124px; }
  .brand-app-name { font-size: 14.5px; }
}

/* ---------- Print / PDF Mode ---------- */
@media print {
  .topbar,
  .sidebar,
  .bottom-nav,
  .drawer-backdrop,
  .modal-backdrop,
  .toast-stack,
  .no-print,
  .toolbar,
  .subtabs,
  .page-header button {
    display: none !important;
  }
  body { background: #fff; }
  .main-content {
    max-width: none;
    padding: 0;
    margin: 0;
  }
  .card {
    box-shadow: none;
    border: 1px solid #cbd5e1;
    break-inside: avoid;
  }
  .desktop-table-wrap { display: block !important; overflow: visible !important; }
  .mobile-cards-list { display: none !important; }
  .print-only-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 10px;
    margin-bottom: 14px;
  }
}
