/* ═══════════════════════════════════════════════════════════════════════════
   css/overlay.css
   Draven SPA Overlay System — Premium panel animations
   Venice AI / Discord / ChatGPT style sheet
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Root container ──────────────────────────────────────────────────────── */
#dov-root {
  position: fixed;
  inset: 0;
  z-index: 8500;
  pointer-events: none;
  isolation: isolate;
}
#dov-root[aria-hidden="false"] {
  pointer-events: auto;
}

/* ── Backdrop ────────────────────────────────────────────────────────────── */
.dov-backdrop {
  position: absolute;
  inset: 0;
  background: transparent;
  backdrop-filter: blur(0px) brightness(1);
  -webkit-backdrop-filter: blur(0px) brightness(1);
  transition:
    background 0.18s cubic-bezier(0.16, 1, 0.3, 1),
    backdrop-filter 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  cursor: default;
}
.dov-backdrop.active {
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(10px) brightness(0.85);
  -webkit-backdrop-filter: blur(10px) brightness(0.85);
  pointer-events: auto;
  cursor: pointer;
}

/* ── Panel ───────────────────────────────────────────────────────────────── */
.dov-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(740px, 100vw);
  background: var(--bg, #020203);
  border-left: 1px solid var(--border, #1e1e24);
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  pointer-events: none;
  will-change: transform;
  overflow: hidden;
  box-shadow:
    -2px 0 0 0 var(--border, #1e1e24),
    -16px 0 60px -8px rgba(0, 0, 0, 0.55),
    -40px 0 80px -20px rgba(0, 0, 0, 0.3);
}

/* Active = visible */
.dov-panel.active {
  pointer-events: auto;
  transform: translateX(0);
  animation: dov-slide-in 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Closing animation */
.dov-panel.dov-closing {
  animation: dov-slide-out 0.16s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes dov-slide-in {
  from  { transform: translateX(105%); opacity: 0.6; }
  to    { transform: translateX(0);    opacity: 1;   }
}
@keyframes dov-slide-out {
  from  { transform: translateX(0);    opacity: 1;   }
  to    { transform: translateX(105%); opacity: 0.5; }
}

/* ── Drag handle (mobile) ────────────────────────────────────────────────── */
.dov-drag-handle {
  display: none;
  width: 36px;
  height: 4px;
  background: var(--border-3, #32323d);
  border-radius: 999px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

/* ── Panel body ──────────────────────────────────────────────────────────── */
.dov-panel-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  min-height: 0;
}

/* ── Scroll content ──────────────────────────────────────────────────────── */
.dov-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  min-height: 0;
}
.dov-content::-webkit-scrollbar { width: 4px; }
.dov-content::-webkit-scrollbar-track { background: transparent; }
.dov-content::-webkit-scrollbar-thumb {
  background: var(--border-2, #272730);
  border-radius: 999px;
}
.dov-content::-webkit-scrollbar-thumb:hover {
  background: var(--border-3, #32323d);
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.dov-layout {
  display: flex;
  min-height: 100%;
}
.dov-layout--single {
  flex-direction: column;
}

/* ── Sidebar nav ─────────────────────────────────────────────────────────── */
.dov-nav {
  width: 210px;
  flex-shrink: 0;
  border-right: 1px solid var(--border, #1e1e24);
  background: var(--surface, #09090c);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 0 24px;
}
.dov-nav-inner {
  flex: 1;
}
/* Override page-sidebar styles for panel context */
.dov-nav .page-sidebar {
  position: static;
  height: auto;
  border-right: none;
  width: 100%;
  padding: 0;
}

/* ── Main scrollable content ─────────────────────────────────────────────── */
.dov-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}
.dov-main::-webkit-scrollbar { width: 4px; }
.dov-main::-webkit-scrollbar-thumb {
  background: var(--border-2, #272730);
  border-radius: 999px;
}

/* ── Close button ────────────────────────────────────────────────────────── */
.dov-close-btn {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 10;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-2, #8a8a96);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    transform 0.15s ease;
}
.dov-close-btn:hover {
  background: var(--surface-3, #161619);
  color: var(--text, #eeeef0);
  transform: scale(1.08);
}
.dov-close-btn:active { transform: scale(0.95); }

/* Inside nav: position relative */
.dov-nav .dov-close-btn {
  position: relative;
  top: auto;
  right: auto;
  flex-shrink: 0;
  margin: 0 4px 0 4px;
}

/* ── Loading skeleton ────────────────────────────────────────────────────── */
.dov-skeleton {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 12px;
  flex-direction: column;
}
.dov-spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border-2, #272730);
  border-top-color: var(--accent, #6474f8);
  border-radius: 50%;
  animation: dov-spin 0.65s linear infinite;
}
@keyframes dov-spin {
  to { transform: rotate(360deg); }
}

/* ── Error state ─────────────────────────────────────────────────────────── */
.dov-error {
  position: relative;
  min-height: 100vh;
}
.dov-error-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 40px;
  text-align: center;
  color: var(--text-2, #8a8a96);
  font-size: 14px;
}
.dov-error-inner svg { color: var(--text-4, #35353f); }
.dov-fallback-link {
  color: var(--accent, #6474f8);
  text-decoration: none;
  font-size: 13px;
  padding: 8px 16px;
  border: 1px solid var(--accent-dim-2, rgba(100,116,248,.18));
  border-radius: var(--r-sm, 10px);
  transition: background 0.15s;
}
.dov-fallback-link:hover { background: var(--accent-dim, rgba(100,116,248,.10)); }

/* ── Body scroll lock ────────────────────────────────────────────────────── */
body.dov-body-open {
  overflow: hidden;
}
/* Prevent layout shift from scrollbar disappearing */
body.dov-body-open:not(.has-no-scrollbar) {
  padding-right: var(--scrollbar-width, 0);
}

/* ── Settings page overrides inside panel ────────────────────────────────── */
/* Remove redundant topbar/nav from injected settings HTML */
.dov-content .topbar,
.dov-content header.topbar {
  display: none !important;
}
/* Settings main: reset padding for panel context */
.dov-main .page-main {
  max-width: none;
  padding: 40px 32px 60px;
}
/* Left sidebar inside settings: already handled by dov-nav */
.dov-main .page-sidebar,
.dov-main .page { flex-direction: column; }
.dov-main .page > .page-sidebar { display: none !important; }
.dov-main .page > .page-main { padding-left: 0; }

/* ── Login page overrides inside panel ───────────────────────────────────── */
.dov-content .topbar-login,
.dov-content .login-topbar,
.dov-content nav.login-nav { display: none !important; }
/* Center login form inside panel */
.dov-main .login-container,
.dov-main .auth-container,
.dov-main .login-page {
  min-height: calc(100vh - 40px);
}

/* ── Mobile: bottom sheet ────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .dov-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 94dvh;
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--border, #1e1e24);
    border-radius: 20px 20px 0 0;
    transform: translateY(105%);
    box-shadow:
      0 -2px 0 0 var(--border, #1e1e24),
      0 -16px 60px -8px rgba(0, 0, 0, 0.5);
  }

  .dov-drag-handle { display: block; }

  .dov-panel.active {
    animation: dov-sheet-in 0.24s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  }
  .dov-panel.dov-closing {
    animation: dov-sheet-out 0.18s cubic-bezier(0.55, 0, 1, 0.45) forwards;
  }

  @keyframes dov-sheet-in {
    from  { transform: translateY(105%); opacity: 0.7; }
    to    { transform: translateY(0);    opacity: 1;   }
  }
  @keyframes dov-sheet-out {
    from  { transform: translateY(0);    opacity: 1;   }
    to    { transform: translateY(105%); opacity: 0.5; }
  }

  .dov-close-btn {
    top: 14px;
    right: 14px;
  }

  /* Stack sidebar + main vertically on mobile */
  .dov-layout {
    flex-direction: column;
  }
  .dov-nav {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border, #1e1e24);
    padding: 12px 0;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .dov-nav-inner {
    display: flex;
    flex-direction: row;
    padding: 0 8px;
  }
  .dov-nav-inner .page-sidebar {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    padding: 0;
    width: auto;
  }
  .dov-nav-inner .sidebar-label,
  .dov-nav-inner .sidebar-divider { display: none; }
  .dov-nav-inner .sidebar-item {
    flex-shrink: 0;
    padding: 8px 14px;
    border-left: none;
    border-bottom: 2px solid transparent;
    border-radius: var(--r-sm, 10px);
    font-size: 13px;
  }
  .dov-nav-inner .sidebar-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent, #6474f8);
    background: var(--accent-dim, rgba(100,116,248,.10));
  }
  .dov-main .page-main {
    padding: 20px 16px 60px;
  }
}

/* ── Reduced motion support ──────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .dov-panel,
  .dov-panel.active,
  .dov-panel.dov-closing,
  .dov-backdrop {
    animation: none !important;
    transition: opacity 0.15s ease !important;
    transform: none !important;
  }
  .dov-panel { opacity: 0; pointer-events: none; }
  .dov-panel.active { opacity: 1; pointer-events: auto; transform: none; }
  .dov-panel.dov-closing { opacity: 0; }
}

/* ── Focus ring inside panel ─────────────────────────────────────────────── */
.dov-panel :focus-visible {
  outline: 2px solid var(--accent, #6474f8);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Smooth content entrance ─────────────────────────────────────────────── */
.dov-layout {
  animation: dov-content-in 0.14s 0.06s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes dov-content-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Theme-aware backdrop on light mode ──────────────────────────────────── */
html.theme-light .dov-backdrop.active {
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px) brightness(0.92);
  -webkit-backdrop-filter: blur(8px) brightness(0.92);
}
html.theme-light .dov-panel {
  background: var(--bg, #f5f5f7);
  box-shadow:
    -2px 0 0 0 var(--border, rgba(0,0,0,.08)),
    -16px 0 60px -8px rgba(0, 0, 0, 0.18);
}
