/* ── Reset & Base ── */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f8fafc; color: #1e293b; }

/* ── Login Screen ── */
.login-screen { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 50%, #f0fdf4 100%); }
.login-screen.hidden { display: none; }
.login-box { background: #fff; border: 1px solid #e2e8f0; border-radius: 14px; padding: 36px; width: 380px; box-shadow: 0 4px 20px rgba(0,0,0,.06); }
.login-box h1 { font-size: 24px; font-weight: 800; color: #1d4ed8; margin-bottom: 4px; text-align: center; }
.login-box .login-subtitle { font-size: 14px; color: #64748b; margin-bottom: 24px; text-align: center; }
.login-box label { font-size: 13px; font-weight: 500; color: #475569; display: block; margin-bottom: 4px; }
.login-box input[type="text"], .login-box input[type="password"] { width: 100%; padding: 9px 12px; font-size: 14px; border: 1px solid #e2e8f0; border-radius: 6px; margin-bottom: 14px; }
.login-box input:focus { outline: none; border-color: #93c5fd; box-shadow: 0 0 0 2px rgba(59,130,246,.1); }
.login-error { display: none; font-size: 12px; color: #ef4444; margin-bottom: 10px; }
.login-error.visible { display: block; }

/* ── Project Selection Screen ── */
.project-screen { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 50%, #f0fdf4 100%); }
.project-screen.hidden { display: none; }
.project-screen-inner { text-align: center; max-width: 600px; padding: 40px; }
.project-screen-inner h1 { font-size: 28px; font-weight: 800; color: #1d4ed8; margin-bottom: 6px; }
.project-screen-inner .subtitle { font-size: 15px; color: #64748b; margin-bottom: 32px; }
.project-card { background: #fff; border: 2px solid #e2e8f0; border-radius: 14px; padding: 28px; text-align: left; cursor: pointer; transition: all .2s; }
.project-card:hover { border-color: #3b82f6; box-shadow: 0 4px 20px rgba(59,130,246,.12); transform: translateY(-2px); }
.project-card .pname { font-size: 18px; font-weight: 700; color: #1e293b; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.project-card .pname .dot { width: 10px; height: 10px; border-radius: 50%; background: #10b981; }
.project-card .pdesc { font-size: 14px; color: #64748b; line-height: 1.6; margin-bottom: 14px; }
.project-card .pmeta { display: flex; gap: 20px; font-size: 12px; color: #94a3b8; }
.project-card .pmeta strong { color: #475569; }

/* ── Main App ── */
.main-app { display: none; }
.main-app.visible { display: block; }

/* ── Nav ── */
.topnav { background: #fff; border-bottom: 1px solid #e2e8f0; padding: 0 24px; display: flex; align-items: center; height: 54px; position: sticky; top: 0; z-index: 100; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.logo { font-weight: 800; font-size: 16px; color: #1d4ed8; margin-right: 24px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.logo span { background: #2563eb; color: #fff; padding: 3px 8px; border-radius: 6px; font-size: 11px; }
.project-indicator { font-size: 12px; color: #64748b; background: #f1f5f9; padding: 4px 12px; border-radius: 6px; margin-right: 20px; display: flex; align-items: center; gap: 6px; }
.project-indicator .pi-dot { width: 7px; height: 7px; border-radius: 50%; background: #10b981; }
.nav-tabs { display: flex; gap: 2px; height: 100%; }
.nav-tab { padding: 0 16px; font-size: 14px; font-weight: 500; color: #64748b; cursor: pointer; border: none; background: none; height: 100%; display: flex; align-items: center; border-bottom: 2px solid transparent; transition: all .15s; }
.nav-tab:hover { color: #334155; background: #f8fafc; }
.nav-tab.active { color: #1d4ed8; border-bottom-color: #2563eb; }
.nav-right { margin-left: auto; font-size: 13px; color: #64748b; display: flex; align-items: center; gap: 16px; }
.nav-user { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #475569; }
.nav-user .avatar { width: 28px; height: 28px; border-radius: 50%; background: #2563eb; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.nav-user .uname { font-weight: 500; }
.nav-link { color: #94a3b8; cursor: pointer; font-size: 13px; }
.nav-link:hover { color: #64748b; }

/* ── Layout ── */
.page { max-width: 1200px; margin: 0 auto; padding: 24px; display: none; }
.page.active { display: block; }

/* ── Tab Intention Bar ── */
.tab-intention { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px; padding: 10px 16px; margin-bottom: 18px; font-size: 13px; color: #1e40af; display: flex; align-items: center; gap: 8px; }
.tab-intention .ti-icon { font-size: 15px; }

/* ── Cards ── */
.card { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 20px; margin-bottom: 16px; }
.card-sm { padding: 16px; }
h2.page-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
h3.section-title { font-size: 15px; font-weight: 600; color: #475569; margin-bottom: 10px; }

/* ── Stat boxes ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-box { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 14px; cursor: pointer; transition: all .15s; }
.stat-box:hover { border-color: #93c5fd; box-shadow: 0 2px 8px rgba(59,130,246,.06); }
.stat-label { font-size: 12px; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; }

/* ── Tags ── */
.tag { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 10px; display: inline-block; }
.tag-bug { background: #fee2e2; color: #991b1b; }
.tag-enhancement { background: #dbeafe; color: #1e40af; }
.tag-self { background: #fef3c7; color: #92400e; }
.tag-user { background: #e0e7ff; color: #4338ca; }
.tag-green { background: #d1fae5; color: #065f46; }
.tag-blue { background: #dbeafe; color: #1e40af; }
.tag-yellow { background: #fef3c7; color: #92400e; }
.tag-red { background: #fee2e2; color: #991b1b; }
.tag-gray { background: #f1f5f9; color: #64748b; }
.tag-purple { background: #ede9fe; color: #6d28d9; }

/* ── Tables ── */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; padding: 10px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: #94a3b8; font-weight: 600; border-bottom: 2px solid #e2e8f0; }
.tbl td { padding: 11px 12px; border-bottom: 1px solid #f1f5f9; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover { background: #f8fafc; }
.mono { font-family: 'SF Mono', Monaco, monospace; font-size: 12px; }

/* ── Status dots ── */
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot-green { background: #10b981; }
.dot-blue { background: #3b82f6; }
.dot-yellow { background: #f59e0b; }
.dot-red { background: #ef4444; }
.dot-gray { background: #94a3b8; }

/* ── Buttons ── */
.btn { padding: 7px 18px; border-radius: 6px; font-size: 13px; font-weight: 500; border: 1px solid #e2e8f0; background: #fff; cursor: pointer; transition: all .15s; }
.btn:hover { background: #f8fafc; }
.btn-primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-success { background: #10b981; color: #fff; border-color: #10b981; }
.btn-success:hover { background: #059669; }
.btn-danger { background: #fff; color: #ef4444; border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-outline-blue { color: #2563eb; border-color: #93c5fd; background: #eff6ff; }
.btn-outline-blue:hover { background: #dbeafe; }

/* ── Filter bar ── */
.filter-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filter-select { padding: 6px 10px; font-size: 13px; border: 1px solid #e2e8f0; border-radius: 6px; background: #fff; cursor: pointer; }
.filter-select:focus { outline: none; border-color: #93c5fd; }
.filter-input { padding: 6px 10px; font-size: 13px; border: 1px solid #e2e8f0; border-radius: 6px; width: 200px; }
.filter-input:focus { outline: none; border-color: #93c5fd; }

/* ── Progress flow ── */
.progress-flow { display: flex; align-items: center; gap: 0; overflow-x: auto; padding: 8px 0; }
.pf-step { font-size: 12px; padding: 5px 12px; border-radius: 12px; white-space: nowrap; font-weight: 500; }
.pf-step.done { background: #d1fae5; color: #065f46; }
.pf-step.active { background: #dbeafe; color: #1e40af; }
.pf-step.review { background: #fef3c7; color: #92400e; }
.pf-step.pending { background: #f1f5f9; color: #94a3b8; }
.pf-arr { color: #cbd5e1; font-size: 12px; padding: 0 3px; }

/* ── Timeline ── */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 4px; bottom: 4px; width: 2px; background: #e2e8f0; }
.tl-item { position: relative; padding-bottom: 18px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot { position: absolute; left: -24px; top: 4px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; }
.tl-dot.done { background: #10b981; }
.tl-dot.active { background: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.2); }
.tl-dot.pending { background: #e2e8f0; }
.tl-dot.review { background: #f59e0b; }
.tl-title { font-size: 14px; font-weight: 600; }
.tl-meta { font-size: 12px; color: #94a3b8; margin-top: 2px; }
.tl-content { font-size: 13px; color: #64748b; margin-top: 5px; padding: 10px 14px; background: #f8fafc; border-radius: 6px; border: 1px solid #f1f5f9; line-height: 1.6; }

/* ── Report viewer ── */
.report-tabs { display: flex; gap: 3px; flex-wrap: wrap; margin-bottom: 12px; }
.report-tab { padding: 6px 14px; font-size: 12px; font-weight: 500; border-radius: 6px; cursor: pointer; border: 1px solid #e2e8f0; background: #fff; color: #64748b; }
.report-tab.active { background: #2563eb; color: #fff; border-color: #2563eb; }
.report-tab.disabled { opacity: .4; cursor: not-allowed; }
.report-content { border: 1px solid #e2e8f0; border-radius: 8px; padding: 16px; background: #fafbfd; font-size: 14px; line-height: 1.7; color: #475569; min-height: 120px; }

/* ── Flow diagram ── */
.flow-grid { display: flex; flex-direction: column; gap: 16px; padding: 20px 0; }
.flow-row { display: flex; align-items: center; justify-content: center; gap: 6px; }
.flow-row-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: #94a3b8; width: 90px; text-align: right; flex-shrink: 0; }
.flow-connector { display: flex; justify-content: center; padding: 2px 0; }
.flow-connector-arrow { font-size: 18px; color: #94a3b8; }
.fbox { border: 2px solid #3b82f6; border-radius: 8px; padding: 10px 16px; font-size: 12px; text-align: center; min-width: 120px; max-width: 160px; flex: 1; background: #eff6ff; }
.fbox b { display: block; font-size: 13px; margin-bottom: 2px; }
.fbox.green { border-color: #10b981; background: #d1fae5; }
.fbox.amber { border-color: #f59e0b; background: #fef3c7; }
.fbox.red { border-color: #ef4444; background: #fee2e2; }
.fbox.purple { border-color: #8b5cf6; background: #ede9fe; }
.fbox.gray { border-color: #94a3b8; background: #f1f5f9; color: #64748b; }
.farr { font-size: 16px; color: #94a3b8; padding: 0 4px; flex-shrink: 0; }

/* ── Agents page: split layout ── */
.agents-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; min-height: 500px; }
.agent-list { overflow-y: auto; max-height: 700px; }
.agent-list-item { padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 8px; margin-bottom: 6px; cursor: pointer; transition: all .15s; background: #fff; }
.agent-list-item:hover { border-color: #93c5fd; background: #f8fafc; }
.agent-list-item.selected { border-color: #2563eb; border-width: 2px; background: #eff6ff; }
.agent-list-item .ali-name { font-size: 14px; font-weight: 600; margin-bottom: 3px; }
.agent-list-item .ali-desc { font-size: 12px; color: #94a3b8; }

/* ── Agent detail (right side) ── */
.agent-detail-panel { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 22px; }
.agent-detail-panel h4 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }

/* ── Tuning ── */
.tuning-area { margin-top: 16px; padding: 16px; border: 1px dashed #cbd5e1; border-radius: 8px; background: #fafbfd; }
.tuning-area textarea { width: 100%; height: 70px; border: 1px solid #e2e8f0; border-radius: 6px; padding: 8px 10px; font-size: 13px; font-family: inherit; resize: vertical; }
.tuning-area textarea:focus { outline: none; border-color: #93c5fd; box-shadow: 0 0 0 2px rgba(59,130,246,.1); }
.saved-instructions { margin-top: 8px; }
.saved-instruction { display: flex; align-items: start; gap: 8px; padding: 8px 12px; background: #fff; border: 1px solid #e2e8f0; border-radius: 6px; margin-bottom: 6px; font-size: 13px; }
.saved-instruction .text { flex: 1; color: #475569; }
.saved-instruction .remove { color: #ef4444; cursor: pointer; font-size: 12px; }

/* ── Deployment pipeline env boxes ── */
.pipeline-env { border: 2px solid #e2e8f0; border-radius: 10px; padding: 16px 20px; min-width: 170px; text-align: center; cursor: pointer; transition: all .15s; flex: 1; }
.pipeline-env:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.06); }
.pipeline-env.env-dev { border-color: #10b981; background: #f0fdf4; }
.pipeline-env.env-stg { border-color: #f59e0b; background: #fffbeb; }
.pipeline-env.env-prod { border-color: #ef4444; background: #fef2f2; }
.pipeline-env b { font-size: 15px; display: block; margin-bottom: 4px; }
.pipeline-env .count { font-size: 24px; font-weight: 700; }

/* ── Env config editor ── */
.env-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.env-tab { padding: 8px 20px; font-size: 14px; font-weight: 600; border-radius: 8px; cursor: pointer; border: 2px solid #e2e8f0; background: #fff; transition: all .15s; }
.env-tab:hover { border-color: #93c5fd; }
.env-tab.active-dev { border-color: #10b981; background: #f0fdf4; color: #065f46; }
.env-tab.active-stg { border-color: #f59e0b; background: #fffbeb; color: #92400e; }
.env-tab.active-prod { border-color: #ef4444; background: #fef2f2; color: #991b1b; }
.config-row { display: grid; grid-template-columns: 180px 1fr 60px; gap: 8px; padding: 8px 0; border-bottom: 1px solid #f1f5f9; align-items: center; }
.config-row:last-child { border-bottom: none; }
.config-key { font-size: 13px; font-weight: 600; color: #64748b; font-family: 'SF Mono', Monaco, monospace; }
.config-val { font-size: 13px; color: #1e293b; font-family: 'SF Mono', Monaco, monospace; }
.config-val input { width: 100%; padding: 5px 8px; font-size: 13px; font-family: 'SF Mono', Monaco, monospace; border: 1px solid #e2e8f0; border-radius: 4px; background: #fff; }
.config-val input:focus { outline: none; border-color: #93c5fd; }
.config-val input:disabled { background: #f8fafc; color: #94a3b8; border-color: #f1f5f9; }

/* ── Modal ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 200; justify-content: center; align-items: flex-start; padding-top: 60px; overflow-y: auto; }
.modal-overlay.visible { display: flex; }
.modal-content { background: #fff; border-radius: 14px; width: 900px; max-width: 95vw; max-height: 85vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.15); }
.modal-header { padding: 18px 22px; border-bottom: 1px solid #e2e8f0; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: #fff; z-index: 10; border-radius: 14px 14px 0 0; }
.modal-body { padding: 22px; }
.modal-sm { width: 500px; }

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 24px; height: 24px; border: 3px solid #e5e7eb; border-top-color: #3b82f6; border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
.spinner-lg { width: 40px; height: 40px; border-width: 4px; }

/* ── Markdown content styling ── */
.prose-content h1 { font-size: 1.5rem; font-weight: 700; margin: 1rem 0 0.5rem; }
.prose-content h2 { font-size: 1.25rem; font-weight: 600; margin: 1rem 0 0.5rem; color: #374151; }
.prose-content h3 { font-size: 1.1rem; font-weight: 600; margin: 0.75rem 0 0.375rem; color: #4b5563; }
.prose-content p { margin: 0.5rem 0; line-height: 1.6; }
.prose-content ul { list-style: disc; margin-left: 1.5rem; margin-top: 0.5rem; margin-bottom: 0.5rem; }
.prose-content ol { list-style: decimal; margin-left: 1.5rem; margin-top: 0.5rem; margin-bottom: 0.5rem; }
.prose-content li { margin: 0.25rem 0; line-height: 1.5; }
.prose-content code { background: #f3f4f6; padding: 0.125rem 0.375rem; border-radius: 0.25rem; font-size: 0.875rem; }
.prose-content pre { background: #1f2937; color: #e5e7eb; padding: 1rem; border-radius: 0.5rem; overflow-x: auto; margin: 0.75rem 0; }
.prose-content pre code { background: transparent; padding: 0; color: inherit; }
.prose-content table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; }
.prose-content th, .prose-content td { border: 1px solid #d1d5db; padding: 0.5rem 0.75rem; text-align: left; }
.prose-content th { background: #f9fafb; font-weight: 600; }
.prose-content blockquote { border-left: 4px solid #3b82f6; padding-left: 1rem; margin: 0.75rem 0; color: #6b7280; }
.prose-content strong { font-weight: 600; }
.prose-content a { color: #2563eb; text-decoration: underline; }

/* ── JSON viewer ── */
.json-viewer { background: #1f2937; color: #e5e7eb; padding: 1rem; border-radius: 0.5rem; font-family: 'Courier New', monospace; font-size: 0.875rem; overflow-x: auto; white-space: pre; line-height: 1.5; }
.json-key { color: #93c5fd; }
.json-string { color: #86efac; }
.json-number { color: #fbbf24; }
.json-boolean { color: #f472b6; }
.json-null { color: #9ca3af; }

/* ── Misc ── */
.empty-state { text-align: center; padding: 32px; color: #94a3b8; font-size: 14px; }
.section-sep { border: none; border-top: 1px solid #f1f5f9; margin: 16px 0; }
.text-muted { color: #94a3b8; font-size: 12px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mb-12 { margin-bottom: 12px; }
.mt-8 { margin-top: 8px; }
.hidden { display: none !important; }

/* ── Custom scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* ── Transition helpers ── */
.fade-in { animation: fadeIn 0.2s ease-in; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Responsive ── */
@media (max-width: 900px) {
  .agents-layout { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
