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

:root {
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #252542;
  --bg-hover: #2d2d52;
  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #2e2e4a;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

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

/* ===== Header ===== */
.header {
  height: 56px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 100;
}

.header-left .logo {
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-center .filename {
  font-size: 14px;
  color: var(--text-secondary);
  padding: 4px 12px;
  background: var(--bg-tertiary);
  border-radius: 4px;
}

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

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(99, 102, 241, 0.4);
}

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

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

.btn-lang {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 10px;
}

.btn-lang:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

/* ===== Main Container ===== */
.main-container {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ===== Sidebar - 2 Column Layout ===== */
.sidebar {
  width: 140px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 8px;
  flex-shrink: 0;
  overflow: hidden;
}

.tool-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 4px;
  border: none;
  border-radius: 10px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 11px;
  min-height: 64px;
}

.tool-btn svg {
  width: 24px;
  height: 24px;
  stroke-width: 1.5;
  transition: all 0.2s ease;
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.tool-btn.active {
  background: var(--accent-gradient);
  color: white;
  box-shadow: var(--shadow);
}

.tool-btn.active svg {
  stroke-width: 2;
}

.tool-divider {
  width: 100%;
  height: 1px;
  background: var(--border-color);
  margin: 4px 0;
}

/* Open button spans full width */
.tool-btn[data-tool="open"] {
  grid-column: span 2;
  flex-direction: row;
  gap: 8px;
  min-height: 44px;
  background: var(--accent-gradient);
  color: white;
}

.tool-btn[data-tool="open"]:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.tool-open {
  background: var(--bg-tertiary);
  color: var(--accent-primary);
}

.tool-open:hover {
  background: var(--accent-primary);
  color: white;
}

/* ===== Editor Area ===== */
.editor-area {
  flex: 1;
  position: relative;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ===== Upload Overlay ===== */
.upload-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  z-index: 50;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.upload-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.upload-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 60px 80px;
  border: 2px dashed var(--border-color);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.upload-box:hover {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.05);
  transform: translateY(-2px);
}

.upload-icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: 16px;
  color: var(--accent-primary);
}

.upload-icon svg {
  width: 32px;
  height: 32px;
}

.upload-box h3 {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-primary);
}

.upload-box p {
  font-size: 14px;
  color: var(--text-secondary);
}

.upload-formats {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 12px;
  background: var(--bg-secondary);
  border-radius: 20px;
}

/* ===== TUI Image Editor Customization ===== */
#tui-image-editor-container {
  width: 100% !important;
  height: 100% !important;
}

.tui-image-editor-container {
  background: var(--bg-primary) !important;
}

.tui-image-editor-container .tui-image-editor {
  background: transparent !important;
}

.tui-image-editor-container .tui-image-editor-canvas-container {
  background: transparent !important;
}

/* Hide default TUI header, we have our own */
.tui-image-editor-container .tui-image-editor-header {
  display: none !important;
}

/* Controls (submenu) styling */
.tui-image-editor-container .tui-image-editor-controls {
  background: var(--bg-secondary) !important;
  border-top: 1px solid var(--border-color) !important;
}

.tui-image-editor-container .tui-image-editor-menu {
  background: var(--bg-secondary) !important;
}

.tui-image-editor-container .tui-image-editor-menu > .tui-image-editor-item {
  color: var(--text-secondary) !important;
}

.tui-image-editor-container .tui-image-editor-menu > .tui-image-editor-item:hover {
  background: var(--bg-tertiary) !important;
  color: var(--text-primary) !important;
}

.tui-image-editor-container .tui-image-editor-menu > .tui-image-editor-item.active {
  background: var(--accent-primary) !important;
  color: white !important;
}

/* Submenu styling */
.tui-image-editor-container .tui-image-editor-submenu {
  background: var(--bg-tertiary) !important;
}

.tui-image-editor-container .tui-image-editor-submenu .tui-image-editor-submenu-style {
  background: var(--bg-tertiary) !important;
}

/* Range slider styling */
.tui-image-editor-container .tui-image-editor-virtual-range-bar {
  background: var(--bg-hover) !important;
}

.tui-image-editor-container .tui-image-editor-virtual-range-subbar {
  background: var(--accent-primary) !important;
}

.tui-image-editor-container .tui-image-editor-virtual-range-pointer {
  background: white !important;
  border: 2px solid var(--accent-primary) !important;
}

/* Checkbox styling */
.tui-image-editor-container .tui-image-editor-checkbox > label > span:before {
  background: var(--bg-hover) !important;
  border: 1px solid var(--border-color) !important;
}

.tui-image-editor-container .tui-image-editor-checkbox input[type="checkbox"]:checked + span:before {
  background: var(--accent-primary) !important;
  border-color: var(--accent-primary) !important;
}

/* Button styling within TUI */
.tui-image-editor-container .tui-image-editor-controls-buttons button,
.tui-image-editor-container .tui-image-editor-header-buttons button {
  background: var(--bg-tertiary) !important;
  border: 1px solid var(--border-color) !important;
  color: var(--text-primary) !important;
}

.tui-image-editor-container .tui-image-editor-download-btn {
  background: var(--accent-primary) !important;
  border-color: var(--accent-primary) !important;
  color: white !important;
}

/* Help menu styling */
.tui-image-editor-container .tui-image-editor-help-menu {
  background: var(--bg-secondary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 8px !important;
}

/* Color picker styling */
.tui-image-editor-container .tui-colorpicker-palette-button {
  border: 1px solid var(--border-color) !important;
}

.tui-image-editor-container .color-picker-control {
  background: var(--bg-secondary) !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: var(--shadow-lg) !important;
}

/* Hide TUI's default controls since we have our own sidebar */
.tui-image-editor-container .tui-image-editor-controls {
  display: none !important;
}

/* Adjust main area to use full height */
.tui-image-editor-container .tui-image-editor-main-container {
  bottom: 0 !important;
}

.tui-image-editor-container .tui-image-editor-main {
  top: 0 !important;
}

/* Grid visual */
.tui-image-editor-container .tui-image-editor-grid-visual {
  border-color: var(--accent-primary) !important;
}

/* Loading state */
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  z-index: 100;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Drag overlay */
.drag-overlay {
  position: absolute;
  inset: 0;
  background: rgba(99, 102, 241, 0.2);
  border: 3px dashed var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.drag-overlay.active {
  opacity: 1;
  visibility: visible;
}

.drag-overlay p {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-primary);
}

/* Hidden file input */
#file-input {
  display: none;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--bg-hover);
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
}

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

.toast.success {
  border-left: 3px solid #22c55e;
}

.toast.error {
  border-left: 3px solid #ef4444;
}
