/* ── Shell ─────────────────────────────────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  background: rgba(7, 8, 13, 0.88);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.4px;
  color: var(--text);
  flex-shrink: 0;
}

.topbar-logo-icon {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--accent), var(--accent-h));
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff;
  flex-shrink: 0;
  box-shadow: 0 0 16px var(--accent-glow);
}

.topbar-divider {
  width: 1px; height: 18px;
  background: var(--border2);
  margin: 0 4px;
}

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

.topbar-btn {
  height: 30px;
  padding: 0 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  display: flex; align-items: center; gap: 6px;
  transition: all .15s;
}
.topbar-btn:hover {
  background: var(--surface3);
  border-color: var(--border2);
  color: var(--text);
}
.topbar-btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-h));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 12px var(--accent-glow);
}
.topbar-btn.primary:hover {
  box-shadow: 0 4px 20px var(--accent-glow);
  transform: translateY(-1px);
}

.icon-btn {
  width: 30px; height: 30px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text3);
  transition: all .15s;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--surface2);
  color: var(--text2);
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: rgba(9, 10, 18, 0.97);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.sidebar-label {
  padding: 4px 16px 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text3);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px 7px 16px;
  cursor: pointer;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  transition: background .12s, color .12s;
  position: relative;
  margin: 0 6px;
  border-radius: 8px;
}
.sidebar-item:hover {
  background: var(--surface2);
  color: var(--text);
}
.sidebar-item.active {
  background: var(--accent-lo);
  color: var(--accent-h);
}
.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: -6px; top: 4px; bottom: 4px;
  width: 3px;
  background: linear-gradient(to bottom, var(--accent), var(--accent-h));
  border-radius: 0 3px 3px 0;
  box-shadow: 0 0 8px var(--accent-glow);
}

.sidebar-item-icon {
  width: 22px; height: 22px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.sidebar-item-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 10px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
}
.sidebar-user:hover { background: var(--surface2); }

.sidebar-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-h));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  flex-shrink: 0;
  box-shadow: 0 0 10px var(--accent-glow);
}

.sidebar-user-name { font-size: 12px; font-weight: 600; color: var(--text); }
.sidebar-user-role { font-size: 11px; color: var(--text3); margin-top: 1px; }

/* ── Main area ────────────────────────────────────────────────────────────── */
.main {
  grid-area: main;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

/* Canvas dot-grid background */
.canvas-viewport-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 60% 50% at 20% 40%, rgba(99,102,241,0.04) 0%, transparent 100%),
    radial-gradient(ellipse 40% 40% at 80% 15%, rgba(168,85,247,0.035) 0%, transparent 100%),
    radial-gradient(ellipse 50% 40% at 65% 85%, rgba(34,197,94,0.025) 0%, transparent 100%),
    var(--bg);
}
.canvas-viewport-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  z-index: 0;
}

/* ── Right panel ──────────────────────────────────────────────────────────── */
.right-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: var(--panel-w);
  background: rgba(9, 10, 18, 0.92);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 50;
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.4,0,.2,1);
}
.right-panel.open { transform: translateX(0); }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: rgba(255,255,255,0.02);
}

.panel-title { font-size: 13px; font-weight: 700; color: var(--text); letter-spacing: -.1px; }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}
.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* ── Toolbar (bottom canvas) ─────────────────────────────────────────────── */
.canvas-toolbar {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(9, 10, 18, 0.88);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 5px 8px;
  box-shadow: var(--shadow-lg), 0 1px 0 rgba(255,255,255,0.06) inset;
  z-index: 50;
}

.canvas-tool {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text3);
  transition: all .12s;
  position: relative;
}
.canvas-tool:hover { background: var(--surface2); color: var(--text2); }
.canvas-tool.active {
  background: var(--accent-lo);
  color: var(--accent-h);
  box-shadow: 0 0 12px var(--accent-lo);
}

.canvas-tool-sep { width: 1px; height: 18px; background: var(--border); margin: 0 2px; }

.zoom-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  min-width: 38px;
  text-align: center;
}

/* ── Minimap ──────────────────────────────────────────────────────────────── */
.minimap {
  position: absolute;
  bottom: 80px;
  right: 16px;
  width: 150px; height: 90px;
  background: rgba(9, 10, 18, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  opacity: .8;
  z-index: 40;
}

/* ── Hints ────────────────────────────────────────────────────────────────── */
.canvas-hints {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 12px;
  font-size: 10px;
  color: var(--text3);
  pointer-events: none;
}
.canvas-hints kbd {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 4px;
  padding: 1px 6px;
  font: inherit;
}

/* ── Mobile nav ───────────────────────────────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 56px;
  background: rgba(9, 10, 18, 0.95);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  z-index: 200;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.mobile-nav::-webkit-scrollbar { display: none; }

.mobile-nav-item {
  flex: 0 0 auto;
  min-width: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0 6px;
  cursor: pointer;
  color: var(--text3);
  font-size: 10px;
  font-weight: 500;
  transition: color .12s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.mobile-nav-item:active { opacity: .7; }
.mobile-nav-item.active { color: var(--accent-h); }
.mobile-nav-item-icon { font-size: 20px; line-height: 1.3; }

/* ── Responsive: ≤ 767px ─────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "main";
  }
  .sidebar { display: none; }
  .mobile-nav {
    display: flex;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    height: calc(56px + env(safe-area-inset-bottom, 0px));
  }
  .canvas-viewport-wrap {
    bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }
  .right-panel {
    width: 100%;
    bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }
  #btn-add-note,
  #btn-add-product-quick,
  #btn-zoom-out,
  #btn-zoom-in,
  #btn-zoom-100,
  #zoom-display { display: none; }
  .topbar-divider { display: none; }
  .canvas-hints { display: none; }
  .minimap      { display: none; }
}

/* ── Responsive: 768–1023px ──────────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  :root {
    --sidebar-w: 56px;
    --panel-w: 260px;
  }
  .sidebar-item span   { display: none; }
  .sidebar-label       { display: none; }
  .sidebar-user-name,
  .sidebar-user-role   { display: none; }
  .sidebar-item        { justify-content: center; padding: 10px; margin: 0 4px; }
  .sidebar-item-icon   { width: 24px; height: 24px; font-size: 14px; }
}
