* {
  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) */
#top-bar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 48px;
  background-color: #0f172a;
  border-bottom: 1px solid #1e293b;
  z-index: 10;
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 8px;
}

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

.header-btn:hover {
  background: #1e293b;
  color: #f8fafc;
  border-color: #334155;
}

.header-btn svg {
  stroke: currentColor !important;
}

/* THANH SIDEBAR DỌC */
#sidebar {
  position: absolute;
  top: 48px;
  left: 0;
  width: 48px;
  height: calc(100vh - 48px);
  background-color: #0f172a;
  border-right: 1px solid #1e293b;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 10px;
  gap: 8px;
  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: 34px;
  height: 34px;
  border-radius: 6px;
  background: #1e293b;
  border: 1px solid #334155;
  color: #cbd5e1;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.sidebar-btn:hover {
  background: #334155;
  color: #fff;
}

.sidebar-btn.active {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #e2e8f0;
}

.sidebar-btn:disabled {
  opacity: 0.3;
  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.5);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

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

/* POPUP THƯ VIỆN & THÔNG TIN */
.catalog-dialog {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  width: 92%;
  max-width: 440px;
  max-height: 82vh;
  display: flex !important;
  flex-direction: column !important;
  padding: 15px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.catalog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #1e293b;
  padding-bottom: 8px;
  margin-bottom: 12px;
  color: #f8fafc;
  flex-shrink: 0;
}

#btn-close-catalog, #btn-close-visibility, #btn-close-camera-views {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 20px;
  cursor: pointer;
  transition: color 0.2s;
}

#btn-close-catalog:hover, #btn-close-visibility:hover, #btn-close-camera-views:hover {
  color: #f8fafc;
}

/* LƯỚI CHỌN MẪU HIỂN THỊ TRỌN VẸN HOA VĂN */
.catalog-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fill, minmax(95px, 1fr)) !important;
  gap: 10px !important;
  overflow-y: auto !important;
  max-height: 65vh;
  padding: 4px;
}

.catalog-item {
  border: 1px solid #1e293b;
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  text-align: center;
  background: #192338;
  transition: all 0.2s ease;
  display: flex !important;
  flex-direction: column !important;
  align-items: center;
  justify-content: space-between;
}

.catalog-item:hover {
  border-color: #64748b;
  background: #23314d;
  transform: translateY(-2px);
}

.catalog-item .model-thumb {
  width: 100%;
  height: 85px;
  border-radius: 4px;
  overflow: hidden;
  background-color: #0b1120;
  display: flex !important;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.catalog-item img {
  max-height: 100% !important;
  width: auto !important;
  height: 85px;
  object-fit: contain !important;
  display: block;
}

.catalog-item span {
  display: block;
  font-size: 11px;
  margin-top: 6px;
  word-break: break-all;
  color: #94a3b8;
  line-height: 1.2;
}

/* DANH SÁCH NÚT CHỌN GÓC NHÌN CAMERA */
.camera-views-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.camera-view-btn {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 10px 14px;
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}

.camera-view-btn:hover {
  background: #334155;
  color: #fff;
  border-color: #475569;
  transform: translateX(2px);
}

/* BẢNG CHỌN ẨN / HIỆN VÁCH */
.visibility-dialog {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  width: 90%;
  max-width: 300px;
  padding: 15px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.visibility-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 5px;
}

.visibility-table th, .visibility-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid #1e293b;
  color: #cbd5e1;
  font-size: 13px;
}

.visibility-table th {
  color: #64748b;
  font-weight: 500;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.visibility-table td:last-child {
  text-align: center;
}

/* NÚT CON MẮT TRONG BẢNG (TỐI GIẢN) */
.eye-toggle-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px;
  cursor: pointer;
  color: #94a3b8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.eye-toggle-btn:hover {
  background: #1e293b;
  color: #f8fafc;
}

.eye-toggle-btn.active .icon-eye-open { display: block; }
.eye-toggle-btn.active .icon-eye-closed { display: none; }

.eye-toggle-btn.hidden-wall {
  color: #475569;
}
.eye-toggle-btn.hidden-wall .icon-eye-open { display: none; }
.eye-toggle-btn.hidden-wall .icon-eye-closed { display: block; }

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

.ps-picker-area {
  display: flex;
  gap: 10px;
  height: 140px;
  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: 8px;
  height: 8px;
  border: 1.5px solid #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#hue-bar {
  width: 16px;
  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: 3px;
  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: 32px;
  height: 32px;
  border-radius: 4px;
  border: 1px solid #334155;
}

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

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

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

.ps-btn {
  flex: 1;
  padding: 6px 0;
  background: #1e293b;
  color: #cbd5e1;
  border: 1px solid #334155;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.ps-btn:hover {
  background: #334155;
  color: #fff;
}

/* POPUP XÁC NHẬN RESET */
.confirm-dialog {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 20px;
  width: 90%;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.confirm-title {
  font-size: 16px;
  font-weight: 600;
  color: #f8fafc;
  margin-bottom: 6px;
}

.confirm-message {
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.4;
  margin-bottom: 16px;
}

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

.confirm-btn {
  flex: 1;
  padding: 8px 0;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.btn-secondary {
  background: #1e293b;
  color: #cbd5e1;
  border-color: #334155;
}

.btn-secondary:hover {
  background: #334155;
  color: #fff;
}

.btn-danger {
  background: #334155;
  color: #f8fafc;
  border-color: #475569;
}

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