/* Custom properties for buttery smooth Apple-like animation */
:root {
  --sidebar-w-expanded: 210px;
  --sidebar-w-collapsed: 64px;
  --sidebar-padding: 12px;
  --sidebar-gap: 20px;
  --apple-ease-smooth: cubic-bezier(0.32, 0.72, 0, 1);
  --apple-duration: 0.5s;
  --sidebar-w: var(--sidebar-w-expanded);
}

body[data-sidebar="collapsed"] {
  --sidebar-w: var(--sidebar-w-collapsed);
}

/* Base utilities */
* {
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.no-scrollbar {
  scrollbar-width: none;
}
.no-scrollbar::-webkit-scrollbar {
  display: none;
}

/* Auth autofill override */
body[data-view="auth"] input:-webkit-autofill,
body[data-view="auth"] input:-webkit-autofill:hover,
body[data-view="auth"] input:-webkit-autofill:focus,
body[data-view="auth"] input:-webkit-autofill:active {
  -webkit-text-fill-color: #0f172a;
  caret-color: #0f172a;
  -webkit-box-shadow: 0 0 0 1000px #ffffff inset;
  box-shadow: 0 0 0 1000px #ffffff inset;
  transition: background-color 9999s ease-out 0s;
}

/* Tippy theme */
.tippy-box[data-theme~="sidebar"] {
  background: #1e293b;
  color: #f1f5f9;
  font-size: 13px;
  font-weight: 500;
  padding: 0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.15);
}
.tippy-box[data-theme~="sidebar"] .tippy-content {
  padding: 6px 12px;
}
.tippy-box[data-theme~="sidebar"] .tippy-arrow {
  display: none;
}

/* Top Logo Block */
.logo-block {
  width: var(--sidebar-w);
  transition: width var(--apple-duration) var(--apple-ease-smooth);
  will-change: width;
  display: flex;
  align-items: center;
  padding: 0 15px;
  overflow: hidden;
  box-sizing: border-box;
}
.logo-icon {
  flex: 0 0 34px;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background-color: #0f172a; color: white;
  border-radius: 10px; font-weight: 700; font-size: 17px;
}
.logo-text {
  flex: 0 0 auto;
  margin-left: 12px;
  font-size: 18px; font-weight: 800; letter-spacing: -0.025em;
  opacity: 1; transition: opacity 0.3s ease;
}
body[data-sidebar="collapsed"] .logo-text {
  opacity: 0; pointer-events: none;
}

/* Main Sidebar Block */
.anim-sidebar-width {
  width: var(--sidebar-w);
  transition: width var(--apple-duration) var(--apple-ease-smooth);
  will-change: width;
}

/* Toggle Button */
.sidebar-toggle {
  position: absolute;
  top: 50%;
  right: -14px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-color: #fff;
  border: 1px solid #e2e8f0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 50;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
  transition: background-color 0.2s, border-color 0.2s;
}
.sidebar-toggle:hover {
  background-color: #f8fafc; border-color: #cbd5e1;
}
.sidebar-toggle i {
  color: #64748b; font-size: 14px; line-height: 1;
  transition: transform var(--apple-duration) var(--apple-ease-smooth);
}
body[data-sidebar="collapsed"] .sidebar-toggle i {
  transform: rotate(180deg);
}

/* Main Wrapper Margin */
.anim-main-margin {
  margin-left: 0;
}
@media (min-width: 1024px) {
  .anim-main-margin {
    margin-left: calc(var(--sidebar-gap) + var(--sidebar-w) + var(--sidebar-gap));
    transition: margin-left var(--apple-duration) var(--apple-ease-smooth);
    will-change: margin-left;
  }
}

/* Navigation Links */
.nav-link {
  width: calc(var(--sidebar-w) - (var(--sidebar-padding) * 2));
  height: 42px;
  padding: 0 7px; /* Adjusting for the 1px border */
  display: flex; align-items: center;
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  background-color: transparent;
  border: 1px solid transparent;
  transition: width var(--apple-duration) var(--apple-ease-smooth),
              background-color 0.2s ease,
              border-color 0.2s ease;
  flex-shrink: 0; box-sizing: border-box;
}
.nav-link:hover { 
  background-color: #f8fafc; 
  border-color: #e2e8f0; 
}
.nav-link.active { 
  background-color: #f8fafc; 
  border-color: #e2e8f0; 
}
.nav-icon {
  flex: 0 0 24px; width: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1; color: #64748b;
  transition: color 0.2s ease;
}
.nav-link:hover .nav-icon { color: #0f172a; }
.nav-link.active .nav-icon { color: #020617; }
.nav-text {
  flex: 0 0 auto;
  font-size: 13.5px; font-weight: 500;
  margin-left: 12px; white-space: nowrap;
  color: #334155; opacity: 1;
  transition: opacity 0.3s ease, color 0.2s ease;
}
.nav-link.active .nav-text { color: #020617; font-weight: 600; }
body[data-sidebar="collapsed"] .nav-text {
  opacity: 0; pointer-events: none;
}

/* User Card */
.user-card {
  width: calc(var(--sidebar-w) - (var(--sidebar-padding) * 2));
  margin: 0 auto;
  padding: 8px 4px;
  background: #f8fafc; border: 1px solid #f1f5f9; border-radius: 12px;
  display: flex; align-items: center;
  overflow: hidden; cursor: pointer; position: relative;
  transition: width var(--apple-duration) var(--apple-ease-smooth),
              background 0.3s, border-color 0.3s;
}
body[data-sidebar="collapsed"] .user-card {
  background: transparent; border-color: transparent;
}
.user-avatar {
  flex: 0 0 32px; width: 32px; height: 32px;
  border-radius: 50%; background-color: #0f172a; color: white;
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.user-info {
  flex: 0 0 auto; margin-left: 12px; white-space: nowrap;
  opacity: 1; transition: opacity 0.3s ease;
}
.user-info-name { font-size: 13px; font-weight: 600; color: #0f172a; line-height: 1.2; }
.user-info-email { font-size: 11px; color: #64748b; line-height: 1.2; }
.user-logout {
  position: absolute; right: 12px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  color: #f87171; transition: opacity 0.3s ease, color 0.2s;
}
.user-logout:hover { color: #ef4444; }
body[data-sidebar="collapsed"] .user-info,
body[data-sidebar="collapsed"] .user-logout {
  opacity: 0; pointer-events: none;
}

/* Mobile Drawer support */
#mobileDrawerPanel {
  --sidebar-w: 100%;
}

/* Account popovers */
#avatarPopover,
#mobileAvatarPopover,
.sidebar-account-popover {
  left: var(--sidebar-padding);
  transform: translateY(0);
  width: 246px;
  min-width: 246px;
  max-width: min(280px, calc(100vw - 40px));
  padding: 6px;
  box-sizing: border-box;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
  transition: opacity 0.2s, transform 0.2s, width var(--apple-duration) var(--apple-ease-smooth), left var(--apple-duration) var(--apple-ease-smooth);
}
#avatarPopover.hidden,
#mobileAvatarPopover.hidden,
.sidebar-account-popover.hidden {
  display: none;
}
#avatarPopover:not(.hidden),
#mobileAvatarPopover:not(.hidden),
.sidebar-account-popover:not(.hidden) {
  display: block;
  z-index: 100;
}

/* Make internal links fill the scaling popover precisely */
#avatarPopover .nav-link,
#mobileAvatarPopover .nav-link,
.sidebar-account-popover .nav-link {
  width: 100%;
  height: 40px;
  padding: 0 10px;
}

#avatarPopover .nav-icon,
#mobileAvatarPopover .nav-icon,
.sidebar-account-popover .nav-icon {
  flex: 0 0 22px;
  width: 22px;
  font-size: 17px;
}

#avatarPopover .nav-text,
#mobileAvatarPopover .nav-text,
.sidebar-account-popover .nav-text {
  white-space: nowrap;
  margin-left: 10px;
  font-size: 13px;
}

body[data-sidebar="collapsed"] #avatarPopover .nav-text,
body[data-sidebar="collapsed"] #mobileAvatarPopover .nav-text,
body[data-sidebar="collapsed"] .sidebar-account-popover .nav-text {
  opacity: 1;
  pointer-events: auto;
}

#mobileAvatarPopover,
.sidebar-account-popover--mobile {
  width: calc(100% - (var(--sidebar-padding) * 2));
  min-width: 0;
  max-width: none;
}

.app-page-footer {
  margin-top: auto;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.app-page-footer-meta {
  font-size: 12px;
  color: #cbd5e1;
  letter-spacing: 0.03em;
}

.app-page-footer-dot {
  width: 3px;
  height: 3px;
  border-radius: 999px;
  background: #e2e8f0;
  display: inline-block;
}

[data-soft-hover] {
  transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

[data-soft-hover]:hover {
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.05);
}

/* Global toasts */
.app-toast-stack {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 4000;
    width: min(320px, calc(100vw - 28px));
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
  }
  
  .app-toast {
    --toast-accent: #2563eb;
    --toast-shadow: rgba(37, 99, 235, 0.28);
      position: relative;
      overflow: hidden;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    width: fit-content;
    max-width: min(100%, 320px);
    min-height: 40px;
    padding: 10px 10px 10px 14px;
    border-radius: 12px;
    border: 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--toast-accent) 92%, white), var(--toast-accent));
      box-shadow:
      0 10px 20px var(--toast-shadow),
        0 4px 10px rgba(15, 23, 42, 0.1);
      opacity: 0;
      transform-origin: bottom right;
      transform: translateY(10px) scale(0.985);
    transition:
      opacity 0.38s cubic-bezier(0.22, 1, 0.36, 1),
      transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
      pointer-events: auto;
    }
  
  .app-toast::before {
    content: none;
  }
  
  .app-toast.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  .app-toast.is-leaving {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  
.app-toast__body {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
  }

.app-toast__spinner {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    border-radius: 999px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: rgba(255, 255, 255, 0.98);
    animation: app-toast-spin 0.7s linear infinite;
  }

.app-toast__title {
    display: block;
    margin: 0;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.01em;
  }
  
.app-toast__message {
    display: block;
    margin: 2px 0 0;
    color: rgba(255, 255, 255, 0.9);
    font-size: 12px;
    line-height: 1.35;
  }
  
  .app-toast__close {
    width: 24px;
    height: 24px;
    margin-right: -1px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: rgba(255, 255, 255, 0.88);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
  }
  
  .app-toast__close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
  }

.app-toast__close:active {
    transform: scale(0.96);
  }

.app-toast__close i {
  font-size: 14px;
  line-height: 1;
}

.app-toast--success {
  --toast-accent: #16a34a;
  --toast-shadow: rgba(22, 163, 74, 0.3);
}
  
.app-toast--warning {
  --toast-accent: #ea580c;
  --toast-shadow: rgba(234, 88, 12, 0.3);
}
  
.app-toast--error {
  --toast-accent: #dc2626;
  --toast-shadow: rgba(220, 38, 38, 0.3);
}
  
.app-toast--info {
  --toast-accent: #2563eb;
  --toast-shadow: rgba(37, 99, 235, 0.3);
}

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

@media (max-width: 640px) {
  .app-toast-stack {
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
  }

  .app-toast {
    width: 100%;
    max-width: none;
    padding: 10px 10px 10px 13px;
  }
}
