/* ── 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;
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

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

.topbar-logo-icon {
  width: 30px; height: 30px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff;
  flex-shrink: 0;
}

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

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

.topbar-btn {
  height: 30px;
  padding: 0 12px;
  border-radius: 6px;
  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(--border); color: var(--text); }
.topbar-btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.topbar-btn.primary:hover { background: var(--accent-h); }

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

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

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

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

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

.sidebar-item-icon {
  width: 20px; height: 20px;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  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: 12px;
  border-top: 1px solid var(--border);
}

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

.sidebar-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

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

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

/* ── Right panel ──────────────────────────────────────────────────────────── */
.right-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 50;
  transform: translateX(100%);
  transition: transform .2s ease;
}
.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;
}

.panel-title { font-size: 14px; font-weight: 600; color: var(--text); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── Toolbar (bottom-left canvas tools) ──────────────────────────────────── */
.canvas-toolbar {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
}

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

.canvas-tool-sep { width: 1px; height: 20px; 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: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  opacity: .8;
  z-index: 40;
}

/* ── Hint bar ─────────────────────────────────────────────────────────────── */
.canvas-hints {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--text3);
  pointer-events: none;
}

.canvas-hints kbd {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font: inherit;
}

/* ── Mobile bottom nav ───────────────────────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 56px;
  background: var(--surface);
  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, background .12s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.mobile-nav-item:active { background: var(--surface2); }
.mobile-nav-item.active { color: var(--accent); }
.mobile-nav-item-icon { font-size: 20px; line-height: 1.3; }

/* ── Responsive: ≤ 767px (phones) ───────────────────────────────────────── */
@media (max-width: 767px) {

  /* Shell: sidebar column removed */
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }

  .sidebar { display: none; }

  /* Bottom nav visible */
  .mobile-nav {
    display: flex;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    height: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  /* Canvas and right panel stop above bottom nav */
  .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));
  }

  /* Topbar: hide secondary controls, keep logo + fit + logout */
  #btn-add-note,
  #btn-add-product-quick,
  #btn-zoom-out,
  #btn-zoom-in,
  #btn-zoom-100,
  #zoom-display { display: none; }

  .topbar-divider { display: none; }

  /* Hide desktop-only hints and minimap */
  .canvas-hints { display: none; }
  .minimap      { display: none; }
}

/* ── Responsive: 768–1023px (tablets) ───────────────────────────────────── */
@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; }
  .sidebar-item-icon   { width: 24px; height: 24px; font-size: 14px; }
}
