:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #10b981;
  --success-bg: #d1fae5;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.1);
  --transition: 0.2s ease;
}

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

a { text-decoration: none; color: inherit; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-left { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 22px; font-weight: 700; color: var(--primary); }
.logo-sub { font-size: 13px; color: var(--text-muted); }
.nav-right { display: flex; align-items: center; gap: 8px; }
.nav-user { font-size: 13px; color: var(--text-muted); padding: 0 8px; border-right: 1px solid var(--border); margin-right: 4px; line-height: 1; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 14px;
  cursor: pointer; transition: var(--transition); white-space: nowrap;
  font-family: inherit; line-height: 1.4;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; margin-top: 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Main */
.main-container {
  flex: 1; display: flex; flex-direction: column;
  padding: 24px; max-width: 1400px; margin: 0 auto; width: 100%;
}

/* Drop Zone */
.drop-zone {
  flex: 1; display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--surface); transition: var(--transition);
  min-height: 400px; cursor: pointer;
}
.drop-zone.drag-over { border-color: var(--primary); background: var(--primary-light); }
.drop-zone-content { text-align: center; }
.upload-icon { color: var(--text-muted); margin-bottom: 16px; }
.drop-zone h2 { font-size: 20px; margin-bottom: 8px; color: var(--text); }
.drop-zone p { color: var(--text-muted); margin-bottom: 20px; font-size: 14px; }

/* Workspace */
.workspace {
  display: flex; gap: 24px; flex: 1; min-height: 0;
}
.preview-area { flex: 1; min-width: 0; }
.preview-panels {
  display: flex; align-items: flex-start; gap: 16px;
}
.preview-card {
  flex: 1; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; min-width: 0;
}
.preview-label {
  padding: 10px 16px; font-size: 13px; font-weight: 600;
  background: var(--bg); border-bottom: 1px solid var(--border);
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;
}
.preview-img-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 250px; background: repeating-conic-gradient(#e2e8f0 0% 25%, transparent 0% 50%) 0 0 / 20px 20px;
  padding: 16px;
}
.preview-img-wrap img { max-width: 100%; max-height: 400px; object-fit: contain; }
.preview-info {
  padding: 10px 16px; font-size: 12px; color: var(--text-muted);
  border-top: 1px solid var(--border); line-height: 1.6;
}
.preview-info.highlight { color: var(--success); font-weight: 600; }
.preview-arrow {
  display: flex; align-items: center; padding-top: 40px;
  color: var(--text-muted); flex-shrink: 0;
}

/* Settings Panel */
.settings-panel {
  width: 300px; flex-shrink: 0;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; overflow-y: auto;
  max-height: calc(100vh - 200px); position: sticky; top: 80px;
}
.settings-panel h3 { font-size: 16px; margin-bottom: 16px; }
.setting-group { margin-bottom: 18px; }
.setting-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.setting-select, .setting-input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; background: var(--surface);
  font-family: inherit; transition: var(--transition);
}
.setting-select:focus, .setting-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.setting-range { width: 100%; accent-color: var(--primary); cursor: pointer; }

/* Mode Tabs */
.mode-tabs { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.mode-tab {
  flex: 1; padding: 8px 4px; border: none; background: var(--surface);
  cursor: pointer; font-size: 12px; font-family: inherit; transition: var(--transition);
  border-right: 1px solid var(--border);
}
.mode-tab:last-child { border-right: none; }
.mode-tab:hover { background: var(--bg); }
.mode-tab.active { background: var(--primary); color: #fff; }

/* Size Inputs */
.size-inputs { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.size-input-wrap { flex: 1; display: flex; align-items: center; gap: 4px; }
.size-input-wrap span { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.size-input-wrap .setting-input { text-align: center; }
.lock-btn {
  background: none; border: none; cursor: pointer; padding: 4px;
  color: var(--primary); border-radius: 4px; display: flex; transition: var(--transition);
}
.lock-btn:hover { background: var(--primary-light); }
.lock-btn.unlocked { color: var(--text-muted); }
.setting-check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); cursor: pointer; }

/* Batch Bar */
.batch-bar {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-top: 16px; padding: 12px 16px;
}
.batch-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.batch-title { font-size: 14px; font-weight: 600; }
.batch-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.batch-item {
  flex-shrink: 0; width: 80px; cursor: pointer;
  border: 2px solid transparent; border-radius: 8px; overflow: hidden;
  transition: var(--transition);
}
.batch-item:hover { border-color: var(--primary-light); }
.batch-item.active { border-color: var(--primary); }
.batch-item img { width: 100%; height: 60px; object-fit: cover; display: block; }
.batch-item .batch-item-name {
  font-size: 10px; padding: 2px 4px; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.batch-item .batch-item-badge {
  font-size: 9px; background: var(--primary-light); color: var(--primary);
  text-align: center; padding: 1px 4px;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 200;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 680px; max-width: 90vw; max-height: 80vh; display: flex; flex-direction: column;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  width: 32px; height: 32px; border: none; background: none;
  font-size: 22px; cursor: pointer; color: var(--text-muted); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg); }
.modal-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); }

/* Gallery */
.modal-gallery { width: 900px; max-width: 95vw; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.gallery-card {
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: var(--transition);
}
.gallery-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.gallery-img-wrap {
  position: relative;
  aspect-ratio: 4/3;
  overflow: hidden;
  background: repeating-conic-gradient(#e2e8f0 0% 25%, transparent 0% 50%) 0 0 / 16px 16px;
}
.gallery-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}
.gallery-card:hover .gallery-img-wrap img {
  transform: scale(1.05);
}
.gallery-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.gallery-card:hover .gallery-overlay {
  opacity: 1;
}
.gallery-info {
  padding: 12px;
}
.gallery-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 6px;
}
.gallery-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.gallery-meta span {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
}
.gallery-date {
  font-size: 11px;
  color: var(--text-muted);
}
.gallery-name-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}
.gallery-name-row .gallery-name {
  flex: 1;
  margin-bottom: 0;
}
.gallery-rename-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 4px;
  transition: var(--transition);
  flex-shrink: 0;
}
.gallery-rename-btn:hover {
  color: var(--primary);
  background: var(--primary-light);
}
.gallery-copy-link {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 5px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.gallery-copy-link:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
}

/* Toast — top right */
.toast-container {
  position: fixed; top: 72px; right: 20px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 20px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow-lg); animation: slideIn 0.3s ease;
  max-width: 360px; color: #fff; font-weight: 500;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Utility */
.loading { text-align: center; padding: 40px; color: var(--text-muted); }
.empty { text-align: center; padding: 40px; color: var(--text-muted); font-size: 14px; }

/* Auth Page */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #4f46e5 100%);
  min-height: 100vh;
}
.auth-container { width: 380px; max-width: 90vw; }
.auth-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 40px 32px; text-align: center;
}
.auth-logo { font-size: 32px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.auth-sub { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }
.auth-form { text-align: left; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: var(--text); }
.form-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; font-family: inherit; transition: var(--transition);
}
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.form-error { color: var(--danger); font-size: 13px; min-height: 20px; margin-bottom: 8px; }
.form-hint { display: block; font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-hint code { background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 11px; }

/* Config Page */
.config-page { display: flex; flex-direction: column; min-height: 100vh; }
.config-container {
  flex: 1; padding: 24px; max-width: 640px; margin: 0 auto; width: 100%;
  display: flex; flex-direction: column; gap: 16px;
}
.config-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
}
.config-card h2 { font-size: 16px; margin-bottom: 4px; }
.config-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.config-desc a { color: var(--primary); }
.config-desc code { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.config-stats { font-size: 13px; color: var(--text-muted); line-height: 1.8; }
.config-msg { text-align: center; font-size: 13px; min-height: 24px; }
.msg-success { color: var(--success); }
.msg-error { color: var(--danger); }
.msg-info { color: var(--primary); }

/* User table */
.user-table-wrap { overflow-x: auto; margin-top: 12px; }
.user-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.user-table th,
.user-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.user-table th { font-weight: 600; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.user-table td { color: var(--text); }
.role-badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 11px; font-weight: 500; }
.role-admin { background: var(--primary-light); color: var(--primary); }
.role-user { background: #f1f5f9; color: var(--text-muted); }
.form-row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.form-group-flex { flex: 1; margin-bottom: 0; }
.modal-sm { width: 380px; }
.modal-actions { display: flex; gap: 8px; padding: 16px; justify-content: flex-end; border-top: 1px solid var(--border); }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
}
.lightbox img {
  max-width: 92vw; max-height: 92vh;
  object-fit: contain; border-radius: 4px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.lightbox-close {
  position: absolute; top: 20px; right: 28px;
  background: none; border: none; color: #fff; font-size: 36px;
  cursor: pointer; z-index: 1; opacity: 0.7; transition: opacity 0.2s;
}
.lightbox-close:hover { opacity: 1; }

/* Cropper */
.modal-crop { width: 700px; max-width: 95vw; }
.crop-body { display: flex; flex-direction: column; align-items: center; }
.crop-container {
  position: relative; display: inline-block;
  max-width: 100%; max-height: 55vh; overflow: hidden;
  cursor: crosshair; user-select: none;
  -webkit-user-select: none;
}
.crop-container canvas {
  display: block; max-width: 100%; max-height: 55vh;
}
.crop-mask {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.45);
}
.crop-box {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.45);
  cursor: move;
}
.crop-handle {
  position: absolute; width: 12px; height: 12px;
  background: #fff; border: 2px solid var(--primary);
  border-radius: 2px;
}
.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-info {
  font-size: 13px; color: var(--text-muted);
  margin: 12px 0; text-align: center;
}
.crop-actions {
  display: flex; gap: 8px; justify-content: center;
}

/* Responsive */
@media (max-width: 900px) {
  .workspace { flex-direction: column; }
  .settings-panel { width: 100%; max-height: none; position: static; }
  .preview-panels { flex-direction: column; }
  .preview-arrow { transform: rotate(90deg); padding-top: 0; justify-content: center; }
  .batch-list { gap: 6px; }
  .nav-right .btn span { display: none; }
  .nav-user { display: none; }
}
