*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f5f5f7;
  --surface: #fff;
  --border: #e0e0e0;
  --text: #1d1d1f;
  --text2: #6e6e73;
  --accent: #007aff;
  --accent-hover: #0062cc;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header h1 { font-size: 20px; font-weight: 600; }
header h1 span { color: var(--accent); }
.container { max-width: 960px; margin: 0 auto; padding: 24px; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--surface);
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: #f0f7ff;
}
.drop-zone p { color: var(--text2); margin-top: 8px; }
.drop-zone .icon { font-size: 32px; color: var(--accent); }
.drop-zone input[type=file] { display: none; }

.options-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 16px;
  padding: 16px 20px;
}
.options-panel summary {
  font-weight: 500;
  cursor: pointer;
  color: var(--text2);
  user-select: none;
}
.options-panel summary:hover { color: var(--text); }
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.option-group { display: flex; flex-direction: column; gap: 4px; }
.option-group label { font-size: 12px; color: var(--text2); font-weight: 500; }
.option-group select,
.option-group input[type=number] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 14px;
  background: var(--bg);
}
.option-group input[type=range] { width: 100%; }
.option-group .range-value { font-size: 12px; color: var(--text2); text-align: right; }
.option-group.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding-top: 18px;
}
.info {
  cursor: help;
  color: var(--accent);
  font-size: 13px;
  margin-right: 2px;
  user-select: none;
}
.info:hover { opacity: 0.7; }

.action-bar {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;

/* ── Balance pill ── */
.balance-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  background: #eee;
  color: var(--text2);
  transition: all 0.2s;
}
.balance-pill.ok { background: #dcfce7; color: #166534; }
.balance-pill.low { background: #fef9c3; color: #854d0e; }
.balance-pill.empty { background: #fee2e2; color: #991b1b; }
.balance-pill.error { background: #fee2e2; color: #991b1b; }
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover:not(:disabled) { background: #28a745; }

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.image-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.15s;
}
.image-card:hover { transform: translateY(-2px); }
.image-card .preview {
  width: 100%;
  height: 160px;
  object-fit: contain;
  background: #fafafa;
  display: block;
}
.image-card .info {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.image-card .info .name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.image-card .info .meta {
  font-size: 11px;
  color: var(--text2);
}
.image-card .info .actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.image-card .info .actions .btn {
  flex: 1;
  justify-content: center;
  padding: 6px;
  font-size: 12px;
}
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.status-pending { background: #f0f0f0; color: var(--text2); }
.status-processing { background: #fff3cd; color: #856404; }
.status-done { background: #d4edda; color: #155724; }
.status-error { background: #f8d7da; color: #721c24; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text2);
}
.empty-state p { margin-top: 8px; }

/* ── Tabs ── */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 24px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); background: #f0f0f0; border-radius: 8px 8px 0 0; }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Generate Form ── */
.gen-form {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.gen-field { margin-bottom: 12px; }
.gen-field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 4px;
}
.gen-field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  background: var(--bg);
}
.gen-field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Generated image card ── */
.image-card .actions .btn-trace {
  background: var(--orange);
  color: #fff;
}
.image-card .actions .btn-trace:hover { background: #e08900; }

/* ── Split controls ── */
.split-controls {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.split-controls .option-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 4px;
}
.split-controls .option-group input {
  width: 80px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
}

/* ── Lightbox ── */
.lightbox {
  display: none;
  position: fixed;
  z-index: 999;
  inset: 0;
  background: rgba(0,0,0,.85);
  cursor: zoom-out;
}
.lightbox.open {
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox img {
  margin: auto;
  max-width: 95vw;
  max-height: 95vh;
  border-radius: 4px;
  box-shadow: 0 4px 30px rgba(0,0,0,.5);
  object-fit: contain;
  image-rendering: auto;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 24px;
  font-size: 36px;
  color: #fff;
  cursor: pointer;
  line-height: 1;
}
.lightbox-close:hover { opacity: .7; }

@media (max-width: 600px) {
  .options-grid { grid-template-columns: 1fr 1fr; }
  .image-grid { grid-template-columns: 1fr; }
  header { flex-direction: column; gap: 8px; text-align: center; }
  .action-bar { flex-direction: column; }
}
