* {
  box-sizing: border-box;
}

:root {
  --bg: #f6f0f8;
  --panel: #ffffff;
  --text: #1d1720;
  --muted: #6f6474;
  --line: #ded2e4;
  --accent: #6e3fa3;
  --accent-dark: #4d2679;
  --soft: #f2e8f7;
  --danger: #a33f3f;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 10px 14px;
}

button:hover {
  border-color: var(--accent);
}

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

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

button.primary:hover {
  background: var(--accent-dark);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

label + label,
.grid + label,
label + .grid {
  margin-top: 14px;
}

label input,
label select,
label textarea {
  margin-top: 6px;
  color: var(--text);
  font-weight: 400;
}

.hidden {
  display: none !important;
}

.panel,
.card,
fieldset {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(45, 22, 61, 0.07);
}

.welcome-panel {
  max-width: 720px;
  margin: 8vh auto;
  padding: 36px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
}

.welcome-panel h1 {
  font-size: clamp(34px, 5vw, 60px);
  max-width: 620px;
}

.lede {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.6;
  max-width: 620px;
}

.card {
  margin-top: 30px;
  padding: 24px;
}

.card button {
  margin-top: 18px;
}

.workspace {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#saveState {
  color: var(--muted);
  font-size: 13px;
}

.columns {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(480px, 0.95fr) minmax(440px, 1.05fr);
  gap: 18px;
  padding: 18px;
}

.form-column,
.assistant-column {
  min-height: 0;
  overflow: auto;
}

.assistant-column {
  display: flex;
}

fieldset {
  margin: 0 0 18px;
  padding: 22px;
}

legend {
  padding: 0 8px;
  color: var(--accent-dark);
  font-size: 18px;
  font-weight: 800;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.check-row input {
  width: auto;
  margin: 0;
}

input:disabled,
select:disabled,
textarea:disabled {
  background: #eee8f2;
  color: #96899d;
  cursor: not-allowed;
}

label.aileen-field-updated input,
label.aileen-field-updated select,
label.aileen-field-updated textarea {
  border-color: #d9a935;
  box-shadow: 0 0 0 4px rgba(217, 169, 53, 0.18), 0 0 22px rgba(217, 169, 53, 0.42);
  background: #fff9e6;
}

.aileen-modified-badge {
  display: inline-block;
  width: auto;
  margin-top: 6px;
  border: 1px solid #d9a935;
  border-radius: 999px;
  background: #fff3c4;
  color: #6f4d00;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 8px;
}

.aileen-modified-badge:hover,
.aileen-modified-badge:focus {
  background: #ffe7a3;
  outline: none;
}

.chat-panel {
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 22px;
  border: 3px solid var(--accent);
  box-shadow: 0 18px 48px rgba(77, 38, 121, 0.18);
}

.chat-panel.agent-attention {
  animation: agent-attention-pulse 1.1s ease-in-out infinite;
}

@keyframes agent-attention-pulse {
  0%,
  100% {
    box-shadow: 0 18px 48px rgba(77, 38, 121, 0.18);
    border-color: var(--accent);
  }

  50% {
    box-shadow: 0 18px 58px rgba(110, 63, 163, 0.48);
    border-color: #b16ce0;
  }
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

#doneStatus {
  border-radius: 999px;
  background: #efe4f7;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  padding: 7px 10px;
  white-space: nowrap;
}

#doneStatus.ready {
  background: #dcf7e8;
  color: #176b3a;
}

.helper {
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.chat-log {
  min-height: 0;
  flex: 1;
  overflow: auto;
  border: 2px solid #d4bce4;
  border-radius: 12px;
  background: var(--soft);
  padding: 16px;
}

.message {
  max-width: 92%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  line-height: 1.45;
}

.message.user {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
}

.message.assistant {
  background: #fff;
  border: 1px solid var(--line);
}

.chat-compose {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  margin-top: 12px;
  align-items: end;
}

#micBtn.listening {
  background: #fff0f0;
  border-color: #c84747;
  color: #9d2d2d;
  font-weight: 800;
}

.mic-status {
  min-height: 18px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.error {
  color: var(--danger);
}

@media (max-width: 980px) {
  .workspace {
    height: auto;
  }

  .columns {
    display: block;
  }

  .assistant-column {
    display: block;
  }

  .chat-panel {
    margin-bottom: 18px;
    min-height: 420px;
  }

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