/* Core reset */
:root {
  --bg-main: #f8fafc;
  --bg-panel: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --border-color: #e2e8f0;
  --border-dark: #cbd5e1;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --accent-text: #1d4ed8;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --success-light: #ecfdf5;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-inner: inset 0 2px 4px 0 rgba(0, 0, 0, 0.06);
  --shadow-accent: 0 10px 15px -3px rgba(37, 99, 235, 0.3), 0 4px 6px -2px rgba(37, 99, 235, 0.2);
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg-main: #0f172a;
  --bg-panel: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  --border-color: #334155;
  --border-dark: #475569;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-light: rgba(59, 130, 246, 0.1);
  --accent-text: #60a5fa;
  --shadow-accent: 0 10px 15px -3px rgba(59, 130, 246, 0.2), 0 4px 6px -2px rgba(59, 130, 246, 0.1);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  height: 64px;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.025em;
}
.logo span {
  background-color: var(--accent);
  color: white;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  font-size: 1rem;
}

.main-nav { display: flex; gap: 24px; }
.main-nav a {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.875rem;
  padding-bottom: 2px;
}
.main-nav a.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}
.main-nav a:hover { color: var(--accent); text-decoration: none; }

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

.privacy-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--success);
  background-color: var(--success-light);
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.icon-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}
.icon-btn:hover { background-color: var(--bg-main); color: var(--text-main); }

[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }
.mobile-menu-btn { display: none; }

/* Workspace */
.app-workspace {
  display: flex;
  flex: 1;
  height: calc(100vh - 64px);
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 256px;
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
}

.sidebar-title {
  padding: 8px 8px 12px;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
}

.tool-list { list-style: none; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.tool-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.875rem;
  transition: all 0.2s;
}
.tool-list li svg { width: 20px; height: 20px; }
.tool-list li:hover { background-color: var(--bg-main); color: var(--text-main); }
.tool-list li.active {
  background-color: var(--accent-light);
  color: var(--accent-text);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
}
.sidebar-footer .btn-ghost {
  border: 1px solid var(--border-color);
  background-color: var(--bg-main);
  font-size: 0.8rem;
  padding: 10px;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-main);
  position: relative;
  overflow: hidden;
}

/* Upload Area */
.upload-area {
  position: absolute;
  inset: 24px;
  border: 2px dashed var(--border-dark);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background-color: var(--bg-panel);
  transition: all 0.3s ease;
  z-index: 5;
  box-shadow: var(--shadow-inner);
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--accent);
  background-color: var(--accent-light);
}
#file-input { display: none; }

.upload-message {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.upload-icon {
  width: 80px; height: 80px;
  background-color: var(--accent-light);
  color: var(--accent);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  border: 1px solid rgba(37, 99, 235, 0.1);
}
.upload-message h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 4px; color: var(--text-main); }
.upload-message p { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 24px; }

.privacy-note {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-subtle);
  margin-top: 24px;
  background-color: var(--bg-main);
  padding: 4px 12px;
  border-radius: 99px;
  border: 1px solid var(--border-color);
}

/* Workspace Panels */
.workspace-panels {
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: auto 1fr;
  grid-template-areas: 
    "toolbar controls"
    "grid controls";
  height: 100%;
}
.workspace-panels.hidden { display: none; }

.workspace-toolbar {
  grid-area: toolbar;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  border-radius: var(--radius-xl) 0 0 0;
  margin: 16px 0 0 16px;
}
.stats { font-size: 0.875rem; font-weight: 700; color: var(--text-main); }

.image-grid {
  grid-area: grid;
  padding: 24px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  align-content: flex-start;
}

.controls-container {
  grid-area: controls;
  background-color: var(--bg-panel);
  border-left: 1px solid var(--border-color);
  padding: 24px;
  overflow-y: auto;
}

/* Tool Panels (Right Sidebar) */
.tool-panel { display: none; animation: fadeIn 0.2s ease; }
.tool-panel.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(5px); }
  to { opacity: 1; transform: translateX(0); }
}

.panel-header { margin-bottom: 24px; }
.panel-header h3 {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-header p { display: none; }

.panel-body.row-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.control-group { display: flex; flex-direction: column; gap: 8px; }
.control-group label {
  font-size: 0.625rem;
  font-weight: 700;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="number"], input[type="text"], select {
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background-color: var(--bg-main);
  color: var(--text-main);
  font-size: 0.875rem;
  font-weight: 600;
  outline: none;
  width: 100%;
  transition: all 0.2s;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
  background-color: var(--bg-panel);
}

.input-with-select { display: flex; }
.input-with-select input { border-top-right-radius: 0; border-bottom-right-radius: 0; flex: 1; }
.input-with-select select, .input-with-select .unit-label {
  border-top-left-radius: 0; border-bottom-left-radius: 0;
  border-left: none; width: auto; background-color: var(--bg-panel);
}
.input-with-select .unit-label {
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-color); border-left: none;
  font-size: 0.875rem; font-weight: 600; color: var(--text-subtle); padding: 0 12px;
}

input[type="color"] {
  height: 40px; padding: 2px; border: 1px solid var(--border-color);
  border-radius: var(--radius); background: var(--bg-main); width: 100%; cursor: pointer;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }

.presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.preset-btn {
  padding: 6px;
  background-color: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.preset-btn:hover { background-color: var(--border-dark); color: var(--text-main); }
.preset-btn.active { background-color: var(--accent); color: white; border-color: var(--accent); box-shadow: var(--shadow-sm); }

.control-actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
}
.control-actions .btn-primary { flex: 1; }

.info-grid {
  display: flex; flex-direction: column; gap: 16px;
  background: var(--bg-main); padding: 16px;
  border-radius: var(--radius); border: 1px solid var(--border-color);
}
.info-item { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.info-item:last-child { border-bottom: none; padding-bottom: 0; }
.info-item span { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; color: var(--text-subtle); }
.info-item strong { font-size: 0.875rem; font-weight: 600; text-align: right; word-break: break-all; max-width: 60%; }

/* Image Card */
.image-card {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.image-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-dark); }

.card-preview {
  height: 160px; background-color: var(--bg-main);
  position: relative; display: flex; align-items: center; justify-content: center; cursor: pointer;
  background-image: linear-gradient(45deg, #e2e8f0 25%, transparent 25%), linear-gradient(-45deg, #e2e8f0 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e2e8f0 75%), linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}
[data-theme="dark"] .card-preview {
  background-image: linear-gradient(45deg, #334155 25%, transparent 25%), linear-gradient(-45deg, #334155 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #334155 75%), linear-gradient(-45deg, transparent 75%, #334155 75%);
}

.card-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.card-preview .zoom-icon {
  position: absolute; inset: 0; background: rgba(15, 23, 42, 0.4);
  color: white; display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.2s; backdrop-filter: blur(2px);
}
.card-preview:hover .zoom-icon { opacity: 1; }

.remove-btn {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px;
  border-radius: 50%; background: var(--bg-panel); color: var(--text-muted);
  border: 1px solid var(--border-color); cursor: pointer;
  display: flex; align-items: center; justify-content: center; z-index: 2;
  box-shadow: var(--shadow-sm); transition: all 0.2s;
}
.remove-btn:hover { background: var(--danger); color: white; border-color: var(--danger); }

.card-details { padding: 16px; flex: 1; display: flex; flex-direction: column; border-top: 1px solid var(--border-color); }
.card-name { font-weight: 700; font-size: 0.875rem; margin-bottom: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-main); }
.card-info { display: flex; justify-content: space-between; font-size: 0.75rem; font-weight: 600; color: var(--text-subtle); margin-bottom: 6px; }
.card-info.after-info { color: var(--success); }
.card-status { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; margin: auto 0 12px; color: var(--accent-text); background: var(--accent-light); padding: 4px 8px; border-radius: 4px; display: inline-block; align-self: flex-start; }
.card-actions { margin-top: auto; }

/* Buttons */
.btn-primary, .btn-secondary, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius); font-weight: 600; font-size: 0.875rem;
  cursor: pointer; transition: all 0.2s; border: none;
}
.btn-primary { background-color: var(--accent); color: white; box-shadow: var(--shadow-accent); }
.btn-primary:hover { background-color: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background-color: var(--bg-panel); border: 1px solid var(--border-dark); color: var(--text-main); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background-color: var(--bg-main); }
.btn-ghost { background-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background-color: var(--bg-main); color: var(--danger); }
.btn-block { width: 100%; }

/* Checkbox */
.custom-checkbox { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 0.875rem; font-weight: 600; color: var(--text-muted); }
.custom-checkbox input { display: none; }
.checkmark { width: 18px; height: 18px; border: 1px solid var(--border-dark); border-radius: 4px; display: flex; align-items: center; justify-content: center; background: var(--bg-panel); transition: all 0.2s; }
.custom-checkbox input:checked + .checkmark { background: var(--accent); border-color: var(--accent); }
.custom-checkbox input:checked + .checkmark::after { content: "✔"; color: white; font-size: 10px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.8); z-index: 100; display: none; align-items: center; justify-content: center; padding: 24px; backdrop-filter: blur(4px); }
.modal.active { display: flex; }
.modal-content { background: var(--bg-panel); border-radius: var(--radius-xl); width: 100%; max-width: 1200px; height: 90vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); }
.modal-header { padding: 16px 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-actions { display: flex; gap: 8px; }
.modal-body {
  flex: 1; background: var(--bg-main); position: relative; overflow: auto; display: flex; align-items: center; justify-content: center;
  background-image: linear-gradient(45deg, #e2e8f0 25%, transparent 25%), linear-gradient(-45deg, #e2e8f0 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e2e8f0 75%), linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}
[data-theme="dark"] .modal-body {
  background-image: linear-gradient(45deg, #334155 25%, transparent 25%), linear-gradient(-45deg, #334155 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #334155 75%), linear-gradient(-45deg, transparent 75%, #334155 75%);
}
#crop-area-wrapper { position: relative; max-width: 100%; max-height: 100%; }
#crop-area-wrapper img, #crop-area-wrapper canvas { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform 0.2s; }

/* SEO Sections */
.seo-section { background: var(--bg-panel); padding: 80px 24px; border-top: 1px solid var(--border-color); }
.container { max-width: 1000px; margin: 0 auto; }
.seo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 64px; }
.seo-content h1 { font-size: 2.5rem; font-weight: 800; margin-bottom: 24px; line-height: 1.1; letter-spacing: -0.025em; }
.seo-content h2 { font-size: 1.5rem; font-weight: 700; margin: 40px 0 16px; letter-spacing: -0.025em; }
.seo-content p { color: var(--text-muted); margin-bottom: 16px; font-size: 1.05rem; }
.seo-content ul, .seo-content ol { color: var(--text-muted); padding-left: 20px; margin-bottom: 16px; font-size: 1.05rem; }
.seo-content li { margin-bottom: 8px; }

/* FAQ Section */
.faq-section { background: var(--bg-main); padding: 80px 24px; border-top: 1px solid var(--border-color); }
.faq-section h2 { text-align: center; margin-bottom: 48px; font-size: 2rem; font-weight: 800; letter-spacing: -0.025em; }
.faq-list { display: flex; flex-direction: column; gap: 16px; max-width: 800px; margin: 0 auto; }
details { background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 20px 24px; box-shadow: var(--shadow-sm); }
summary { font-weight: 700; cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; font-size: 1.1rem; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; font-size: 1.5rem; color: var(--text-subtle); font-weight: 400; }
details[open] summary::after { content: "−"; }
details p { margin-top: 16px; color: var(--text-muted); font-size: 1rem; line-height: 1.6; }

/* Footer */
.app-footer { background: var(--bg-panel); border-top: 1px solid var(--border-color); }
.footer-top { padding: 64px 24px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 40px; }
.footer-brand p { color: var(--text-muted); margin-top: 16px; max-width: 300px; font-size: 0.9rem; }
.footer-links { display: flex; gap: 80px; }
.footer-links h4 { margin-bottom: 20px; font-size: 0.875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-main); }
.footer-links a { display: block; color: var(--text-muted); margin-bottom: 12px; font-size: 0.95rem; font-weight: 500; }
.footer-links a:hover { color: var(--accent); }
.footer-bottom { padding: 24px; text-align: center; border-top: 1px solid var(--border-color); color: var(--text-subtle); font-size: 0.875rem; font-weight: 500; }

/* Responsive */
@media (max-width: 1024px) {
  .seo-grid { grid-template-columns: 1fr; gap: 32px; }
  .workspace-panels { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; grid-template-areas: "controls" "toolbar" "grid"; }
  .controls-container { border-left: none; border-bottom: 1px solid var(--border-color); }
  .workspace-toolbar { border-radius: 0; margin: 0; }
}

@media (max-width: 768px) {
  .app-workspace { flex-direction: column; }
  .sidebar { width: 100%; height: auto; flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border-color); padding: 12px; }
  .sidebar-title { display: none; }
  .tool-list { display: flex; flex-direction: row; }
  .tool-list li { white-space: nowrap; }
  .sidebar-footer { display: none; }
  .main-nav { display: none; }
  .mobile-menu-btn { display: flex; }
  
  .image-grid { grid-template-columns: 1fr; padding: 16px; }
  .footer-top { flex-direction: column; gap: 48px; }
  .footer-links { flex-direction: column; gap: 32px; }
}
