@import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');

:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --accent: #2563eb;
  --muted: #64748b;
  --radius: 10px;
  --gap: 12px;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: #0f172a
}

.hidden {
  display: none;
}

/* App layout: full viewport, column-based */
.app {
  height: 100vh;
  display: flex;
  flex-direction: column
}

header {
  flex: 0 0 auto;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px
}

.brand {
  font-weight: 700
}

.log-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted)
}

/* main area holds the scrollable messages only */
main.content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow: hidden
}

/* messages div should be the only scrollable element */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  background: linear-gradient(180deg, #fff, #fbfdff);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  -webkit-overflow-scrolling: touch
}

.lbl {
  padding: 2px 10px;
  word-break: break-word;
  color: var(--muted);
}

/* composer/footer is pinned at the bottom of the viewport (last child in column) */
footer.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid #e6eef8;
  background: var(--bg)
}

.composer-inner {
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: center
}

textarea {
  flex: 1;
  min-height: 48px;
  max-height: 160px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #e6eef8;
  background: var(--card);
  font-size: 15px;
  line-height: 1.3;
  outline: none;
  resize: none;
  overflow: auto
}

textarea:focus {
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
  border-color: var(--accent)
}

/* ── Morphing Send ↔ Cancel action button ─────────────────────────── */
.action-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 0;
  background: var(--accent);
  color: white;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    border-radius 0.25s ease;
  overflow: visible;
}

.action-btn:hover:enabled {
  background: #1d4ed8;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.45);
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* In cancel mode the button turns red */
.action-btn.cancel {
  background: #ef4444;
  border-radius: 10px;
}

.action-btn.cancel:hover:enabled {
  background: #dc2626;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.45);
}

/* Pulsing ring behind the cancel button */
.action-btn.cancel::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 14px;
  border: 2px solid rgba(239, 68, 68, 0.55);
  animation: cancel-pulse 1.4s ease-out infinite;
}

@keyframes cancel-pulse {
  0%   { transform: scale(1);    opacity: 1; }
  80%  { transform: scale(1.22); opacity: 0; }
  100% { transform: scale(1.22); opacity: 0; }
}

/* ── Icon layers inside the action button ─────────────────────────── */
.action-icon {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Default: send icon visible, cancel icon hidden */
.action-btn .send-icon   { opacity: 1; transform: scale(1);    }
.action-btn .cancel-icon { opacity: 0; transform: scale(0.55); }

/* Flipped when button gains .cancel class */
.action-btn.cancel .send-icon   { opacity: 0; transform: scale(0.55); }
.action-btn.cancel .cancel-icon { opacity: 1; transform: scale(1);    }

.textbox {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid #e6eef8;
  background: white;
  color: var(--muted);
  border-radius: 4px;
  padding: 3px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid #e6eef8;
  background: white;
  color: var(--muted);
  cursor: pointer;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.button:hover:disabled {
  cursor: not-allowed
}

.button:hover:enabled {
  background: #f8fafc;
  color: var(--accent);
  border-color: var(--accent);
}

.button svg {
  color: currentColor;
}

.message {
  padding: 8px;
  border-radius: 6px;
  margin-top: 12px;
}

.message aside {
  position: relative;
  top: -16px;
  left: 8px;
  border-radius: 4px;
  display: inline-block;
  font-weight: bolder;
  padding: 2px 12px;
}

.message p {
  padding: 2px;
  margin: 0;
}

/* Collapsible styles */
.message.collapsed {
  background-color: #f1f5f9;
  border: 1px dashed #cbd5e1;
  margin-top: 8px;
  padding-bottom: 4px;
  transition: all 0.2s ease;
}

.message.collapsible-active {
  cursor: default;
}

.message.collapsible-active aside {
  cursor: pointer;
}

.message.collapsed:hover {
  background-color: #e2e8f0;
}

.message.collapsed>*:not(aside) {
  display: none !important;
}

.message.collapsed aside::after {
  content: " ▾";
  opacity: 0.5;
}

.message:not(.collapsed).collapsible-active aside::after {
  content: " ▴";
  opacity: 0.5;
}

.human {
  background-color: #229b1c40;
}

div.message.human {
  margin-right: 6.66em;
}

.human aside {
  background-color: #229b1c;
  color: #FFFFFF;
}

.agent {
  background-color: #3457d740;
}

div.message.agent {
  margin-left: 6.66em;
}

.agent aside {
  background-color: #3458d7;
  color: #FFFFFF;
}

.system {
  background-color: #E0E0E0;
  color: #404040;
}

.system aside {
  background-color: #808080;
  color: #FFFFFF;
}

.loading-container {
  display: flex;
  gap: 15px;
  justify-content: center;
  align-items: center;
  height: 100px;
}

.bullet {
  width: 30px;
  height: 30px;
  /* Name | Duration | Timing | Iteration */
  animation: jump 1s ease-in-out infinite;
}

/* Staggering the start times */
.bullet:nth-child(2) {
  animation-delay: 0.2s;
}

.bullet:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes jump {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    /* The "Jump" height */
    transform: translateY(-20px);
  }
}

@media (max-width:520px) {
  main.content {
    padding: 12px
  }

  textarea {
    min-height: 40px
  }
}

/* Modal Dialog Styles */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.3s ease;
}

.overlay.hidden {
  display: none !important;
}

.dialog {
  background: var(--card);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 80%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dialog h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
}

.dlg-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dlg-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dlg-field label {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.dlg-field input,
.dlg-field select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #e6eef8;
  font-size: 14px;
  width: 100%;
  outline: none;
}

.dlg-field input:focus,
.dlg-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper input {
  padding-right: 40px !important;
  /* Space for the icon */
}

.password-toggle {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  z-index: 10;
}

.password-toggle:hover {
  color: var(--accent);
}

.dlg-field input[type="checkbox"] {
  width: auto;
  align-self: flex-start;
}

.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 12px;
}

.button.accent {
  background-color: var(--accent);
  color: white;
  border: none;
}

.button.accent:hover:enabled {
  background-color: #1d4ed8;
  color: white;
}

/* Complex Field Table Styles */
.complex-table-container {
  overflow-x: auto;
  border: 1px solid #e6eef8;
  border-radius: 8px;
  margin-bottom: 8px;
}

.complex-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.complex-table th,
.complex-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #e6eef8;
}

.complex-table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.complex-table tr:last-child td {
  border-bottom: none;
}

.complex-table input,
.complex-table select {
  padding: 6px 8px !important;
  border-radius: 4px !important;
  height: 32px !important;
}

.complex-table-actions {
  width: 40px;
  text-align: center;
}

.delete-row-btn {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.delete-row-btn:hover {
  background: #fef2f2;
}

.add-row-btn {
  align-self: flex-start;
  height: 32px !important;
  font-size: 13px !important;
}

@media print {

  /* Reset layout for paper */
  html,
  body {
    height: auto !important;
    overflow: visible !important;
    background: white !important;
  }

  .app {
    height: auto !important;
    display: block !important;
  }

  /* Hide UI elements that don't make sense on paper */
  header,
  footer,
  .log-toggle,
  .export-btn {
    display: none !important;
  }

  /* Expand the main content area */
  main.content {
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    display: block !important;
  }

  /* Remove scrollbars and constraints from messages container */
  .messages {
    height: auto !important;
    overflow: visible !important;
    box-shadow: none !important;
    background: transparent !important;
    padding: 0 !important;
  }

  /* Ensure messages take full width and don't break in the middle */
  .message {
    page-break-inside: avoid;
    break-inside: avoid;
    margin-left: 0 !important;
    margin-right: 0 !important;
    margin-top: 30px !important;
    /* Extra space for the label aside */
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: none !important;
  }

  /* Ensure background colors are printed (if user allows) */
  .human,
  .agent,
  .system {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Adjust aside label position for print readability */
  .message aside {
    box-shadow: none !important;
    border: 1px solid rgba(0, 0, 0, 0.1);
  }
}