:root {
  --bg: #f3f1ec;
  --card: #ffffff;
  --ink: #1d2a30;
  --muted: #66727a;
  --line: #e2ded6;
  --accent: #1f5f6b;
  --accent-ink: #ffffff;
  --guest: #1f5f6b;
  --bot: #eef2f1;
  --staff: #fdf1dc;
  --error: #a3322a;
  --wait: #c9822b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: grid;
  place-items: center;
  padding: 16px;
}

h1, h2 { margin: 0; font-weight: 650; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }

button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.link { background: none; color: var(--accent); padding: 0; text-decoration: underline; }

input {
  font: inherit;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.chat-card {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.sub { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }

.messages {
  list-style: none;
  margin: 0;
  padding: 16px;
  height: 52vh;
  min-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg { max-width: 82%; padding: 8px 12px; border-radius: 12px; background: var(--bot); align-self: flex-start; }
.msg p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .who { display: block; font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.msg time { display: block; font-size: 0.7rem; color: var(--muted); margin-top: 2px; }
.msg-staff { background: var(--staff); }
.msg.mine { align-self: flex-end; background: var(--guest); color: #fff; }
.msg.mine .who, .msg.mine time { color: rgba(255, 255, 255, 0.75); }
.msg-system { align-self: center; background: none; color: var(--muted); font-size: 0.85rem; text-align: center; max-width: 100%; }

.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }

.end-form { padding: 12px; border-top: 1px solid var(--line); background: #faf9f6; }
.end-form label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 8px; }
.feedback { margin: 6px 0 0; font-size: 0.9rem; min-height: 1.2em; }
.feedback.error { color: var(--error); padding: 0 16px; }

.transport { margin-top: 10px; font-size: 0.8rem; color: var(--muted); text-align: center; }
.chat-card .transport { margin: 0; padding: 8px; border-top: 1px solid var(--line); }

/* Login */
.login-card { max-width: 360px; padding: 24px; gap: 12px; }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form button { margin-top: 8px; }
.login-card .feedback.error { padding: 0; }

/* Personale */
body.staff { display: block; }
.staff-bar { display: flex; align-items: center; gap: 16px; max-width: 1100px; margin: 0 auto 12px; }
.staff-bar span { color: var(--muted); font-size: 0.9rem; margin-left: auto; }
.staff-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; max-width: 1100px; margin: 0 auto; }
.staff-chat { max-width: none; }
.actions { display: flex; gap: 8px; }
aside h2 { margin-bottom: 8px; }
.conv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.conv button {
  width: 100%;
  text-align: left;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
}
.conv button strong { display: block; font-size: 0.85rem; }
.conv button span { display: block; font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-needs_staff button { border-left-color: var(--wait); }
.conv-staff button { border-left-color: var(--accent); }
.conv.active button { outline: 2px solid var(--accent); }

@media (max-width: 760px) {
  .staff-layout { grid-template-columns: 1fr; }
  .chat-header { flex-wrap: wrap; }
}
