/* ============================================
   Studio — Photo Editor Styles
   ============================================ */

:root {
  --bg-darkest: #0a0a0a;
  --bg-dark: #111111;
  --bg-panel: #191919;
  --bg-surface: #222222;
  --bg-hover: #2a2a2a;
  --bg-active: #333333;
  --border: #2a2a2a;
  --border-light: #383838;
  --text: #e0e0e0;
  --text-dim: #888888;
  --text-muted: #555555;
  --accent: #5b9cf6;
  --accent-hover: #7ab4ff;
  --accent-dim: #3a6db5;
  --danger: #e55c5c;
  --success: #4ecb71;
  --radius: 6px;
  --radius-sm: 4px;
  --sidebar-width: 220px;
  --toolbar-height: 48px;
  --statusbar-height: 28px;
  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg-darkest);
  overflow: hidden;
  height: 100vh;
  user-select: none;
  -webkit-user-select: none;
}

/* Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ============================================
   Toolbar
   ============================================ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--toolbar-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  gap: 12px;
  z-index: 100;
}

.toolbar-left, .toolbar-center, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-right: 12px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tb-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  white-space: nowrap;
}

.tb-btn:hover { background: var(--bg-hover); color: var(--text); }
.tb-btn:active { background: var(--bg-active); }
.tb-btn:disabled { opacity: 0.3; cursor: default; pointer-events: none; }
.tb-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.tb-btn.primary:hover { background: var(--accent-hover); }

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

.tb-select {
  padding: 5px 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
}

/* ============================================
   Sidebars
   ============================================ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
}

.sidebar-right {
  border-right: none;
  border-left: 1px solid var(--border);
}

.sidebar-section {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* Scrollbar */
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ============================================
   Tool Buttons
   ============================================ */
.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 10px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}

.tool-btn:hover { background: var(--bg-hover); color: var(--text); }
.tool-btn.active {
  background: var(--bg-surface);
  border-color: var(--accent-dim);
  color: var(--accent);
}

/* ============================================
   Sliders
   ============================================ */
.slider-group { margin-bottom: 8px; }

.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-dim);
}

.slider-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  min-width: 30px;
  text-align: right;
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--bg-active);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--text);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s;
  border: 2px solid var(--bg-panel);
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.slider::-webkit-slider-thumb:hover {
  background: var(--accent);
}

.slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--text);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--bg-panel);
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* ============================================
   Ratio / Action Buttons
   ============================================ */
.ratio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  margin-bottom: 12px;
}

.ratio-btn {
  padding: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}

.ratio-btn:hover { border-color: var(--border-light); color: var(--text); }
.ratio-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(91,156,246,0.1); }

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  padding: 7px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  margin-bottom: 4px;
}

.action-btn:hover { background: var(--bg-hover); color: var(--text); }
.action-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.action-btn.primary:hover { background: var(--accent-hover); }

.crop-actions, .transform-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.draw-controls, .text-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-input {
  width: 100%;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  cursor: pointer;
  padding: 2px;
}

.text-field {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}

.text-field:focus { border-color: var(--accent); }

/* ============================================
   Filter Grid
   ============================================ */
.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.filter-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.filter-card:hover { border-color: var(--border-light); }
.filter-card.active { border-color: var(--accent); }

.filter-preview {
  width: 100%;
  height: 48px;
  border-radius: 3px;
  margin-bottom: 4px;
  object-fit: cover;
}

.filter-name {
  font-size: 10px;
  color: var(--text-dim);
}

.filter-card.active .filter-name { color: var(--accent); }

/* ============================================
   Canvas Area
   ============================================ */
.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  position: relative;
  overflow: hidden;
  background-image:
    linear-gradient(45deg, #151515 25%, transparent 25%),
    linear-gradient(-45deg, #151515 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #151515 75%),
    linear-gradient(-45deg, transparent 75%, #151515 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#canvas {
  max-width: 100%;
  max-height: 100%;
  image-rendering: auto;
  cursor: default;
}

#canvas.grabbing { cursor: grabbing; }
#canvas.crosshair { cursor: crosshair; }

/* Drop Zone */
.drop-zone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.drop-zone-content {
  text-align: center;
  color: var(--text-dim);
}

.drop-zone-content p { margin-top: 12px; font-size: 14px; }
.drop-hint { font-size: 12px !important; color: var(--text-muted); }

.drop-zone.drag-over {
  background: rgba(91, 156, 246, 0.05);
  border: 2px dashed var(--accent);
}

.drop-zone.drag-over .drop-zone-content { color: var(--accent); }

/* ============================================
   Crop Overlay
   ============================================ */
.crop-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}

.crop-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.crop-rect {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  pointer-events: all;
  cursor: move;
}

.crop-rect::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to right, rgba(255,255,255,0.3) 1px, transparent 1px) 0 0 / 33.33% 100%,
    linear-gradient(to bottom, rgba(255,255,255,0.3) 1px, transparent 1px) 0 0 / 100% 33.33%;
}

.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 2px;
  pointer-events: all;
}

.crop-handle.nw { top: -6px; left: -6px; cursor: nw-resize; }
.crop-handle.ne { top: -6px; right: -6px; cursor: ne-resize; }
.crop-handle.sw { bottom: -6px; left: -6px; cursor: sw-resize; }
.crop-handle.se { bottom: -6px; right: -6px; cursor: se-resize; }
.crop-handle.n { top: -6px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.crop-handle.s { bottom: -6px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.crop-handle.e { right: -6px; top: 50%; transform: translateY(-50%); cursor: e-resize; }
.crop-handle.w { left: -6px; top: 50%; transform: translateY(-50%); cursor: w-resize; }

/* ============================================
   Status Bar
   ============================================ */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--statusbar-height);
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 0 14px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

#canvas {
  animation: fadeIn 0.3s ease;
}

/* ============================================
   Mode Tabs
   ============================================ */
.mode-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-surface);
  border-radius: var(--radius);
  padding: 2px;
  margin-left: 8px;
}

.mode-tab {
  padding: 5px 14px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}

.mode-tab:hover { color: var(--text); }
.mode-tab.active {
  background: var(--accent);
  color: #fff;
}

/* ============================================
   Creator Workspace
   ============================================ */
.create-workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.creator-sidebar-left,
.creator-sidebar-right {
  display: flex;
  flex-direction: column;
}

.creator-sidebar-right {
  width: 240px;
}

.creator-size-info {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.creator-add-btns {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ============================================
   Creator Layer List
   ============================================ */
.creator-layer-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.clayer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
  font-size: 12px;
  color: var(--text-dim);
}

.clayer-item:hover { background: var(--bg-hover); }
.clayer-item.selected {
  background: var(--bg-surface);
  color: var(--accent);
  outline: 1px solid var(--accent-dim);
}

.clayer-icon {
  font-size: 13px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.clayer-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clayer-vis,
.clayer-up,
.clayer-down,
.clayer-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1;
  transition: all 0.1s;
}

.clayer-vis:hover,
.clayer-up:hover,
.clayer-down:hover { color: var(--text); background: var(--bg-hover); }
.clayer-del:hover { color: var(--danger); background: rgba(229,92,92,0.1); }

.clayer-actions {
  display: flex;
  gap: 2px;
  margin-left: auto;
  flex-shrink: 0;
}

/* ============================================
   Creator Properties Panel
   ============================================ */
.creator-props {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}

.props-empty {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 20px 0;
}

.prop-group {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.prop-group:last-child { border-bottom: none; }

.prop-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.prop-row.full { flex-direction: column; align-items: stretch; }

.prop-row label {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 32px;
  flex-shrink: 0;
}

.prop-input {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
}

.prop-input:focus { border-color: var(--accent); }
.prop-input.sm { max-width: 60px; }

.prop-textarea {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  outline: none;
  resize: vertical;
  min-height: 50px;
}

.prop-textarea:focus { border-color: var(--accent); }

.prop-color {
  width: 32px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
}

.prop-color.sm { width: 28px; height: 24px; }

.prop-slider {
  flex: 1;
  min-width: 0;
}

.prop-val {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  min-width: 36px;
  text-align: right;
  flex-shrink: 0;
}

.prop-select {
  flex: 1;
  padding: 4px 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
}

.prop-btn-group {
  display: flex;
  gap: 2px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.prop-btn {
  padding: 4px 10px;
  background: transparent;
  border: none;
  border-radius: 3px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.1s;
  font-family: var(--font);
}

.prop-btn:hover { color: var(--text); }
.prop-btn.active { background: var(--accent); color: #fff; }

.prop-check {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.action-btn.danger { color: var(--danger); border-color: rgba(229,92,92,0.3); }
.action-btn.danger:hover { background: rgba(229,92,92,0.1); }

/* Creator canvas container */
#creator-canvas-area {
  display: flex;
  align-items: center;
  justify-content: center;
}

#creator-canvas {
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  border-radius: 2px;
}

/* ============================================
   PDF Studio
   ============================================ */
.pdf-workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.pdf-sidebar-left,
.pdf-sidebar-right {
  display: flex;
  flex-direction: column;
}

.pdf-sidebar-right {
  width: 260px;
}

.pdf-doc-btns {
  display: flex;
  gap: 4px;
}

.pdf-doc-btns .action-btn {
  flex: 1;
}

/* Page thumbnails */
.pdf-page-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 180px;
  overflow-y: auto;
}

.pdf-page-thumb {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 11px;
  color: var(--text-dim);
  transition: background 0.1s;
}

.pdf-page-thumb:hover { background: var(--bg-hover); }
.pdf-page-thumb.active {
  background: var(--bg-surface);
  color: var(--accent);
  outline: 1px solid var(--accent-dim);
}

/* Page navigation */
.pdf-page-nav {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-dim);
  z-index: 20;
}

.pdf-nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  padding: 2px 8px;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  transition: all 0.15s;
}

.pdf-nav-btn:hover { background: var(--bg-hover); color: var(--text); }

/* AI Panel */
.pdf-ai-status {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
  cursor: pointer;
}

.pdf-ai-status:hover { color: var(--accent); }

.pdf-ai-prompt {
  width: 100%;
  padding: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  outline: none;
  resize: vertical;
  min-height: 56px;
  margin-bottom: 8px;
}

.pdf-ai-prompt:focus { border-color: var(--accent); }

.pdf-ai-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 8px;
}

.pdf-ai-btn { font-size: 11px; padding: 5px 6px; }

.pdf-ai-result {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  margin-top: 8px;
}

.pdf-ai-result pre {
  font-size: 11px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 150px;
  overflow-y: auto;
  margin-bottom: 8px;
  font-family: var(--font);
}

/* API Key Modal */
.pdf-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.pdf-modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 360px;
  max-width: 90%;
}

.pdf-modal-content h3 {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 8px;
}

.pdf-modal-content p {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

/* PDF Canvas */
#pdf-canvas {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  border-radius: 2px;
}

#pdf-canvas-area {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 900px) {
  :root {
    --sidebar-width: 180px;
  }
  .tb-btn span { display: none; }
}

@media (max-width: 700px) {
  .sidebar-left { display: none; }
  .sidebar-right { display: none; }
}
