:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --panel: #fffdf9;
  --ink: #202426;
  --muted: #66706f;
  --line: #ded8cf;
  --accent: #146c72;
  --accent-dark: #0d5156;
  --assistant: #eef5f3;
  --user: #1f4750;
  --shadow: 0 24px 70px rgba(31, 45, 44, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0)),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

.app-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 22px;
}

.chat-panel {
  position: relative;
  width: min(980px, 100%);
  height: min(860px, calc(100vh - 44px));
  min-height: 560px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.drop-overlay {
  position: absolute;
  inset: 12px;
  z-index: 20;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: rgba(255, 253, 249, 0.9);
  color: var(--accent-dark);
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  pointer-events: none;
}

.drop-overlay[hidden] {
  display: none;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--line);
}

.title-block {
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

#status {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.prompt-summary {
  max-width: 720px;
  margin: 7px 0 0;
  color: #405150;
  font-size: 13px;
  line-height: 1.45;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.text-button,
.primary-button,
.secondary-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.text-button {
  min-height: 42px;
  padding: 0 14px;
  background: #edf1ee;
  color: var(--accent-dark);
  white-space: nowrap;
}

.text-button:hover,
.secondary-button:hover {
  background: #e2e8e4;
}

#clearButton,
#sendButton {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

#clearButton {
  width: 42px;
  height: 42px;
  background: #edf1ee;
  color: var(--ink);
  font-size: 22px;
}

#clearButton:hover {
  background: #e2e8e4;
}

.password-panel {
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: #fbf6ed;
}

.password-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.password-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.password-row input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: white;
}

.password-row button {
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 24, 24, 0.38);
}

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

.modal {
  width: min(620px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.modal-header p,
.modal-status {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.modal-close {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 8px;
  background: #edf1ee;
  color: var(--ink);
  cursor: pointer;
  font-size: 24px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  color: var(--ink);
  line-height: 1.4;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.field-label {
  display: block;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

#improvementInput {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  outline: none;
  background: white;
  color: var(--ink);
}

#improvementInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 108, 114, 0.14);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 0 15px;
}

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

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

.secondary-button {
  background: #edf1ee;
  color: var(--ink);
}

.messages {
  overflow-y: auto;
  padding: 24px;
}

.empty {
  max-width: 620px;
  margin: 90px auto 0;
  color: var(--muted);
  text-align: center;
  line-height: 1.55;
}

.message {
  display: flex;
  margin: 0 0 16px;
}

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

.bubble {
  max-width: min(720px, 86%);
  padding: 13px 15px;
  border-radius: 8px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.assistant .bubble {
  background: var(--assistant);
  border: 1px solid #d9e6e2;
}

.user .bubble {
  background: var(--user);
  color: white;
}

.composer {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 12px;
  padding: 18px 20px 20px;
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 249, 0.92);
}

.analysis-status {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid #c9ddd9;
  border-radius: 8px;
  background: #e8f4f1;
  color: var(--accent-dark);
  font-size: 14px;
  font-weight: 800;
}

.analysis-status[hidden] {
  display: none;
}

.analysis-status button {
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  background: #fffdf9;
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 800;
}

.analysis-status button:hover {
  background: #f3eee6;
}

.attachment-bar {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  min-height: 38px;
  padding: 10px;
  border: 1px solid #d9e6e2;
  border-radius: 8px;
  background: var(--assistant);
  color: var(--ink);
  font-size: 14px;
}

.attachment-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.attachment-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-bar button {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
}

#messageInput {
  min-height: 48px;
  max-height: 180px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  outline: none;
  background: white;
  color: var(--ink);
}

#messageInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 108, 114, 0.14);
}

#sendButton {
  width: 48px;
  height: 48px;
  align-self: end;
  background: var(--accent);
  color: white;
  font-size: 20px;
}

.icon-button {
  width: 48px;
  height: 48px;
  align-self: end;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf1ee;
  color: var(--ink);
  cursor: pointer;
  font-size: 24px;
}

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

#sendButton:hover {
  background: var(--accent-dark);
}

#sendButton:disabled,
#messageInput:disabled,
.icon-button:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 700px) {
  .app-shell {
    padding: 0;
  }

  .chat-panel {
    height: 100vh;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .topbar,
  .messages {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .text-button {
    flex: 1;
  }

  .bubble {
    max-width: 92%;
  }
}
