/* Design system Pixartprinting (come Bazar): Montserrat per titoli e marchio, Open Sans per il testo,
   blu #1174BA per le azioni, scala di grigi del brand. */
@font-face {
  font-family: "Montserrat";
  src: url("assets/Montserrat-Variable.ttf") format("truetype");
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Open Sans";
  src: url("assets/OpenSans-Variable.ttf") format("truetype");
  font-weight: 300 800; font-style: normal; font-display: swap;
}

:root {
  --white: #fff;
  --grey-25: #f7f7f7;
  --grey-50: #f2f2f2;
  --grey-100: #e5e5e5;
  --grey-200: #cacaca;
  --grey-500: #7b7b7b;
  --grey-700: #4a4a4a;
  --grey-850: #252525;
  --blue-50: #e7f1f8;
  --blue-500: #1174ba;
  --blue-600: #0e5d95;
  --blue-800: #072e4a;
  --red-500: #dd3e3e;
  --red-50: #fcecec;
  --yellow-500: #f7cd1b;
  --yellow-700: #99793b;

  --text-primary: var(--grey-850);
  --text-secondary: var(--grey-700);
  --text-tertiary: var(--grey-500);
  --border: var(--grey-100);
  --border-strong: var(--grey-200);
  --shadow: 0 8px 24px 0 #072e4a1f;

  --font-display: "Montserrat", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Open Sans", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --column: 780px;
  --gutter: clamp(16px, 4vw, 32px);
  --radius: 8px;
  /* dimensione del testo della conversazione, regolata dai pulsanti A− / A+ */
  --chat-size: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--grey-25);
  color: var(--text-primary);
  font: 16px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 2px; }

/* ---------- Marchio: logo Pixartprinting + nome dello strumento */
.brand { display: inline-flex; align-items: center; gap: 14px; margin: 0; white-space: nowrap; }
.brand-logo { height: 18px; width: auto; display: block; }
.brand-name {
  font: 600 1rem/1 var(--font-display); color: var(--text-primary);
  padding-left: 14px; border-left: 1px solid var(--border-strong);
}
.brand-large .brand-logo { height: 28px; }
.brand-large .brand-name { font-size: 1.5rem; padding-left: 18px; }
.brand-large { gap: 18px; }

/* ---------- Pulsanti */
.button {
  font: 600 .9375rem/1.2 var(--font-body); border-radius: var(--radius); cursor: pointer;
  padding: .7rem 1.25rem; border: 1px solid transparent;
}
.button-primary { background: var(--blue-500); color: var(--white); }
.button-primary:hover { background: var(--blue-600); }
.button-primary:disabled { background: var(--grey-200); color: var(--grey-500); cursor: progress; }
.button-quiet { background: transparent; color: var(--text-secondary); padding: .45rem .75rem; font-weight: 600; }
.button-quiet:hover { background: #1919191a; color: var(--text-primary); }

/* ---------- Accesso */
.login {
  min-height: 100%; max-width: 560px; margin: 0 auto;
  padding: 16vh var(--gutter) 4rem;
  display: flex; flex-direction: column; align-items: flex-start; gap: 1.5rem;
}
.login-text { margin: 0; font-size: 1.0625rem; line-height: 1.6; color: var(--text-secondary); max-width: 34em; }
.login-message { margin: 0; color: var(--red-500); min-height: 1.5em; font-size: .9375rem; }

/* ---------- Struttura */
.app { display: grid; grid-template-rows: auto auto 1fr auto; height: 100%; }
.topbar {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 14px var(--gutter); background: var(--white);
  border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.session-label { font-size: .8125rem; color: var(--text-tertiary); white-space: nowrap; }
.session-label.is-warning { color: var(--yellow-700); }
.session-label.is-expired { color: var(--red-500); }
.user-email { font-size: .8125rem; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Quanto resta della sessione */
.ink { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: transparent; }
.ink-level { height: 100%; width: 100%; background: var(--blue-500); transition: width 1s linear, background-color .4s; }
.ink-level.is-warning { background: var(--yellow-500); }
.ink-level.is-expired { background: var(--red-500); width: 100% !important; }

/* ---------- Schede delle conversazioni (come quelle del browser) */
.tabbar {
  display: flex; align-items: flex-end; gap: 2px;
  padding: 8px var(--gutter) 0; background: var(--grey-50); border-bottom: 1px solid var(--border);
}
.tablist { display: flex; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.tab {
  position: relative; display: flex; align-items: center; flex: 0 1 220px; min-width: 120px;
  border: 1px solid transparent; border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0;
  margin-bottom: -1px; color: var(--text-secondary);
}
.tab:hover { background: var(--grey-100); }
.tab.is-active { background: var(--grey-25); border-color: var(--border); color: var(--text-primary); }
.tab-open {
  flex: 1; min-width: 0; font: inherit; font-size: .8125rem; color: inherit; text-align: left;
  background: none; border: 0; cursor: pointer; padding: .5rem .25rem .5rem .75rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tab.is-active .tab-open { font-weight: 600; }
.tab.is-busy .tab-open::before {
  content: ""; display: inline-block; width: 7px; height: 7px; margin-right: .45rem; vertical-align: 1px;
  border-radius: 50%; background: var(--blue-500); animation: pulse 1.2s ease-in-out infinite;
}
.tab-close {
  flex: none; width: 22px; height: 22px; margin-right: 6px; padding: 0;
  font: 400 1rem/1 var(--font-body); color: var(--text-tertiary);
  background: none; border: 0; border-radius: 50%; cursor: pointer;
}
.tab-close:hover { background: var(--grey-200); color: var(--text-primary); }
.tab-new {
  flex: none; width: 30px; height: 30px; margin: 0 0 4px 4px; padding: 0;
  font: 400 1.25rem/1 var(--font-body); color: var(--text-secondary);
  background: none; border: 0; border-radius: 50%; cursor: pointer;
}
.tab-new:hover:not(:disabled) { background: var(--grey-100); color: var(--text-primary); }
.tab-new:disabled { color: var(--grey-200); cursor: not-allowed; }

/* ---------- Conversazione */
.conversation { overflow-y: auto; padding: 2rem var(--gutter) 1rem; font-size: var(--chat-size); }
.conversation > * { max-width: var(--column); margin-left: auto; margin-right: auto; }

.empty { padding-top: 9vh; }
.empty-title { margin: 0 0 1.25rem; font: 700 1.75em/1.25 var(--font-display); letter-spacing: -0.01em; }
.examples { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.example {
  font: inherit; font-size: .9375em; color: var(--text-secondary); text-align: left; cursor: pointer;
  background: var(--white); border: 1px solid var(--border-strong); border-radius: 999px; padding: .45rem .95rem;
}
.example:hover { border-color: var(--blue-500); color: var(--blue-600); background: var(--blue-50); }

.message { margin-bottom: 1.5rem; }
.message-user {
  /* allineata a destra della colonna (la regola .conversation > * la centrerebbe) */
  margin-left: auto; margin-right: max(0px, calc((100% - var(--column)) / 2));
  width: fit-content; max-width: min(85%, calc(var(--column) * .85));
  background: var(--blue-50); color: var(--blue-800);
  padding: .65rem 1rem; border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.message-agent {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.25rem; line-height: 1.6; overflow-wrap: anywhere;
}
.message-agent > :last-child { margin-bottom: 0; }
.message-agent p, .message-agent ul, .message-agent ol, .message-agent pre, .message-agent table { margin: 0 0 .85em; }
.message-agent h3, .message-agent h4, .message-agent h5 { font: 700 1em/1.4 var(--font-display); margin: 1.1em 0 .4em; }
.message-agent h3:first-child, .message-agent h4:first-child { margin-top: 0; }
.message-agent ul, .message-agent ol { padding-left: 1.4em; }
.message-agent li { margin-bottom: .25em; }
.message-agent a { color: var(--blue-500); }
.message-agent a:hover { color: var(--blue-600); }
.message-agent code { font: .875em/1.4 var(--font-mono); background: var(--grey-50); padding: .1em .35em; border-radius: 4px; }
.message-agent pre {
  font: .8125em/1.5 var(--font-mono); background: var(--grey-850); color: #f2f2f2;
  padding: .9rem 1rem; border-radius: var(--radius); overflow-x: auto;
}
.message-agent pre code { background: none; padding: 0; color: inherit; font: inherit; }
.message-agent table { border-collapse: collapse; font-size: .875em; display: block; overflow-x: auto; }
.message-agent th, .message-agent td { text-align: left; padding: .45rem .9rem .45rem 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.message-agent th { font-weight: 700; color: var(--text-secondary); border-bottom-color: var(--border-strong); }
.message-error {
  color: var(--red-500); background: var(--red-50); border-radius: var(--radius);
  padding: .75rem 1rem; font-size: .9375em;
}
.message-error .button { margin-left: .5rem; color: var(--red-500); }

/* ---------- Dimensione del testo */
.text-size { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.text-size .button-quiet { border-radius: 0; padding: .3rem .55rem; font-family: var(--font-display); line-height: 1; }
.text-size .button-quiet + .button-quiet { border-left: 1px solid var(--border-strong); }
.text-size .size-down { font-size: .75rem; }
.text-size .size-up { font-size: 1rem; }
.text-size .button-quiet:disabled { color: var(--grey-200); cursor: default; background: none; }

/* Mentre l'agente lavora */
.message-agent:has(.working) { background: transparent; border-color: transparent; padding-left: 0; }
.working { display: inline-flex; gap: 6px; padding: .25rem 0; }
.working span { width: 8px; height: 8px; border-radius: 50%; background: var(--blue-500); animation: pulse 1.2s ease-in-out infinite; }
.working span:nth-child(2) { animation-delay: .15s; }
.working span:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- Area di scrittura */
.composer {
  display: flex; gap: .6rem; align-items: flex-end;
  padding: .9rem var(--gutter) 1.25rem;
  max-width: calc(var(--column) + 2 * var(--gutter)); width: 100%; margin: 0 auto;
}
.composer textarea {
  flex: 1; resize: none; font: inherit; font-size: var(--chat-size); color: var(--text-primary); max-height: 40vh;
  padding: .7rem .9rem; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--white); box-shadow: var(--shadow);
}
.composer textarea:focus { border-color: var(--blue-500); outline: none; }

@media (max-width: 640px) {
  .user-email, .session-label { display: none; }
  .tab { flex-basis: 150px; min-width: 96px; }
  .topbar { padding-top: 10px; padding-bottom: 10px; }
  .topbar-right { gap: .25rem; }
  .brand { gap: 10px; }
  .brand-logo { height: 15px; }
  .brand-name { padding-left: 10px; font-size: .9375rem; }
  .brand-large .brand-logo { height: 22px; }
  .brand-large .brand-name { font-size: 1.25rem; }
  .message-user { max-width: 92%; }
}
@media (prefers-reduced-motion: reduce) {
  .working span, .tab.is-busy .tab-open::before { animation: none; opacity: .7; }
  .ink-level { transition: none; }
}
