/* ═══════════════════════════════════════════════════════════════
   HIGH 5 CONNECT CRM — V2 Sidebar + Bottom Nav + Auth Screen
   2026 Glassmorphism — Frosted glass sidebar, translucent nav
   ═══════════════════════════════════════════════════════════════ */

/* ─── Auth Screen — Glassmorphic Login ─────────────────────── */
.auth-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0a1628 0%, #0f2040 40%, #1a3155 70%, #068bc3 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: var(--s4);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
}

/* iOS PWA: the home indicator area shows the body/html background.
   background-attachment:fixed is broken on iOS, so we use a plain
   gradient on html (not body) sized to 100% viewport. */
html.auth-visible {
  background: linear-gradient(to bottom, #0a1628 0%, #1a3155 60%, #068bc3 100%) !important;
  min-height: 100% !important;
}
html.auth-visible body {
  background: transparent !important;
}

.auth-screen.hidden {
  display: none;
}

.auth-card {
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: var(--blur-lg);
  -webkit-backdrop-filter: var(--blur-lg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--r-xl);
  padding: var(--s8) var(--s6);
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  box-shadow: var(--shadow-glass);
  text-align: center;
}

@media (max-width: 640px) {
  .auth-card {
    padding: var(--s6) var(--s5);
  }

  .auth-logo img {
    width: 140px;
    height: 140px;
  }
}

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: var(--s6);
}

.auth-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: #ffffff;
  margin-bottom: var(--s1);
  letter-spacing: var(--tracking-tight);
}

.auth-subtitle {
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: var(--s8);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  text-align: left;
}

.auth-form .input-label {
  color: rgba(255, 255, 255, 0.7);
}

.auth-form .input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border-radius: var(--r-md);
  padding: var(--s3) var(--s4);
  min-height: 44px;
  font-size: var(--text-base);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}

.auth-form .input:focus {
  outline: none;
  border-color: rgba(6, 139, 195, 0.6);
  box-shadow: 0 0 0 3px rgba(6, 139, 195, 0.15);
  background: rgba(255, 255, 255, 0.1);
}

.auth-form .input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.auth-error {
  font-size: var(--text-sm);
  color: #f87171;
  min-height: 20px;
  text-align: center;
}

.auth-submit {
  width: 100%;
  margin-top: var(--s2);
  background: linear-gradient(135deg, var(--navy-base) 0%, var(--navy-darkest) 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s6);
  font-size: var(--text-base);
  font-weight: 600;
  min-height: 48px;
  cursor: pointer;
  transition: all var(--t-fast);
  box-shadow: 0 2px 8px rgba(10, 22, 40, 0.3);
}

.auth-submit:hover:not(:disabled) {
  box-shadow: 0 4px 16px rgba(10, 22, 40, 0.4);
  transform: translateY(-1px);
  background: linear-gradient(135deg, var(--navy-medium) 0%, var(--navy-base) 100%);
}

.auth-submit:active:not(:disabled) {
  transform: translateY(0);
}

.auth-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-footer {
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.35);
  margin-top: var(--s8);
}

/* ─── Desktop Sidebar — Frosted Dark Glass ─────────────────── */
.app-sidebar {
  display: none;
}

/* Tablet (641-1024px): show sidebar as icon-only */
@media (min-width: 641px) {
  .app-sidebar {
    display: flex;
    flex-direction: column;
    background: rgba(10, 22, 40, 0.92);
    backdrop-filter: var(--blur-lg);
    -webkit-backdrop-filter: var(--blur-lg);
    color: var(--text-inverse);
    width: var(--sidebar-collapsed);
    height: 100dvh;
    position: sticky;
    top: 0;
    flex-shrink: 0;
    transition: width var(--t-slow);
    z-index: var(--z-sticky);
    overflow: hidden;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
  }

  /* Force icon-only at tablet */
  .app-sidebar .sidebar-label,
  .app-sidebar .sidebar-brand,
  .app-sidebar .sidebar-user-info {
    display: none;
  }

  .app-sidebar .sidebar-header {
    justify-content: center;
    padding: var(--s3);
  }

  .app-sidebar .sidebar-item {
    justify-content: center;
    padding: var(--s3);
  }

  .app-sidebar .sidebar-user {
    justify-content: center;
    gap: 0;
  }

  /* Hide the collapse toggle at tablet — always icon-only */
  .app-sidebar .sidebar-collapse-btn {
    display: none;
  }
}

/* Desktop (1025px+): full sidebar with labels */
@media (min-width: 1025px) {
  .app-sidebar {
    width: var(--sidebar-width);
  }

  /* Restore labels and full layout at desktop */
  .app-sidebar .sidebar-label,
  .app-sidebar .sidebar-brand,
  .app-sidebar .sidebar-user-info {
    display: initial;
    opacity: 1;
    transition: opacity var(--t-fast);
  }

  .app-sidebar .sidebar-header {
    justify-content: space-between;
    padding: var(--s5) var(--s4) var(--s3);
  }

  .app-sidebar .sidebar-item {
    justify-content: flex-start;
    padding: var(--s2) var(--s3);
  }

  .app-sidebar .sidebar-user {
    justify-content: flex-start;
    gap: var(--s3);
  }

  .app-sidebar .sidebar-collapse-btn {
    display: flex;
  }

  .app-sidebar.collapsed {
    width: var(--sidebar-collapsed);
  }

  .app-sidebar.collapsed .sidebar-label,
  .app-sidebar.collapsed .sidebar-brand,
  .app-sidebar.collapsed .sidebar-user-info {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
  }

  .app-sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: var(--s3);
  }

  .app-sidebar.collapsed .sidebar-item {
    justify-content: center;
    padding: var(--s3);
  }

  .app-sidebar.collapsed .sidebar-user {
    justify-content: center;
    gap: 0;
  }
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s5) var(--s4) var(--s3);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--s3);
}

/* ─── Sync Status Dot ────────────────────────────────── */
.sync-dot {
  position: absolute;
  top: var(--s2);
  right: var(--s2);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
  transition: background 0.3s ease, box-shadow 0.3s ease;
  z-index: 1;
}

.sidebar-header {
  position: relative;
}

.sync-dot.synced {
  background: #16a34a;
  box-shadow: 0 0 6px rgba(22, 163, 74, 0.5);
}

.sync-dot.syncing {
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
  animation: sync-pulse 1s ease-in-out infinite;
}

.sync-dot.error {
  background: #dc2626;
  box-shadow: 0 0 6px rgba(220, 38, 38, 0.5);
}

@keyframes sync-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.sidebar-brand {
  font-size: var(--text-md);
  font-weight: 700;
  white-space: nowrap;
  color: #ffffff;
}

.sidebar-collapse-btn {
  color: var(--sidebar-text);
}

.sidebar-collapse-btn:hover {
  color: var(--text-inverse);
  background: var(--sidebar-hover-bg);
}

/* ─── Sidebar Navigation ───────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: var(--s2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--r-md);
  color: var(--sidebar-text);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: all var(--t-fast);
  white-space: nowrap;
  width: 100%;
  text-align: left;
  position: relative;
}

.sidebar-item:hover {
  background: var(--sidebar-hover-bg);
  color: var(--text-inverse);
}

/* Active state — left accent bar + subtle gradient highlight */
.sidebar-item.active {
  background: linear-gradient(90deg, rgba(6, 139, 195, 0.25) 0%, rgba(6, 139, 195, 0.08) 100%);
  color: var(--accent-light);
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  border-radius: 0 var(--r-xs) var(--r-xs) 0;
  background: var(--accent-light);
}

.sidebar-item svg {
  flex-shrink: 0;
}

.sidebar-label {
  white-space: nowrap;
}

/* Sidebar badge (count) */
.sidebar-badge {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.8);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--r-full);
  min-width: 20px;
  text-align: center;
}

.sidebar-item.active .sidebar-badge {
  background: rgba(6, 139, 195, 0.3);
  color: var(--accent-light);
}

/* ─── Sidebar Footer ───────────────────────────────────────── */
.sidebar-footer {
  padding: var(--s2);
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--r-md);
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--sidebar-text-hover);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-role {
  display: block;
  font-size: var(--text-xs);
  color: var(--sidebar-text-muted);
  text-transform: capitalize;
}

/* ─── Mobile Top Bar — Translucent Navy with Blur ──────────── */
.app-topbar {
  display: flex;
}

.topbar-title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-inverse);
}

.topbar-spacer {
  flex: 1;
}

.topbar-btn {
  color: rgba(255, 255, 255, 0.8);
}

.topbar-btn:hover {
  color: var(--text-inverse);
}

/* Refresh button spin animation */
.topbar-refresh.spinning svg {
  animation: topbar-spin 0.8s linear infinite;
}

@keyframes topbar-spin {
  to { transform: rotate(360deg); }
}

@media (min-width: 641px) {
  .app-topbar {
    display: none;
  }
}

/* ─── Notification Badge ───────────────────────────────────── */
.notif-badge-wrap {
  position: relative;
}

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ─── Desktop Top Bar (inside main) ─────────────────────────── */
.desktop-topbar {
  display: none;
}

@media (min-width: 641px) {
  .desktop-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s4) var(--s6);
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: var(--blur-sm);
    -webkit-backdrop-filter: var(--blur-sm);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
  }

  [data-theme="dark"] .desktop-topbar {
    background: rgba(15, 23, 42, 0.85);
  }

  .desktop-topbar-title {
    font-size: var(--text-xl);
    font-weight: 700;
    letter-spacing: var(--tracking-tight);
  }

  .desktop-topbar-right {
    display: flex;
    align-items: center;
    gap: var(--s3);
  }

  .desktop-search {
    width: 320px;
  }
}

/* ─── Mobile Bottom Nav ─────────────────────────────────────── */
.bottomnav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--s1) var(--s2);
  color: var(--text-label);
  font-size: 10px;
  font-weight: 500;
  transition: color var(--t-fast);
  border: none;
  background: none;
  flex: 1;
  min-width: 0;
}

.bottomnav-item:hover {
  color: var(--text-primary);
}

.bottomnav-item.active {
  color: var(--accent);
}

.bottomnav-item.active svg {
  stroke: var(--accent);
}

.bottomnav-label {
  white-space: nowrap;
}

/* ─── Centered FAB in Bottom Nav ───────────────────────────── */
.bottomnav-fab {
  position: relative;
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: -20px;
  box-shadow: 0 4px 16px rgba(6, 139, 195, 0.35);
  transition: transform 150ms ease, box-shadow 150ms ease;
  z-index: 1;
}

.bottomnav-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(6, 139, 195, 0.45);
}

.bottomnav-fab:active {
  transform: scale(0.95);
}

@media (min-width: 641px) {
  .app-bottomnav {
    display: none;
  }
}

/* ─── Search Modal (Cmd+K) ─────────────────────────────────── */
.search-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-panel);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: min(20vh, 160px);
}

.search-modal-backdrop.hidden {
  display: none;
}

.search-modal {
  width: 100%;
  max-width: 560px;
  max-height: 480px;
  background: var(--bg-card);
  border-radius: var(--r-xl);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: search-modal-in 0.15s ease-out;
}

@keyframes search-modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(-8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.search-modal-header {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
}

.search-modal-icon {
  flex-shrink: 0;
  color: var(--text-label);
}

.search-modal-input {
  flex: 1;
  border: none;
  outline: none;
  background: none;
  font-size: var(--text-base);
  color: var(--text-primary);
  font-family: inherit;
}

.search-modal-input::placeholder {
  color: var(--text-label);
}

.search-modal-kbd {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-label);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 2px 6px;
  line-height: 1;
  flex-shrink: 0;
}

.search-modal-results {
  flex: 1;
  overflow-y: auto;
  padding: var(--s2) var(--s3);
  max-height: 400px;
}

.search-modal-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s8) var(--s4);
  text-align: center;
}

.search-result-group {
  margin-bottom: var(--s2);
}

.search-result-group-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-label);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  padding: var(--s1) var(--s2);
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--t-fast);
}

.search-result-item:hover,
.search-result-item.active {
  background: var(--bg-hover);
}

.search-result-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-detail {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* Mobile: full-width modal with less padding */
@media (max-width: 640px) {
  .search-modal-backdrop {
    padding-top: calc(env(safe-area-inset-top) + var(--s4));
    padding-left: var(--s3);
    padding-right: var(--s3);
  }

  .search-modal {
    max-height: 70vh;
  }
}

/* ─── Theme Toggle Icons + Labels ────────────────────────── */
/* Light mode: show moon + "Dark Mode", hide sun + "Light Mode" */
.theme-icon-sun,
.app-sidebar .theme-label-dark,
.app-topbar .theme-label-dark,
.theme-label-dark {
  display: none !important;
}

[data-theme="dark"] .theme-icon-moon,
[data-theme="dark"] .app-sidebar .theme-label-light,
[data-theme="dark"] .app-topbar .theme-label-light,
[data-theme="dark"] .theme-label-light {
  display: none !important;
}

[data-theme="dark"] .theme-icon-sun,
[data-theme="dark"] .app-sidebar .theme-label-dark,
[data-theme="dark"] .app-topbar .theme-label-dark,
[data-theme="dark"] .theme-label-dark {
  display: inline !important;
}

/* ─── FAB positioning adjustments ───────────────────────────── */
@media (min-width: 1025px) {
  .fab {
    display: none;
  }

  .fab-menu:not(.open) {
    display: none;
  }
}

/* Ensure bottomnav-fab SVG doesn't capture pointer events */
.bottomnav-fab svg, .bottomnav-fab svg * {
  pointer-events: none;
}
