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

:root {
  --bg: #f5f5f7; --surface: #ffffff; --border: #e2e2e5; --border-hover: #d0d0d5;
  --text: #1d1d1f; --text-dim: #6e6e73; --text-muted: #aeaeb2;
  --accent: #3a3aff; --accent-dim: #2c2cd6; --accent-bg: #eeeeff;
  --green: #34c759; --green-bg: #eafbef; --red: #ff3b30; --red-bg: #ffeeed;
  --yellow: #ff9f0a; --yellow-bg: #fff7e6;
  --radius: 10px; --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.6; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* Header */
header { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; margin-bottom: 28px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { width: 40px; height: 40px; background: #dde0f8; border-radius: 50%; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.brand-logo img { width: 100%; height: 100%; object-fit: cover; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-size: 14px; font-weight: 700; letter-spacing: -0.3px; color: var(--text); }
.brand-service { font-size: 11px; color: var(--text-muted); font-weight: 500; letter-spacing: 0.5px; text-transform: uppercase; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.session-id-badge { font-size: 11px; font-family: 'SF Mono', 'Cascadia Code', monospace; background: var(--accent-bg); color: var(--accent); padding: 4px 10px; border-radius: 6px; font-weight: 500; cursor: pointer; user-select: all; }
.session-id-badge:hover { background: var(--accent); color: #fff; }

select, input, textarea, button { font-family: var(--font); font-size: 14px; }
textarea { resize: vertical; }

.hidden { display: none !important; }

/* Form */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; color: var(--text-dim); margin-bottom: 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.form-group textarea, .form-group input { width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 12px 14px; border-radius: var(--radius); transition: border-color 0.15s; }
.form-group textarea:focus, .form-group input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58,58,255,0.1); }
.form-group textarea { min-height: 60px; }
.form-group .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Input layout — template + field side by side */
.input-layout { display: flex; gap: 28px; align-items: flex-start; }
.brief-template { flex: 0 0 340px; position: sticky; top: 20px; max-height: calc(100vh - 60px); overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.brief-input { flex: 1; min-width: 0; }

.template-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.template-title { font-size: 11px; font-weight: 700; color: var(--accent); letter-spacing: 0.8px; text-transform: uppercase; }

.template-section { display: flex; gap: 10px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.template-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.template-section-num { background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px; }
.template-section-title { font-size: 12px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.template-section-title .req { color: var(--accent); font-size: 9px; font-weight: 600; text-transform: uppercase; margin-left: 4px; }
.template-section-title .opt { color: var(--text-muted); font-size: 9px; font-weight: 500; text-transform: uppercase; margin-left: 4px; }
.template-section ul { list-style: none; padding: 0; margin: 0; }
.template-section li { font-size: 12px; color: var(--text-dim); line-height: 1.5; margin-bottom: 1px; }
.template-section li b { color: var(--text); font-weight: 600; }

#field-brief { min-height: 500px; font-size: 13px; line-height: 1.7; }

@media (max-width: 800px) {
  .input-layout { flex-direction: column; }
  .brief-template { flex: none; width: 100%; position: static; max-height: none; }
  #field-brief { min-height: 300px; }
}

/* Language selector */
.lang-selector { display: flex; gap: 4px; margin-bottom: 16px; }
.lang-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text-dim); padding: 7px 16px; border-radius: var(--radius); cursor: pointer; font-weight: 500; font-size: 13px; transition: all 0.15s; }
.lang-btn:hover { border-color: var(--accent); color: var(--accent); }
.lang-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

/* Dropzone */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--text-muted); cursor: pointer; transition: all 0.2s; font-size: 13px; }
.dropzone:hover { border-color: var(--accent); color: var(--text-dim); }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); }
.doc-previews { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.file-entry { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); padding: 8px 12px; border-radius: var(--radius); font-size: 13px; }
.file-ext { background: var(--accent-bg); color: var(--accent); padding: 2px 8px; border-radius: 4px; text-transform: uppercase; font-size: 10px; font-weight: 600; }
.file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--text-muted); font-size: 12px; }
.remove { background: none; border: none; color: var(--red); cursor: pointer; font-size: 18px; padding: 0 4px; }

/* Buttons */
.btn-primary { background: var(--accent); color: #fff; border: none; padding: 14px 24px; border-radius: var(--radius); cursor: pointer; font-weight: 700; font-size: 15px; width: 100%; transition: background 0.15s; }
.btn-primary:hover { background: var(--accent-dim); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-small { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 7px 14px; border-radius: var(--radius); cursor: pointer; font-size: 13px; font-weight: 500; transition: all 0.15s; }
.btn-small:hover { border-color: var(--accent); color: var(--accent); }

/* Session select */
#session-select { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 7px 12px; border-radius: var(--radius); max-width: 300px; font-size: 13px; }

/* Step trail */
.step-trail { list-style: none; display: flex; flex-direction: column; gap: 4px; margin-bottom: 20px; }
.step-trail li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-radius: var(--radius); border-left: 3px solid var(--border); box-shadow: var(--shadow-sm); }
.step-trail li[data-status="running"] { border-left-color: var(--accent); background: var(--accent-bg); }
.step-trail li[data-status="done"] { border-left-color: var(--green); }
.step-trail li[data-status="awaiting_approval"] { border-left-color: var(--yellow); background: var(--yellow-bg); }
.step-trail li[data-status="error"] { border-left-color: var(--red); background: var(--red-bg); }
.step-name { flex: 1; font-weight: 500; }
.step-status { font-size: 11px; color: var(--text-muted); text-transform: uppercase; font-weight: 600; letter-spacing: 0.3px; }
li[data-status="running"] .step-status { color: var(--accent); }
li[data-status="done"] .step-status { color: var(--green); }
li[data-status="awaiting_approval"] .step-status { color: var(--yellow); }

/* Logs */
.log-area { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; max-height: 300px; overflow-y: auto; font-size: 12px; color: var(--text-dim); font-family: 'SF Mono', 'Cascadia Code', monospace; box-shadow: var(--shadow-sm); }
.log-area div { margin-bottom: 2px; white-space: pre-wrap; word-break: break-word; }

/* Approval Gate */
.gate { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-top: 20px; box-shadow: var(--shadow-md); }
.gate-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.gate-subtitle { font-size: 13px; color: var(--text-dim); margin-bottom: 16px; }
.gate-stats { font-size: 13px; margin-bottom: 14px; }

.gate-item-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 10px; transition: border-color 0.15s; }
.gate-item-card[data-decision="approved"] { border-color: var(--green); background: var(--green-bg); }
.gate-item-card[data-decision="rejected"] { border-color: var(--red); background: var(--red-bg); }
.item-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.item-id { font-size: 12px; color: var(--accent); font-weight: 600; }
.item-name { font-weight: 600; }
.badge { font-size: 10px; padding: 3px 8px; border-radius: 4px; text-transform: uppercase; font-weight: 600; }
.badge.approved { background: var(--green-bg); color: var(--green); }
.badge.flagged { background: var(--yellow-bg); color: var(--yellow); }
.badge.rejected { background: var(--red-bg); color: var(--red); }

.meta-row { display: flex; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.meta-label { color: var(--text-muted); min-width: 120px; flex-shrink: 0; font-weight: 500; }

.gate-section-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin: 12px 0 4px; border-top: 1px solid var(--border); padding-top: 8px; font-weight: 600; }
.gate-list { list-style: disc; padding-left: 20px; font-size: 13px; color: var(--text-dim); }
.gate-quotes blockquote { font-size: 13px; color: var(--text-dim); font-style: italic; border-left: 2px solid var(--border); padding-left: 10px; margin: 4px 0; }

.gate-item-actions { display: flex; gap: 8px; margin-top: 12px; }
.btn-approve, .btn-reject { padding: 8px 18px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: 13px; font-weight: 600; transition: all 0.15s; }
.btn-approve:hover, .btn-approve.active { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.btn-reject:hover, .btn-reject.active { background: var(--red-bg); border-color: var(--red); color: var(--red); }

.gate-item-comment { margin-top: 8px; }
.gate-item-comment input { width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 8px 12px; border-radius: var(--radius); font-size: 13px; }

.gate-actions { display: flex; gap: 12px; margin-top: 20px; flex-direction: column; }
.gate-actions textarea { width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 10px 14px; border-radius: var(--radius); min-height: 60px; margin-bottom: 10px; }
.gate-actions .btn-primary { flex: 1; }
.btn-revise { background: var(--surface); color: var(--yellow); border: 1px solid var(--yellow); padding: 12px 20px; border-radius: var(--radius); cursor: pointer; font-weight: 600; flex: 1; font-size: 14px; }
.btn-revise:hover { background: var(--yellow-bg); }

/* Results */
.results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.export-actions { display: flex; gap: 8px; }

.angle-result { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 10px; box-shadow: var(--shadow-sm); }
.angle-result .angle-name { font-weight: 700; font-size: 15px; margin-bottom: 8px; }

.json-export { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-top: 16px; position: relative; box-shadow: var(--shadow-sm); }
.json-export pre { white-space: pre-wrap; word-break: break-all; font-size: 12px; color: var(--text-dim); max-height: 400px; overflow-y: auto; font-family: 'SF Mono', 'Cascadia Code', monospace; }
.copy-btn { position: absolute; top: 10px; right: 10px; }
