/* ImageAnnotator — styles */

/* ── Design tokens ── */
.pkp-container {
  --ia-bg: #f4f5f7;
  --ia-surface: #ffffff;
  --ia-border: #e5e7eb;
  --ia-border-strong: #d1d5db;
  --ia-text: #111827;
  --ia-text-muted: #6b7280;
  --ia-accent: #2563eb;
  --ia-accent-light: #3b82f6;
  --ia-accent-bg: rgba(37, 99, 235, 0.06);
  --ia-danger: #ef4444;
  --ia-radius: 10px;
  --ia-radius-sm: 6px;
  --ia-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --ia-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  --ia-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
  --ia-transition: 0.15s ease;

  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  color: var(--ia-text);
  -webkit-font-smoothing: antialiased;
  height: 100%;
}

.pkp-container svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ══════════════════════════════════════
   DESKTOP: Minimal top bar
   ══════════════════════════════════════ */

.pkp-topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--ia-surface);
  border-bottom: 1px solid var(--ia-border);
  user-select: none;
  flex-shrink: 0;
  z-index: 10;
  position: relative;
}

/* Done button floats right in topbar */
.pkp-topbar .pkp-done-btn {
  position: absolute;
  right: 10px;
}

.pkp-topbar-group {
  display: flex;
  align-items: center;
  gap: 3px;
}

.pkp-topbar-group + .pkp-topbar-group {
  padding-left: 8px;
  border-left: 1px solid var(--ia-border);
}

.pkp-topbar-spacer {
  flex: 1;
}

/* Active tool indicator in topbar */
.pkp-active-tool-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--ia-accent-bg);
  border: 1px solid rgba(37, 99, 235, 0.15);
  border-radius: var(--ia-radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--ia-accent);
  cursor: pointer;
  transition: all var(--ia-transition);
}
.pkp-active-tool-badge:hover {
  background: rgba(37, 99, 235, 0.1);
}
.pkp-active-tool-badge .pkp-badge-hint {
  font-weight: 400;
  opacity: 0.5;
  font-size: 11px;
}

/* Shared button styles */
.pkp-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--ia-border);
  border-radius: var(--ia-radius-sm);
  background: var(--ia-surface);
  color: var(--ia-text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all var(--ia-transition);
}
.pkp-btn:hover {
  background: var(--ia-bg);
  border-color: var(--ia-border-strong);
}
.pkp-btn:active {
  transform: scale(0.96);
}
.pkp-btn:disabled {
  opacity: 0.3;
  cursor: default;
  transform: none;
}
.pkp-btn.active {
  background: var(--ia-accent);
  color: #fff;
  border-color: var(--ia-accent);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

/* Done button (desktop topbar) */
.pkp-done-btn {
  background: #16a34a;
  color: #fff;
  border-color: #16a34a;
  font-weight: 600;
}
.pkp-done-btn:hover {
  background: #15803d;
  border-color: #15803d;
}

/* Done button (mobile bottombar) */
.pkp-bottom-done {
  color: #4ade80 !important;
}
.pkp-bottom-done:active {
  background: rgba(74, 222, 128, 0.12);
}

/* ══════════════════════════════════════
   CANVAS — takes max space
   ══════════════════════════════════════ */

.pkp-canvas-wrap {
  position: relative;
  z-index: 0; /* contain stacking context */
  overflow: hidden;
  flex: 1;
  background: #1e1e22;
  cursor: crosshair;
  touch-action: none;
}

.pkp-canvas-wrap canvas {
  display: block;
}

.pkp-canvas-inner {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.pkp-canvas-inner.pkp-animating {
  transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.pkp-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* ══════════════════════════════════════
   CONTEXT MENU (desktop right-click)
   ══════════════════════════════════════ */

.pkp-ctx-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.pkp-ctx-menu {
  position: fixed;
  z-index: 1001;
  min-width: 200px;
  max-width: 280px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  padding: 4px;
  user-select: none;
  animation: ia-ctx-in 0.12s ease-out;
}

@keyframes ia-ctx-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.pkp-ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: var(--ia-radius-sm);
  background: transparent;
  color: var(--ia-text);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  transition: background var(--ia-transition);
}
.pkp-ctx-item:hover {
  background: var(--ia-bg);
}
.pkp-ctx-item.active {
  background: var(--ia-accent-bg);
  color: var(--ia-accent);
  font-weight: 600;
}
.pkp-ctx-item.active .pkp-ctx-icon svg {
  stroke: var(--ia-accent);
}
.pkp-ctx-item .pkp-ctx-icon {
  width: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.pkp-ctx-item .pkp-ctx-icon svg {
  width: 18px;
  height: 18px;
}

.pkp-ctx-sub {
  font-size: 12px !important;
  color: #6b7280;
}
.pkp-ctx-sub.active {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.06);
  font-weight: 600;
}

.pkp-ctx-divider {
  height: 1px;
  background: var(--ia-border);
  margin: 4px 6px;
}

.pkp-ctx-section {
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pkp-ctx-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ia-text-muted);
  width: 100%;
  margin-bottom: 2px;
}

/* ══════════════════════════════════════
   MOBILE BOTTOM BAR
   ══════════════════════════════════════ */

/* ── Mobile dark bottom bar (kuvakirja-inspired) ── */

.pkp-bottombar {
  display: none; /* shown via media query */
  position: relative;
  z-index: 50;
  background: #1a1a1a;
  padding: 6px 0 max(6px, env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
  touch-action: manipulation; /* prevent double-tap zoom */
}

.pkp-bottombar-row {
  display: flex;
  justify-content: space-around;
  align-items: center;
  max-width: 420px;
  margin: 0 auto;
}

.pkp-bottom-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  font-size: 10px;
  font-family: inherit;
  font-weight: 500;
  transition: all var(--ia-transition);
  -webkit-tap-highlight-color: transparent;
}
.pkp-bottom-btn:active {
  background: rgba(255, 255, 255, 0.08);
}
.pkp-bottom-btn.active {
  color: #60a5fa; /* blue-400 */
}
.pkp-bottom-btn .pkp-bottom-icon {
  line-height: 1;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pkp-bottom-btn .pkp-bottom-icon svg {
  width: 22px;
  height: 22px;
}
.pkp-bottom-btn .pkp-bottom-color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

/* ── Bottom sheet panel ── */

.pkp-panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.25);
}

@keyframes ia-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.pkp-panel {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  z-index: 51;
  max-height: 40vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 8px 16px 12px;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
  animation: ia-panel-in 0.2s ease-out;
}

@keyframes ia-panel-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.pkp-panel-handle {
  padding: 10px 0 8px;
  margin: -8px -16px 4px;
  cursor: grab;
  -webkit-tap-highlight-color: transparent;
}
.pkp-panel-handle::after {
  content: "";
  display: block;
  width: 40px;
  height: 5px;
  background: #d1d5db;
  border-radius: 3px;
  margin: 0 auto;
}

.pkp-panel-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.pkp-panel-tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ia-text);
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  transition: all var(--ia-transition);
  -webkit-tap-highlight-color: transparent;
}
.pkp-panel-tool:active {
  transform: scale(0.94);
  background: #f3f4f6;
}
.pkp-panel-tool.active {
  background: #eff6ff; /* blue-50 */
  color: #2563eb; /* blue-600 */
  font-weight: 600;
}
.pkp-panel-tool .pkp-panel-tool-icon {
  height: 30px;
  display: flex;
  align-items: center;
}
.pkp-panel-tool .pkp-panel-tool-icon svg {
  width: 24px;
  height: 24px;
}

.pkp-panel-colors {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 6px 0;
}

.pkp-panel-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid #f3f4f6;
}

.pkp-panel-slider-row label {
  font-size: 13px;
  font-weight: 500;
  min-width: 40px;
  color: #6b7280;
}

.pkp-panel-actions {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid #f3f4f6;
}

/* ══════════════════════════════════════
   SHARED: Color buttons
   ══════════════════════════════════════ */

.pkp-color-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: all var(--ia-transition);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}
.pkp-color-btn:hover {
  transform: scale(1.12);
}
.pkp-color-btn.active {
  border-color: var(--ia-text);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #3b82f6;
  transform: scale(1.05);
}

/* ══════════════════════════════════════
   SHARED: Size slider
   ══════════════════════════════════════ */

.pkp-size-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 5px;
  border-radius: 3px;
  background: #d1d5db;
  outline: none;
  cursor: pointer;
  flex-shrink: 0;
}
.pkp-size-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ia-accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.35);
  cursor: pointer;
}
.pkp-size-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ia-accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.35);
  cursor: pointer;
}
.pkp-size-slider::-moz-range-track {
  height: 5px;
  border-radius: 3px;
  background: #d1d5db;
}

/* ══════════════════════════════════════
   Upload area
   ══════════════════════════════════════ */

.pkp-upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 300px;
  border: 2px dashed var(--ia-border-strong);
  border-radius: var(--ia-radius);
  background: var(--ia-bg);
  color: var(--ia-text-muted);
  cursor: pointer;
  transition: all var(--ia-transition);
  margin: 16px;
  position: relative;
  z-index: 1;
}
.pkp-upload-area:hover,
.pkp-upload-area.dragover {
  border-color: var(--ia-accent);
  background: var(--ia-accent-bg);
  color: var(--ia-accent);
}
.pkp-upload-area svg {
  width: 44px;
  height: 44px;
  opacity: 0.45;
}

.pkp-upload-input {
  display: none;
}

/* ══════════════════════════════════════
   Crops bar
   ══════════════════════════════════════ */

.pkp-crops-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  font-size: 13px;
  flex-shrink: 0;
}

.pkp-crop-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: #fff;
  border: 1px solid #fde68a;
  border-radius: 4px;
  font-size: 12px;
}
.pkp-crop-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ia-danger);
  font-size: 14px;
  padding: 0 0 0 2px;
  line-height: 1;
}

/* ══════════════════════════════════════
   Overlays (number edit, text input)
   ══════════════════════════════════════ */

.pkp-number-edit-wrap {
  position: absolute;
  z-index: 100;
}
.pkp-number-edit {
  width: 42px;
  height: 30px;
  border: 2px solid var(--ia-accent);
  border-radius: var(--ia-radius-sm);
  padding: 2px 4px;
  font-size: 16px; /* >= 16px prevents iOS auto-zoom */
  font-weight: 600;
  text-align: center;
  background: rgba(255, 255, 255, 0.95);
  outline: none;
  box-shadow: var(--ia-shadow);
  -moz-appearance: textfield;
}
.pkp-number-edit::-webkit-inner-spin-button,
.pkp-number-edit::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.pkp-text-input-wrap {
  position: absolute;
  z-index: 10;
}
.pkp-text-input {
  border: 2px solid #3b82f6;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 16px; /* >= 16px prevents iOS auto-zoom */
  font-family: inherit;
  outline: none;
  min-width: 100px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--ia-shadow);
}

/* ══════════════════════════════════════
   RESPONSIVE: Mobile layout
   ══════════════════════════════════════ */

@media (max-width: 640px) {
  .pkp-container {
    height: 100dvh;
  }

  .pkp-topbar {
    display: none;
  }

  .pkp-bottombar {
    display: block;
  }

  .pkp-canvas-wrap {
    flex: 1 1 0;
    min-height: 0;
    overflow: auto;
  }

  .pkp-upload-area {
    margin: 8px;
    min-height: 200px;
  }

  .pkp-crops-bar {
    font-size: 12px;
    padding: 4px 8px;
  }
}

/* ══════════════════════════════════════
   Touch: larger targets
   ══════════════════════════════════════ */

@media (pointer: coarse) {
  .pkp-color-btn {
    width: 32px;
    height: 32px;
  }

  .pkp-size-slider::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }
  .pkp-size-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  .pkp-panel-tool {
    padding: 12px 4px;
  }
}

/* Legacy class compat for JS references */
.pkp-tool-btn { /* alias for pkp-btn */ }
