/* ==================================== */
/* Sugarbaker PCI - Custom Styles       */
/* ==================================== */

/* Form container */
.sugarbaker-form .score-form-content {
  padding: 16px;
}

.sugarbaker-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Schema section - horizontal layout */
.sugarbaker-schema-section {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 16px;
}

/* Legend - vertical on the left */
.sugarbaker-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--bg-sidebar-hover, #f5f5f5);
  border-radius: var(--border-radius-md, 8px);
  flex-shrink: 0;
}

.sugarbaker-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sugarbaker-legend-color {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  flex-shrink: 0;
}

.sugarbaker-legend-label {
  font-size: 12px;
  color: var(--text-secondary, #666);
}

/* Schema wrapper for grid + intestinal */
.sugarbaker-schema-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

/* Grid container */
.sugarbaker-grid-container {
  width: 100%;
  max-width: 360px;
}

/* HTML Grid (3x3) */
.sugarbaker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: #ddd;
  border-radius: 12px;
  padding: 4px;
  overflow: hidden;
}

/* Grid cell */
.sugarbaker-cell {
  position: relative;
  aspect-ratio: 1;
  background: rgba(240, 240, 240, 0.5);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  overflow: hidden;
}

.sugarbaker-cell:hover {
  transform: scale(1.02);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 1;
}

.sugarbaker-cell:active {
  transform: scale(0.98);
}

/* Cell region number (top left) */
.sugarbaker-cell-num {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 11px;
  font-weight: 600;
  color: #666;
  z-index: 2;
}

/* Cell score (top right) */
.sugarbaker-cell-score {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 14px;
  font-weight: 700;
  color: #333;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 4px;
  padding: 2px 6px;
  z-index: 2;
}

/* Cell label (center) */
.sugarbaker-cell-label {
  font-size: 10px;
  color: #444;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 2;
  max-width: 90%;
}

/* Image container (fills entire cell) */
.sugarbaker-cell-image {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 1;
  opacity: 0;
  pointer-events: none;
}

.sugarbaker-cell-image.has-image {
  opacity: 1;
  pointer-events: auto;
}

.sugarbaker-cell-image.has-image:hover {
  filter: brightness(1.05);
}

/* Camera icon (bottom-left) */
.sugarbaker-cell-camera {
  position: absolute;
  bottom: 6px;
  left: 6px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 3;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.sugarbaker-cell-camera svg {
  width: 14px;
  height: 14px;
}

.sugarbaker-cell-camera:hover {
  background: var(--accent-primary, #D97757);
  color: white;
}

/* Delete button (top right corner, shown on hover when image exists) */
.sugarbaker-cell-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(196, 92, 92, 0.9);
  color: white;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sugarbaker-cell:hover .sugarbaker-cell-delete {
  opacity: 1;
}

.sugarbaker-cell-delete:hover {
  background: #c45c5c;
  transform: scale(1.1);
}

/* Section titles */
.sugarbaker-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #333);
  margin: 0 0 12px 0;
}

/* Intestinal section */
.sugarbaker-intestinal-section {
  width: 100%;
  max-width: 400px;
}

.sugarbaker-intestinal-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.sugarbaker-intestinal-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px;
  border: 2px solid #ccc;
  border-radius: var(--border-radius-md, 8px);
  background: rgba(240, 240, 240, 0.5);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  min-height: 90px;
}

.sugarbaker-intestinal-btn:hover {
  transform: scale(1.02);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.sugarbaker-intestinal-header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 4px;
}

.sugarbaker-intestinal-num {
  font-size: 10px;
  font-weight: 600;
  color: #666;
}

.sugarbaker-intestinal-score {
  font-size: 12px;
  font-weight: 700;
  color: #333;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 3px;
  padding: 1px 5px;
}

.sugarbaker-intestinal-label {
  font-size: 11px;
  color: var(--text-primary, #333);
  margin-bottom: 6px;
}

/* Intestinal image container (fills entire button) */
.sugarbaker-intestinal-image {
  position: absolute;
  inset: 0;
  border-radius: var(--border-radius-md, 8px);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  transition: all 0.2s ease;
  opacity: 0;
  pointer-events: none;
}

.sugarbaker-intestinal-image.has-image {
  opacity: 1;
  pointer-events: auto;
}

.sugarbaker-intestinal-image.has-image:hover {
  filter: brightness(1.05);
}

/* Intestinal camera icon (bottom-left) */
.sugarbaker-intestinal-camera {
  position: absolute;
  bottom: 6px;
  left: 6px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  z-index: 3;
}

.sugarbaker-intestinal-camera svg {
  width: 12px;
  height: 12px;
}

.sugarbaker-intestinal-camera:hover {
  background: var(--accent-primary, #D97757);
  color: white;
}

/* Intestinal delete button */
.sugarbaker-intestinal-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(196, 92, 92, 0.9);
  color: white;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
}

.sugarbaker-intestinal-btn:hover .sugarbaker-intestinal-delete {
  opacity: 1;
}

.sugarbaker-intestinal-delete:hover {
  background: #c45c5c;
}

/* Image viewer modal */
.sugarbaker-viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 24px;
}

.sugarbaker-viewer-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.sugarbaker-viewer-close {
  position: absolute;
  top: -40px;
  right: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.sugarbaker-viewer-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.sugarbaker-viewer-image {
  max-width: 100%;
  max-height: calc(90vh - 120px);
  object-fit: contain;
  border-radius: var(--border-radius-md, 8px);
}

.sugarbaker-viewer-label {
  color: white;
  font-size: 14px;
  margin-bottom: 8px;
}

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

.sugarbaker-viewer-btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--border-radius-md, 8px);
  background: rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sugarbaker-viewer-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.sugarbaker-viewer-btn-danger {
  background: rgba(196, 92, 92, 0.8);
}

.sugarbaker-viewer-btn-danger:hover {
  background: rgba(196, 92, 92, 1);
}

/* Responsive */
@media (max-width: 480px) {
  .sugarbaker-schema-section {
    flex-direction: column;
  }

  .sugarbaker-legend {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sugarbaker-grid-container {
    max-width: 100%;
  }

  .sugarbaker-cell-camera {
    width: 24px;
    height: 24px;
  }

  .sugarbaker-cell-camera svg {
    width: 12px;
    height: 12px;
  }

  .sugarbaker-intestinal-grid {
    grid-template-columns: 1fr;
  }
}

/* Dark theme support */
[data-theme="dark"] .sugarbaker-grid {
  background: #444;
}

[data-theme="dark"] .sugarbaker-cell {
  background: rgba(60, 60, 60, 0.5);
}

[data-theme="dark"] .sugarbaker-cell-num {
  color: #aaa;
}

[data-theme="dark"] .sugarbaker-cell-score {
  background: rgba(0, 0, 0, 0.5);
  color: #eee;
}

[data-theme="dark"] .sugarbaker-cell-label {
  color: #ccc;
}

[data-theme="dark"] .sugarbaker-cell-camera {
  background: rgba(60, 60, 60, 0.9);
  color: #aaa;
}

[data-theme="dark"] .sugarbaker-cell-camera:hover {
  background: var(--accent-primary, #D97757);
  color: white;
}

[data-theme="dark"] .sugarbaker-intestinal-btn {
  border-color: #555;
  background: rgba(60, 60, 60, 0.5);
}

[data-theme="dark"] .sugarbaker-intestinal-label {
  color: #ccc;
}

[data-theme="dark"] .sugarbaker-intestinal-score {
  background: rgba(0, 0, 0, 0.5);
  color: #eee;
}

[data-theme="dark"] .sugarbaker-intestinal-camera {
  background: rgba(60, 60, 60, 0.9);
  color: #aaa;
}
