/* Reset & Base Variables */
:root {
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  --card-bg: rgba(30, 41, 59, 0.7);
  --card-border: rgba(255, 255, 255, 0.08);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: rgba(59, 130, 246, 0.15);
  --primary-glow: rgba(59, 130, 246, 0.35);
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.15);
  --danger-hover: #dc2626;
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.3);
  --border-radius-lg: 16px;
  --border-radius-md: 10px;
  --border-radius-sm: 6px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.2);
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Outfit', var(--font-sans);
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* App Container */
.app-container {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding: 0.75rem 1.25rem;
  background: rgba(30, 41, 59, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius-md);
  animation: fadeInDown 0.6s ease-out;
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
    padding: 1rem;
  }
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon {
  width: 1.5rem;
  height: 1.5rem;
  color: var(--primary);
  filter: drop-shadow(0 0 6px var(--primary-glow));
  animation: rotateLogo 20s linear infinite;
}

.logo h1 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  background: linear-gradient(to right, #3b82f6, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo h1 span {
  font-weight: 300;
  color: #a78bfa;
  -webkit-text-fill-color: initial;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 400;
}

/* Common Card style (Glassmorphism) */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transition: var(--transition);
}

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-bottom: 2rem;
}

/* Upload Section */
.upload-section {
  width: 100%;
  max-width: 680px;
  padding: 2rem;
  animation: scaleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dropzone {
  border: 2px dashed rgba(255, 255, 255, 0.15);
  border-radius: var(--border-radius-md);
  padding: 4.5rem 2rem;
  text-align: center;
  position: relative;
  cursor: pointer;
  background: rgba(30, 41, 59, 0.3);
  transition: var(--transition);
  overflow: hidden;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.05);
  box-shadow: var(--shadow-glow);
}

.file-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 10;
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.upload-icon-container {
  width: 72px;
  height: 72px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.5rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: var(--transition);
}

.dropzone:hover .upload-icon-container {
  transform: translateY(-5px);
  background: var(--primary-light);
  border-color: rgba(59, 130, 246, 0.3);
}

.upload-icon {
  width: 32px;
  height: 32px;
  color: var(--text-muted);
  transition: var(--transition);
}

.dropzone:hover .upload-icon {
  color: var(--primary);
}

.dropzone-content h3 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.dropzone-content p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}

.dropzone-content p span {
  color: var(--primary);
  font-weight: 600;
  text-decoration: underline;
}

.file-limit {
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.7;
}

/* Editor Section */
.editor-section {
  width: 100%;
  animation: fadeIn 0.4s ease-out;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  min-height: 600px;
  width: 100%;
}

@media (max-width: 1024px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }
}

/* Workspace (Cropper Area) */
.editor-workspace {
  background: #090d16;
  display: flex;
  flex-direction: column;
  position: relative;
  border-right: 1px solid var(--card-border);
  min-height: 450px;
}

.cropper-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  max-height: calc(100vh - 180px);
  min-height: 480px;
  padding: 1.5rem;
}

.cropper-container img {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

/* Customize Cropper look to match dark theme */
.cropper-view-box {
  outline: 2px solid var(--primary);
  outline-color: var(--primary);
}

.cropper-line, .cropper-point {
  background-color: var(--primary);
}

.cropper-bg {
  background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGklEQVQYlWNgYGD4DwUMIEwMZGBkGFSGgYEBAF3hAfkhW50eAAAAAElFTkSuQmCC');
}

.cropper-modal {
  background-color: rgba(9, 13, 22, 0.85);
}

/* Workspace Toolbar */
.workspace-toolbar {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.6);
  border-top: 1px solid var(--card-border);
  flex-wrap: wrap;
}

/* Sidebar Controls */
.editor-sidebar {
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  background: rgba(20, 30, 48, 0.4);
  max-height: calc(100vh - 150px);
  overflow-y: auto;
}

@media (max-width: 1024px) {
  .editor-sidebar {
    max-height: none;
    overflow-y: visible;
  }
}

.sidebar-group {
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 1.5rem;
}

.sidebar-group:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

.group-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-main);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.group-title i {
  color: var(--primary);
  width: 1.1rem;
  height: 1.1rem;
}

/* Ratio Grid */
.ratio-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.btn-ratio {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  padding: 0.6rem 0.25rem;
  border-radius: var(--border-radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-ratio:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.btn-ratio.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.1);
}

/* Custom Ratio Input */
.custom-ratio-inputs {
  animation: slideDown 0.3s ease-out;
}

.custom-ratio-inputs .input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.custom-ratio-inputs span {
  color: var(--text-muted);
  font-weight: bold;
}

/* Form Inputs */
.form-input {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  padding: 0.6rem 0.75rem;
  border-radius: var(--border-radius-sm);
  font-size: 0.9rem;
  width: 100%;
  outline: none;
  font-family: var(--font-sans);
  transition: var(--transition);
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.form-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Size Inputs */
.size-inputs.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.size-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}

.size-separator {
  color: var(--text-muted);
  padding-bottom: 0.5rem;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.input-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.label-row span {
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 600;
}

/* Checkbox */
.checkbox-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.custom-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.checkbox-container label {
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.checkbox-container label:hover {
  color: var(--text-main);
}

.current-crop-size p {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  padding: 0.5rem 0.75rem;
  border-radius: var(--border-radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.current-crop-size span {
  font-weight: 600;
  color: var(--text-main);
}

/* Form Select */
.select-wrapper {
  position: relative;
}

.form-select {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  padding: 0.6rem 0.75rem;
  border-radius: var(--border-radius-sm);
  font-size: 0.9rem;
  width: 100%;
  outline: none;
  cursor: pointer;
  font-family: var(--font-sans);
  appearance: none;
  -webkit-appearance: none;
  transition: var(--transition);
}

.select-wrapper::after {
  content: '▼';
  font-size: 0.7rem;
  color: var(--text-muted);
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.form-select:focus {
  border-color: var(--primary);
}

/* Ranges */
.form-range {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius-sm);
  outline: none;
  accent-color: var(--primary);
  cursor: pointer;
}

.filename-input-container {
  display: flex;
  align-items: center;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--border-radius-sm);
  padding-right: 0.75rem;
}

.filename-input-container:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.filename-input-container .form-input {
  border: none;
  background: transparent;
  padding-right: 0;
}

.filename-input-container .form-input:focus {
  box-shadow: none;
}

.filename-input-container span {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  user-select: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--border-radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: var(--transition);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.btn-danger-soft {
  background: var(--danger-light);
  border-color: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.btn-danger-soft:hover {
  background: var(--danger);
  color: white;
}

.btn-primary-soft {
  background: var(--primary-light);
  border-color: rgba(59, 130, 246, 0.2);
  color: var(--primary);
}

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

.btn-outline {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-muted);
}

.btn-outline:hover {
  border-color: var(--text-main);
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.03);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border-radius: var(--border-radius-sm);
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(9, 13, 22, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease-out;
}

.modal-card {
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--border-radius-lg);
  width: 90%;
  max-width: 550px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  animation: scaleIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.success-icon {
  color: var(--success);
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-close:hover {
  color: var(--text-main);
  transform: rotate(90deg);
}

.modal-body {
  padding: 1.5rem;
}

.preview-output-container {
  background: #090d16;
  border-radius: var(--border-radius-md);
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.5rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
  min-height: 200px;
  max-height: 300px;
  overflow: hidden;
}

.preview-output-container img {
  max-width: 100%;
  max-height: 280px;
  border-radius: var(--border-radius-sm);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.meta-info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 1rem;
  border-radius: var(--border-radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.meta-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.meta-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.meta-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
}

.modal-footer {
  padding: 1.25rem 1.5rem;
  background: rgba(15, 23, 42, 0.4);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--primary);
  border-radius: var(--border-radius-md);
  padding: 0.75rem 1.5rem;
  box-shadow: var(--shadow-glow), var(--shadow-lg);
  z-index: 2000;
  animation: fadeInUp 0.3s ease-out;
  pointer-events: none;
}

.toast.error {
  border-color: var(--danger);
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.2), var(--shadow-lg);
}

#toastMsg {
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 500;
}

/* Footer */
.app-footer {
  text-align: center;
  padding-top: 2rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  opacity: 0.7;
}

/* Utility classes */
.hidden {
  display: none !important;
}

.mb-3 {
  margin-bottom: 1rem;
}

.mt-2 {
  margin-top: 0.5rem;
}

.mt-3 {
  margin-top: 1rem;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes fadeInDown {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeInUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

@keyframes rotateLogo {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Loading Overlay for AVIF */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(9, 13, 22, 0.9);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  animation: fadeIn 0.3s ease-out;
}

.loading-spinner-container {
  text-align: center;
  color: var(--text-main);
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-left-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 1.5rem;
  animation: spin 1s linear infinite;
}

.loading-note {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* History items styling */
.history-container {
  margin-top: 0.75rem;
  animation: fadeIn 0.3s ease-out;
}

.history-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.35rem;
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn-history {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  padding: 0.3rem 0.6rem;
  border-radius: var(--border-radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}

.btn-history:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--text-main);
  transform: translateY(-1px);
}

/* Color picker stylings */
.color-pickers-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  animation: slideDown 0.3s ease-out;
}

.color-picker-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--border-radius-sm);
  padding: 0.25rem 0.5rem;
}

.color-picker-input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.form-color {
  border: none;
  background: transparent;
  width: 36px;
  height: 30px;
  cursor: pointer;
  border-radius: 4px;
  padding: 0;
}

/* Chrome/Safari custom appearance for color picker */
.form-color::-webkit-color-swatch-wrapper {
  padding: 0;
}
.form-color::-webkit-color-swatch {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.color-text {
  border: none !important;
  background: transparent !important;
  padding: 0 !important;
  font-family: monospace;
  font-size: 0.85rem;
}
.color-text:focus {
  box-shadow: none !important;
}


