/* ============================================================
   Il Tuo Primo Collaboratore AI - Editorial (viola AIM)
   White, type-first, high-contrast. Accent: #512BC1.
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --paper: #fbfaf8;          /* page */
  --surface: #ffffff;        /* cards, chat */
  --surface-2: #f6f4f1;      /* alt message band */
  --ink: #0a0a0a;            /* titles */
  --text: #1a1a1a;           /* body */
  --text-2: #6b6b72;         /* muted */
  --text-3: #9a9aa2;         /* faint */
  --accent: #512bc1;         /* viola AIM */
  --accent-press: #431f9f;
  --accent-soft: #f1edfb;    /* viola tint bg */
  --accent-line: #ded4f6;    /* viola hairline */
  --blue: #3b5eff;           /* secondary accent, rare */
  --border: #e7e4ea;
  --border-2: #efedf1;
  --shadow-lg: 0 1px 2px rgba(20,10,50,0.04), 0 12px 40px rgba(30,15,70,0.08);
  --r: 4px;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--sans);
  background: var(--paper);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app { height: 100%; display: flex; flex-direction: column; }

/* ===================== WELCOME (editorial hero) ===================== */

.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  background: var(--paper);
}

.welcome-content {
  width: 100%;
  max-width: 640px;
  animation: fadeUp 0.55s cubic-bezier(.2,.7,.2,1);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.welcome-logo { display: none; }  /* editorial: type-first, no app-icon */

.welcome-eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.welcome-eyebrow::before {
  content: "";
  width: 26px;
  height: 2px;
  background: var(--accent);
  display: inline-block;
}

.welcome-title {
  font-size: clamp(38px, 7vw, 64px);
  font-weight: 800;
  letter-spacing: -2.5px;
  line-height: 0.98;
  color: var(--ink);
  margin-bottom: 22px;
}

.welcome-sub {
  font-size: 19px;
  color: var(--text-2);
  line-height: 1.55;
  margin-bottom: 30px;
  max-width: 30em;
  font-weight: 400;
}
.welcome-sub strong { color: var(--ink); font-weight: 600; }

.welcome-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 30px;
}

.pill {
  font-size: 13px;
  font-weight: 500;
  padding: 9px 15px;
  border-radius: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.18s ease;
}
.pill:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.welcome-microline {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 34px;
  letter-spacing: 0.2px;
}

.welcome-by {
  font-size: 15px;
  color: var(--text);
  padding-top: 26px;
  border-top: 1px solid var(--border);
}
.welcome-by strong { font-weight: 700; color: var(--ink); }

.welcome-trust {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 6px;
  line-height: 1.5;
}

.welcome-footer { margin-top: 18px; }
.welcome-footer a {
  font-size: 12px;
  color: var(--text-3);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.welcome-footer a:hover { color: var(--text-2); }

/* ===================== CHAT ===================== */

.chat-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

@media (min-width: 800px) {
  .chat-wrapper {
    margin-top: 20px;
    margin-bottom: 20px;
    height: calc(100% - 40px);
    flex: none;
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
  }
}

/* Header */
.header {
  padding: 16px 26px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-content { display: flex; align-items: center; justify-content: space-between; }
.header-left { display: flex; align-items: center; gap: 11px; }
.header-logo { display: none; }
.header-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.2px;
}
.header-left::before {
  content: "";
  width: 9px; height: 9px;
  border-radius: 2px;
  background: var(--accent);
  transform: rotate(45deg);
  display: inline-block;
}

.btn-icon {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px;
  cursor: pointer;
  color: var(--text-3);
  transition: all 0.15s;
  display: flex;
  align-items: center;
}
.btn-icon:hover { color: var(--accent); border-color: var(--accent-line); }

/* Chat area */
.chat-area {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  background: var(--surface);
}
.chat-messages { display: flex; flex-direction: column; }

/* Messages: editorial, label + rule + reading measure */
.message {
  padding: 26px 30px;
  animation: msgIn 0.3s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: translateY(0);} }

.message.user { background: var(--surface-2); }
.message.ai { background: var(--surface); }
.message + .message { border-top: 1px solid var(--border-2); }

.message-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  margin-bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.message.ai .message-label { color: var(--accent); }
.message.ai .message-label::after {
  content: "";
  flex: 0 0 22px;
  height: 1px;
  background: var(--accent-line);
}
.message.user .message-label { color: var(--text-3); }

.message-content {
  line-height: 1.72;
  font-size: 15.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text);
}
.message-content strong { font-weight: 700; color: var(--ink); }
.message-content em { font-style: italic; color: var(--text-2); }

/* section heading emitted by formatContent (### -> .md-h) */
.md-h {
  font-size: 15px;
  font-weight: 800;
  display: block;
  margin: 24px 0 8px;
  color: var(--ink);
  letter-spacing: -0.2px;
}

.message-content code {
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent-press);
}
.message-content a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* Profile / code blocks: the deliverable, framed */
.profile-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--r);
  padding: 22px 24px;
  margin: 22px 0;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.72;
  white-space: pre-wrap;
  color: var(--text);
  position: relative;
  box-shadow: 0 1px 2px rgba(20,10,50,0.03);
  overflow-x: auto;
}
.profile-block::before {
  content: "PROMPT PRONTO / COPIA E INCOLLA";
  display: block;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--accent);
  margin-bottom: 15px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-2);
}

/* ===================== THINKING INDICATOR ===================== */
.thinking { padding: 26px 30px; animation: msgIn 0.3s ease; }
.thinking-label {
  font-size: 11px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--accent); margin-bottom: 12px; display: inline-flex; align-items: center; gap: 8px;
}
.thinking-row { display: flex; align-items: center; gap: 12px; }
.thinking-mark {
  width: 11px; height: 11px; border-radius: 2px; flex-shrink: 0;
  background: var(--accent);
  animation: thinkPulse 1.15s ease-in-out infinite;
}
@keyframes thinkPulse {
  0%, 100% { transform: rotate(45deg) scale(0.7); opacity: 0.45; }
  50% { transform: rotate(45deg) scale(1); opacity: 1; }
}
.thinking-text {
  font-size: 15px; color: var(--text-2); line-height: 1.5;
  transition: opacity 0.35s ease;
}
.thinking-text.swap { opacity: 0; }

/* ===================== DOWNLOAD / KIT BAR ===================== */
.download-bar {
  padding: 14px 26px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: none;
  flex-shrink: 0;
}
.download-bar.visible { display: block; animation: slideUp 0.3s ease; }
@keyframes slideUp { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

.download-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn-download, .btn-kit {
  flex: 1 1 220px;
  padding: 13px 20px;
  border-radius: var(--r);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-download {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--accent-line);
}
.btn-download:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn-download svg { stroke: var(--accent); }

.btn-kit {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
}
.btn-kit:hover { background: var(--accent-press); }

.kit-confirm {
  font-size: 13.5px;
  color: var(--accent-press);
  margin-top: 10px;
  line-height: 1.5;
  display: none;
}
.kit-confirm.visible { display: block; }

/* ===================== INPUT ===================== */
.input-area {
  padding: 16px 26px 22px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 8px 8px 18px;
  transition: all 0.18s;
}
.input-container:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#userInput {
  flex: 1;
  border: none;
  background: none;
  font-size: 15.5px;
  line-height: 1.5;
  resize: none;
  outline: none;
  font-family: inherit;
  color: var(--text);
  max-height: 132px;
  padding: 6px 0;
}
#userInput::placeholder { color: var(--text-3); }

.btn-send {
  width: 40px; height: 40px;
  border-radius: var(--r);
  border: none;
  background: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.btn-send svg { stroke: #fff; }
.btn-send:disabled { background: var(--border); cursor: not-allowed; }
.btn-send:disabled svg { stroke: var(--text-3); }
.btn-send:not(:disabled):hover { background: var(--accent-press); }

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,8,40,0.42);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0;} to { opacity: 1;} }
.modal {
  background: var(--surface);
  border-radius: 8px;
  padding: 30px 30px 28px;
  width: 100%;
  max-width: 440px;
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.28s cubic-bezier(.2,.7,.2,1);
}
.modal-close {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none;
  font-size: 26px; line-height: 1;
  color: var(--text-3); cursor: pointer;
}
.modal-close:hover { color: var(--ink); }
.modal-title { font-size: 22px; font-weight: 800; color: var(--ink); letter-spacing: -0.5px; margin-bottom: 8px; }
.modal-text { font-size: 14.5px; color: var(--text-2); line-height: 1.55; margin-bottom: 20px; }
.modal-field { display: block; margin-bottom: 14px; }
.modal-field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.modal-field input, .modal-field select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 14.5px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: all 0.15s;
}
.modal-field input:focus, .modal-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.modal-consent {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 16px 0 6px;
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.5;
}
.modal-consent input { margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; }
.modal-consent a { color: var(--accent); }
.modal-error { color: #c0392b; font-size: 13px; margin: 4px 0 0; }
.btn-kit-submit {
  width: 100%;
  margin-top: 16px;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-kit-submit:hover { background: var(--accent-press); }
.btn-kit-submit:disabled { background: var(--text-3); cursor: not-allowed; }

/* ===================== SCROLLBAR ===================== */
.chat-area::-webkit-scrollbar { width: 8px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.chat-area::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 800px) {
  .chat-wrapper { border: none; }
  .message, .thinking { padding: 22px 18px; }
  .header { padding: 14px 18px; }
  .input-area { padding: 12px 18px 18px; }
  .download-bar { padding: 12px 18px; }
}
@media (max-width: 480px) {
  .welcome-sub { font-size: 17px; }
  .message-content { font-size: 15px; }
  .profile-block { padding: 18px; font-size: 12.5px; }
  .btn-download, .btn-kit { flex-basis: 100%; }
}
