/* Page-level layout: topbar across the top, sidebar + viewport below. */

body {
  display: grid;
  grid-template-rows: var(--topbar-height) 1fr;
}

/* ────────── Topbar ────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-logo {
  width: 26px;
  height: 26px;
}

.topbar-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

.topbar-subtitle {
  font-size: 12px;
  color: var(--color-text-muted);
  border-left: 1px solid var(--color-border);
  padding-left: var(--space-3);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-status {
  font-size: 12px;
  color: var(--color-text-muted);
}

/* ────────── App body: sidebar + viewport ────────── */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  overflow: hidden;
  height: 100%;
}

.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  overflow-x: hidden;
}

.viewport {
  position: relative;
  background: var(--color-bg);
  overflow: hidden;
}

.viewport-canvas {
  width: 100%;
  height: 100%;
}

/* ────────── Mobile sidebar toggle (FAB) ────────── */

.mobile-toggle {
  display: none;
  position: fixed;
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  /* Bottom-left so the Assistant FAB owns the right corner. */
  left:   calc(var(--space-4) + env(safe-area-inset-left, 0px));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-accent);
  color: white;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  z-index: 30;
  transition: transform var(--t-fast), background var(--t-fast);
}

.mobile-toggle:hover { background: var(--color-accent-hover); }
.mobile-toggle:active { transform: scale(0.95); }

.mobile-toggle .material-icons {
  font-size: 24px;
}

/* The sidebar-open state — change the FAB icon visually */
.sidebar.is-open ~ .mobile-toggle .material-icons::before {
  /* Replace via content swap not reliable for ligature fonts;
     keep the menu icon — backdrop + tap-out handles the close. */
}

/* ────────── Mobile sidebar backdrop ────────── */

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 14;
  opacity: 0;
  transition: opacity var(--t-base);
}

.sidebar-backdrop.is-visible {
  display: block;
  opacity: 1;
}

/* ────────── Breakpoint: ≤ 920 px (tablet portrait + smaller) ────────── */

@media (max-width: 920px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    width: min(85vw, 320px);
    max-width: 100vw;
    height: calc(100% - var(--topbar-height));
    transform: translateX(-100%);
    transition: transform var(--t-base);
    z-index: 15;
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.45);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
  .mobile-toggle {
    display: flex;
  }
  .topbar-subtitle { display: none; }
}

/* ────────── Breakpoint: ≤ 540 px (phone portrait) ────────── */

@media (max-width: 540px) {
  .topbar { padding: 0 var(--space-3); }
  .topbar-status { display: none; }    /* hide "No model loaded" text */
  .topbar-actions { gap: var(--space-2); }

  /* Topbar buttons become icon-only */
  .topbar .btn .btn-label { display: none; }
  .topbar .btn {
    width: 40px;
    height: 36px;
    padding: 0;
    justify-content: center;
  }
  .topbar .btn .material-icons {
    font-size: 18px;
  }
}

/* ────────── Safe-area padding for notched phones ────────── */

@supports (padding: env(safe-area-inset-bottom)) {
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
