:root {
  --navy: #0f1d31;
  --red: #ed1b2e;
  --orange: #f87424;
  --orange-soft: #fff1e8;
  --blue: #0972bd;
  --blue-soft: #e8f3fb;
  --green: #17a06a;
  --ink: #212734;
  --muted: #647082;
  --line: #dde2ea;
  --bg: #f5f7fa;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 14px 24px; background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  background: var(--red); color: #fff; font-weight: 800; padding: 8px 10px; border-radius: 8px;
}
.brand h1 { margin: 0; font-size: 18px; }
.brand p { margin: 2px 0 0; font-size: 13px; color: #c6cfdc; }

.path-indicator {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 999px;
  background: #24324a; font-weight: 700; font-size: 14px; white-space: nowrap;
}
.path-indicator .dot { width: 12px; height: 12px; border-radius: 50%; background: #8a96a8; }
.path-indicator[data-path="connect"] { background: var(--orange); }
.path-indicator[data-path="connect"] .dot { background: #fff; animation: pulse 1.2s infinite; }
.path-indicator[data-path="fti"] { background: var(--blue); }
.path-indicator[data-path="fti"] .dot { background: #fff; animation: pulse 1.2s infinite; }
.path-indicator[data-path="fallback"] { background: var(--red); }
.path-indicator[data-path="fallback"] .dot { background: #fff; animation: pulse .6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.layout {
  display: grid; grid-template-columns: 360px minmax(360px, 1fr) 420px; gap: 18px;
  padding: 18px 24px; align-items: start;
}
.panel {
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 16px;
  box-shadow: 0 2px 8px rgba(15, 29, 49, .05);
}
.panel h2 { margin: 0 0 12px; font-size: 15px; color: var(--navy); }

/* customer phone */
.phone {
  border: 10px solid var(--navy); border-radius: 30px; overflow: hidden; background: #fff;
  height: 640px; display: flex; flex-direction: column;
}
.phone-head {
  display: flex; flex-direction: column; padding: 12px 16px; background: var(--red); color: #fff;
}
.phone-head span { font-size: 12px; opacity: .9; }

.messages {
  flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px;
  background: #fafbfc;
}
.placeholder { color: var(--muted); font-size: 13px; text-align: center; margin-top: 40px; }
.bubble { max-width: 82%; padding: 8px 11px; border-radius: 12px; font-size: 14px; line-height: 1.35; }
.bubble.mine { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 3px; }
.bubble.theirs { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.bubble .via {
  display: inline-block; margin-top: 5px; font-size: 10px; font-weight: 700; letter-spacing: .02em;
  padding: 1px 6px; border-radius: 999px;
}
.bubble .via.connect { background: var(--orange); color: #fff; }
.bubble .via.fti { background: var(--blue); color: #fff; }
.bubble .meta { display: block; }

.start-form, .composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: #fff; }
.start-form { flex-direction: column; }
input, textarea {
  flex: 1; font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; resize: none;
}
button {
  font: inherit; font-size: 14px; font-weight: 600; border: 0; border-radius: 8px; padding: 8px 14px;
  background: var(--navy); color: #fff; cursor: pointer;
}
button:disabled { opacity: .45; cursor: not-allowed; }
.link-button { background: none; color: var(--muted); font-weight: 500; padding: 6px; }

/* status */
.meter { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.card {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex;
  flex-direction: column; gap: 2px;
}
.card span { font-size: 12px; color: var(--muted); }
.card strong { font-size: 24px; color: var(--navy); }
.card em { font-size: 11px; color: var(--muted); font-style: normal; }
.card.connect { background: var(--orange-soft); border-color: #f9c9a8; }
.card.connect strong { color: var(--orange); }
.card.fti { background: var(--blue-soft); border-color: #b6d7ef; }
.card.fti strong { color: var(--blue); }
.card.saving { grid-column: span 2; background: #e9f7f1; border-color: #b4e3cf; }
.card.saving strong { color: var(--green); }

.fallback { width: 100%; margin: 12px 0 8px; background: #fff; color: var(--red); border: 1px solid var(--red); }
.fallback.active { background: var(--red); color: #fff; }

.legend { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.badge { font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 999px; color: #fff; }
.badge.connect { background: var(--orange); }
.badge.fti { background: var(--blue); }
.badge.system { background: var(--muted); }

.timeline { list-style: none; margin: 0; padding: 0; max-height: 430px; overflow-y: auto; }
.timeline li {
  display: grid; grid-template-columns: 62px 1fr; gap: 10px; padding: 9px 0;
  border-bottom: 1px dashed var(--line); animation: slide .25s ease-out;
}
.timeline time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline .title { font-size: 13px; font-weight: 600; }
.timeline .detail { font-size: 12px; color: var(--muted); }
@keyframes slide { from { opacity: 0; transform: translateY(-4px); } }

/* agent */
.agent-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; }
.agent-bar #agentName { font-weight: 600; flex: 1; }
.agent-state { padding: 3px 8px; border-radius: 999px; background: var(--bg); font-size: 12px; }
.agent-state.routable { background: #e9f7f1; color: var(--green); font-weight: 700; }
.ccp-frame { height: 420px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 10px; }
.ccp-frame.collapsed { height: 0; border: 0; margin: 0; }
.ccp-frame iframe { width: 100%; height: 100%; border: 0; }
.agent-chat {
  border: 1px solid var(--line); border-radius: 10px; height: 460px; display: flex;
  flex-direction: column; overflow: hidden;
}
.incoming {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--orange-soft); border-bottom: 1px solid #f9c9a8; font-size: 13px;
}
.incoming button { background: var(--green); }
