/* ===========================
   CSS VARIABLES & RESET
   =========================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base: #0d0f17;
  --bg-panel: #141724;
  --bg-card: #1c2034;
  --bg-hover: #212540;
  --border: rgba(255,255,255,0.08);
  --border-active: rgba(99,102,241,0.6);
  --text-primary: #e8eaf6;
  --text-secondary: #8892b0;
  --text-muted: #4a5580;
  --accent: #6366f1;
  --accent-glow: rgba(99,102,241,0.35);
  --accent-hover: #7c7ff5;
  --success: #10b981;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.18s ease;

  --header-h: 60px;
  --sidebar-w: 240px;
  --sidebar-r-w: 280px;
}

html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
}

/* ===========================
   SCROLLBAR
   =========================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ===========================
   HEADER
   =========================== */
.header {
  height: var(--header-h);
  background: rgba(20,23,36,0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 20px;
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 26px; }
.logo-text {
  font-size: 18px;
  color: var(--text-secondary);
  letter-spacing: -0.3px;
}
.logo-text strong { color: var(--text-primary); font-weight: 700; }

/* ===========================
   BUTTONS
   =========================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 4px 20px var(--accent-glow); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #2a2f52; }

.btn-accent {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  box-shadow: 0 2px 12px rgba(16,185,129,0.3);
}
.btn-accent:hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(16,185,129,0.4); }

.btn-danger {
  background: rgba(239,68,68,0.15);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.25); }

.btn-sm { padding: 6px 12px; font-size: 12px; }

.badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  min-width: 20px;
  text-align: center;
}

/* ===========================
   MAIN LAYOUT
   =========================== */
.main-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--sidebar-r-w);
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ===========================
   SIDEBARS
   =========================== */
.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.sidebar-right { border-right: none; border-left: 1px solid var(--border); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ===========================
   DROP ZONE
   =========================== */
.drop-zone {
  margin: 12px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  transition: all var(--transition);
  flex-shrink: 0;
}
.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(99,102,241,0.08);
  box-shadow: 0 0 0 4px var(--accent-glow);
}
.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 12px;
  text-align: center;
}
.drop-zone-inner svg { color: var(--text-muted); margin-bottom: 4px; }
.drop-zone-inner p { font-size: 11px; color: var(--text-secondary); line-height: 1.4; }

/* ===========================
   THUMBNAIL LIST
   =========================== */
.thumbnail-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.thumb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.thumb-item:hover { background: var(--bg-hover); border-color: var(--border); }
.thumb-item.active { background: rgba(99,102,241,0.12); border-color: var(--border-active); }

.thumb-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
  z-index: 5;
}

.thumb-img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.thumb-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.thumb-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thumb-marker {
  background: #10b981;
  color: white;
  font-size: 10px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: bold;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.thumb-size { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

.thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(239,68,68,0.8);
  border: none;
  color: #fff;
  font-size: 10px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.thumb-item:hover .thumb-remove { display: flex; }

/* ===========================
   EDITOR AREA
   =========================== */
.editor-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg-base);
  position: relative;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 60px; filter: grayscale(0.4); }
.empty-state h2 { font-size: 18px; color: var(--text-secondary); }
.empty-state p { font-size: 13px; }

/* ===========================
   EDITOR LOADING OVERLAY
   =========================== */
.editor-loading {
  position: absolute;
  inset: 0;
  background: rgba(13,15,23,0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: all 0.3s ease;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 240px;
}

.spinner-ring {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.progress-container {
  width: 100%;
  height: 6px;
  background: var(--bg-card);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover), var(--accent));
  background-size: 200% 100%;
  box-shadow: 0 0 10px var(--accent-glow);
  transition: width 0.3s ease;
  animation: shimmer 1.5s infinite linear;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

#editor-loading-msg {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ===========================
   CANVAS WRAPPER
   =========================== */
.canvas-wrapper {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.toolbar-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.ml-auto { margin-left: auto; }

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-hover);
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
  cursor: pointer;
}

.canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 0 40px;
}

.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(20,23,36,0.6);
  border: 1px solid var(--border);
  color: var(--text);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: all var(--transition);
  backdrop-filter: blur(4px);
}

.nav-arrow:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  transform: translateY(-50%) scale(1.1);
  box-shadow: 0 0 15px var(--accent-glow);
}

.nav-arrow.left { left: 10px; }
.nav-arrow.right { right: 10px; }

@media (max-width: 768px) {
  .nav-arrow { width: 36px; height: 36px; }
  .canvas-container { padding: 0 5px; }
}

.canvas-viewport {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Resim boyutu JS ile ayarlanacak */
}

#main-canvas {
  display: block;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sticker-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 5;
}

.emoji-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 10;
}

.emoji-overlay .emoji-sticker {
  position: absolute;
  cursor: move;
  user-select: none;
  pointer-events: all;
  transition: transform 0.1s;
  border: 2px solid transparent;
  border-radius: 4px;
}
.emoji-sticker:hover { border-color: rgba(99,102,241,0.5); background: rgba(99,102,241,0.05); }
.emoji-sticker.selected {
  border-color: var(--accent);
  background: rgba(99,102,241,0.1);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.emoji-sticker span {
  display: none !important; /* Drawn on canvas instead */
}

/* Resize handles — shown only on selected sticker */
.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 3px;
  pointer-events: all;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.emoji-sticker.selected .resize-handle { opacity: 1; }
.resize-handle.nw { top: -6px;  left: -6px;  cursor: nw-resize; }
.resize-handle.ne { top: -6px;  right: -6px; cursor: ne-resize; }
.resize-handle.sw { bottom: -6px; left: -6px;  cursor: sw-resize; }
.resize-handle.se { bottom: -6px; right: -6px; cursor: se-resize; }

/* Size label shown while resizing */
.resize-label {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--border-active);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-primary);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 20;
}
.emoji-sticker.resizing .resize-label { opacity: 1; }

/* ===========================
   EMOJI PANEL (RIGHT)
   =========================== */
.emoji-side {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.emoji-search-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.emoji-search {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color var(--transition);
}
.emoji-search:focus { border-color: var(--border-active); }
.emoji-search::placeholder { color: var(--text-muted); }

.emoji-category-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  overflow-x: auto;
  flex-wrap: nowrap;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  scrollbar-width: none;
}
.emoji-category-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
  flex-shrink: 0;
  font-size: 18px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  background: transparent;
  line-height: 1;
}
.cat-tab:hover { background: var(--bg-hover); }
.cat-tab.active { background: rgba(99,102,241,0.18); border-color: var(--border-active); }

.emoji-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
  padding: 12px;
  align-content: start;
}

.emoji-btn {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "Android Emoji", EmojiSymbols, sans-serif;
  font-size: 26px;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  padding: 8px;
  transition: all var(--transition);
  line-height: 1;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.emoji-btn:hover { background: var(--bg-hover); border-color: var(--border); transform: scale(1.15); }
.emoji-btn.selected { background: rgba(99,102,241,0.2); border-color: var(--border-active); }

/* ===========================
   SELECTED EMOJI BAR
   =========================== */
.selected-emoji-bar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--border-active);
  border-radius: 99px;
  padding: 8px 18px;
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 200;
  backdrop-filter: blur(12px);
  animation: slide-up 0.3s ease;
}
#current-emoji-display { font-size: 22px; }
.change-hint { font-size: 11px; color: var(--text-muted); }

/* ===========================
   UTILITIES
   =========================== */
.hidden { display: none !important; }

@keyframes slide-up {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0); opacity: 1; }
}

@keyframes pop-in {
  0%   { transform: scale(0) rotate(-10deg); opacity: 0; }
  70%  { transform: scale(1.1) rotate(3deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.emoji-sticker { animation: pop-in 0.25s ease; }

/* ===========================
   DETECTION TOAST
   =========================== */
.detection-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(20,23,36,0.95);
  border: 1px solid var(--border-active);
  border-radius: 99px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 300;
  backdrop-filter: blur(12px);
  animation: slide-down 0.25s ease;
}

@keyframes slide-down {
  from { transform: translate(-50%, -60%); opacity: 0; }
  to   { transform: translate(-50%, -50%); opacity: 1; }
}

.toast-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===========================
   MOBILE NAVIGATION
   =========================== */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 64px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  grid-template-columns: repeat(3, 1fr);
  z-index: 1000;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.nav-item svg { transition: transform var(--transition); }
.nav-item.active { color: var(--accent); }
.nav-item.active svg { transform: translateY(-2px); }

/* ===========================
   RESPONSIVE DESIGN
   =========================== */
@media (max-width: 900px) {
  :root { --sidebar-w: 180px; --sidebar-r-w: 220px; }
}

@media (max-width: 768px) {
  body { padding-bottom: 64px; }
  
  .mobile-nav { display: grid; }
  
  .header-inner { padding: 0 12px; }
  .logo-text { font-size: 14px; }
  .logo-icon { font-size: 20px; }

  .main-layout {
    display: block;
    position: relative;
    overflow: hidden;
  }

  /* Sidebars and Editor in Mobile */
  .sidebar, .editor-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    background: var(--bg-base);
  }

  /* Show only active tab */
  .main-layout.show-sidebar-left .sidebar-left { display: flex; z-index: 10; }
  .main-layout.show-editor-area .editor-area { display: flex; z-index: 10; }
  .main-layout.show-sidebar-right .sidebar-right { display: flex; z-index: 10; }

  .sidebar-header { padding: 10px 12px; }
  
  .canvas-toolbar {
    padding: 8px;
    gap: 10px;
    justify-content: space-between;
  }
  
  .toolbar-group { gap: 6px; }
  .btn { padding: 6px 10px; font-size: 12px; }
  .btn span { display: none; } /* Hide text on some buttons if needed */
  
  .canvas-container { padding: 10px; }
  
  .selected-emoji-bar {
    bottom: 80px;
    width: 90%;
    max-width: 320px;
  }

  .emoji-grid {
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 8px;
    padding: 12px;
  }
  
  .emoji-btn { font-size: 28px; }

  /* Adjust drop zone for mobile */
  .drop-zone { margin: 10px; }
  .drop-zone-inner { padding: 16px 10px; }
}
