/* ─────────────────────────────────────────────
   Color tokens
   ───────────────────────────────────────────── */
:root {
  --c-text:         #1a1d27;
  --c-accent:       #5b6ef5;
  --c-deep-indigo:  #534ab7;
  --c-indigo-tint:  #eeedfe;
  --c-off-white:    #f9fafb;
  --c-light-grey:   #f5f6fa;
  --c-border:       #e2e4ee;
  --c-muted:        #8b8fa8;
  --c-light-muted:  #adb0c2;
  --c-body:         #5a5e78;
  --c-green:        #639922;
  --c-red:          #e24b4a;

  --topbar-h:    44px;
  --sidebar-w:   172px;
  --breadcrumb-h: 32px;
}

/* ─────────────────────────────────────────────
   Reset & base
   ───────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  color: var(--c-text);
  background: var(--c-off-white);
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

ul {
  list-style: none;
}

button {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.hidden {
  display: none !important;
}

/* ─────────────────────────────────────────────
   Top Bar
   ───────────────────────────────────────────── */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 0.5px solid var(--c-border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 100;
}

.top-bar-left {
  flex-shrink: 0;
}

.top-bar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 300px;
  margin: 0 auto;
}

.top-bar-right {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Logo */
.logo {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 7px;
}

.logo-img {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  flex-shrink: 0;
}

.logo-bayze {
  color: var(--c-text);
}

.logo-lab {
  color: #22c55e;
}

/* Search */
.search-input {
  width: 100%;
  height: 28px;
  background: var(--c-light-grey);
  border: 0.5px solid var(--c-border);
  border-radius: 7px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--c-text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.search-input::placeholder {
  color: var(--c-light-muted);
}

.search-input:focus {
  border-color: var(--c-accent);
}

/* User email */
.user-email {
  font-size: 11px;
  color: var(--c-muted);
}

@media (max-width: 900px) {
  .user-email {
    display: none;
  }
}

/* Avatar */
.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--c-indigo-tint);
  color: var(--c-deep-indigo);
  font-size: 10px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  user-select: none;
  flex-shrink: 0;
}

.avatar-sm {
  width: 22px;
  height: 22px;
  font-size: 9px;
}

/* ─────────────────────────────────────────────
   App layout
   ───────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: calc(100vh - var(--topbar-h));
  margin-top: var(--topbar-h);
}

/* ─────────────────────────────────────────────
   Sidebar
   ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #fff;
  border-right: 0.5px solid var(--c-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px 0;
}

/* Nav groups */
.nav-group {
  margin-bottom: 16px;
}

.nav-group-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--c-light-muted);
  letter-spacing: 0.07em;
  padding: 0 4px;
  margin-bottom: 4px;
}

/* Nav list items */
.nav-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--c-body);
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}

.nav-item:hover {
  background: var(--c-light-grey);
}

.nav-item.active {
  background: var(--c-indigo-tint);
  color: var(--c-deep-indigo);
  font-weight: 500;
}

.nav-item .nav-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--c-border);
  flex-shrink: 0;
}

.nav-item.active .nav-dot {
  background: var(--c-accent);
}

.nav-item .nav-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item .nav-count {
  font-size: 10px;
  color: var(--c-light-muted);
  flex-shrink: 0;
}

/* In This Section nav items (11px) */
#nav-in-section-list .nav-item {
  font-size: 11px;
}

/* ─────────────────────────────────────────────
   Identity block
   ───────────────────────────────────────────── */
.identity-block {
  padding: 0 8px 12px;
  flex-shrink: 0;
}

.identity-divider {
  height: 0.5px;
  background: var(--c-border);
  margin: 0 0 10px;
}

.identity-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--c-light-muted);
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}

.identity-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.identity-email {
  font-size: 11px;
  color: var(--c-body);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity-kernel {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--c-body);
  margin-top: 8px;
}

/* ─────────────────────────────────────────────
   Status dots
   ───────────────────────────────────────────── */
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-light-muted);
  flex-shrink: 0;
  display: inline-block;
}

.dot-green  { background: var(--c-green); }
.dot-red    { background: var(--c-red); }
.dot-idle   { background: var(--c-light-muted); }
.dot-indigo { background: var(--c-accent); }

/* ─────────────────────────────────────────────
   Main content area
   ───────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ─────────────────────────────────────────────
   Portal landing view
   ───────────────────────────────────────────── */
.portal-view {
  flex: 1;
  overflow-y: auto;
  background: var(--c-off-white);
  padding: 20px 20px 32px;
}

.portal-section {
  margin-bottom: 28px;
}

.portal-section.hidden {
  display: none !important;
}

/* Section header */
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.section-header-label {
  font-size: 11px;
  color: var(--c-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.section-header-rule {
  flex: 1;
  height: 0.5px;
  background: var(--c-border);
}

/* Notebook grid */
.notebook-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

/* Notebook card */
.notebook-card {
  background: #fff;
  border: 0.5px solid var(--c-border);
  border-radius: 10px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s;
  display: flex;
  flex-direction: column;
}

.notebook-card:hover {
  border-color: var(--c-accent);
}

.notebook-card.hidden {
  display: none !important;
}

/* Thumbnail */
.card-thumbnail {
  width: 100%;
  height: 82px;
  overflow: hidden;
  background: var(--c-light-grey);
  flex-shrink: 0;
}

.card-thumbnail img {
  width: 100%;
  height: 82px;
  object-fit: cover;
  display: block;
}

.card-thumbnail svg {
  display: block;
}

/* Card body */
.card-body {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.card-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--c-text);
  line-height: 1.3;
}

.badge-new {
  font-size: 9px;
  background: var(--c-indigo-tint);
  color: var(--c-deep-indigo);
  border-radius: 3px;
  padding: 1px 5px;
  white-space: nowrap;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 1px;
}

.card-description {
  font-size: 11px;
  color: var(--c-muted);
  line-height: 1.4;
}

.card-params {
  font-size: 10px;
  font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
  color: var(--c-accent);
  margin-top: 2px;
}

/* ─────────────────────────────────────────────
   Notebook view
   ───────────────────────────────────────────── */
.notebook-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Breadcrumb bar */
.breadcrumb-bar {
  height: var(--breadcrumb-h);
  background: var(--c-light-grey);
  border-bottom: 0.5px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  gap: 12px;
  flex-shrink: 0;
}

.breadcrumb-left {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  min-width: 0;
}

.breadcrumb-link {
  font-size: 11px;
  color: var(--c-accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.breadcrumb-link:hover {
  text-decoration: underline;
}

.breadcrumb-sep {
  font-size: 11px;
  color: var(--c-border);
  flex-shrink: 0;
}

.breadcrumb-current {
  font-size: 11px;
  color: var(--c-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breadcrumb-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* Share button */
.share-btn {
  font-size: 11px;
  color: var(--c-accent);
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.1s;
}

.share-btn:hover {
  opacity: 0.75;
}

/* Kernel status */
.kernel-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--c-body);
  white-space: nowrap;
}

/* Notebook iframe */
.iframe-wrapper {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

#notebook-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Loading spinner overlay */
.iframe-loading {
  position: absolute;
  inset: 0;
  background: var(--c-off-white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 10;
  font-size: 12px;
  color: var(--c-muted);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--c-border);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

/* Data freshness badge on cards */
.card-freshness {
  font-size: 10px;
  color: var(--c-light-muted);
  margin-top: 2px;
}

/* ─────────────────────────────────────────────
   Scrollbar styling (Webkit)
   ───────────────────────────────────────────── */
.sidebar-nav::-webkit-scrollbar,
.portal-view::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track,
.portal-view::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb,
.portal-view::-webkit-scrollbar-thumb {
  background: var(--c-border);
  border-radius: 2px;
}

/* ─────────────────────────────────────────────
   Mobile (≤ 640px)
   ───────────────────────────────────────────── */
@media (max-width: 640px) {
  html, body {
    overflow: auto;
  }

  .app-layout {
    height: auto;
    min-height: calc(100vh - var(--topbar-h));
    flex-direction: column;
  }

  /* Hide sidebar — nav not needed on small screens */
  .sidebar {
    display: none;
  }

  /* Search takes full available width */
  .top-bar-center {
    max-width: none;
    flex: 1;
  }

  /* Single-column card grid */
  .notebook-grid {
    grid-template-columns: 1fr;
  }

  /* Portal view scrolls naturally */
  .portal-view {
    overflow-y: visible;
    padding: 12px 12px 24px;
  }

  /* Notebook view fills viewport height minus topbar + breadcrumb */
  .notebook-view {
    height: calc(100vh - var(--topbar-h));
  }

  .iframe-wrapper {
    height: calc(100vh - var(--topbar-h) - var(--breadcrumb-h));
  }

  /* Breadcrumb: hide share button on very small screens */
  .share-btn {
    display: none;
  }

  /* Kernel status shorter label */
  #kernel-label {
    display: none;
  }
}
