: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;
}

.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); }

/* ---------- 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;
}

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

.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-wrap: wrap;
}

.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: 5px 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: 6px 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 ---------- */
.sidebar {
  width: 252px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  flex-shrink: 0;
}

.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: auto;
  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: 1360px;
  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: 28px; 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(300px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 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;
  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; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.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: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

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

/* ---------- Tables ---------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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: 150px; }
.toolbar .grow { flex: 1; min-width: 200px; }

.subtabs {
  display: inline-flex;
  background: #e2e8f0;
  padding: 4px;
  border-radius: 12px;
  gap: 4px;
  margin-bottom: 16px;
}
.subtab-btn {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 13px;
  color: #475569;
  cursor: pointer;
}
.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: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
}
.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 & Mobile Drawer ---------- */
.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;
}

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

@media (max-width: 900px) {
  .mobile-menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 58px;
    bottom: 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 24px rgba(15, 23, 42, 0.16);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { padding: 14px 12px 84px; }
  .bottom-nav { display: flex; }
  .toast-stack { bottom: 72px; right: 12px; left: 12px; max-width: none; }
}
