/* Frostpeak Panel — application shell layout (top bar, sidebar, drawer, content) */

.app {
  --banner-height: 0px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app.has-demo { --banner-height: 32px; }

/* ---------- Boot screen (static, from index.html) ---------- */
.boot {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  color: var(--muted-foreground);
  font-size: var(--text-sm);
}
.boot-logo { width: 48px; height: 48px; }
.noscript {
  margin: var(--space-8) auto;
  max-width: 480px;
  padding: var(--space-4);
  text-align: center;
  color: var(--foreground);
}

/* ---------- Skip link ---------- */
.skip-link {
  position: fixed;
  left: var(--space-2);
  top: var(--space-2);
  z-index: calc(var(--z-toast) + 1);
  transform: translateY(-200%);
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-radius: var(--radius-control);
  background: var(--primary-button);
  color: var(--primary-foreground);
  font-size: var(--text-sm);
  font-weight: 600;
}
.skip-link:focus-visible { transform: none; }

/* ---------- Sticky header group (demo banner + top bar) ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  background: var(--background);
}

.demo-banner {
  height: var(--banner-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  background: repeating-linear-gradient(135deg, #3b2a05 0 12px, #2e2104 12px 24px);
  border-bottom: 1px solid var(--warning-border);
  color: var(--warning-strong);
  font-size: var(--text-xs);
  line-height: var(--leading-xs);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
}
.demo-banner .demo-tag {
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--warning);
  color: #1a1203;
}
.demo-banner .demo-text { overflow: hidden; text-overflow: ellipsis; }

.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4) 0 var(--space-3);
  border-bottom: 1px solid transparent;
}
.app.is-scrolled .topbar { border-bottom-color: var(--border); }

.icon-btn.topbar-menu { display: none; }
.search-box kbd { white-space: nowrap; flex-shrink: 0; }

/* Brand */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-2);
  color: var(--foreground);
  border-radius: var(--radius-control);
  flex-shrink: 0;
}
.brand:hover { color: var(--foreground); text-decoration: none; }
.brand-logo { width: 28px; height: 28px; }
.brand-name {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
}
.brand-tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, #0f6fd6 0%, #1d6fe0 60%, #2f7ff0 100%);
  color: #ffffff;
  font-family: var(--font-mono);
  font-size: 0.6875rem; /* brand tag (badge, DESIGN) */
  font-weight: 600;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.brand-cursor { animation: brand-blink 1.1s steps(1) infinite; }
@keyframes brand-blink { 50% { opacity: 0; } }

/* Section pills */
.topnav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: var(--space-4);
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.topnav::-webkit-scrollbar { display: none; }
.topnav-item {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-control);
  color: var(--nav-foreground);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.topnav-item:hover {
  background: var(--nav-hover-bg);
  color: var(--nav-hover-foreground);
  text-decoration: none;
}
.topnav-item[aria-current="true"] {
  background: var(--nav-selected-bg);
  color: var(--nav-selected-foreground);
}

.topbar-spacer { flex: 1 1 auto; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Quick search (Ctrl K) */
.search {
  position: relative;
  width: 260px;
}
.search-box {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 32px;
  padding: 0 6px 0 10px;
  border: 1px solid var(--input);
  border-radius: var(--radius-sm);
  background: var(--input-background);
  color: var(--muted-foreground);
  transition: border-color var(--transition-fast);
}
.search-box:hover { border-color: var(--input-hover); }
.search-box:focus-within { border-color: var(--ring); box-shadow: 0 0 0 1px var(--ring); }
.search-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--foreground);
  font-size: var(--text-sm);
  outline: none;
}
.search-input::placeholder { color: var(--muted-foreground); opacity: 1; }
.search-input::-webkit-search-cancel-button { display: none; }
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: var(--z-popover);
  max-height: 360px;
  overflow-y: auto;
  padding: var(--space-1);
  border-radius: var(--radius-control);
  background: var(--popover);
  box-shadow: var(--shadow-popover);
  list-style: none;
  margin: 0;
}
.search-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 36px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--nav-foreground);
  font-size: var(--text-sm);
  cursor: pointer;
}
.search-option[aria-selected="true"],
.search-option:hover {
  background: var(--nav-selected-bg);
  color: var(--nav-selected-foreground);
}
.search-option-section { margin-left: auto; color: var(--muted-foreground); font-size: var(--text-xs); }
.search-empty { padding: 10px; color: var(--muted-foreground); font-size: var(--text-sm); }

/* Icon buttons in the top bar */
.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--nav-foreground);
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.icon-btn:hover { background: var(--nav-hover-bg); color: var(--foreground); }
.icon-btn[aria-expanded="true"] { background: var(--nav-selected-bg); color: var(--foreground); }
.icon-btn-count {
  position: absolute;
  top: 3px;
  right: 3px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--primary-button);
  color: #fff;
  font-size: 0.6875rem; /* counter */
  line-height: 16px;
  font-weight: 700;
  text-align: center;
}

/* Popovers (notifications, user menu) */
.popover-anchor { position: relative; }
.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: var(--z-popover);
  width: 300px;
  max-width: calc(100vw - 24px);
  padding: var(--space-2);
  border-radius: var(--radius-card);
  background: var(--popover);
  box-shadow: var(--shadow-popover);
}
.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-1);
}
.popover-title { font-size: var(--text-sm); font-weight: 600; }
.notif-list { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; }
.notif-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
}
.notif-item + .notif-item { border-top: 1px solid var(--border); }
.notif-item .icon { margin-top: 2px; }
.notif-time { display: block; color: var(--muted-foreground); font-size: var(--text-xs); }
.notif-empty { padding: var(--space-4) var(--space-2); color: var(--muted-foreground); font-size: var(--text-sm); text-align: center; }

.avatar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
}
.avatar-btn:hover .avatar,
.avatar-btn[aria-expanded="true"] .avatar { box-shadow: 0 0 0 2px var(--glow); }

.user-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-1);
}
.user-card-name { font-weight: 600; font-size: var(--text-sm); line-height: var(--leading-sm); }
.user-card-sub { color: var(--muted-foreground); font-size: var(--text-xs); line-height: var(--leading-xs); }

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--nav-foreground);
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: left;
}
.menu-item:hover,
.menu-item:focus-visible {
  background: var(--nav-hover-bg);
  color: var(--nav-hover-foreground);
  text-decoration: none;
}
.menu-item-danger { color: var(--danger-light); }
.menu-item-danger:hover, .menu-item-danger:focus-visible { color: var(--danger-pale); background: var(--danger-bg); }
.menu-sep { height: 1px; margin: var(--space-1) 0; background: var(--border); }

/* ---------- Shell body ---------- */
.shell {
  flex: 1 1 auto;
  display: flex;
  align-items: flex-start;
  min-height: 0;
}

.sidebar {
  position: sticky;
  top: calc(var(--topbar-height) + var(--banner-height) + 8px);
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height) - var(--banner-height) - 16px);
  margin: 8px 0 8px 8px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--card);
  overflow: hidden;
  transition: width var(--transition-fast), flex-basis var(--transition-fast);
}

.sidebar-head { display: none; }

.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-3) var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.nav-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: 24px;
  padding: 0 10px var(--space-1);
}
.nav-group-title {
  color: var(--muted-foreground);
  font-size: var(--text-xs);
  line-height: var(--leading-xs);
  font-weight: 600;
}
.nav-group-toggle {
  border: 0;
  padding: 2px 4px;
  border-radius: 4px;
  background: transparent;
  color: var(--link);
  font-size: var(--text-xs);
  font-weight: 600;
}
.nav-group-toggle:hover { color: var(--link-hover); text-decoration: underline; }

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-control);
  color: var(--nav-foreground);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.nav-item:hover {
  background: var(--nav-hover-bg);
  color: var(--nav-hover-foreground);
  text-decoration: none;
}
.nav-item[aria-current="page"] {
  background: var(--nav-selected-bg);
  color: var(--nav-selected-foreground);
  box-shadow: inset 2px 0 0 var(--glow);
}
.nav-label { overflow: hidden; text-overflow: ellipsis; }

.sidebar-foot {
  padding: var(--space-2);
  border-top: 1px solid var(--border);
}
.sidebar-collapse {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--nav-foreground);
  font-size: var(--text-sm);
  font-weight: 500;
}
.sidebar-collapse:hover { background: var(--nav-hover-bg); color: var(--nav-hover-foreground); }
.sidebar-version {
  padding: var(--space-2) 10px 0;
  color: var(--muted-foreground);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
}

/* Collapsed (icon-only) sidebar — desktop only */
@media (min-width: 900px) {
  .app.sidebar-collapsed .sidebar {
    flex-basis: var(--sidebar-collapsed-width);
    width: var(--sidebar-collapsed-width);
  }
  .app.sidebar-collapsed .nav-label,
  .app.sidebar-collapsed .nav-group-title,
  .app.sidebar-collapsed .nav-group-toggle,
  .app.sidebar-collapsed .sidebar-collapse-label,
  .app.sidebar-collapsed .sidebar-version { display: none; }
  .app.sidebar-collapsed .nav-group-head {
    min-height: 1px;
    padding: 0;
    margin: 0 10px var(--space-2);
    border-top: 1px solid var(--border);
  }
  .app.sidebar-collapsed .nav-group:first-child .nav-group-head { border-top: 0; margin-bottom: 0; }
  .app.sidebar-collapsed .nav-item,
  .app.sidebar-collapsed .sidebar-collapse { justify-content: center; padding: 0; }
  .app.sidebar-collapsed .nav-list[hidden] { display: flex !important; }
  .app.sidebar-collapsed .sidebar-collapse .icon { transform: rotate(180deg); }
}

.drawer-backdrop { display: none; }

.main {
  flex: 1 1 auto;
  min-width: 0;
  padding: var(--space-6) var(--space-8) var(--space-10);
}
.main:focus { outline: none; }

.page {
  max-width: var(--content-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* Bare layout (login, logged-out 404) */
.bare {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}
.bare > .page {
  flex: 1 1 auto;
  width: 100%;
  max-width: none;
}

/* ---------- Responsive: drawer below 900 px ---------- */
@media (max-width: 1100px) {
  .search { width: 200px; }
}

@media (max-width: 899.98px) {
  .topbar { padding: 0 var(--space-3) 0 var(--space-2); gap: var(--space-2); }
  .icon-btn.topbar-menu { display: inline-flex; width: 40px; height: 40px; }
  .topnav, .search { display: none; }
  .brand-name { font-size: var(--text-md); }
  .icon-btn { width: 40px; height: 40px; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: calc(var(--z-topbar) + 2);
    width: min(300px, 86vw);
    height: auto;
    margin: 0;
    border-radius: 0 var(--radius-card) var(--radius-card) 0;
    border-left: 0;
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 180ms ease, visibility 0s linear 180ms;
  }
  .app.drawer-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform 180ms ease, visibility 0s;
  }
  .sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    height: var(--topbar-height);
    padding: 0 var(--space-2) 0 var(--space-3);
    border-bottom: 1px solid var(--border);
  }
  .sidebar-collapse { display: none; }
  .nav-item { height: 44px; }

  .drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-topbar) + 1);
    background: rgba(2, 3, 8, 0.72);
  }
  .app.drawer-open .drawer-backdrop { display: block; }

  .main { padding: var(--space-4) var(--space-4) var(--space-8); }
  .page { gap: var(--space-4); }
}

@media (max-width: 480px) {
  .brand-tag { display: none; }
  .demo-banner .demo-text-long { display: none; }
}
@media (min-width: 480.02px) {
  .demo-banner .demo-text-short { display: none; }
}
