/*
 * Copyright (C) 2025 Jema Technology
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

/* Properties Sidebar (Replaces old Annotation Sidebar) */
.properties-sidebar {
  width: 280px;
  background-color: var(--surface-color);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 20px;
  z-index: 100;
  overflow-y: auto;
  transition: transform 0.3s ease, width 0.3s ease;
  /* Position is handled by flex layout in parent */
  flex-shrink: 0;
}

.properties-sidebar.hidden {
  width: 0;
  padding: 0;
  border-left: none;
  overflow: hidden;
}

/* Split Save Button */
.split-btn-container {
  position: relative;
  display: flex;
  width: 100%;
  margin-bottom: 10px;
}

.split-btn-main {
  flex: 1;
  background-color: #6569d0;
  color: #ffffff;
  border: none;
  border-radius: 4px 0 0 4px;
  padding: 0 16px;
  height: 36px;
  font-family: 'Roboto', sans-serif;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.2s;
}

.split-btn-main:hover {
  background-color: #6569d0;
}

.split-btn-arrow {
  width: 36px;
  background-color: #6569d0;
  color: #ffffff;
  border: none;
  border-left: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 0 4px 4px 0;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

.split-btn-arrow:hover {
  background-color: #6569d0;
}

.split-btn-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background-color: var(--surface-variant);
  border-radius: 4px;
  box-shadow: var(--shadow-md);
  min-width: 180px;
  z-index: 200;
  display: none;
  flex-direction: column;
  padding: 4px 0;
}

.split-btn-dropdown.show {
  display: flex;
}

.split-btn-item {
  background: none;
  border: none;
  color: var(--on-surface);
  padding: 10px 16px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: 'Roboto', sans-serif;
  font-size: 14px;
  transition: background-color 0.2s;
}

.split-btn-item:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.split-btn-item .material-icons {
  font-size: 20px;
  color: var(--on-surface-variant);
}

/* Groups */
.sidebar-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--on-surface-variant);
  font-weight: 500;
  margin-left: 4px;
}

/* Size Group */
.size-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  background-color: var(--surface-variant);
  padding: 8px 12px;
  border-radius: 8px;
}

.size-btn {
  flex: 1;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  opacity: 0.5;
  transition: opacity 0.2s;
  padding: 0 2px;
}

.size-btn:hover {
  opacity: 0.8;
}

.size-btn.active {
  opacity: 1;
}

.size-line {
  background-color: var(--on-surface);
  width: 100%;
  border-radius: 100px;
}

/* Color Group */
.color-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  justify-items: center;
}

.color-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.color-btn:hover {
  transform: scale(1.1);
}

.color-btn.active {
  border-color: var(--surface-color);
  transform: scale(1.1);
  box-shadow: 0 0 0 2px var(--on-surface); /* Ring effect */
}

/* Text Tool Options */
.text-options-group {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.text-options-group.hidden {
  display: none;
}

.font-controls {
  display: flex;
  gap: 8px;
}

.font-family-select {
  flex: 2;
  background-color: var(--surface-variant);
  color: var(--on-surface);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.font-size-select {
  flex: 1;
  background-color: var(--surface-variant);
  color: var(--on-surface);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.font-family-select:focus,
.font-size-select:focus {
  border-color: #6569d0;
}

.style-controls {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.style-toggle-group {
  display: flex;
  background-color: var(--surface-variant);
  border-radius: 4px;
  padding: 2px;
  gap: 2px;
}

.style-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--on-surface-variant);
  border-radius: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.style-btn:hover {
  background-color: var(--border-color);
  color: var(--on-surface);
}

.style-btn.active {
  background-color: var(--primary-color);
  color: var(--on-primary);
}

.style-btn .material-icons {
  font-size: 18px;
}

/* Canvas Overlay */
.annotation-canvas {
  position: absolute;
  top: 0;
  left: 0;
  touch-action: none;
  pointer-events: all;
  z-index: 10;
  cursor: crosshair;
}

.annotation-canvas.eraser-mode {
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/></svg>') 12 12, auto;
}

/* Eraser Options */
.eraser-options-group {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.eraser-options-group.hidden {
  display: none;
}

/* Toggle Switch */
.toggle-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--on-surface);
  font-size: 14px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--secondary-color);
  transition: .4s;
  border-radius: 20px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: var(--primary-color);
}

input:checked + .toggle-slider:before {
  transform: translateX(20px);
  background-color: var(--on-primary);
}

/* Range Slider */
.slider-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--on-surface);
  font-size: 14px;
}

.slider-value {
  color: var(--on-surface);
  font-size: 14px;
}

.range-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--secondary-color);
  border-radius: 2px;
  outline: none;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  border: 2px solid var(--surface-color);
}

.range-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  border: 2px solid var(--surface-color);
}

/* Text Input Wrapper */
.text-input-wrapper {
    border: 1px solid transparent;
}

.text-input-wrapper.selected {
    border: 1px solid #6569d0;
}

.text-input-wrapper:not(.selected) .resize-handle,
.text-input-wrapper:not(.selected) .rotate-handle,
.text-input-wrapper:not(.selected) .rotate-line {
    display: none;
}

.text-input-wrapper textarea {
    cursor: default;
}

.text-input-wrapper.selected textarea {
    cursor: text;
}
