/* ── DPanel Layout ───────────────────────────────────────────────────────────── */

:root {
  --sidebar-w:  188px;
  --topbar-h:   48px;
}

/* ── Reset ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg-base); color: var(--text-primary); }

/* ── Sidebar — fixed left column ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100dvh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo-mark {
  width: 26px; height: 26px;
  background: linear-gradient(135deg, var(--accent) 0%, #7b5cf6 100%);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.7rem; font-weight: 500; color: #fff;
  letter-spacing: -0.03em;
  box-shadow: 0 2px 8px rgba(79,142,247,0.4);
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}

.sidebar-logo-version {
  font-family: var(--font-mono);
  font-size: 0.575rem;
  color: var(--text-muted);
  margin-left: auto;
  background: var(--bg-elevated);
  padding: 2px 5px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
}
/* Clickable variant — same look, hover state hints it's interactive */
.sidebar-version-btn {
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast), border-color var(--duration-fast);
}
.sidebar-version-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

/* ── Sidebar footer: User Guide link ───────────────────────────────────────── */
.sidebar-guide-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin: 4px 8px 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: transparent;
  transition: background var(--duration-fast), color var(--duration-fast), border-color var(--duration-fast);
}
.sidebar-guide-link:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--accent);
}
.sidebar-guide-link svg:first-child { color: var(--accent); flex-shrink: 0; }

.sidebar-nav {
  flex: 1;
  padding: 6px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-section-label {
  font-size: 0.575rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 6px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background var(--duration-fast) var(--ease-out-expo),
              color var(--duration-fast) var(--ease-out-expo);
  user-select: none;
  border: 1px solid transparent;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--border-accent);
}
.nav-item.active .nav-icon { color: var(--accent); }

.nav-icon {
  width: 15px; height: 15px;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity var(--duration-fast);
}
.nav-item:hover .nav-icon,
.nav-item.active .nav-icon { opacity: 1; }

.nav-badge {
  margin-left: auto;
  font-size: 0.575rem;
  font-family: var(--font-mono);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: var(--radius-pill);
}

.sidebar-footer {
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration-fast);
}
.sidebar-user:hover { background: var(--bg-hover); }

.user-avatar {
  width: 26px; height: 26px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #3a4a6a 0%, #1e2a45 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 600; color: var(--accent);
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name  { font-size: 0.8rem; font-weight: 500; color: var(--text-primary); }
.user-role  { font-size: 0.6875rem; color: var(--text-muted); }

/* ── Topbar — fixed top strip, starts after sidebar ─────────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 30;
  gap: 12px;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.topbar-breadcrumb .current { color: var(--text-primary); font-weight: 500; }
.topbar-sep { color: var(--text-muted); }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-hostname {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
}

.topbar-clock {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

/* ── App shell — just a wrapper ──────────────────────────────────────────────── */
.app-shell { min-height: 100dvh; }

/* ── Content area — pushed right of sidebar, below topbar ───────────────────── */
.content-area {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: 16px;
  min-height: calc(100dvh - var(--topbar-h));
  overflow-y: auto;
}

/* ── Page sections ───────────────────────────────────────────────────────────── */
.page-section {
  display: none;
  animation: fadeUp var(--duration-slow) var(--ease-out-expo) forwards;
}
.page-section.active { display: block; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}

.page-header-left h2 {
  font-size: 1.1875rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.page-header-left p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 1px;
}

/* ── Login page ──────────────────────────────────────────────────────────────── */
.login-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.login-bg {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(79,142,247,0.1) 0%, transparent 70%),
              radial-gradient(ellipse 60% 50% at 80% 90%, rgba(123,92,246,0.06) 0%, transparent 70%);
  pointer-events: none;
}

.login-card-outer {
  width: 100%; max-width: 400px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 3px;
  box-shadow: 0 32px 80px -12px rgba(0,0,0,0.8), 0 1px 0 0 rgba(255,255,255,0.06) inset;
  animation: fadeUp var(--duration-slow) var(--ease-out-expo) forwards;
}

.login-card-inner {
  background: var(--bg-surface);
  border-radius: calc(var(--radius-xl) - 3px);
  padding: 40px;
  box-shadow: 0 1px 0 0 rgba(255,255,255,0.04) inset;
}

.login-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 32px;
}

.login-logo-mark {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent) 0%, #7b5cf6 100%);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.9rem; font-weight: 500; color: #fff;
  box-shadow: 0 4px 16px rgba(79,142,247,0.4);
}

.login-title    { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.025em; }
.login-subtitle { font-size: 0.8125rem; color: var(--text-muted); margin-top: 4px; }

/* ── Hamburger toggle (mobile only) ──────────────────────────────────────── */
.topbar-hamburger {
  display: none;            /* hidden by default; shown < 768px */
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  margin-right: var(--space-3);
  flex-shrink: 0;
  transition: background var(--duration-fast), color var(--duration-fast);
}
.topbar-hamburger:hover { background: var(--bg-elevated); color: var(--text-primary); }
.topbar-hamburger:focus-visible { box-shadow: var(--shadow-focus); }

/* Backdrop when the mobile sidebar is open — tap to dismiss */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 39;
  animation: fadeIn 180ms var(--ease-out-expo);
}
.sidebar.open ~ .sidebar-backdrop,
body.sidebar-open .sidebar-backdrop { display: block; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar slides off-screen by default; .open class slides it in */
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--duration-base) var(--ease-out-expo);
    z-index: 50;
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { left: 0; }
  .content-area { margin-left: 0; padding: 12px; }

  /* Show hamburger button */
  .topbar-hamburger { display: inline-flex; }

  /* Tighten topbar — hide hostname + clock on phones; keep breadcrumb + essentials */
  .topbar-hostname,
  .topbar-clock { display: none !important; }
  .topbar-breadcrumb { font-size: 0.875rem; }
  .topbar-right { gap: var(--space-2); }
}

@media (max-width: 600px) {
  /* Hide the Webmail button too — too crowded; users can reach it from Apps section */
  .topbar-webmail-btn { display: none !important; }
  /* Even shorter breadcrumb */
  .topbar-breadcrumb span:first-child { display: none; }
  .topbar-breadcrumb .topbar-sep { display: none; }
  .content-area { padding: 8px; }
}

/* ── Sidebar resize & collapse ───────────────────────────────────────────────── */

/* Smooth transitions on layout-critical props (toggle only, not drag) */
.sidebar       { transition: width 200ms ease-in-out; }
.topbar        { transition: left  200ms ease-in-out; }
.content-area  { transition: margin-left 200ms ease-in-out; }

/* Kill transitions during active drag so resize is 1-to-1 with cursor */
body.sidebar-dragging .sidebar,
body.sidebar-dragging .topbar,
body.sidebar-dragging .content-area { transition: none !important; }

/* Kill transitions when restoring state on load (avoid FOUC flash) */
body.sidebar-instant .sidebar,
body.sidebar-instant .topbar,
body.sidebar-instant .content-area { transition: none !important; }

/* Drag resize handle — sits on the inner-right edge of the sidebar */
.sidebar-resize-handle {
  position: absolute;
  top: 0; right: 0;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 50;
}
.sidebar-resize-handle::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 2px;
  background: transparent;
  border-radius: 1px;
  transition: background 180ms, opacity 180ms;
}
.sidebar-resize-handle:hover::after,
body.sidebar-dragging .sidebar-resize-handle::after {
  background: var(--accent);
  opacity: 0.5;
}

/* Collapse toggle — sits in the sidebar footer row */
.sidebar-footer-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
}
.sidebar-collapse-btn {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--duration-fast), color var(--duration-fast), border-color var(--duration-fast);
}
.sidebar-collapse-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

/* Floating expand tab — visible only when sidebar is collapsed */
.sidebar-expand-tab {
  position: fixed;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 16px; height: 52px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  z-index: 45;
  padding: 0;
  transition: width 150ms ease-in-out, color 150ms, background 150ms;
}
.sidebar-expand-tab:hover {
  width: 22px;
  background: var(--bg-elevated);
  color: var(--accent);
}
.sidebar-expand-tab.visible { display: flex; }

/* On mobile, hide resize & collapse controls (sidebar uses transform already) */
@media (max-width: 768px) {
  .sidebar-resize-handle,
  .sidebar-collapse-btn,
  .sidebar-expand-tab { display: none !important; }
}

/* ── [NEW] Sidebar search ─────────────────────────────────────────────────── */

.nav-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin: 2px 0 6px;
}

.nav-search-icon {
  position: absolute;
  left: 9px;
  color: var(--text-muted);
  pointer-events: none;
  flex-shrink: 0;
  /* vertically centred inside the input */
  top: 50%;
  transform: translateY(-50%);
}

.nav-search-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  padding: 6px 26px 6px 28px;
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out-expo),
              box-shadow    var(--duration-fast) var(--ease-out-expo);
  /* hide browser native search chrome (×, magnifier) */
  -webkit-appearance: none;
  appearance: none;
}
.nav-search-input::-webkit-search-cancel-button,
.nav-search-input::-webkit-search-decoration { display: none; }
.nav-search-input::placeholder { color: var(--text-muted); }
.nav-search-input:focus {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-focus);
}

/* custom × clear button */
.nav-search-clear {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 3px 5px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--duration-fast);
  line-height: 1;
}
.nav-search-clear:hover { color: var(--text-secondary); }

/* ── [NEW] Collapsible nav groups ─────────────────────────────────────────── */

/* wrapper: gap between groups is handled by sidebar-nav's existing gap:1px */
.nav-group { }

/* The category label is now a button; reset defaults then re-apply label style */
.nav-group-btn {
  /* full button reset */
  all: unset;
  box-sizing: border-box;
  /* match the original .nav-section-label layout */
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 6px 4px;
  /* match the original .nav-section-label typography */
  font-family: var(--font-ui);
  font-size: 0.575rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  /* interactive */
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color var(--duration-fast) var(--ease-out-expo);
  user-select: none;
  -webkit-user-select: none;
}
.nav-group-btn:hover { color: var(--text-secondary); }
/* visible focus ring — keyboard only */
.nav-group-btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* chevron — rotates –90° when group is collapsed */
.nav-group-chevron {
  flex-shrink: 0;
  opacity: 0.45;
  transition: transform    var(--duration-base) var(--ease-out-expo),
              opacity      var(--duration-fast)  var(--ease-out-expo);
}
.nav-group-btn:hover .nav-group-chevron { opacity: 0.75; }
.nav-group.is-collapsed .nav-group-chevron { transform: rotate(-90deg); }

/*
 * CSS grid trick for smooth height animation without JS measurement.
 * grid-template-rows: 1fr → 0fr collapses to content height 0 while
 * allowing the transition to animate. Requires a min-height:0 inner wrapper.
 */
.nav-group-items {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows var(--duration-base) var(--ease-out-expo);
  overflow: hidden;
}
.nav-group.is-collapsed .nav-group-items {
  grid-template-rows: 0fr;
}

/* inner wrapper must have min-height:0 for the grid trick to work */
.nav-group-inner {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  /* tiny vertical padding so focus rings on first/last item aren't clipped */
  padding: 1px 0 2px;
}

/* ── [NEW] Search filter state ────────────────────────────────────────────── */

/* Items hidden by the search filter */
.nav-item.nav-hidden {
  display: none;
}

/* When a group has no visible children during search, hide the whole group */
.nav-group.nav-group-hidden {
  display: none;
}

/* "no results" message shown inside nav when search yields nothing */
.nav-search-empty {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  padding: 12px 8px;
}

/* ── [NEW] Collapse-all / Expand-all button ──────────────────────────────── */

.nav-collapseall-btn {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 2px 6px 7px;
  font-family: var(--font-ui);
  font-size: 0.575rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color var(--duration-fast) var(--ease-out-expo);
  user-select: none;
  -webkit-user-select: none;
}
.nav-collapseall-btn:hover { color: var(--text-secondary); }
.nav-collapseall-btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

/* Rotate icon 180° when all groups are collapsed (expand state) */
.nav-collapseall-btn.is-all-collapsed .nav-collapseall-icon {
  transform: rotate(180deg);
}
.nav-collapseall-icon {
  flex-shrink: 0;
  opacity: 0.6;
  transition: transform var(--duration-base) var(--ease-out-expo);
}
.nav-collapseall-btn:hover .nav-collapseall-icon { opacity: 0.9; }
