:root {
  --bg-color: #f0f2f5;
  --card-bg: #ffffff;
  --text-primary: #333;
  --text-secondary: #666;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  --accent: #4a90d9;
  --accent-hover: #357abd;
  --sidebar-width: 260px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background-color: var(--bg-color);
  margin: 0;
  display: flex;
  min-height: 100vh;
}

/* Sidebar Toggle (attached to sidebar edge) */
.sidebar-toggle-fixed {
  padding: unset;
  position: fixed;
  left: 0;
  top: 9px;
  z-index: 0;
  width: 32px;
  height: 40px;
  background: white;
  border: 1px solid #ddd;
  border-left: none;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  /* Match sidebar transition exactly */
  transition: transform 0.3s ease, background 0.2s;
  /* Start hidden with sidebar */
  /* transform: translateX(0); default */
}

.sidebar-toggle-fixed.open {
  transform: translateX(260px);
}

.sidebar-toggle-fixed:hover {
  background: #f0f0f0;
}

.sidebar-toggle-fixed svg {
  width: 18px;
  height: 18px;
  display: block;
}

.sidebar-toggle-fixed svg path {
  stroke: #555;
  stroke-width: 2;
}

/* Icon visibility toggle */
.sidebar-toggle-fixed .icon-close {
  display: none;
}

/* Conflict removed: .sidebar.open ~ .sidebar-toggle-fixed handled by .sidebar-toggle-fixed.open class */

.sidebar-toggle-fixed.open .icon-hamburger {
  display: none;
}

.sidebar-toggle-fixed.open .icon-close {
  display: block;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: white;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 18px;
}

.sidebar-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 5px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-close:hover {
  background: #f0f0f0;
  color: var(--text-primary);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
}

.btn-new-collection {
  width: 100%;
  padding: 12px 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.2s;
}

.btn-new-collection:hover {
  opacity: 0.9;
}

.btn-new-collection svg {
  flex-shrink: 0;
}

.collection-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.collection-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  margin-bottom: 8px;
  background: #f8f9fa;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.collection-item:hover {
  background: #e9ecef;
}

.collection-item.active {
  background: var(--accent);
  color: white;
}

.collection-item .collection-name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.collection-item .collection-count {
  font-size: 12px;
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
}

.collection-item.active .collection-count {
  background: rgba(255, 255, 255, 0.3);
}

.collection-item .delete-btn {
  margin-left: 4px;
  background: none;
  border: none;
  color: #dc3545;
  cursor: pointer;
  padding: 4px;
  opacity: 0;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  flex-shrink: 0;
}

.collection-item .delete-btn svg {
  width: 16px;
  height: 16px;
}

.collection-item .delete-btn:hover {
  background: rgba(220, 53, 69, 0.1);
}

.collection-item:hover .delete-btn {
  opacity: 1;
}

.collection-item.active .delete-btn {
  color: rgba(255, 255, 255, 0.8);
}

.collection-item.active .delete-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.empty-collections {
  text-align: center;
  padding: 30px 15px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 15px;
  border-top: 1px solid #eee;
  display: flex;
  gap: 10px;
}

.btn-sidebar-action {
  flex: 1;
  padding: 10px 12px;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.btn-sidebar-action:hover {
  background: #eee;
  color: var(--text-primary);
  border-color: #ccc;
}

.btn-sidebar-action svg {
  flex-shrink: 0;
}

/* Main Content */
/* Main Content */
.main-content {
  flex: 1;
  margin-left: 60px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: margin-left 0.3s ease;
  will-change: margin-left; /* Optimize animation */
}

/* Styled File Input */
#fileInput {
  padding: 10px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-family: inherit;
  cursor: pointer;
}

#fileInput::file-selector-button {
  padding: 8px 16px;
  margin-right: 15px;
  border-radius: 6px;
  border: none;
  background: #e0e0e0;
  color: #333;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

#fileInput::file-selector-button:hover {
  background: #d0d0d0;
}

.sidebar.open ~ .main-content {
  margin-left: var(--sidebar-width);
}

header {
  text-align: center;
  margin-bottom: 30px;
  width: 100%;
  max-width: 1000px;
}

h1 {
  margin-bottom: 10px;
  color: var(--text-primary);
}

p {
  color: var(--text-secondary);
  margin-top: 0;
}

/* Controls */
.controls {
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 15px;
}

.selection-controls {
  background: white;
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: none;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.selection-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.selection-controls.active {
  display: flex;
}

input[type="file"] {
  border: 1px solid #ddd;
  padding: 10px;
  border-radius: 6px;
}

input[type="text"] {
  padding: 12px 35px 12px 15px;
  border: 1px solid #ddd;
  border-radius: 6px;
  width: 100%;
  box-sizing: border-box;
  font-size: 16px;
}

.search-wrapper {
  position: relative;
  flex-grow: 1;
}

.clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #999;
  font-size: 20px;
  cursor: pointer;
  padding: 0 5px;
  display: none;
  line-height: 1;
}

.clear-btn:hover {
  color: #333;
}

/* Buttons */
button {
  padding: 10px 18px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  background: #aaa;
  cursor: not-allowed;
}

.btn-secondary {
  background: #e0e0e0;
  color: #333;
}

.btn-secondary:hover {
  background: #d0d0d0;
}

.btn-danger {
  background: #dc3545;
  color: white;
}

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

.btn-danger:disabled {
  background: #aaa;
  cursor: not-allowed;
}

.btn-export {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-export:hover {
  background: linear-gradient(135deg, #5a6fd6 0%, #6a4190 100%);
}

.btn-export:disabled {
  background: #aaa;
  cursor: not-allowed;
}

.selection-count {
  font-size: 14px;
  color: var(--text-secondary);
  padding: 0 10px;
}

/* Grid Layout */
.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 20px;
  width: 100%;
  max-width: 1400px;
}

/* Card Styles */
.card {
  background: var(--card-bg);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  position: relative;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.15);
}

.card.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.color-swatch {
  height: 120px;
  width: 100%;
  border-bottom: 1px solid #eee;
  position: relative;
}

/* Remove from Collection Button */
.remove-from-collection {
  padding: unset;
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  background: rgba(220, 53, 69, 0.95);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s, transform 0.2s;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  color: white;
}

.remove-from-collection svg {
  width: 14px;
  height: 14px;
}

.remove-from-collection:hover {
  background: #dc3545;
  transform: scale(1.1);
}

.card:hover .remove-from-collection {
  opacity: 1;
}

.checkbox-wrapper {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.card:hover .checkbox-wrapper,
.card.selected .checkbox-wrapper {
  opacity: 1;
}

.checkbox-wrapper input {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}

.card-info {
  padding: 12px;
  font-size: 14px;
}

.code {
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.name {
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hex {
  font-family: "Courier New", monospace;
  background: #eee;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: #444;
  display: inline-block;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 12px 24px;
  border-radius: 50px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px;
  color: #888;
  border: 2px dashed #ccc;
  border-radius: 12px;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: white;
  padding: 30px;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  max-width: 400px;
  width: 90%;
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal h2 {
  margin: 0 0 10px 0;
  color: var(--text-primary);
}

.modal p {
  margin: 0 0 20px 0;
  color: var(--text-secondary);
}

.modal input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 20px;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Format Selector */
.format-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.format-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.format-option:hover {
  border-color: var(--accent);
  background: #f8f9ff;
}

.format-option:has(input:checked) {
  border-color: var(--accent);
  background: #f0f4ff;
}

.format-option input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  margin: 0;
}

.format-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.format-label strong {
  color: var(--text-primary);
  font-size: 14px;
}

.format-label small {
  color: var(--text-secondary);
  font-size: 12px;
}

/* Search Info for Hex Search */
.search-info {
  grid-column: 1 / -1;
  background: white;
  padding: 16px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.search-color {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 2px solid #ddd;
  flex-shrink: 0;
}

.search-info span {
  color: var(--text-secondary);
  font-size: 14px;
}

.search-info strong {
  color: var(--text-primary);
  font-family: monospace;
}

/* Delta Badge */
.delta-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  font-family: monospace;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.delta-exact {
  background: #22c55e;
  color: white;
}

.delta-close {
  background: #84cc16;
  color: white;
}

.delta-medium {
  background: #f59e0b;
  color: white;
}

.delta-far {
  background: #ef4444;
  color: white;
}

/* Collection Indicator */
.collection-indicator {
  background: white;
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
}

.collection-badge {
  font-weight: 600;
  color: var(--accent);
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.collection-badge svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

/* Add to Collection Button */
.btn-add-collection {
  background: #10b981;
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-add-collection:hover {
  background: #059669;
}

.btn-add-collection:disabled {
  background: #aaa;
  cursor: not-allowed;
}

.selection-right {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Collection Select Dropdown */
.collection-select {
  width: 100%;
  padding: 12px 15px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 16px;
  margin-bottom: 15px;
  cursor: pointer;
}

.or-divider {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin: 10px 0;
  position: relative;
}

.or-divider::before,
.or-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: #ddd;
}

/* Context Menu */
.context-menu {
  position: fixed; /* Fixed so it overlays everything */
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 5px 0;
  z-index: 10000;
  min-width: 180px;
  display: none;
}

.context-menu.active {
  display: block;
}

.context-menu .menu-item {
  padding: 8px 16px;
  font-size: 14px;
  color: #333;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background 0.1s;
}

.context-menu .menu-item:hover {
  background: #f5f5f5;
}

.context-menu .menu-item svg {
  margin-right: 8px;
  color: #666;
}

.context-menu .separator {
  height: 1px;
  background: #eee;
  margin: 5px 0;
}

.or-divider::before {
  left: 0;
}

.or-divider::after {
  right: 0;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .mobile-menu-btn {
    display: block;
  }
}
