/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg:      #f7f8fc;
  --white:   #ffffff;
  --border:  #e3e6ee;
  --text:    #111827;
  --muted:   #6b7280;
  --accent:  #4f46e5;
  --accentH: #4338ca;
  --green:   #16a34a;
  --red:     #dc2626;
  --yellow:  #d97706;
  --blue:    #2563eb;
  --r:       12px;
}

html, body { height: 100%; overflow: hidden; font-size: 14px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Page system ───────────────────────────────────────────── */
.page {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  background: var(--bg);
  transition: opacity .38s cubic-bezier(.4,0,.2,1),
              transform .38s cubic-bezier(.4,0,.2,1);
}

.page-active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.page-right {
  opacity: 0;
  transform: translateX(48px);
  pointer-events: none;
}

.page-left {
  opacity: 0;
  transform: translateX(-48px);
  pointer-events: none;
}

/* ── PAGE 1 ────────────────────────────────────────────────── */
.page-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 3.5rem 1.5rem 4rem;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

/* Brand */
.brand { text-align: center; }

.brand-logo {
  width: 52px; height: 52px;
  margin: 0 auto .75rem;
}

.brand-logo svg { width: 100%; height: 100%; }

.brand h1 {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -.04em;
  color: var(--text);
}

.brand-sub {
  color: var(--muted);
  margin-top: .4rem;
  font-size: .9rem;
}

/* Tool grid */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 1rem;
}

/* Tool card */
.tool-card {
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem 1.25rem 1.25rem;
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: .6rem;
  transition: border-color .2s, box-shadow .2s, transform .18s;
  user-select: none;
}

.tool-card:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 24px rgba(79,70,229,.13);
  transform: translateY(-3px);
}

.tool-card.connected {
  border-color: var(--green);
  background: #f0fdf4;
}

/* Circular logo container */
.tc-logo-wrap {
  width: 64px; height: 64px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}

.tc-logo-wrap svg,
.tc-logo-wrap img {
  width: 100%; height: 100%;
  object-fit: contain;
}

/* Connected badge */
.tc-badge {
  position: absolute;
  top: .65rem; right: .65rem;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: .6rem;
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  transform: scale(.6);
  font-weight: 700;
}

.tool-card.connected .tc-badge {
  opacity: 1;
  transform: scale(1);
}

.tc-name {
  font-weight: 700;
  font-size: .9rem;
  color: var(--text);
}

.tc-desc {
  font-size: .73rem;
  color: var(--muted);
  line-height: 1.4;
}

.tc-status {
  font-size: .72rem;
  font-weight: 600;
  min-height: .9rem;
}

.tc-status.ok  { color: var(--green); }
.tc-status.err { color: var(--red); }

/* Footer */
.page-footer { text-align: center; }

.footer-hint {
  font-size: .83rem;
  color: var(--muted);
  margin-bottom: .9rem;
  min-height: 1.2rem;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: .72rem 1.75rem;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .12s, opacity .2s;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accentH);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: .4;
  cursor: not-allowed;
  transform: none;
}

.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--muted);
  padding: .6rem 1.2rem;
  border-radius: 8px;
  font-size: .85rem;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-back {
  background: none; border: none;
  color: var(--muted);
  font-size: .8rem;
  cursor: pointer;
  padding: .35rem .6rem;
  border-radius: 6px;
  display: inline-flex; align-items: center; gap: .25rem;
  transition: background .15s, color .15s;
}

.btn-back:hover { background: var(--bg); color: var(--text); }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(17,24,39,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
  backdrop-filter: blur(2px);
}

.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--white);
  border-radius: 16px;
  padding: 1.85rem;
  width: min(440px, 93vw);
  box-shadow: 0 24px 64px rgba(0,0,0,.18);
  animation: modal-pop .22s cubic-bezier(.34,1.56,.64,1);
}

@keyframes modal-pop {
  from { opacity: 0; transform: scale(.9) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-top {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 1.4rem;
}

.modal-title-row { display: flex; align-items: center; gap: .9rem; }

.modal-tool-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

.modal-tool-icon svg { width: 100%; height: 100%; }

.modal-name { font-weight: 700; font-size: 1.05rem; }
.modal-tool-desc { font-size: .78rem; color: var(--muted); margin-top: .15rem; line-height: 1.4; }

.modal-x {
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  padding: .25rem; border-radius: 6px;
  transition: color .15s, background .15s;
  display: flex; align-items: center; justify-content: center;
}
.modal-x:hover { color: var(--text); background: var(--bg); }

.field-group { margin-bottom: .85rem; }

.field-group label {
  display: block;
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-bottom: .3rem;
}

.field-group input {
  width: 100%;
  padding: .6rem .8rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  color: var(--text);
  background: var(--bg);
  transition: border-color .15s, box-shadow .15s;
}

.field-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
  background: #fff;
}

.modal-err {
  min-height: 1.1rem;
  font-size: .78rem;
  color: var(--red);
  margin-bottom: .65rem;
}

.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; }

/* ── PAGE 2 – Chat ─────────────────────────────────────────── */
#page-chat { overflow: hidden; }

.chat-wrap {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Chat column */
.chat-col {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column;
  background: var(--white);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.chat-header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}

.chat-header-left { display: flex; align-items: center; gap: .75rem; }

.chat-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.chat-title { font-weight: 700; font-size: .9rem; }

.chat-pills { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .15rem; }

.pill {
  display: inline-flex; align-items: center; gap: .25rem;
  background: #eff6ff; color: var(--blue);
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  padding: .08rem .5rem;
  font-size: .65rem; font-weight: 700;
}

.pill.green { background: #f0fdf4; color: var(--green); border-color: #bbf7d0; }
.pill svg   { width: 10px; height: 10px; }

/* Messages */
.chat-messages {
  flex: 1 1 0; min-height: 0;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex; flex-direction: column;
  gap: .85rem;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.msg-row { display: flex; }
.msg-row.user  { justify-content: flex-end; }
.msg-row.agent { justify-content: flex-start; }

.bubble {
  max-width: 74%;
  padding: .75rem 1rem;
  border-radius: 14px;
  font-size: .875rem;
  line-height: 1.6;
}

.msg-row.user  .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.agent .bubble { background: var(--bg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.bubble-hint { color: var(--muted); font-size: .8rem; }

/* Typing */
.typing-bubble {
  display: flex; align-items: center; gap: .4rem;
  color: var(--muted); font-size: .8rem;
  padding: .55rem .85rem;
}
.typing-dots { display: flex; gap: .25rem; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: td .9s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .18s; }
.typing-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes td {
  0%,80%,100% { transform: translateY(0); opacity: .5; }
  40%          { transform: translateY(-5px); opacity: 1; }
}

/* Result card */
.result-card {
  max-width: 90%;
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 1.2rem 1.3rem;
  display: flex; flex-direction: column; gap: .95rem;
}

.sev-pill {
  display: inline-block;
  padding: .2rem .7rem;
  border-radius: 20px;
  font-size: .68rem; font-weight: 700;
  letter-spacing: .05em;
  width: fit-content;
}
.sev-Critical { background:#fef2f2; color:var(--red);    border:1px solid #fecaca; }
.sev-High     { background:#fffbeb; color:var(--yellow);  border:1px solid #fde68a; }
.sev-Medium   { background:#eff6ff; color:var(--blue);    border:1px solid #bfdbfe; }
.sev-Low      { background:#f0fdf4; color:var(--green);   border:1px solid #bbf7d0; }

.rc-label {
  font-size: .65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin-bottom: .25rem;
}
.rc-text { font-size: .85rem; line-height: 1.55; }

.fix-ol { counter-reset: fix; list-style: none; display: flex; flex-direction: column; gap: .35rem; }
.fix-ol li {
  counter-increment: fix;
  padding: .45rem .65rem .45rem 2.1rem;
  background: var(--bg); border-radius: 6px;
  font-size: .8rem; line-height: 1.45; position: relative;
}
.fix-ol li::before {
  content: counter(fix);
  position: absolute; left: .6rem; top: .48rem;
  font-size: .65rem; font-weight: 700; color: var(--accent);
}

/* Input bar */
.chat-input-bar {
  flex-shrink: 0;
  display: flex; align-items: flex-end; gap: .6rem;
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--white);
}

.chat-input-bar textarea {
  flex: 1; min-width: 0;
  padding: .6rem .8rem;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: .875rem; font-family: inherit;
  resize: none; max-height: 110px; overflow-y: auto; line-height: 1.5;
  transition: border-color .15s, box-shadow .15s;
}
.chat-input-bar textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}

.btn-send {
  flex-shrink: 0; width: 38px; height: 38px;
  background: var(--accent); border: none; border-radius: 8px;
  color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.btn-send svg { width: 15px; height: 15px; }
.btn-send:hover:not(:disabled) { background: var(--accentH); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; }

/* ── Log column ────────────────────────────────────────────── */
.log-col {
  width: 340px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: #0f1117; color: #cbd5e1;
  overflow: hidden;
}

.log-col-header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1rem;
  border-bottom: 1px solid #1e2535;
}

.log-col-title {
  font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: #475569;
}

.log-status-row { display: flex; align-items: center; gap: .4rem; }

.log-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #1e2535; transition: background .3s;
}
.log-dot.active { background: #22c55e; animation: ldp 1.1s infinite; }
@keyframes ldp { 0%,100%{opacity:1} 50%{opacity:.3} }

.log-status-text { font-size: .7rem; color: #475569; }

.log-feed {
  flex: 1 1 0; min-height: 0;
  overflow-y: auto;
  padding: .65rem .75rem;
}

.log-feed::-webkit-scrollbar { width: 4px; }
.log-feed::-webkit-scrollbar-thumb { background: #1e2535; border-radius: 10px; }

.log-empty { color: #334155; font-style: italic; font-size: .72rem; padding: .4rem; }

.log-entry {
  padding: .2rem .4rem; border-radius: 4px; margin-bottom: .18rem;
  font-family: 'SF Mono','Fira Code','Cascadia Code',monospace;
  font-size: .68rem; line-height: 1.55; word-break: break-word;
}

.log-ts { color: #334155; margin-right: .4rem; }

.log-entry.ev-start  { color: #38bdf8; }
.log-entry.ev-tool   { color: #fbbf24; }
.log-entry.ev-result { color: #4ade80; }
.log-entry.ev-llm    { color: #a78bfa; }
.log-entry.ev-finish { color: #f472b6; font-weight: 600; }
.log-entry.ev-error  { color: #f87171; }
.log-entry.ev-step   { color: #374151; }
.log-entry.ev-other  { color: #4b5563; }

/* Cost row */
.cost-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .4rem;
  padding: .55rem .7rem;
  background: var(--bg);
  border-radius: 7px;
  border: 1px solid var(--border);
  margin-top: .25rem;
}

.cost-label {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}

.cost-total {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.cost-detail {
  font-size: .72rem;
  color: var(--muted);
  flex: 1;
}

/* Responsive */
@media (max-width: 680px) {
  .chat-wrap { flex-direction: column; }
  .log-col { width: 100%; height: 200px; flex-shrink: 0; border-top: 1px solid #1e2535; }
  .chat-col { border-right: none; }
}
