:root {
  --bg: #0a0e16;
  --bg-2: #0c111c;
  --panel: #111726;
  --panel-2: #0e1420;
  --border: rgba(255, 255, 255, 0.08);
  --border-2: rgba(255, 255, 255, 0.14);
  --text: #cbd5e1;
  --text-dim: #64748b;
  --text-bright: #f1f5f9;
  --indigo: #6366f1;
  --indigo-700: #4338ca;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--indigo); text-decoration: none; }
button { font-family: inherit; }

.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

/* sidebar */
.sidebar {
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 11px;
  background: linear-gradient(135deg, var(--indigo), var(--indigo-700));
  display: grid; place-items: center; color: white; font-size: 18px;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
}
.brand .title { font-weight: 600; color: var(--text-bright); font-size: 13.5px; }
.brand .sub { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-dim); font-family: ui-monospace, monospace; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px; cursor: pointer; color: var(--text);
  border: 1px solid transparent; font-size: 13.5px;
}
.nav-item:hover { background: rgba(255,255,255,0.04); }
.nav-item.active { background: rgba(99,102,241,0.14); border-color: rgba(99,102,241,0.3); color: var(--text-bright); }
.nav-item .ic { width: 18px; text-align: center; opacity: 0.8; }
.nav-spacer { flex: 1; }
.nav-foot { font-size: 11px; color: var(--text-dim); border-top: 1px solid var(--border); padding-top: 12px; line-height: 1.6; }

/* main */
.main { overflow-y: auto; max-height: 100vh; }
.main-inner { max-width: 1080px; margin: 0 auto; padding: 32px 40px 80px; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; color: var(--text-bright); margin: 0; font-weight: 650; }
.page-head .crumbs { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.page-head .crumbs a { cursor: pointer; }

/* buttons */
.btn {
  border: 1px solid var(--border-2); background: var(--panel); color: var(--text-bright);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-size: 13px; display: inline-flex;
  align-items: center; gap: 7px; transition: 0.12s;
}
.btn:hover { border-color: var(--indigo); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--indigo), var(--indigo-700)); border: none; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: #fca5a5; border-color: rgba(239,68,68,0.4); }
.btn.danger:hover { background: rgba(239,68,68,0.12); border-color: var(--red); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }

/* cards / panels */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.panel + .panel { margin-top: 18px; }
.panel h2 { font-size: 15px; color: var(--text-bright); margin: 0 0 14px; font-weight: 600; }
.panel h3 { font-size: 13px; color: var(--text-bright); margin: 18px 0 8px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.products { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* product card */
.product-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: 0.14s; }
.product-card:hover { border-color: var(--indigo); transform: translateY(-2px); }
.product-card .thumb { aspect-ratio: 4/3; background: var(--panel-2); display: grid; place-items: center; overflow: hidden; }
.product-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-card .thumb .ph { color: var(--text-dim); font-size: 28px; }
.product-card .body { padding: 13px 14px; }
.product-card .code { font-family: ui-monospace, monospace; font-size: 11px; color: var(--indigo); }
.product-card .name { color: var(--text-bright); font-weight: 600; margin: 3px 0; font-size: 14px; }
.product-card .meta { font-size: 11.5px; color: var(--text-dim); display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }

/* form */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.input, .textarea, .select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text-bright);
  padding: 9px 11px; border-radius: 8px; font-size: 13px; font-family: inherit;
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--indigo); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }

/* image strip */
.img-strip { display: flex; gap: 10px; flex-wrap: wrap; }
.img-tile { position: relative; width: 96px; height: 96px; border-radius: 9px; overflow: hidden; border: 1px solid var(--border-2); background: var(--panel-2); }
.img-tile img { width: 100%; height: 100%; object-fit: cover; }
.img-tile .x { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,0.6); color: white; border: none; border-radius: 6px; width: 22px; height: 22px; cursor: pointer; font-size: 12px; }
.img-tile .tag { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.55); font-size: 9px; text-align: center; padding: 2px; color: #cbd5e1; text-transform: uppercase; letter-spacing: 0.05em; }
.uploader { width: 96px; height: 96px; border: 1.5px dashed var(--border-2); border-radius: 9px; display: grid; place-items: center; cursor: pointer; color: var(--text-dim); font-size: 11px; text-align: center; }
.uploader:hover { border-color: var(--indigo); color: var(--indigo); }

/* status pill */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.draft, .pill.prompt_ready { color: var(--text-dim); background: rgba(100,116,139,0.15); }
.pill.queued, .pill.opening_chatgpt, .pill.opening_project, .pill.creating_conversation,
.pill.uploading_images, .pill.submitting_message, .pill.waiting_chatgpt, .pill.waiting_action,
.pill.receiving_result { color: var(--blue); background: rgba(59,130,246,0.14); }
.pill.completed { color: var(--green); background: rgba(34,197,94,0.14); }
.pill.failed { color: var(--red); background: rgba(239,68,68,0.14); }
.pill.cancelled { color: var(--text-dim); background: rgba(100,116,139,0.15); }
.pill.waiting_manual_chatgpt { color: var(--amber); background: rgba(245,158,11,0.14); }

/* job rows + timeline */
.job-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; background: var(--panel-2); }
.job-row .jid { font-family: ui-monospace, monospace; font-size: 12px; color: var(--text-bright); }
.job-row .step { font-size: 12px; color: var(--text-dim); }
.job-row .spacer { flex: 1; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: 10px; padding: 7px 0; font-size: 12.5px; border-bottom: 1px solid var(--border); }
.timeline .lv { width: 54px; font-size: 10px; text-transform: uppercase; font-weight: 700; padding-top: 2px; }
.timeline .lv.info { color: var(--blue); }
.timeline .lv.warn { color: var(--amber); }
.timeline .lv.error { color: var(--red); }
.timeline .when { color: var(--text-dim); font-size: 10.5px; width: 64px; flex-shrink: 0; }
.timeline .msg { flex: 1; color: var(--text); }
.timeline .shot a { font-size: 11px; }

.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.result-grid .r { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--panel-2); }
.result-grid .r img { width: 100%; display: block; }
.result-grid .r .cap { padding: 8px; font-size: 11px; color: var(--text-dim); }

.copybox { background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 9px; padding: 12px; font-size: 12.5px; line-height: 1.6; white-space: pre-wrap; color: var(--text-bright); position: relative; }
.copybox .copy { position: absolute; top: 8px; right: 8px; }

.banner { padding: 12px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start; }
.banner.amber { background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.3); color: #fcd34d; }
.banner.red { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: #fca5a5; }
.banner.blue { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.3); color: #93c5fd; }
.banner.green { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: #86efac; }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; font-size: 12.5px; }
.kv .k { color: var(--text-dim); }
.kv .v { color: var(--text-bright); word-break: break-word; }

.muted { color: var(--text-dim); }
.mono { font-family: ui-monospace, monospace; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 7px; padding: 4px 9px; font-size: 11.5px; }

.toast-wrap { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--panel); border: 1px solid var(--border-2); border-radius: 9px; padding: 11px 16px; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); animation: slidein 0.18s; }
.toast.ok { border-color: rgba(34,197,94,0.4); }
.toast.err { border-color: rgba(239,68,68,0.4); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } }

.empty { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty .big { font-size: 40px; margin-bottom: 12px; opacity: 0.5; }

.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.2); border-top-color: var(--indigo); border-radius: 50%; display: inline-block; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: grid; place-items: center; z-index: 90; }
.modal { background: var(--panel); border: 1px solid var(--border-2); border-radius: 14px; padding: 24px; width: min(520px, 92vw); }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
