* {
  box-sizing: border-box;
}

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-soft: #f2f4f7;
  --text: #172033;
  --muted: #727b8d;
  --line: #e7eaf0;
  --primary: #172033;
  --primary-soft: #f0f3f7;
  --online: #22c55e;
  --danger: #b91c1c;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;

  font-family:
    Inter,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;

  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  justify-content: center;
  overscroll-behavior: none;
}

button,
textarea,
input {
  font-family: inherit;
}

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}


/* ===== Application ===== */

.app {
  width: 100%;
  max-width: 760px;

  height: 100dvh;
  min-height: 100dvh;

  display: flex;
  flex-direction: column;

  background: var(--surface);
  overflow: hidden;
}


/* ===== Header ===== */

.header {
  flex: 0 0 auto;

  min-height: 68px;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  padding:
    calc(8px + env(safe-area-inset-top))
    12px
    8px;

  border-bottom: 1px solid var(--line);

  background: rgba(255,255,255,.97);

  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);

  z-index: 5;
}

.agent-identity {
  min-width: 0;

  display: flex;
  align-items: center;
  gap: 10px;
}

.agent-avatar {
  flex: 0 0 auto;

  width: 38px;
  height: 38px;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 12px;

  background: var(--primary);
  color: #ffffff;

  font-size: 16px;
  font-weight: 750;

  box-shadow: 0 2px 8px rgba(23,32,51,.08);
}

.agent-details {
  min-width: 0;
}

.agent-name {
  font-size: 16px;
  line-height: 1.15;

  font-weight: 750;
  letter-spacing: -.2px;
}

.agent-role {
  margin-top: 4px;

  display: flex;
  align-items: center;
  gap: 6px;

  max-width: 230px;

  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;

  font-size: 11.5px;
  line-height: 1.2;

  color: var(--muted);
}

.status {
  flex: 0 0 auto;

  width: 7px;
  height: 7px;

  border-radius: 50%;

  background: var(--online);

  box-shadow:
    0 0 0 3px rgba(34,197,94,.11);
}

.session-info {
  display: flex;
  align-items: center;
  gap: 7px;

  min-width: 0;

  color: var(--muted);
  font-size: 12px;
}

#userDisplay {
  display: none;
}

.logout-button {
  min-height: 34px;

  padding: 0 11px;

  border-radius: 11px;

  background: var(--surface-soft);
  color: #4b5563;

  font-size: 12px;
  font-weight: 650;
}

.logout-button:active {
  transform: scale(.97);
}


/* ===== Conversation ===== */

.conversation {
  flex: 1 1 auto;
  min-height: 0;

  overflow-y: auto;
  overscroll-behavior-y: contain;

  padding:
    18px
    12px
    20px;

  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;

  background:
    linear-gradient(
      180deg,
      #ffffff 0%,
      #fbfcfd 100%
    );
}

.message {
  display: flex;

  width: 100%;

  margin-bottom: 13px;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(86%, 600px);

  padding: 11px 13px;

  border-radius: 17px;

  font-size: 15px;
  line-height: 1.48;

  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.assistant .bubble {
  background: var(--surface-soft);
  color: var(--text);

  border-bottom-left-radius: 5px;
}

.user .bubble {
  background: var(--primary);
  color: #ffffff;

  border-bottom-right-radius: 5px;

  box-shadow:
    0 2px 6px rgba(23,32,51,.06);
}


/* ===== Composer ===== */

.composer {
  flex: 0 0 auto;

  width: 100%;

  display: flex;
  align-items: flex-end;
  gap: 7px;

  padding:
    8px
    8px
    calc(8px + env(safe-area-inset-bottom));

  border-top: 1px solid var(--line);

  background: rgba(255,255,255,.98);

  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);

  z-index: 5;
}

textarea {
  flex: 1;

  width: 100%;

  min-height: 44px;
  max-height: 126px;

  resize: none;

  padding:
    11px
    13px;

  border: 1px solid #d8dde6;
  border-radius: 17px;

  background: #ffffff;
  color: var(--text);

  font-size: 16px;
  line-height: 1.35;

  outline: none;

  transition:
    border-color .15s ease,
    box-shadow .15s ease;
}

textarea::placeholder {
  color: #9ba3af;
}

textarea:focus {
  border-color: #aeb6c3;

  box-shadow:
    0 0 0 3px rgba(23,32,51,.055);
}

.audio-button,
.send-button {
  flex: 0 0 auto;

  width: 44px;
  min-width: 44px;
  height: 44px;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 50%;

  transition:
    transform .1s ease,
    opacity .15s ease;
}

.audio-button:active,
.send-button:active {
  transform: scale(.95);
}

.audio-button {
  background: var(--primary-soft);
  color: var(--primary);

  font-size: 16px;
}

.send-button {
  padding: 0;

  background: var(--primary);
  color: #ffffff;

  font-size: 14px;
  font-weight: 700;

  box-shadow:
    0 2px 7px rgba(23,32,51,.12);
}

.send-button:disabled {
  cursor: default;
  opacity: .42;
  box-shadow: none;
}

.send-label {
  display: none;
}

.send-icon {
  display: inline;

  font-size: 20px;
  line-height: 1;

  transform: translateY(-1px);
}


/* ===== Authentication ===== */

.login-screen {
  width: 100%;
  min-height: 100dvh;

  display: flex;
  align-items: center;
  justify-content: center;

  padding:
    calc(24px + env(safe-area-inset-top))
    24px
    calc(24px + env(safe-area-inset-bottom));

  background:
    linear-gradient(
      180deg,
      #f8fafc,
      #eef1f5
    );
}

.login-card {
  width: 100%;
  max-width: 420px;

  padding: 30px;

  border: 1px solid var(--line);
  border-radius: 22px;

  background: #ffffff;

  box-shadow:
    0 18px 55px rgba(23,32,51,.09);
}

.login-brand {
  font-size: 28px;
  font-weight: 780;
  letter-spacing: -.8px;
}

.login-title {
  margin-top: 4px;

  font-size: 16px;
  font-weight: 650;

  color: #374151;
}

.login-description {
  margin: 18px 0 24px;

  color: var(--muted);

  line-height: 1.5;
}

.login-card form {
  display: flex;
  flex-direction: column;
}

.login-card label {
  margin: 0 0 6px;

  font-size: 13px;
  font-weight: 650;

  color: #374151;
}

.login-card input {
  width: 100%;
  min-height: 48px;

  margin-bottom: 16px;
  padding: 10px 12px;

  border: 1px solid #d1d5db;
  border-radius: 12px;

  font-size: 16px;

  outline: none;
}

.login-card input:focus {
  border-color: var(--primary);

  box-shadow:
    0 0 0 3px rgba(23,32,51,.06);
}

.login-button {
  min-height: 48px;

  margin-top: 4px;

  border-radius: 12px;

  background: var(--primary);
  color: #ffffff;

  font-weight: 700;
}

.login-button:disabled {
  cursor: default;
  opacity: .65;
}

.login-error {
  min-height: 20px;

  margin-top: 14px;

  font-size: 13px;

  color: var(--danger);
}


/* ===== Small mobile ===== */

@media (max-width: 480px) {

  .header {
    min-height: 64px;

    padding-left: 9px;
    padding-right: 9px;
  }

  .agent-avatar {
    width: 37px;
    height: 37px;

    border-radius: 12px;

    font-size: 15px;
  }

  .agent-role {
    max-width: 185px;
  }

  .conversation {
    padding:
      16px
      8px
      18px;
  }

  .bubble {
    max-width: 90%;

    font-size: 15px;
  }

  .composer {
    gap: 6px;

    padding-left: 7px;
    padding-right: 7px;
  }

  textarea {
    min-height: 44px;

    padding-left: 12px;
    padding-right: 12px;
  }
}


/* ===== Desktop ===== */

@media (min-width: 761px) {

  .app {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);

    box-shadow:
      0 0 45px rgba(23,32,51,.04);
  }

  .conversation {
    padding-left: 22px;
    padding-right: 22px;
  }
}
