@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Prompt:wght@300;400;500;600;700&display=swap');

/* ── MULTI-THEME TOKENS ── */
:root, [data-theme="dark"] {
  --bg-main: #0b0f19;
  --bg-panel: #111827;
  --bg-card: rgba(31, 41, 55, 0.7);
  --border-color: rgba(255, 255, 255, 0.15);
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-sub: #6b7280;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.3);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --sidebar-width: 240px;
  --shadow: 0 10px 30px rgba(0,0,0,0.5);
}

[data-theme="light"] {
  --bg-main: #f3f4f6;
  --bg-panel: #ffffff;
  --bg-card: #ffffff;
  --border-color: #e5e7eb;
  --text-main: #1f2937;
  --text-muted: #4b5563;
  --text-sub: #9ca3af;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --accent: #2563eb;
  --accent-glow: rgba(37, 99, 235, 0.2);
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: 0 4px 15px rgba(0,0,0,0.06);
}

[data-theme="colorful"] {
  --bg-main: #0d0722;
  --bg-panel: #170d38;
  --bg-card: rgba(38, 20, 85, 0.7);
  --border-color: rgba(236, 72, 153, 0.25);
  --text-main: #ffffff;
  --text-muted: #c4b5fd;
  --text-sub: #a78bfa;
  --primary: #ec4899;
  --primary-hover: #db2777;
  --accent: #8b5cf6;
  --accent-glow: rgba(236, 72, 153, 0.4);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 10px 30px rgba(236, 72, 153, 0.25);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Prompt', sans-serif;
}

body, .app-sidebar, .panel, .settings-panel, .theme-btn {
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
}

/* ── STANDARDIZED COLLAPSIBLE SIDEBAR (60 FPS GPU-ACCELERATED DRAWER OVERLAY) ── */
.app-sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 10000;
  will-change: transform;
  transform: translateZ(0);
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  box-shadow: 10px 0 30px rgba(0,0,0,0.5);
  backface-visibility: hidden;
}

/* FULL COLLAPSE: GPU slide off-screen 100% (ไม่มีการคำนวณการ์ดใหม่ การ์ดอยู่นิ่ง 60 FPS) */
body.sidebar-is-collapsed .app-sidebar {
  transform: translateX(-100%) !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* FLOATING MENU TOGGLE BUTTON (เมื่อปิดเมนูจะแสดงปุ่มนี้สำหรับเปิดใหม่) */
.sidebar-float-toggle {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 10001;
  background: var(--primary);
  color: #fff;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0,0,0,0.4);
  transition: all 0.2s ease;
}

body.sidebar-is-collapsed .sidebar-float-toggle {
  display: flex !important;
}

.sidebar-float-toggle:hover {
  transform: scale(1.1);
  background: var(--primary-hover);
}

.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 15px;
  color: var(--text-main);
  text-decoration: none;
  white-space: nowrap;
}

.sidebar-toggle-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-toggle-btn:hover {
  background: var(--primary);
  color: #fff;
}

.sidebar-nav {
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
}

.nav-section-title {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 12px 10px 4px;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.nav-item:hover, .nav-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
}

.nav-subitem {
  padding-left: 28px;
  font-size: 12px;
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theme-selector {
  display: flex;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.theme-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.theme-btn.active, .theme-btn:hover {
  background: var(--primary);
  color: #fff;
}

/* ── LAYOUT CONTAINER FOR NORMAL PAGES (ZERO REFLOW 60 FPS) ── */
.app-layout {
  padding: 30px 30px 30px calc(var(--sidebar-width) + 30px);
  width: 100%;
  min-height: 100vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

body.sidebar-is-collapsed .app-layout {
  padding-left: 54px !important;
  margin-left: 0 !important;
  width: 100% !important;
}

/* ── STUDIO & BUILDER ADJUSTMENTS WHEN SIDEBAR IS OPEN ── */
/* When sidebar is OPEN in builder.html: shift top navbar & left scene selector panel to the right */
body:not(.sidebar-is-collapsed) .studio-navbar {
  left: var(--sidebar-width) !important;
  width: calc(100% - var(--sidebar-width)) !important;
}

body:not(.sidebar-is-collapsed) .left-sidebar {
  left: var(--sidebar-width) !important;
}

/* When sidebar is COLLAPSED in builder.html: navbar and scene selector sit flush at left 0 */
body.sidebar-is-collapsed .studio-navbar {
  left: 0 !important;
  width: 100% !important;
  padding-left: 54px !important; /* Make room for floating menu toggle button */
}

body.sidebar-is-collapsed .left-sidebar {
  left: 0 !important;
}

/* ── STITCHING LIBRARY GRID OPTIMIZATION (60 FPS GPU-ACCELERATED & CONTAINED) ── */
#stitchingGrid {
  contain: layout paint;
  will-change: width;
  transform: translateZ(0);
}

#stitchingGrid .project-card {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}
