:root {
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-primary: #0ea5e9;
  --color-primary-hover: #0284c7;
  --color-accent: #f472b6;
  --color-success: #22c55e;
  --color-danger: #ef4444;
  --color-warning: #f59e0b;
  --radius: 14px;
  --shadow: 0 10px 30px -10px rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 4px 12px -6px rgba(15, 23, 42, 0.06);
  --transition: 150ms ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
}
.container { max-width: 900px; margin: 0 auto; padding: 0 1rem; }

/* Header */
.header { position: sticky; top: 0; z-index: 40; background: rgba(255,255,255,0.7); backdrop-filter: blur(10px); border-bottom: 1px solid var(--color-border); }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-icon { width: 32px; height: 32px; }
.brand-name { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.03em; }
.brand-name { color: #0f172a; }
.brand-accent { color: #22c55e; }
.header-actions { display: flex; align-items: center; gap: 0.75rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 10px; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition); gap: 0.5rem;
}
.btn-ghost { background: transparent; color: var(--color-text-muted); padding: 0.5rem 0.85rem; }
.btn-ghost:hover { background: #f1f5f9; color: var(--color-text); }
.btn-outline { background: transparent; color: var(--color-primary); border: 1.5px solid var(--color-primary); padding: 0.5rem 1rem; }
.btn-outline:hover { background: var(--color-primary); color: #fff; }
.btn-primary { background: var(--color-primary); color: #fff; padding: 0.6rem 1.2rem; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-full { width: 100%; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-close { background: transparent; border: none; cursor: pointer; color: var(--color-text-muted); font-size: 0.85rem; }

/* Mode chip */
.mode-chip { display: flex; align-items: center; gap: 0.45rem; padding: 0.3rem 0.7rem; border-radius: 20px; background: #e0f2fe; color: #0369a1; font-size: 0.78rem; font-weight: 600; border: 1px solid #bae6fd; }

/* Language selector */
#langSelector { margin-left: 0.6rem; font-size: 0.9rem; }
.mode-chip.byok { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.chip-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.chip-text { }

/* Cards / steps */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 1rem; overflow: hidden; }
.step-header { display: flex; align-items: center; gap: 0.75rem; padding: 1.25rem 1.25rem 0.75rem; border-bottom: 1px solid var(--color-border); }
.step-badge { width: 26px; height: 26px; border-radius: 50%; background: var(--color-primary); color: #fff; font-size: 0.8rem; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.step-header h2 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; }
.step-header button { margin-left: auto; }
.step-footer { padding: 1rem 1.25rem 1.25rem; display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  background: #fcfcfc;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 1rem;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--color-primary); background: #f0f9ff; }
.dropzone-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.3rem; }
.dropzone-sub { font-size: 0.85rem; color: var(--color-text-muted); margin-bottom: 1rem; }
.dropzone-actions { display: flex; gap: 0.6rem; justify-content: center; margin-top: 0.5rem; }
#fileInput { display: none; }

/* Gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.8rem; margin-bottom: 1rem; }
.thumb {
  position: relative; aspect-ratio: 4/5; border-radius: 10px; border: 1px solid var(--color-border); background: #f1f5f9; overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-remove { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; background: rgba(0,0,0,0.65); color: #fff; border: none; cursor: pointer; font-size: 1rem; line-height: 1; display: flex; align-items: center; justify-content: center; }
.thumb-progress { position: absolute; inset: 0; background: rgba(14,165,233,0.85); color: #fff; font-size: 0.75rem; font-weight: 700; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity var(--transition); }
.thumb-progress.show { opacity: 1; }

/* Results */
.results-grid { display: grid; gap: 1rem; }
.group-card {
  border: 1px solid var(--color-border); border-radius: 12px; overflow: hidden; background: var(--color-surface);
  animation: slideIn 0.35s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.group-header { display: flex; align-items: center; justify-content: space-between; padding: 0.85rem 1rem; background: #f8fafc; border-bottom: 1px solid var(--color-border); cursor: pointer; }
.group-header h3 { font-size: 0.95rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-primary); }
.group-header .group-count { font-size: 0.78rem; font-weight: 600; color: var(--color-text-muted); background: #e2e8f0; padding: 0.15rem 0.5rem; border-radius: 12px; }
.group-body { padding: 0.9rem 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.item-row {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.7rem; border-radius: 8px; background: #fff; border: 1px solid #f1f5f9; transition: all var(--transition);
}
.item-row:hover { border-color: var(--color-primary); background: #f0f9ff; }
.item-checkbox { width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid #cbd5e1; cursor: pointer; appearance: none; position: relative; }
.item-checkbox:checked { background: var(--color-success); border-color: var(--color-success); }
.item-checkbox:checked::after { content: "✔"; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); color: #fff; font-size: 0.8rem; font-weight: 700; }
.item-text { flex: 1; font-size: 0.92rem; }
.item-text.done { text-decoration: line-through; color: var(--color-text-muted); }
.item-actions { color: var(--color-text-muted); cursor: pointer; opacity: 0; transition: opacity var(--transition); }
.item-edit { color: var(--color-primary); cursor: pointer; opacity: 0; transition: opacity var(--transition); font-size: 0.85rem; margin-left: 0.3rem; }
.item-move { color: var(--color-primary); cursor: pointer; opacity: 0; transition: opacity var(--transition); font-size: 0.85rem; margin-left: 0.3rem; }
.item-row:hover .item-actions, .item-row:hover .item-edit, .item-row:hover .item-move { opacity: 1; }
.item-edit-input, .group-edit-input { width: 100%; padding: 0.25rem 0.4rem; font-size: 0.92rem; border: 1px solid var(--color-primary); border-radius: 6px; background: #fff; }
.results-toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.batch-bar { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; padding: 0.6rem 0.8rem; background: #e0f2fe; border: 1px solid #bae6fd; border-radius: 8px; margin-bottom: 0.75rem; }
.batch-count { font-weight: 600; font-size: 0.85rem; color: #0369a1; margin-right: 0.3rem; }
.item-select { width: 18px; height: 18px; accent-color: var(--color-primary); cursor: pointer; }
.group-header { display: flex; align-items: center; justify-content: space-between; padding: 0.85rem 1rem; background: #f8fafc; border-bottom: 1px solid var(--color-border); cursor: default; }
.group-header h3 { margin: 0; cursor: default; }
.group-edit { color: var(--color-primary); cursor: pointer; margin-left: 0.6rem; font-size: 0.85rem; }
.group-header:hover .group-edit { opacity: 1; }

/* Settings drawer */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.35); backdrop-filter: blur(4px); z-index: 50; opacity: 0; pointer-events: none; transition: opacity var(--transition); }
.overlay.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; width: min(420px, 100%); height: 100vh; background: var(--color-surface); border-left: 1px solid var(--color-border); z-index: 55; transform: translateX(100%); transition: transform var(--transition); box-shadow: var(--shadow); }
.drawer.open { transform: translateX(0); }
.drawer-header { padding: 1.25rem; border-bottom: 1px solid var(--color-border); display: flex; justify-content: space-between; align-items: center; }
.drawer-header h2 { font-size: 1.15rem; font-weight: 700; }
.drawer-body { padding: 1.25rem; overflow-y: auto; height: calc(100vh - 110px); }
.drawer-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--color-border); display: flex; gap: 0.75rem; justify-content: flex-end; }

.card { margin-bottom: 1rem; }
.card h3 { font-size: 0.95rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--color-text); }
.sub { font-size: 0.82rem; color: var(--color-text-muted); margin-bottom: 0.9rem; }
.field { margin-bottom: 0.9rem; }
.field.row { display: flex; gap: 0.6rem; align-items: center; }
.field-label { font-size: 0.82rem; font-weight: 600; color: var(--color-text-muted); display: block; margin-bottom: 0.35rem; }
.field input, .field-select { width: 100%; padding: 0.55rem 0.75rem; border: 1.5px solid #cbd5e1; border-radius: 8px; font-size: 0.9rem; background: #fff; transition: border-color var(--transition); }
.field input:focus, .field-select:focus { outline: none; border-color: var(--color-primary); }
.field-select { cursor: pointer; }
.input-group { display: flex; gap: 0.4rem; }
.hint { font-size: 0.78rem; color: var(--color-text-muted); margin-top: 0.35rem; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.55rem 0; border-bottom: 1px solid #f1f5f9; }
.toggle-row:last-child { border-bottom: none; }
.checkbox { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--color-primary); }
.categories-list { display: flex; flex-direction: column; gap: 0.45rem; }
.category-chip { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.7rem; border: 1px solid #e2e8f0; border-radius: 8px; background: #fff; font-size: 0.88rem; }
.category-chip .chip-actions { display: flex; gap: 0.3rem; opacity: 0.6; }
.category-chip:hover .chip-actions { opacity: 1; }
.category-chip button { background: none; border: none; cursor: pointer; color: var(--color-text-muted); padding: 0.2rem; }
.category-chip button:hover { color: var(--color-danger); }

/* Toast */
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%) translateY(120px); background: #0f172a; color: #fff; padding: 0.75rem 1.2rem; border-radius: 10px; font-size: 0.88rem; z-index: 100; opacity: 0; pointer-events: none; transition: all 0.3s ease; box-shadow: var(--shadow); }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
.toast-undo { background: var(--color-primary); color: #fff; border: none; padding: 0.15rem 0.5rem; border-radius: 4px; cursor: pointer; font-size: 0.8rem; margin-left: 0.5rem; }
.toast-undo:hover { opacity: 0.9; }

.hidden { display: none !important; }

/* Responsive */
@media (max-width: 600px) {
  .header-inner { height: 56px; }
  .step-footer { flex-direction: column; }
  .btn-full { width: 100%; }
  .drawer { width: 100%; }
  .dropzone-actions { flex-direction: column; gap: 0.5rem; }
}
