*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #edf3fb;
  --surface: #ffffff;
  --border: rgba(115, 130, 151, 0.18);
  --text: #111827;
  --text2: #4b5563;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f97316;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}
body {
  font-family: Inter, 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: radial-gradient(circle at top left, rgba(37,99,235,0.12), transparent 28%),
              radial-gradient(circle at bottom right, rgba(34,197,94,0.12), transparent 22%),
              var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
header {
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(148,163,184,0.18);
  border-radius: 22px;
  padding: 22px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  box-shadow: 0 24px 50px rgba(15, 23, 42, 0.08);
}
header h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.04em; }
header h1 span { color: var(--accent); }
header span { color: var(--text2); font-size: 14px; }
.container { max-width: 1080px; margin: 0 auto; padding: 32px 28px 40px; }

.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: linear-gradient(180deg, rgba(37,99,235,0.08), rgba(255,255,255,0.95));
  transform: translateY(-1px);
}
.drop-zone p { color: var(--text2); margin-top: 10px; }
.drop-zone .icon { font-size: 38px; 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;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 12px 25px rgba(15, 23, 42, 0.08);
}
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

/* ── 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; }
.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: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 26px;
}
.tab {
  padding: 14px 18px;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.8);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  color: var(--text2);
  border-radius: 16px;
  transition: all 0.18s ease;
  text-align: center;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.98); box-shadow: 0 10px 20px rgba(15, 23, 42, 0.06); }
.tab.active {
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.18);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-iframe-container {
  background: rgba(255,255,255,0.96);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: 0 24px 50px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  min-height: 720px;
}

.panel-iframe-container iframe {
  width: 100%;
  min-height: 720px;
  height: calc(100vh - 280px);
  border: none;
  background: #f8fafc;
}

/* ── 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);
}

/* ── 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; }
}
