:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --panel: #242424;
  --panel2: #2e2e2e;
  --border: #333333;
  --border2: #404040;
  --text: #e8e8e8;
  --text2: #b0b0b0;
  --muted: #808080;
  --accent: #4facf7;
  --accent2: #00f2fe;
  --red: #ff4b2b;
  --red2: #ff416c;
  --blue: #3b82f6;
  --blue2: #1d4ed8;
  --green: #22c55e;
  --orange: #f59e0b;
  --shadow: rgba(0, 0, 0, 0.5);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  display: flex;
  flex-direction: column;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  Common Components */
/* ─────────────────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--border2);
  background: var(--panel);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 5px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--panel2);
  border-color: var(--border);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn.primary:hover {
  background: var(--accent2);
  border-color: var(--accent2);
}

.btn.danger {
  background: var(--red2);
  color: #fff;
  border-color: var(--red2);
}

.btn.danger:hover {
  background: var(--red);
  border-color: var(--red);
}

.btn.sm {
  height: 28px;
  padding: 0 10px;
  font-size: 11px;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
}

.btn.ghost:hover {
  background: var(--panel);
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  Header */
/* ─────────────────────────────────────────────────────────────────────────── */

.header {
  height: 52px;
  min-height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 100;
}

.logo {
  font-family: 'Rajdhani', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.logo em {
  color: var(--text2);
  font-style: normal;
  font-weight: 400;
}

.h-sep {
  width: 1px;
  height: 26px;
  background: var(--border);
  flex-shrink: 0;
}

.header-file {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}

.fname {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.header-right {
  display: flex;
  gap: 6px;
  align-items: center;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  height: 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
}

.unfold-badge {
  background: var(--accent);
  color: #fff;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  App Body & Layout */
/* ─────────────────────────────────────────────────────────────────────────── */

.app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.panels-wrap {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.panel {
  display: none;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.panel.active {
  display: flex;
  flex-direction: column;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  3D Panel */
/* ─────────────────────────────────────────────────────────────────────────── */

.panel-3d {
  background: #000;
}

#canvas3d {
  width: 100%;
  height: 100%;
  display: block;
}

.toolbar-3d {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}

.tool-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px var(--shadow);
}

.tool-btn:hover {
  background: var(--panel2);
  border-color: var(--accent);
}

.tool-color-wrap {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--shadow);
}

#colorInput {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.tool-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  pointer-events: none;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  2D Panel */
/* ─────────────────────────────────────────────────────────────────────────── */

.panel-2d {
  background: #fff;
}

.svg-viewer {
  flex: 1;
  overflow: hidden; /* Changed from auto to hidden to prevent scrollbars during zoom/pan */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0; /* Removed padding to allow full use of viewport for centering */
  position: relative;
  background: #f0f0f0;
}

#svgLayer {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none; /* Let events pass to svgViewer if needed, though we use svgViewer for pan */
}

#svgLayer svg {
  pointer-events: auto; /* Re-enable for interaction if necessary */
}

.empty-2d {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.empty-2d-icon {
  font-size: 48px;
}

.empty-2d-text {
  font-size: 14px;
}

.zoom-pill {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  padding: 4px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border2);
  box-shadow: 0 4px 12px var(--shadow);
  z-index: 10;
}

.zoom-btn {
  width: 36px;
  height: 36px;
  border-radius: 18px;
  border: none;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
}

.zoom-btn:hover {
  background: var(--panel2);
}

.zoom-fit-btn {
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
}

.zoom-divider {
  width: 1px;
  height: 20px;
  background: var(--border2);
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  Library Panel */
/* ─────────────────────────────────────────────────────────────────────────── */

.panel-library {
  background: var(--surface);
}

.library-topbar {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

.library-upload-btn {
  width: 100%;
  max-width: 300px;
  height: 40px;
  background: var(--panel);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.library-upload-btn:hover {
  background: var(--panel2);
  border-color: var(--accent);
}

  .library-grid {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px;
    align-content: start;
  }

  .library-slot {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 0;
  }

  @media (max-width: 768px) {
    .library-grid {
      grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
      padding: 15px;
      gap: 15px;
    }
    
    .library-slot {
      padding: 10px;
      gap: 8px;
      min-height: 0;
    }

    .library-slot-name {
      font-size: 12px;
    }
  }

  .library-slot:hover {
    transform: translateY(-5px);
    border-color: var(--accent);
    box-shadow: 0 10px 25px var(--shadow);
  }

  .library-slot-thumbnail {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--muted);
    overflow: hidden;
    border: 1px solid var(--border2);
    flex-shrink: 0;
  }

  .library-slot-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .library-slot-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    width: 100%;
    display: block;
  }


  .library-slot {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  @media (max-width: 768px) {
    .library-grid {
      grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
      padding: 15px;
      gap: 15px;
    }
    
    .library-slot {
      padding: 10px;
      gap: 8px;
    }

    .library-slot-name {
      font-size: 12px;
    }
  }

  .library-slot:hover {
    transform: translateY(-5px);
    border-color: var(--accent);
    box-shadow: 0 10px 25px var(--shadow);
  }

  .library-slot-thumbnail {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--muted);
    overflow: hidden;
    border: 1px solid var(--border2);
    flex-shrink: 0;
  }

  .library-slot-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .library-slot-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    width: 100%;
    display: block;
  }


  .library-slot {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  @media (max-width: 768px) {
    .library-grid {
      grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
      padding: 10px;
      gap: 10px;
    }
    
    .library-slot {
      padding: 8px;
      gap: 6px;
    }
  }

  .library-slot:hover {
    transform: translateY(-5px);
    border-color: var(--accent);
    box-shadow: 0 10px 25px var(--shadow);
  }

  .library-slot-thumbnail {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--muted);
    overflow: hidden;
    border: 1px solid var(--border2);
    flex-shrink: 0;
  }

  .library-slot-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .library-slot-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    width: 100%;
  }


  .library-slot {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 0;
  }


.library-slot:hover {
  transform: translateY(-5px);
  border-color: var(--accent);
  box-shadow: 0 10px 25px var(--shadow);
}

  .library-slot-thumbnail {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--muted);
    overflow: hidden;
    border: 1px solid var(--border2);
    flex-shrink: 0;
  }


.library-slot-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

  .library-slot-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    width: 100%;
  }


/* ─────────────────────────────────────────────────────────────────────────── */
/*  Action Bar */
/* ─────────────────────────────────────────────────────────────────────────── */

.action-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
  z-index: 100;
}

.action-bar-main {
  display: flex;
  align-items: center;
  gap: 16px;
}

.action-bar-spacer {
  flex: 1;
}

.action-btns {
  display: flex;
  gap: 12px;
}

.unfold-btn {
  height: 40px;
  padding: 0 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.unfold-btn:hover:not(:disabled) {
  background: var(--accent2);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

.unfold-btn:disabled {
  background: var(--panel);
  color: var(--muted);
  cursor: not-allowed;
}

.unfold-btn .counter-pip {
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 11px;
}

.download-btn {
  height: 40px;
  padding: 0 20px;
  background: var(--panel);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.download-btn:hover:not(:disabled) {
  background: var(--panel2);
  border-color: var(--accent);
}

.download-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  Dimensions */
/* ─────────────────────────────────────────────────────────────────────────── */

.dims-row {
  display: flex;
  gap: 12px;
}

.dim-field {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.dim-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
}

.dim-input {
  width: 50px;
  height: 24px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  text-align: center;
}

.dim-input:focus {
  outline: none;
}

.dim-unit {
  font-size: 9px;
  color: var(--muted);
}

/* Mobile Dimensions (Expanded) */
.dims-expanded {
  display: none;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  Stats Drawer */
/* ─────────────────────────────────────────────────────────────────────────── */

.stats-toggle {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  justify-content: center;
}

.stats-toggle:hover {
  color: var(--text);
}

.stats-row {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.stats-row.show {
  display: grid;
}

.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--panel2);
  padding: 8px;
  border-radius: 8px;
  text-align: center;
}

.stat-chip strong {
  font-size: 14px;
  color: var(--accent);
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  Navigation (Tabs / Bottom Nav) */
/* ─────────────────────────────────────────────────────────────────────────── */

.tab-bar {
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 48px;
  z-index: 100;
}

.tab-btn {
  flex: 1;
  height: 100%;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

.tab-icon {
  font-size: 18px;
}

.bottom-nav {
  display: none;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  Mobile Styles */
/* ─────────────────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .tab-bar {
    display: none;
  }

  .bottom-nav {
    display: block;
    background: var(--surface);
    border-top: 1px solid var(--border);
    height: 64px;
    padding: 0 12px;
    z-index: 100;
  }

  .bottom-nav-inner {
    display: flex;
    height: 100%;
    justify-content: space-around;
    align-items: center;
  }

  .nav-btn {
    flex: 1;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s;
  }

  .nav-btn.active {
    color: var(--accent);
  }

  .nav-btn .nav-icon {
    font-size: 24px;
  }

  .nav-btn .nav-label {
    font-size: 11px;
  }

  .action-bar {
    padding: 8px 12px;
  }

  .action-bar-main {
    flex-direction: row;
    align-items: center;
  }

  .dims-row {
    display: none;
  }

  .dims-expanded {
    display: flex;
    justify-content: space-around;
    gap: 8px;
    width: 100%;
  }

  .dim-field {
    flex: 1;
  }

  .dim-input {
    width: 100%;
  }

  .size-toggle-btn {
    display: block;
  }
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  Parametric Controls ────────────────────────────────────────────────────── */
.parametric-controls {
  display: flex;
  gap: 16px;
  padding: 0 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.param-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

.param-section-title {
  font-family: 'Rajdhani', sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 2px;
}

.param-section-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.param-group {
  display: flex;
  flex-direction: column;
  font-size: 10px;
  color: var(--text2);
  min-width: 55px;
}

.param-group label {
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 9px;
  color: var(--muted);
}

.param-input {
  width: 60px;
  height: 28px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 4px;
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 12px;
  padding: 0 6px;
  text-align: center;
  transition: border-color 0.2s;
}

.param-input:focus {
  outline: none;
  border-color: var(--accent);
}

.param-range-hint {
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--muted);
  font-size: 9px;
  margin-top: 2px;
  text-align: center;
}

.param-rebuild-btn {
  margin-left: auto;
  align-self: center;
  height: 38px;
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.param-rebuild-btn:hover {
  background: var(--accent2);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 172, 247, 0.2);
}

@media (max-width: 768px) {
  .parametric-controls {
    display: none; /* Hide on mobile */
  }
}
/* ─────────────────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  background: var(--panel);
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  display: none;
  z-index: 2000;
  box-shadow: 0 8px 24px var(--shadow);
}

.toast.show {
  display: block;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translate(-50%, 100%);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}
