:root {
  color-scheme: dark;

  --bg: #000000;
  --sidebar-bg: #111111;
  --sidebar-border: #242424;
  --sidebar-hover: #1f1f1f;
  --composer: #242424;
  --composer-border: #333333;
  --text: #ffffff;
  --muted: #a3a3a3;
  --button: #ffffff;
  --button-text: #000000;
  --user: #2f2f2f;
  --assistant: transparent;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

body {
  overflow: hidden;
}

/* ========================= */
/* LAYOUT GENERALE */
/* ========================= */

.app-layout {
  height: 100vh;
  display: flex;
  background: var(--bg);
}

/* ========================= */
/* SIDEBAR SINISTRA */
/* ========================= */

.sidebar {
  width: 280px;
  height: 100vh;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 14px 12px;
  overflow-y: auto;
}

.sidebar-header {
  padding: 4px 8px 14px;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.sidebar-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.sidebar-section {
  margin-top: 8px;
}

.sidebar-section-title {
  width: 100%;
  height: auto;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  cursor: pointer;
}

.sidebar-section-title:hover {
  background: var(--sidebar-hover);
}

.sidebar-toggle-icon {
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.recent-people-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sidebar-empty {
  padding: 10px 8px;
  color: var(--muted);
  font-size: 14px;
}

.recent-person-button {
  width: 100%;
  height: auto;
  border: 0;
  border-radius: 8px;
  padding: 3px 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  display: block;
  margin-bottom: 8px;
}

.recent-person-button:hover {
  background: var(--sidebar-hover);
}

.recent-person-button.selected {
  background: #2a2a2a;
  box-shadow: inset 3px 0 0 #ffffff;
}

.recent-person-button::before {
  content: "";
}

.recent-person-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-person-email {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shopping-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.shopping-item {
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 8px;
}

.shopping-item:hover {
  background: var(--sidebar-hover);
}

.shopping-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-list-item-text {
  color: var(--text);
  font-family: Calibri, Arial, sans-serif;
  font-size: 12pt;
  font-weight: 400;
  line-height: 1.2;
  margin: 0;
  padding: 0;
}

.shopping-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.shopping-icon-button {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  display: grid;
  place-items: center;
}

.shopping-icon-button:hover {
  background: #2b2b2b;
}

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

.chat-app {
  height: 100vh;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.chat-header {
  display: none;
}

.mobile-header,
.mobile-suggestions {
  display: none;
}

.agent-mode-exit {
  width: auto;
  height: 42px;
  flex-shrink: 0;
  border-radius: 999px;
  margin-left: auto;
  padding: 0 16px;
  background: rgba(21, 21, 21, 0.72);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(14px);
  font-size: 14px;
  font-weight: 700;
}

.agent-mode-exit:hover {
  color: var(--text);
  background: rgba(42, 42, 42, 0.82);
}

.agent-mode-exit[hidden] {
  display: none;
}

/* ========================= */
/* AREA MESSAGGI */
/* ========================= */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 20px 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.message {
  width: min(840px, 100%);
  display: flex;
  margin-bottom: 24px;
}

.message.assistant {
  justify-content: flex-start;
}

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

.bubble {
  max-width: 720px;
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.assistant .bubble {
  background: transparent;
  color: var(--text);
}

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

/* ========================= */
/* STATO INIZIALE */
/* ========================= */

.chat-app.empty .messages {
  justify-content: center;
  padding-bottom: 260px;
}

.chat-app.empty .message {
  justify-content: center;
  margin-bottom: 0;
}

.chat-app.empty .message.assistant .bubble {
  width: 100%;
  max-width: 100%;
  padding: 0;
  background: transparent;
  font-size: 30px;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
  white-space: normal;
}

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

.chat-app:not(.empty) .messages {
  justify-content: flex-start;
  padding-top: 48px;
}

.chat-app.agent-mode:not(.empty) .messages {
  padding-top: 90px;
}

.chat-app:not(.empty) .welcome-message {
  display: none;
}

.chat-app:not(.empty) .message.assistant .bubble {
  font-size: 16px;
  font-weight: 400;
  text-align: left;
  width: auto;
  max-width: 720px;
  margin-top: 0;
}

.chat-app:not(.empty) .message.user .bubble {
  max-width: 70%;
}

/* ========================= */
/* INPUT */
/* ========================= */

.composer {
  position: absolute;
  left: 0;
  right: 0;
  padding: 0 20px 24px;
  transition: bottom 0.25s ease;
}

.chat-app.empty .composer {
  bottom: 32%;
}

.chat-app:not(.empty) .composer {
  bottom: 0;
}

.composer-inner {
  max-width: 840px;
  margin: 0 auto;
}

.composer-box {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  background: var(--composer);
  border: 1px solid var(--composer-border);
  border-radius: 999px;
  padding: 8px 10px 8px 20px;
}

textarea {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  max-height: 140px;
}

textarea::placeholder {
  color: var(--muted);
}

button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  font-size: 24px;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
}

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

.composer-tool-button {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: transparent;
  color: var(--text);
  font-size: 20px;
}

.composer-tool-button:hover {
  background: #333333;
}

/* ========================= */
/* BOTTONI SCELTA EVENTI */
/* ========================= */

.choice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.choice-button {
  width: 100%;
  height: auto;
  border-radius: 14px;
  padding: 14px;
  text-align: left;
  font-size: 14px;
  background: #242424;
  color: white;
  border: 1px solid #444;
}

.choice-button.danger {
  background: #5f1f1f;
  border-color: #9f3a3a;
}

.contact-choice-button {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.contact-choice-name,
.contact-choice-email {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.contact-choice-name {
  font-weight: 700;
}

.contact-choice-email {
  color: var(--muted);
  font-size: 13px;
}

.choice-button::before {
  content: "";
}

/* ========================= */
/* MOBILE */
/* ========================= */

@media (max-width: 768px) {
  html,
  body {
    height: 100dvh;
  }

  body {
    overflow: hidden;
  }

  .app-layout {
    display: block;
    height: 100dvh;
  }

  .sidebar {
    display: none;
  }

  body.mobile-sidebar-open .sidebar {
    display: block;
    position: fixed;
    z-index: 30;
    top: calc(env(safe-area-inset-top) + 84px);
    left: 18px;
    right: 18px;
    width: auto;
    height: auto;
    max-height: min(58dvh, 430px);
    border: 1px solid var(--sidebar-border);
    border-radius: 24px;
    overflow-y: auto;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
  }

  .chat-app {
    height: 100dvh;
    min-height: 100dvh;
    background: #000000;
    overflow: hidden;
  }

  .mobile-header {
    position: absolute;
    z-index: 20;
    top: calc(env(safe-area-inset-top) + 45px);
    left: 15px;
    right: 15px;
    display: flex;
    align-items: center;
    gap: 11px;
    pointer-events: none;
  }

  .mobile-header-button,
  .mobile-title-pill {
    pointer-events: auto;
  }

  .mobile-header-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #151515;
    color: #ffffff;
    border: 1px solid #2d2d2d;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0;
  }

  .mobile-header-button span {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 999px;
    background: #ffffff;
  }

  .mobile-title-pill {
    height: 42px;
    min-width: 96px;
    padding: 0 15px;
    border-radius: 999px;
    background: #151515;
    border: 1px solid #2d2d2d;
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    line-height: 42px;
    text-align: center;
  }

  .messages {
    height: 100%;
    padding: calc(env(safe-area-inset-top) + 112px) 30px 118px;
    overflow-y: auto;
  }

  .agent-mode-exit {
    height: 42px;
    padding: 0 14px;
    font-size: 13px;
  }

  .chat-app.empty .messages {
    justify-content: flex-start;
    padding-bottom: 118px;
  }

  .chat-app.empty .welcome-message {
    display: none;
  }

  .chat-app.empty .message.assistant .bubble {
    font-size: 24px;
  }

  .mobile-suggestions {
    position: absolute;
    z-index: 10;
    left: 24px;
    right: 24px;
    bottom: calc(env(safe-area-inset-bottom) + 94px);
    display: none;
    flex-direction: column;
    gap: 20px;
  }

  .chat-app.empty .mobile-suggestions {
    display: flex;
  }

  .mobile-suggestion-button {
    width: 100%;
    height: 34px;
    border-radius: 0;
    background: transparent;
    border: 0;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 17px;
    padding: 0;
    font-size: 16px;
    font-weight: 400;
    text-align: left;
  }

  .mobile-suggestion-icon {
    width: 22px;
    flex: 0 0 22px;
    color: #ffffff;
    font-size: 19px;
    line-height: 1;
    text-align: center;
  }

  .composer,
  .chat-app.empty .composer,
  .chat-app:not(.empty) .composer {
    bottom: env(safe-area-inset-bottom);
    padding: 0 30px 24px;
  }

  .composer-inner {
    max-width: none;
  }

  .composer-box {
    min-height: 43px;
    gap: 9px;
    padding: 5px 5px 5px 14px;
    border-radius: 999px;
    background: #151515;
    border-color: #333333;
  }

  textarea {
    font-size: 16px;
    line-height: 1.25;
  }

  textarea::placeholder {
    color: #858585;
  }

  .composer-tool-button {
    order: -1;
    width: 25px;
    height: 25px;
    color: #ffffff;
    font-size: 0;
  }

  .composer-tool-button::before {
    content: "+";
    font-size: 34px;
    line-height: 25px;
    font-weight: 300;
  }

  #createButton {
    width: 35px;
    height: 35px;
    flex-shrink: 0;
    font-size: 20px;
  }

  .chat-app:not(.empty) .messages {
    padding-top: calc(env(safe-area-inset-top) + 112px);
  }

  .message {
    width: 100%;
  }

  .chat-app:not(.empty) .message.assistant .bubble {
    max-width: 100%;
  }

  .chat-app:not(.empty) .message.user .bubble {
    max-width: 85%;
  }
}
