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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, sans-serif;
  background-color: #0f172a;
}

/* KHUNG VIEWPORT VÀ CANVAS 3D */
#viewport, #canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
}

canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* THANH TRÊN NGANG (TOP BAR) - NỀN TỐI TRẢI DÀI */
#top-bar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 50px;
  background-color: #0d1527;
  z-index: 10;
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* NÚT TRÊN THANH TOP BAR */
.header-btn {
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 6px 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ff9800;
  transition: background 0.2s;
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}


/* THANH SIDEBAR DỌC - NỀN TỐI TRẢI DÀI */
#sidebar {
  position: absolute;
  top: 50px;
  left: 0;
  width: 50px;
  height: calc(100vh - 50px);
  background-color: #0d1527;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 10px;
  gap: 10px;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.3s ease, opacity 0.3s ease;
}

#sidebar.sidebar-hidden {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

/* NÚT BẤM TRONG SIDEBAR DỌC */
.sidebar-btn {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: #19263e;
  border: none;
  color: #fff;
  font-weight: bold;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.sidebar-btn:hover {
  background: #253759;
}

.sidebar-btn.active {
  background: #ff9800;
  color: #fff;
  border-color: #ff9800;
}

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

/* LỚP OVERLAY BẢNG CHỌN */
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.dialog-overlay.active {
  display: flex !important;
}

/* POPUP CHỌN MẪU THƯ VIỆN */
.catalog-dialog {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  width: 90%;
  max-width: 450px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 15px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.8);
}

.catalog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #334155;
  padding-bottom: 10px;
  margin-bottom: 15px;
  color: #ffffff;
}

#btn-close-catalog {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 24px;
  cursor: pointer;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
  overflow-y: auto;
  max-height: 60vh;
  padding: 5px;
}

.catalog-item {
  border: 2px solid #334155;
  border-radius: 6px;
  padding: 5px;
  cursor: pointer;
  text-align: center;
  background: #1e293b;
  transition: all 0.2s ease;
}

.catalog-item:hover {
  border-color: #ff9800;
  transform: scale(1.03);
}

.catalog-item img {
  width: 100%;
  height: 75px;
  object-fit: contain;
  border-radius: 4px;
}

.catalog-item span {
  display: block;
  font-size: 11px;
  margin-top: 4px;
  word-break: break-all;
  color: #cbd5e1;
}

/* BẢNG CHỌN MÀU HSV (PHOTOSHOP COLOR PICKER) */
.ps-dialog {
  background: #1e293b;
  padding: 15px;
  border-radius: 10px;
  color: #fff;
  width: 260px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.ps-picker-area {
  display: flex;
  gap: 10px;
  height: 150px;
  margin-bottom: 12px;
}

#sat-val-box {
  flex: 1;
  position: relative;
  background-color: red;
  cursor: crosshair;
  border-radius: 4px;
  overflow: hidden;
}

.sat-val-white {
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, #fff, rgba(255, 255, 255, 0));
}

.sat-val-black {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, #000, rgba(0, 0, 0, 0));
}

#sat-val-cursor {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#hue-bar {
  width: 20px;
  position: relative;
  background: linear-gradient(to bottom, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
  cursor: pointer;
  border-radius: 4px;
}

#hue-cursor {
  position: absolute;
  left: -2px;
  right: -2px;
  height: 4px;
  background: #fff;
  border: 1px solid #000;
  transform: translateY(-50%);
  pointer-events: none;
}

.ps-controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.ps-preview-box {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid #475569;
}

.ps-hex-group {
  display: flex;
  align-items: center;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 4px 8px;
}

#val-hex {
  background: transparent;
  border: none;
  color: #fff;
  width: 70px;
  font-family: monospace;
  font-size: 14px;
  outline: none;
  margin-left: 4px;
}

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

.ps-btn {
  flex: 1;
  padding: 6px 0;
  background: #334155;
  color: #fff;
  border: 1px solid #475569;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.ps-btn:hover {
  background: #475569;
}

/* POPUP XÁC NHẬN RESET */
.confirm-dialog {
  background: #ffffff;
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.confirm-title {
  font-size: 18px;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 8px;
}

.confirm-message {
  font-size: 14px;
  color: #64748b;
  line-height: 1.5;
  margin-bottom: 20px;
}

.confirm-actions {
  display: flex;
  gap: 12px;
}

.confirm-btn {
  flex: 1;
  padding: 10px 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s;
}

.confirm-btn:hover {
  opacity: 0.9;
}

.btn-secondary {
  background: #f1f5f9;
  color: #475569;
}

.btn-danger {
  background: #ef4444;
  color: #ffffff;
}

/* Đảm bảo stroke của SVG nhận đúng màu cam tươi */
.header-btn svg {
  stroke: #ff9800 !important;
}
