:root {
  --bg: #9dc8df;
  --bg-soft: #d9ecf6;
  --surface: #ffffff;
  --surface-soft: #fbfbfb;
  --surface-strong: #f5f5f5;
  --line: #e4e2de;
  --text: #232428;
  --muted: #9a9792;
  --accent: #1697e5;
  --accent-strong: #0b7ec3;
  --accent-soft: #d8efff;
  --danger: #df7e74;
  --shadow: 0 24px 60px rgba(79, 118, 140, 0.25);
  --radius: 18px;
  --window-radius: 8px;
  --font: "Avenir Next", "Nunito Sans", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(180deg, #a9c8d6 0%, #84c7ec 100%);
  color: var(--text);
  font-family: var(--font);
}

body {
  min-height: 100vh;
}

.page-backdrop {
  min-height: 100vh;
  padding: 58px 28px;
}

.app-window,
.admin-window {
  max-width: 1300px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.35);
  border-radius: var(--window-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.window-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  height: 34px;
  padding: 0 18px;
  background: #d8d7d7;
}

.window-bar span {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.65);
}

.app-shell {
  display: grid;
  grid-template-columns: 390px 1fr;
  min-height: calc(100vh - 150px);
  background: var(--surface);
}

.sidebar {
  padding: 0;
  border-right: 1px solid var(--line);
  background: var(--surface-soft);
}

.brand,
.panel,
.token-card,
.admin-card {
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 22px 26px;
  margin-bottom: 0;
  border-left: 0;
  border-right: 0;
  border-top: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: transparent;
  border: 4px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
  font-size: 18px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 14px;
  flex: 0 0 auto;
}

.token-card,
.panel {
  padding: 26px;
  margin-bottom: 0;
  border-left: 0;
  border-right: 0;
  border-top: 0;
}

.panel-header {
  margin-bottom: 18px;
}

.chat-stage {
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0;
  gap: 0;
  background: var(--surface);
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 26px 38px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.messages {
  overflow: auto;
  padding: 24px 34px 30px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
}

.message {
  max-width: min(980px, 100%);
  min-height: 0;
  height: auto;
  padding: 0;
  border-radius: 0;
  margin-bottom: 18px;
  border: 0;
  line-height: 1.58;
  white-space: normal;
  position: relative;
}

.message.assistant {
  background: transparent;
  color: #252a31;
}

.message.user {
  margin-left: auto;
  max-width: min(320px, 88%);
  padding: 15px;
  border-radius: 22px;
  background: #f1f1ef;
  color: #2a2f35;
}

.message-role,
.message-time,
.eyebrow,
.muted,
small {
  color: var(--muted);
}

.message-role,
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 11px;
  font-weight: 700;
}

.messages .message-role {
  display: none;
}

.message-text {
  white-space: pre-wrap;
}

.message.assistant .message-text {
  max-width: min(980px, 100%);
  font-size: 21px;
  line-height: 1.54;
  letter-spacing: -0.02em;
}

.message.user .message-text {
  font-size: 21px;
  line-height: 1.54;
  letter-spacing: -0.02em;
}

#session-panel h2 + #session-subtitle {
  margin-top: 8px;
}

#session-panel #session-subtitle + #logout-button {
  margin-top: 14px;
}

.chat-launch {
  max-width: 540px;
  margin: 11vh auto 0;
  text-align: center;
}

.chat-launch h3 {
  margin: 14px 0 0;
  font-size: 34px;
  letter-spacing: -0.03em;
}

.chat-launch-text {
  margin: 18px 0 0;
  color: #6f746f;
  font-size: 18px;
  line-height: 1.7;
}

.chat-start-button {
  display: inline-flex;
  min-width: 180px;
  margin-top: 24px;
}

.message-time {
  font-size: 12px;
  margin-top: 10px;
}

.composer {
  display: block;
  padding: 22px 28px 26px;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
}

textarea,
input,
select,
button {
  font: inherit;
}

textarea,
input,
select {
  width: 100%;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

button,
.admin-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 15px 20px;
  border-radius: 10px;
  border: 0;
  background: var(--accent);
  color: white;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  margin-top: 10px;
  margin-bottom: 10px;
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

button.outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

button.outline:hover {
  background: var(--accent-soft);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.button-full {
  width: 100%;
}

#email-step .button-full {
  margin-top: 22px;
}

.conversation-list {
  display: grid;
  gap: 0;
}

.conversation-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  background: var(--surface);
  color: var(--text);
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 18px 22px;
  font-size: 16px;
  min-height: 0;
  text-align: left;
}

.conversation-item span,
.conversation-item small {
  display: block;
  width: 100%;
  text-align: left;
}

.conversation-item span {
  line-height: 1.25;
}

.conversation-item small {
  margin-top: 6px;
  line-height: 1.35;
}

.conversation-item.active {
  background: var(--accent);
  color: white;
}

.conversation-item.active small {
  color: rgba(255, 255, 255, 0.8);
}

.empty-state {
  max-width: 480px;
  margin: 12vh auto 0;
  text-align: center;
}

.hidden {
  display: none;
}

.admin-body {
  padding: 0;
}

.admin-shell {
  max-width: none;
  margin: 0;
  display: grid;
  gap: 0;
  background: var(--surface);
}

.admin-grid {
  max-width: none;
}

.admin-card {
  padding: 30px 34px;
  border-left: 0;
  border-right: 0;
  border-top: 0;
}

.admin-action-bar {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 18px 34px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.admin-action-bar button {
  margin: 0;
}

.admin-directory-button {
  margin-left: 4px;
}

.admin-action-bar .admin-logout {
  margin-left: auto;
}

.admin-action-bar.hidden {
  display: none;
}

.admin-columns {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(360px, 1.6fr);
  gap: 28px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(21, 27, 31, 0.28);
}

.modal-backdrop.hidden {
  display: none;
}

.modal-panel {
  position: relative;
  width: min(520px, 100%);
  max-height: min(86vh, 820px);
  overflow: auto;
  padding: 30px 34px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(38, 53, 61, 0.22);
}

.modal-panel-wide {
  width: min(980px, calc(100vw - 56px));
  max-height: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 10px 18px;
  overflow: visible;
  padding: 22px 28px;
}

.modal-panel-list {
  width: min(680px, calc(100vw - 56px));
  max-height: min(86vh, 720px);
}

.modal-panel:not(.modal-panel-wide) > * + * {
  margin-top: 18px;
}

.modal-panel h2 {
  margin: 0 42px 2px 0;
}

.modal-lead {
  margin: 10px 0 18px;
  line-height: 1.55;
}

.modal-panel-wide h2,
.modal-panel-wide .modal-actions,
.modal-panel-wide .field-caption {
  grid-column: 1 / -1;
}

.modal-field {
  min-width: 0;
}

.modal-field .field-label {
  margin-bottom: 7px;
}

.modal-field textarea {
  min-height: 0;
  resize: vertical;
}

.modal-field:nth-of-type(3) {
  grid-column: 1;
}

.modal-field:nth-of-type(4) {
  grid-column: 1 / -1;
  grid-row: auto;
}

.modal-field-documents {
  grid-column: 1 / -1;
}

.modal-inner-label {
  margin-top: 10px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.modal-actions button {
  margin: 4px 0 0;
}

.modal-back-button {
  grid-column: 1 / -1;
  justify-self: flex-start;
  margin: 0;
  padding: 10px 14px;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 34px;
  height: 34px;
  min-width: 34px;
  padding: 0;
  margin: 0;
  border-radius: 999px;
  background: #f2f2f0;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  text-transform: none;
  letter-spacing: 0;
}

.admin-messages {
  max-height: 70vh;
}

.compact-list {
  border-top: 1px solid var(--line);
}

.admin-compact-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  min-height: 44px;
}

.admin-compact-main,
.admin-faq-question {
  width: 100%;
  justify-content: flex-start;
  min-height: 42px;
  padding: 10px 12px;
  margin: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
  font-weight: 600;
}

.admin-compact-main.active,
.admin-faq-question:hover,
.admin-compact-main:hover {
  background: #f3f6f8;
  color: var(--text);
}

.admin-compact-action {
  min-height: 34px;
  padding: 8px 12px;
  margin: 0;
  font-size: 11px;
  white-space: nowrap;
}

.document-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.document-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafb;
}

.document-row a {
  min-width: 0;
  color: #3b5f84;
  font-weight: 700;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-row small {
  color: var(--muted);
  white-space: nowrap;
}

.admin-faq-list {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
}

.admin-faq-item {
  border-bottom: 1px solid var(--line);
}

.admin-faq-answer {
  padding: 18px 18px 10px;
  background: #fbfbfa;
}

.admin-faq-answer .message {
  margin-bottom: 16px;
}

.compact-empty {
  margin: 28px auto;
}

.admin-stack {
  display: grid;
  gap: 16px;
}

.assignment-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
}

.field-label {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #78756f;
}

.field-caption {
  margin-top: 18px;
  line-height: 1.6;
}

.field-hint {
  margin-top: 14px;
  line-height: 1.6;
  font-size: 14px;
}

.token-card input,
.token-card button,
.token-card textarea,
.panel button,
.admin-card input,
.admin-card button,
.admin-card textarea {
  margin-top: 0;
}

.token-card > * + *,
.panel > * + *,
.admin-card > * + *,
.admin-stack > * + * {
  margin-top: 22px;
}

.token-card > .field-label + input,
.admin-stack > .field-label + input,
.admin-stack > .field-label + textarea,
.admin-card > .field-label + input {
  margin-top: 0;
}

.token-card > input + .field-hint,
.admin-card > input + .field-hint,
.admin-stack > input + .field-hint,
.token-card > textarea + .field-hint,
.admin-stack > textarea + .field-hint {
  margin-top: 14px;
}

.token-card > .field-hint + button,
.admin-card > .field-hint + button,
.admin-stack > .field-hint + button {
  margin-top: 22px;
}

.token-card > button + .field-caption,
.admin-card > button + .field-caption,
.admin-stack > button + .field-caption {
  margin-top: 18px;
}

.brand h1,
.chat-header h2,
.admin-card h1,
.admin-card h2,
.empty-state h3 {
  margin: 0;
}

.brand p,
.chat-header p,
.panel p,
.token-card p,
.admin-card p {
  margin: 0;
}

.chat-header h2 {
  font-size: 22px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.chat-description {
  margin-top: 8px;
}

textarea#message-input {
  min-height: 84px;
  border: 0;
  background: transparent;
  padding: 8px 0 0;
  border-radius: 0;
  resize: none;
  font-size: 18px;
  line-height: 1.55;
}

textarea#message-input:focus {
  outline: none;
}

.composer-shell {
  border: 1px solid #d8d6d3;
  border-radius: 34px;
  background: var(--surface);
  padding: 20px 22px 16px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}

.composer-text-wrap {
  min-height: 96px;
}

.composer-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  padding-top: 8px;
}

.composer-left,
.composer-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.composer-note {
  color: #9b9894;
  font-size: 13px;
  line-height: 1.4;
}

.composer-status {
  margin: 4px 0 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #eef7ff;
  color: #365d78;
  font-size: 13px;
  line-height: 1.45;
}

.composer-status-error {
  background: #fff1ed;
  color: #9a3f2f;
}

.composer-status-processing {
  position: relative;
  padding-left: 36px;
}

.composer-status-processing::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 12px;
  width: 15px;
  height: 15px;
  margin-top: -8px;
  border-radius: 999px;
  border: 2px solid #d5dadd;
  border-top-color: var(--accent);
  animation: processing-spin 0.9s linear infinite;
}

@keyframes processing-spin {
  to {
    transform: rotate(360deg);
  }
}

.icon-button {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 0;
  margin: 0;
  background: transparent;
  color: #9d9b98;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: none;
  letter-spacing: 0;
  position: relative;
  transition:
    transform 180ms ease,
    background 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease;
}

.icon-button:hover {
  background: #f3f3f3;
}

.composer-plus {
  font-size: 34px;
  line-height: 1;
  font-weight: 300;
}

.icon-button svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
}

.send-button {
  background: #9d9d9d;
  color: white;
}

.send-button:hover {
  background: #8f8f8f;
}

.icon-button.recording {
  width: 82px;
  height: 82px;
  margin: -13px 0;
  color: white;
  background: #d93630;
  box-shadow: 0 0 0 12px rgba(217, 54, 48, 0.16), 0 14px 34px rgba(217, 54, 48, 0.34);
  transform: scale(1.16);
  animation: mic-recording-pulse 1.05s ease-in-out infinite;
}

.icon-button.recording:hover {
  background: #c92f2a;
}

.icon-button.recording::before {
  content: "";
  position: absolute;
  inset: -16px;
  border-radius: 999px;
  background: rgba(217, 54, 48, 0.12);
  z-index: -1;
}

.icon-button.recording svg {
  width: 38px;
  height: 38px;
}

@keyframes mic-recording-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 12px rgba(217, 54, 48, 0.16), 0 14px 34px rgba(217, 54, 48, 0.34);
  }

  50% {
    box-shadow: 0 0 0 20px rgba(217, 54, 48, 0.08), 0 16px 42px rgba(217, 54, 48, 0.42);
  }
}

.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 6px 0 10px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 9px 12px;
  border-radius: 999px;
  background: #f3f6f8;
  color: #4c5259;
  font-size: 13px;
}

.attachment-remove {
  margin: 0;
  padding: 0;
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: 999px;
  background: transparent;
  color: #7e848b;
  font-size: 18px;
  line-height: 1;
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
}

.message-attachments:empty {
  display: none;
}

.message.assistant .message-attachments {
  margin-top: 12px;
}

.message.user .message-attachments {
  margin-top: 10px;
}

.message-attachment.file {
  min-width: 180px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.message-attachment.file a {
  display: block;
  color: #3b5f84;
  text-decoration: none;
  font-weight: 600;
  margin-bottom: 6px;
}

.message-attachment .attachment-status {
  display: block;
  margin-top: 6px;
  color: #7e848b;
  font-size: 12px;
}

.message-attachment.image {
  display: block;
  width: 132px;
  height: 96px;
  border-radius: 14px;
  overflow: hidden;
}

.message-attachment.image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

pre {
  overflow: auto;
  padding: 18px;
  border-radius: 18px;
  background: #f7f7f7;
  border: 1px solid var(--line);
}

@media (max-width: 920px) {
  .page-backdrop {
    padding: 0;
  }

  .app-window,
  .admin-window {
    border-radius: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 100%;
  }

  .admin-columns {
    grid-template-columns: 1fr;
  }

  .modal-panel-wide {
    grid-template-columns: 1fr;
    max-height: min(86vh, 820px);
    overflow: auto;
  }

  .modal-field:nth-of-type(3),
  .modal-field:nth-of-type(4) {
    grid-column: auto;
    grid-row: auto;
  }

  .modal-field-documents {
    grid-column: auto;
  }

  .document-row {
    grid-template-columns: 1fr;
    align-items: flex-start;
  }
}
