/* ── Variables ────────────────────────────── */
:root {
  --sidebar-width: 240px;
  --sidebar-bg: #0f1623;
  --sidebar-border: rgba(255,255,255,.07);
  --sidebar-link-color: rgba(255,255,255,.7);
  --sidebar-link-hover-bg: rgba(255,255,255,.07);
  --sidebar-link-active-bg: rgba(13,110,253,.25);
  --sidebar-link-active-color: #93c5fd;
  --sidebar-section-color: rgba(255,255,255,.35);
  --topbar-height: 56px;
  --card-radius: 1rem;
}

/* ── Base ─────────────────────────────────── */
body {
  font-family: 'Inter', 'Segoe UI', sans-serif;
  background-color: #f0f2f8;
  color: #1a1d23;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
body.has-sidebar {
  overflow-x: hidden;
}

/* ═══════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════ */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1050;
  overflow: hidden;
  transition: transform .25s ease;
}

/* Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: 1rem;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-brand-icon {
  width: 42px;
  height: 32px;
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
  padding: 2px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 1rem;
  flex-shrink: 0;
}
.sidebar-brand-text {
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -.3px;
  flex: 1;
}
.sidebar-close-btn {
  background: none; border: none;
  color: rgba(255,255,255,.5);
  font-size: 1rem;
  padding: .25rem;
  cursor: pointer;
  transition: color .15s;
}
.sidebar-close-btn:hover { color: #fff; }

/* Company badge */
.sidebar-company {
  display: flex;
  align-items: center;
  padding: .65rem 1rem;
  background: rgba(255,255,255,.04);
  border-bottom: 1px solid var(--sidebar-border);
  color: rgba(255,255,255,.65);
  font-size: .78rem;
  flex-shrink: 0;
  min-width: 0;
}
.sidebar-company-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar-company-name {
  font-weight: 600;
  color: rgba(255,255,255,.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-company-id {
  background: rgba(255,255,255,.1);
  color: #93c5fd;
  font-size: .7rem;
  padding: 1px 5px;
  border-radius: 3px;
  margin-top: 2px;
  display: inline-block;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: .5rem 0;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

.sidebar-section-label {
  padding: .8rem 1rem .3rem;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--sidebar-section-color);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .52rem 1rem;
  margin: 1px .5rem;
  border-radius: .5rem;
  color: var(--sidebar-link-color);
  text-decoration: none;
  font-size: .855rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.sidebar-link i {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.sidebar-link:hover {
  background: var(--sidebar-link-hover-bg);
  color: #fff;
}
.sidebar-link.active {
  background: var(--sidebar-link-active-bg);
  color: var(--sidebar-link-active-color);
}
.sidebar-link.active i { color: #93c5fd; }

/* Footer */
.sidebar-footer {
  padding: .75rem;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: .6rem;
}
.sidebar-user-avatar {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, #0a2e5c, #6610f2);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}
.sidebar-user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.sidebar-user-name {
  color: rgba(255,255,255,.85);
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: .65rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  display: inline-block;
  margin-top: 2px;
}
.role-admin   { background: rgba(255,193,7,.2);  color: #ffc107; }
.role-business{ background: rgba(13,202,240,.2); color: #0dcaf0; }

.sidebar-logout-btn {
  color: rgba(255,255,255,.4);
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: color .15s;
  text-decoration: none;
  padding: .25rem;
}
.sidebar-logout-btn:hover { color: #dc3545; }

/* ═══════════════════════════════════════════
   PAGE WRAPPER & TOPBAR
═══════════════════════════════════════════ */
.page-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Mobile topbar */
.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: .75rem;
  position: sticky;
  top: 0;
  z-index: 900;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.topbar-toggle {
  background: none; border: none;
  font-size: 1.4rem;
  color: #495057;
  padding: .2rem .3rem;
  cursor: pointer;
  line-height: 1;
}
.topbar-title {
  flex: 1;
  font-weight: 700;
  font-size: .95rem;
  color: #1a1d23;
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1040;
}
.sidebar-overlay.active { display: block; }

/* Content area */
.content-area {
  flex: 1;
  padding: 1.5rem;
}

/* ═══════════════════════════════════════════
   RESPONSIVE — Mobile
═══════════════════════════════════════════ */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.3);
  }
  .page-wrapper {
    margin-left: 0;
  }
}

/* ── Cards ───────────────────────────────── */
.card { border-radius: var(--card-radius) !important; }
.hover-card { transition: transform .15s ease, box-shadow .15s ease; cursor: pointer; }
.hover-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,.10) !important; }

/* ── Tables ──────────────────────────────── */
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; color: #6c757d; }
.table td { font-size: .875rem; }

/* ── Badges ──────────────────────────────── */
.badge { font-weight: 600; font-size: .7rem; letter-spacing: .2px; }

/* ── Code / keywords ────────────────────── */
code {
  background: #e8f0fe;
  color: #0a2e5c;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: .82em;
}

/* ── Upload area ─────────────────────────── */
.upload-area {
  border-color: #dee2e6 !important;
  transition: border-color .2s, background .2s;
  cursor: pointer;
}
.upload-area:hover, .upload-area.border-primary { border-color: #0a2e5c !important; background: #f0f6ff; }

/* ── Form builder drag list ─────────────── */
.field-item { background: #fff; transition: background .15s; }
.field-item:hover { background: #f8f9fa; }
.field-item.dragging { opacity: .4; }
.drag-handle:hover { color: #0a2e5c !important; }
.sortable-list { min-height: 60px; }

/* ── Progress bars ───────────────────────── */
.progress { border-radius: 99px; background: #e9ecef; }
.progress-bar { border-radius: 99px; }

/* ── Toasts ──────────────────────────────── */
.toast { min-width: 260px; font-size: .875rem; border-radius: .75rem !important; }

/* ── PWA Install Bar ────────────────────── */
#pwa-install-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* ── Alert refinements ───────────────────── */
.alert { border-radius: .75rem; border: none; }

/* ── Buttons ─────────────────────────────── */
.btn { 
  border-radius: .5rem; 
  font-size: .875rem; 
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.btn-sm { border-radius: .4rem; }
.btn-primary { background: #0a2e5c; border-color: #0a2e5c; }

/* ── Inputs ──────────────────────────────── */
.form-control, .form-select {
  border-radius: .5rem;
  font-size: .875rem;
  border-color: #dee2e6;
}
.form-control:focus, .form-select:focus {
  border-color: #0a2e5c;
  box-shadow: 0 0 0 3px rgba(13,110,253,.12);
}

/* ── Sticky top offset ───────────────────── */
.sticky-top { z-index: 100; }

/* ── Font-monospace override ─────────────── */
.font-monospace { font-size: .78rem; }

/* ── Responsive content padding ─────────── */
@media (max-width: 768px) {
  .content-area { padding: 1rem !important; }
}

/* ═══════════════════════════════════════════
   SIDEBAR — Categorized Dropdown Groups
═══════════════════════════════════════════ */

/* Group wrapper */
.sidebar-group {
  margin: 1px 0;
}

/* Group header toggle button */
.sidebar-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: .52rem 1rem .52rem .75rem;
  margin: 1px .5rem;
  width: calc(100% - 1rem);
  border-radius: .5rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--sidebar-link-color);
  font-size: .855rem;
  font-weight: 600;
  letter-spacing: .01em;
  text-align: left;
  transition: background .15s, color .15s;
}
.sidebar-group-toggle:hover {
  background: var(--sidebar-link-hover-bg);
  color: #fff;
}
/* When the group is open (Bootstrap sets aria-expanded="true") */
.sidebar-group-toggle[aria-expanded="true"] {
  color: #fff;
  background: rgba(255,255,255,.05);
}

/* Special styling for Paper Work group toggle */
.sidebar-group-toggle[data-bs-target="#grp-paperwork"] {
  background: linear-gradient(135deg, rgba(13,110,253,.1) 0%, rgba(77,159,255,.05) 100%);
  border: 1px solid rgba(13,110,253,.15);
  color: rgba(77,159,255,.9);
  font-weight: 700;
  letter-spacing: .5px;
  transition: all .25s ease;
  margin: 2px .5rem;
  padding: .6rem 1rem .6rem .75rem;
}

.sidebar-group-toggle[data-bs-target="#grp-paperwork"]:hover {
  background: linear-gradient(135deg, rgba(13,110,253,.15) 0%, rgba(77,159,255,.1) 100%);
  border-color: rgba(13,110,253,.25);
  color: #fff;
  box-shadow: 0 2px 10px rgba(13,110,253,.12);
}

.sidebar-group-toggle[data-bs-target="#grp-paperwork"][aria-expanded="true"] {
  background: linear-gradient(135deg, rgba(13,110,253,.2) 0%, rgba(77,159,255,.15) 100%);
  border-color: rgba(13,110,253,.3);
  color: #93c5fd;
  box-shadow: 0 4px 16px rgba(13,110,253,.15);
}

/* Left side: icon + label */
.sidebar-group-left {
  display: flex;
  align-items: center;
  gap: .65rem;
}
.sidebar-group-left i {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

/* Chevron arrow — rotates when open */
.sidebar-group-arrow {
  font-size: .7rem;
  flex-shrink: 0;
  transition: transform .22s ease;
  color: rgba(255,255,255,.35);
}
.sidebar-group-toggle[aria-expanded="true"] .sidebar-group-arrow {
  transform: rotate(180deg);
  color: rgba(255,255,255,.65);
}

/* Group items container */
.sidebar-group-items {
  padding: .2rem 0 .35rem 0;
  border-left: 1px solid rgba(255,255,255,.08);
  margin-left: 1.65rem;
  margin-right: .5rem;
}

/* Sub-links (indented child items) */
.sidebar-sub-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .42rem .75rem;
  margin: 1px 0;
  border-radius: .45rem;
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: .83rem;
  font-weight: 400;
  transition: background .15s, color .15s;
}

/* Nested sub-group links with enhanced styling */
.sidebar-sub-group-items .sidebar-sub-link {
  padding: .45rem .6rem;
  margin: 2px 0;
  font-size: .8rem;
  border-radius: .4rem;
  transition: all .15s ease;
  position: relative;
}

.sidebar-sub-group-items .sidebar-sub-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(77,159,255,0);
  border-radius: 0 2px 2px 0;
  transition: background .2s ease;
}

.sidebar-sub-link i {
  font-size: .9rem;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  opacity: .75;
}
.sidebar-sub-link:hover {
  background: var(--sidebar-link-hover-bg);
  color: #fff;
}

.sidebar-sub-group-items .sidebar-sub-link:hover {
  background: rgba(77,159,255,.12);
  color: #fff;
}

.sidebar-sub-group-items .sidebar-sub-link:hover::before {
  background: rgba(77,159,255,.6);
}

.sidebar-sub-link:hover i {
  opacity: 1;
}
.sidebar-sub-link.active {
  background: var(--sidebar-link-active-bg);
  color: var(--sidebar-link-active-color);
  font-weight: 500;
}

.sidebar-sub-group-items .sidebar-sub-link.active {
  background: rgba(77,159,255,.15);
  color: #93c5fd;
  font-weight: 500;
}

.sidebar-sub-group-items .sidebar-sub-link.active::before {
  background: #93c5fd;
}

.sidebar-sub-link.active i {
  color: #93c5fd;
  opacity: 1;
}

/* Group header highlight when a child is active (parent glow) */
.sidebar-group:has(.sidebar-sub-link.active) .sidebar-group-toggle {
  color: rgba(255,255,255,.9);
}

/* ═══════════════════════════════════════════
   SIDEBAR — Nested Sub-groups (for Paper Work)
═══════════════════════════════════════════ */

/* Nested sub-group wrapper */
.sidebar-sub-group {
  margin: 4px 0;
}

/* Nested sub-group toggle button */
.sidebar-sub-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: .65rem .75rem;
  margin: 4px 0;
  border-radius: .6rem;
  background: linear-gradient(135deg, rgba(255,255,255,.08) 0%, rgba(255,255,255,.04) 100%);
  border: 1.5px solid rgba(13,110,253,.2);
  cursor: pointer;
  color: rgba(255,255,255,.75);
  font-size: .83rem;
  font-weight: 500;
  text-align: left;
  transition: all .25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.sidebar-sub-group-toggle::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(13,110,253,.1), transparent);
  transition: left .6s ease;
  z-index: 0;
}

.sidebar-sub-group-toggle > * {
  position: relative;
  z-index: 1;
}

.sidebar-sub-group-toggle:hover {
  background: linear-gradient(135deg, rgba(13,110,253,.18) 0%, rgba(13,110,253,.12) 100%);
  border-color: rgba(13,110,253,.35);
  color: #fff;
  box-shadow: 0 4px 12px rgba(13,110,253,.2);
  transform: translateY(-1px);
}

.sidebar-sub-group-toggle:hover::before {
  left: 100%;
}

/* When the sub-group is open */
.sidebar-sub-group-toggle[aria-expanded="true"] {
  color: #fff;
  background: linear-gradient(135deg, rgba(13,110,253,.25) 0%, rgba(77,159,255,.15) 100%);
  border-color: rgba(13,110,253,.4);
  box-shadow: 0 4px 16px rgba(13,110,253,.18);
  font-weight: 600;
}

.sidebar-sub-group-toggle[aria-expanded="true"]:hover {
  background: linear-gradient(135deg, rgba(13,110,253,.3) 0%, rgba(77,159,255,.2) 100%);
  box-shadow: 0 6px 20px rgba(13,110,253,.25);
}

/* Nested sub-group items container */
.sidebar-sub-group-items {
  padding: .2rem 0 .3rem 0;
  border-left: 2px solid rgba(13,110,253,.2);
  margin-left: 1rem;
  margin-right: 0;
  transition: border-color .2s ease;
}

/* Smooth collapse animation override for sidebar */
.sidebar-nav .collapse {
  transition: none; /* Bootstrap handles the height animation */
}
/* ── Custom Grids ────────────────────────── */
@media (min-width: 992px) {
  .col-md-5th {
    flex: 0 0 auto;
    width: 20%;
  }
}
