:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #d4dbe5;
  --accent: #ef4444;
  --accent-2: #dc2626;
  --user-bubble: #e9f1ff;
  --assistant-bubble: #ffffff;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.chat-shell {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto auto;
}

.chat-header {
  background: linear-gradient(120deg, #ff5a5a, #f0453d);
  color: #fff;
  padding: 14px 16px;
  border-bottom: 1px solid #e73b3b;
}

.chat-title {
  font-size: 22px;
  font-weight: 700;
}

.chat-subtitle {
  margin-top: 4px;
  font-size: 12px;
  opacity: 0.9;
}

.chat-body {
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 92%;
  width: fit-content;
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--assistant-bubble);
  align-self: flex-start;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
}

.message-content {
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.message-content ul {
  margin: 6px 0 2px 18px;
  padding: 0;
}

.message-content li {
  margin: 2px 0;
}

.message-content .attachment-row {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  margin: 8px 0 10px;
}

.message-content .attachment-row-item {
  display: inline-block;
}

.message-content .attachment-row img {
  margin-top: 0;
}

.message.message-has-image {
  max-width: min(420px, 92%);
}

.message.message-estimate {
  width: min(92%, 1100px);
  max-width: min(92%, 1100px);
}

.estimate-render {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.estimate-line {
  font-size: 14px;
  line-height: 1.35;
}

.estimate-hidden-summary {
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid #dbe4f0;
  border-radius: 10px;
  background: #f8fbff;
  font-size: 13px;
  line-height: 1.45;
  color: #334155;
}

.estimate-hidden-summary-line + .estimate-hidden-summary-line {
  margin-top: 4px;
}

.estimate-hidden-hint {
  margin-top: -2px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

.estimate-route {
  font-size: 22px;
  font-weight: 700;
}

.estimate-group {
  margin-top: 14px;
}

.estimate-group-head {
  display: flex;
  justify-content: flex-start;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 8px;
}

.estimate-group-title {
  font-size: 14px;
  font-weight: 700;
}

.estimate-group-pickup {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.estimate-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: start;
}

.rate-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  align-self: start;
  height: auto;
}

.rate-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.rate-airline {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  flex: 1 1 auto;
}

.rate-route {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.rate-heading {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.rate-schedule {
  margin-top: 4px;
  width: 100%;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.25;
}

.rate-total {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  text-align: right;
}

.agent-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e7edf5;
  border: 1px solid #cad7e6;
  color: #40566f;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.agent-badge--interactive {
  cursor: pointer;
}

.agent-badge__hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
  opacity: 0.78;
  flex: 0 0 auto;
}

.rate-confidence {
  flex: 0 0 64px;
  width: 64px;
}

.rate-confidence-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #fee2e2 0%, #fef3c7 50%, #dcfce7 100%);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.2);
}

.rate-confidence-fill {
  height: 100%;
  border-radius: inherit;
  min-width: 0;
  transition: width 0.25s ease;
}

.rate-footer {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.rate-toggle {
  border: 0;
  padding: 0;
  background: transparent;
  color: #374151;
  font-size: 12px;
  cursor: pointer;
}

.rate-toggle:focus-visible {
  outline: 2px solid rgba(239, 68, 68, 0.25);
  outline-offset: 2px;
  border-radius: 4px;
}

.rate-details-panel {
  margin-top: 4px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.2s ease, opacity 0.18s ease;
}

.rate-details-list {
  margin: 0;
  padding-left: 16px;
  display: grid;
  gap: 2px;
  font-size: 12px;
  color: #374151;
}

.rate-details-list li {
  margin: 0;
}

.estimate-manager-block {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: #fffaf5;
}

.estimate-manager-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

.estimate-manager-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: #374151;
}

.message-content pre {
  background: #0f172a;
  color: #f8fafc;
  padding: 8px;
  border-radius: 8px;
  overflow-x: auto;
}

.message-content code {
  font-family: "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
}

.message-content img {
  max-width: min(100%, 320px);
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-top: 6px;
  cursor: zoom-in;
}

.message-time {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  align-self: flex-end;
}

.typing-indicator {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #98a2b3;
  animation: bounce 1s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.12s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: scale(0.7);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 14px 10px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
}

.attachment-chip button {
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
}

.chat-footer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 10px 14px 12px;
}

.composer-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #fff;
}

.composer-wrap:focus-within {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.composer-wrap.is-drop-active {
  border-color: #ef4444;
  background: #fff5f5;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18);
}

.composer {
  flex: 1;
  min-height: 38px;
  max-height: 180px;
  resize: none;
  border: 0;
  border-radius: 8px;
  padding: 8px 8px;
  font-size: 14px;
  line-height: 1.35;
  outline: none;
  background: transparent;
}

.composer:focus {
  box-shadow: none;
}

.chat-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
}

.icon-btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  background: #fff;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.icon-btn-muted {
  color: #374151;
}

.icon-btn-muted:hover:enabled {
  background: #f3f4f6;
  border-color: #c2c9d6;
}

.icon-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.icon-btn-primary:hover:enabled {
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.file-input {
  display: none;
}

.image-modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1000;
}

.image-modal.is-open {
  display: block;
}

.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.78);
}

.image-modal-content {
  position: absolute;
  inset: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-modal-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

.image-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  font-size: 28px;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

.agent-popover {
  position: fixed;
  z-index: 1001;
  width: min(420px, calc(100vw - 48px));
  max-height: 320px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #d7dfeb;
  background: #ffffff;
  box-shadow: 0 16px 40px rgba(13, 44, 84, 0.18);
}

.agent-popover[hidden] {
  display: none !important;
}

.agent-popover-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: transparent;
}

.agent-popover-backdrop[hidden] {
  display: none !important;
}

.agent-popover__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.agent-popover__title {
  font-size: 13px;
  font-weight: 700;
  color: #0d2c54;
  flex: 1;
  min-width: 0;
}

.agent-popover__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #edf2f7;
  color: #5b6f86;
  cursor: pointer;
  flex: 0 0 auto;
  position: relative;
}

.agent-popover__close::before {
  content: "×";
  font-size: 16px;
  line-height: 1;
  transform: translateY(-1px);
}

.agent-popover__close:hover {
  background: #dfe8f2;
  color: #0d2c54;
}

.agent-popover__body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 272px;
  overflow-y: auto;
  padding-right: 4px;
  padding-bottom: 16px;
}

.agent-popover__section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.agent-popover__label {
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6a7f96;
}

.agent-popover__value {
  font-size: 12px;
  line-height: 1.45;
  color: #24384f;
  white-space: pre-line;
  word-break: break-word;
}

@media (min-width: 768px) {
  .estimate-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1280px) {
  .estimate-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
