/* ===== CSS Variables ===== */
:root {
  --bg-primary: #111827;
  --bg-secondary: #1f2937;
  --border-color: #374151;
  --text-primary: #f9fafb;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  
  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  
  /* Border radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
}

/* ===== Base Styles ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Layout Components ===== */
.header {
  background-color: var(--bg-secondary);
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border-color);
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sidebar {
  width: 300px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 1.5rem;
  overflow-y: auto;
}

.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  position: relative;
  overflow: auto;
}

.canvas-wrapper {
  position: relative;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  background: white;
  transition: all var(--transition-normal);
}

.canvas-wrapper.drawing-mode {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.5), 0 4px 6px rgba(0, 0, 0, 0.3);
  transform: scale(1.02);
}

.drawing-mode-tooltip {
  position: absolute;
  top: -2rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(59, 130, 246, 0.9);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  z-index: 1000;
  animation: fadeInDown 0.3s ease;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-0.5rem);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

#mainCanvas {
  display: block;
  cursor: move;
}

.section {
  margin-bottom: 2rem;
}

.section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.8;
}

/* ===== Form Elements ===== */
.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  opacity: 0.9;
}

select, input, button {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
}

select:focus, input:focus, button:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

/* Improve focus visibility for accessibility */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Skip to main content link for keyboard users */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: white;
  padding: 8px;
  text-decoration: none;
  border-radius: 0 0 4px 0;
}

.skip-link:focus {
  top: 0;
}

button {
  cursor: pointer;
  transition: all var(--transition-normal);
  font-weight: 500;
}

button:hover {
  background-color: var(--border-color);
}

button.primary {
  background-color: var(--accent);
  border-color: var(--accent);
}

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

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.button-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

/* ===== Transform Controls ===== */
.transform-controls {
  display: grid;
  gap: 0.5rem;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

input[type="range"] {
  flex: 1;
  padding: 0;
}

.slider-value {
  min-width: 3rem;
  text-align: right;
  font-size: 0.875rem;
}

/* ===== Drawing Tools ===== */
.drawing-tools {
  display: none;
}

.drawing-tools.active {
  display: block;
}

.drawing-status {
  margin-bottom: 1rem;
  padding: 0.75rem;
  background-color: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-sm);
}

.drawing-instruction {
  margin: 0;
  font-size: 0.875rem;
  color: #93c5fd;
  text-align: center;
  line-height: 1.4;
}

.drawing-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 1rem;
}

.apply-button {
  position: relative;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.button-icon {
  font-size: 1rem;
  font-weight: bold;
}

.apply-button:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

/* ===== Canvas Elements ===== */
#drawingCanvas {
  position: absolute;
  top: 0;
  left: 0;
  cursor: crosshair;
  display: none;
  z-index: 5;
}

#drawingCanvas.active {
  display: block;
}

/* ===== Transform Handles ===== */
.signature-box {
  position: absolute;
  border: 2px dashed var(--accent);
  pointer-events: none;
  display: none;
}

.signature-box.active {
  display: block;
}

.transform-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 2px solid white;
  border-radius: 50%;
  cursor: pointer;
  z-index: 10;
  pointer-events: auto;
}

.transform-handle.tl { top: -6px; left: -6px; cursor: nw-resize; }
.transform-handle.tr { top: -6px; right: -6px; cursor: ne-resize; }
.transform-handle.bl { bottom: -6px; left: -6px; cursor: sw-resize; }
.transform-handle.br { bottom: -6px; right: -6px; cursor: se-resize; }
.transform-handle.rotate { 
  top: -30px; 
  left: 50%; 
  transform: translateX(-50%);
  cursor: crosshair;
}

/* ===== File Input ===== */
.file-input-wrapper {
  position: relative;
  overflow: hidden;
}

input[type="file"] {
  position: absolute;
  left: -9999px;
}

.file-input-label {
  display: block;
  padding: 0.5rem 0.75rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition-normal);
}

.file-input-label:hover {
  background-color: var(--border-color);
}

/* ===== Toast Notifications ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  opacity: 0;
  transform: translateY(1rem);
  transition: all var(--transition-normal);
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  border-color: #10b981;
  background: #065f46;
}

.toast-error {
  border-color: #ef4444;
  background: #7f1d1d;
}

.toast-warning {
  border-color: #f59e0b;
  background: #78350f;
}

.toast-info {
  border-color: var(--accent);
  background: var(--bg-secondary);
}

/* ===== Footer ===== */
.footer {
  padding: 1rem;
  text-align: center;
  font-size: 0.875rem;
  opacity: 0.7;
}

/* ===== Utility Classes ===== */
.hidden { display: none !important; }
.active { display: block !important; }