:root {
  --bg-main: #0f172a;
  --bg-surface: #1e293b;
  --bg-card: #334155;
  --border-color: #475569;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-active: #4338ca;
  --accent: #06b6d4;
  --success: #10b981;
  --danger: #ef4444;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* Header */
.app-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 10;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-brand img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.header-brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, #a5b4fc, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-brand .badge {
  font-size: 0.75rem;
  padding: 2px 6px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Button styles */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover {
  background-color: var(--bg-card);
  border-color: #64748b;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

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

.btn-success {
  background-color: #059669;
  border-color: #059669;
  color: #ffffff;
}

.btn-success:hover {
  background-color: #047857;
}

.btn-icon-only {
  padding: 6px;
  min-width: 34px;
  justify-content: center;
}

.btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* Toolbar */
.app-toolbar {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 9;
}

.tool-group {
  display: flex;
  align-items: center;
  background-color: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
}

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.tool-btn:hover {
  background-color: var(--bg-card);
  color: var(--text-main);
}

.tool-btn.active {
  background-color: var(--primary);
  color: #ffffff;
}

.tool-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.toolbar-separator {
  width: 1px;
  height: 24px;
  background-color: var(--border-color);
  margin: 0 4px;
}

/* Color presets */
.color-picker-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.color-dot:hover {
  transform: scale(1.15);
}

.color-dot.active {
  border-color: #ffffff;
  transform: scale(1.15);
  box-shadow: 0 0 0 2px var(--primary);
}

/* Custom color input */
.custom-color-wrapper {
  position: relative;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--border-color);
  cursor: pointer;
}

.custom-color-wrapper input[type="color"] {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  border: none;
  background: none;
}

/* Line width selector */
.line-width-selector {
  display: flex;
  align-items: center;
  gap: 4px;
}

.width-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
}

.width-btn.active {
  background-color: var(--bg-card);
  border-color: var(--primary);
}

.width-indicator {
  background-color: var(--text-main);
  border-radius: 2px;
}

/* Tool options popup / inline controls */
.tool-options {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tool-options select,
.tool-options input[type="number"] {
  background-color: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
}

/* Main Workspace */
.workspace {
  flex: 1;
  position: relative;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #0b0f19;
  background-image: 
    radial-gradient(#1e293b 1px, transparent 1px);
  background-size: 20px 20px;
  padding: 24px;
}

/* Dropzone (when no image) */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 48px;
  text-align: center;
  background-color: rgba(30, 41, 59, 0.5);
  backdrop-filter: blur(4px);
  max-width: 520px;
  width: 100%;
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background-color: rgba(99, 102, 241, 0.08);
}

.dropzone-icon {
  width: 56px;
  height: 56px;
  color: var(--primary);
  margin-bottom: 16px;
}

.dropzone-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.dropzone-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 20px;
}

.dropzone-desc kbd {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.8rem;
  color: #e2e8f0;
}

/* Canvas container */
.canvas-wrapper {
  position: relative;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  display: inline-block;
  line-height: 0;
  border-radius: 4px;
  overflow: visible;
}

#annotation-canvas {
  display: block;
  cursor: crosshair;
  background-color: transparent;
}

#annotation-canvas.tool-select {
  cursor: default;
}

#annotation-canvas.tool-text {
  cursor: text;
}

/* Hidden elements */
.is-hidden {
  display: none !important;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: #1e293b;
  border: 1px solid var(--border-color);
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 30px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast svg {
  width: 18px;
  height: 18px;
  fill: var(--success);
}

/* Text edit popover container */
.text-editor-container {
  position: absolute;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.95);
  border: 2px solid var(--primary);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
  min-width: 220px;
  max-width: calc(100% - 24px);
  gap: 6px;
  backdrop-filter: blur(8px);
}

.text-editor-container.is-hidden {
  display: none !important;
}

#text-editor-overlay {
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  padding: 6px 8px;
  border-radius: 4px;
  outline: none;
  resize: vertical;
  min-height: 48px;
  caret-color: #38bdf8;
}

#text-editor-overlay:focus {
  border-color: var(--primary);
}

.text-editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.text-editor-tip {
  font-size: 0.7rem;
  color: #94a3b8;
  white-space: nowrap;
}

.text-editor-btns {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-sm {
  padding: 3px 8px;
  font-size: 0.75rem;
  border-radius: 4px;
  cursor: pointer;
}

/* Status Bar */
.status-bar {
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: 4px 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

@media (max-width: 768px) {
  .app-header h1 {
    font-size: 0.95rem;
  }
  .app-toolbar {
    overflow-x: auto;
    padding-bottom: 8px;
  }
}
