:root {
  --taronja: #ff6b35;
  --taronja-fosc: #d94f1e;
  --blau: #1e4f9e;
  --blau-fosc: #143a75;
  --ceramica: #faf3e7;
  --paper: #fffdf8;
  --tinta: #1d1d1b;
  --gris: #6b6660;
  --ombra: 0 2px 10px rgba(29, 29, 27, .12);
  --mida-base: 100%;
}

* { box-sizing: border-box; }

html { font-size: var(--mida-base); }

body {
  margin: 0;
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--ceramica);
  color: var(--tinta);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Títol general ---------- */
.cap-general {
  text-align: center;
  padding: 1.1rem 1rem .9rem;
  background: var(--paper);
  border-bottom: 4px solid var(--taronja);
}

.cap-general h1 {
  margin: 0;
  font-weight: 800;
  font-size: 1.6rem;
  letter-spacing: .04em;
  color: var(--blau-fosc);
}

/* ---------- Barra d'eines ---------- */
.barra {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: .5rem;
  padding: .55rem 1.2rem;
  background: var(--paper);
  border-bottom: 1px solid #e8ddc9;
  position: sticky;
  top: 0;
  z-index: 10;
}

.grup { display: flex; gap: .25rem; }

.boto {
  font-family: inherit;
  font-weight: 700;
  border: 2px solid var(--blau);
  background: var(--blau);
  color: #fff;
  border-radius: 10px;
  padding: .35rem .8rem;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.boto:hover { background: var(--blau-fosc); border-color: var(--blau-fosc); }
.boto:active { transform: scale(.96); }

.boto.eina {
  background: var(--paper);
  color: var(--blau);
  border-color: var(--blau);
}

.boto.eina:hover { background: #eef3fb; }

.boto.eina.actiu {
  background: var(--taronja);
  border-color: var(--taronja);
  color: #fff;
}

.boto.or {
  background: var(--taronja);
  border-color: var(--taronja);
}

.boto.or:hover { background: var(--taronja-fosc); border-color: var(--taronja-fosc); }

.boto:disabled,
.boto.eina:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
}

.seleccio-idioma select {
  font-family: inherit;
  font-weight: 700;
  padding: .35rem .5rem;
  border: 2px solid var(--blau);
  border-radius: 10px;
  background: var(--paper);
  color: var(--blau-fosc);
  cursor: pointer;
}

/* ---------- Contingut: xat + rajola ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
}

.dua-col {
  display: flex;
  gap: 1.2rem;
  align-items: flex-start;
  flex: 1;
}

.columna-xat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.xat {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  padding: .8rem;
  min-height: 48vh;
  background: var(--paper);
  border: 2px solid var(--blau);
  border-radius: 16px;
}

.rajola {
  flex: 0 0 300px;
  max-width: 300px;
  margin-left: auto;
}

.rajola img {
  width: 100%;
  border-radius: 18%;
  border: 3px solid var(--blau);
  box-shadow: var(--ombra);
  display: block;
}

.missatge {
  max-width: 85%;
  padding: .65rem .9rem;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  box-shadow: var(--ombra);
  animation: apareix .2s ease-out;
}

@keyframes apareix {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.missatge.usuari {
  align-self: flex-end;
  background: var(--blau);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.missatge.agent {
  align-self: flex-start;
  background: var(--paper);
  border: 2px solid var(--taronja);
  border-bottom-left-radius: 4px;
}

.missatge.agent.pensant::after {
  content: "▍";
  color: var(--taronja);
  animation: parpella 1s infinite;
}

@keyframes parpella { 50% { opacity: 0; } }

/* ---------- Formulari ---------- */
.formulari {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-top: .7rem;
}

#entrada {
  flex: 1;
  font-family: inherit;
  font-size: 1rem;
  padding: .7rem .9rem;
  border: 2px solid var(--blau);
  border-radius: 12px;
  background: #fff;
  color: var(--tinta);
}

#entrada:focus { outline: 3px solid var(--taronja); border-color: var(--taronja); }

#entrada:disabled {
  background: #f0e9da;
  opacity: .7;
  cursor: not-allowed;
}

.boto.gran { font-size: 1.05rem; padding: .6rem .95rem; }

.estat {
  min-height: 1.3em;
  margin: .4rem .1rem 0;
  color: var(--gris);
  font-weight: 500;
}

/* ---------- Descàrrega ---------- */
.descarrega {
  text-align: center;
  margin-top: 1.2rem;
  padding: 1rem;
  background: var(--paper);
  border: 2px solid var(--taronja);
  border-radius: 16px;
  box-shadow: var(--ombra);
}

.descarrega p {
  margin: 0 0 .7rem;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--blau-fosc);
}

/* ---------- Peu ---------- */
.peu {
  text-align: center;
  padding: .9rem 1rem 1.2rem;
  background: var(--paper);
  border-top: 4px solid var(--blau);
  color: var(--gris);
}

.peu p { margin: .25rem 0; font-size: .95rem; }
.peu a { color: var(--taronja-fosc); font-weight: 700; }

.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;
}

/* ---------- Adaptacions ---------- */
[dir="rtl"] .missatge.usuari { align-self: flex-start; border-bottom-left-radius: 4px; border-bottom-right-radius: 16px; }
[dir="rtl"] .missatge.agent { align-self: flex-end; border-bottom-right-radius: 4px; border-bottom-left-radius: 16px; }
[dir="rtl"] .dua-col { flex-direction: row-reverse; }

@media (max-width: 680px) {
  .dua-col { flex-direction: column; }
  .rajola { flex: none; max-width: 220px; margin: 0 auto; }
  .cap-general h1 { font-size: 1.25rem; }
  .barra { gap: .35rem; padding: .5rem .7rem; }
  .missatge { max-width: 92%; }
}
