:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f242e;
  --border: #2a313d;
  --text: #e7eaf0;
  --muted: #9aa4b2;
  --accent: #e2231a;      /* rosso accento primario */
  --accent-2: #2d7ff9;
  --user-bubble: #243043;
  --bot-bubble: #1b2029;
  --ok: #2ecc71;
  --err: #ff6b6b;
  --radius: 12px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
}

a { color: var(--accent-2); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; letter-spacing: 0.5px; }
.topbar .brand span { color: var(--accent); }
.topbar .brand .plurimedia {
  height: 30px;
  margin-left: 0.9rem;
  padding-left: 0.9rem;
  border-left: 1px solid var(--border);
  box-sizing: content-box;
  opacity: 0.9;
  vertical-align: middle;
}
.topbar .right { display: flex; align-items: center; gap: 1rem; }
.topbar .user { color: var(--muted); font-size: 0.9rem; }

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: var(--panel-2); border: 1px solid var(--border); }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.danger { background: #7a1f1f; }

/* --- Login --- */
.center-wrap {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 360px;
  max-width: 92vw;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.25rem; }
.card h1 { margin: 0; font-size: 1.4rem; }
.card h1 span { color: var(--accent); }
.card p.sub { margin: 0 0 1.5rem; color: var(--muted); font-size: 0.9rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; }
.field input, .field select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.6rem 0.7rem;
  font-size: 0.95rem;
}
.full { width: 100%; }
.card .powered {
  display: flex;
  justify-content: center;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.card .powered img { height: 30px; opacity: 0.9; }
.msg { font-size: 0.9rem; margin-top: 0.75rem; min-height: 1.2em; }
.msg.error { color: var(--err); }
.msg.ok { color: var(--ok); }

/* --- Chat --- */
.chat-shell { display: flex; flex-direction: column; height: 100vh; }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.messages-inner { max-width: 820px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 1rem; }
.bubble {
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  line-height: 1.5;
  white-space: normal;
  overflow-wrap: anywhere;
}
.bubble.user { background: var(--user-bubble); align-self: flex-end; max-width: 80%; }
.bubble.bot { background: var(--bot-bubble); align-self: flex-start; max-width: 92%; }
.bubble.bot.thinking { color: var(--muted); font-style: italic; }

/* contenuto markdown */
.bubble :first-child { margin-top: 0; }
.bubble :last-child { margin-bottom: 0; }
.bubble table { border-collapse: collapse; width: 100%; margin: 0.5rem 0; font-size: 0.9rem; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 0.4rem 0.55rem; text-align: left; }
.bubble th { background: var(--panel-2); }
.bubble code { background: #0d1017; padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.9em; }
.bubble pre { background: #0d1017; padding: 0.75rem; border-radius: 8px; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }

.composer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 1rem 1.5rem;
}
.composer-inner { max-width: 820px; margin: 0 auto; display: flex; gap: 0.75rem; align-items: flex-end; }
.composer textarea {
  flex: 1;
  resize: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 0.75rem;
  font-size: 0.97rem;
  font-family: inherit;
  max-height: 200px;
  min-height: 48px;
}
.hint { text-align: center; color: var(--muted); font-size: 0.75rem; margin: 0.5rem 0 0; }

.empty-state { color: var(--muted); text-align: center; margin: auto; max-width: 520px; }
.empty-state h2 { color: var(--text); }
.empty-state .examples { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1.25rem; }
.empty-state .example {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.7rem 0.9rem; cursor: pointer; text-align: left;
}
.empty-state .example:hover { border-color: var(--accent-2); }

/* --- Selettore lingua --- */
.lang-switch {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}
.lang-switch button {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.lang-switch button + button { border-left: 1px solid var(--border); }
.lang-switch button:hover { color: var(--text); }
.lang-switch button.active { background: var(--accent); color: #fff; }

/* --- Carrello --- */
.cart-btn { position: relative; display: inline-flex; align-items: center; }
.cart-count {
  position: absolute; top: -7px; right: -7px;
  background: var(--accent); color: #fff; border-radius: 999px;
  font-size: 0.68rem; line-height: 1; padding: 0.22rem 0.4rem; font-weight: 700;
}

/* Codici prodotto cliccabili nelle risposte del modello */
.bubble a[href^="#product="] {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.02rem 0.45rem;
  color: var(--text);
  text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.bubble a[href^="#product="]::after { content: " +"; color: var(--accent-2); font-weight: 700; }
.bubble a[href^="#product="]:hover { border-color: var(--accent-2); background: var(--user-bubble); }

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.overlay[hidden] { display: none; }
.dialog {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
  width: 440px; max-width: 100%;
  max-height: 85vh; overflow-y: auto;
}
.dialog h3 { margin: 0 0 1rem; }
.dialog-body { min-height: 40px; }
.dialog-loading { color: var(--muted); }
.dialog-product { margin: 0 0 0.25rem; }
.dialog-desc { margin: 0 0 0.5rem; color: var(--muted); font-size: 0.9rem; }
.dialog-meta { margin: 0; color: var(--muted); font-size: 0.9rem; }
.dialog-meta .discontinued { color: var(--err); }
.dialog-actions {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 1rem; margin-top: 1.25rem;
}
.qty-wrap label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; }
.qty-wrap input {
  width: 84px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: 0.5rem 0.6rem; font-size: 0.95rem;
}
.dialog-buttons { display: flex; gap: 0.5rem; }

.cart-panel { width: 640px; }
.cart-row {
  display: grid; grid-template-columns: 1fr 74px 92px 92px 30px;
  gap: 0.6rem; align-items: center;
  padding: 0.6rem 0; border-bottom: 1px solid var(--border);
}
.cart-article { font-size: 0.95rem; }
.cart-code { color: var(--muted); font-size: 0.8rem; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.cart-qty {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: 0.4rem 0.5rem;
}
.cart-price, .cart-line-total { text-align: right; font-size: 0.92rem; }
.cart-line-total { font-weight: 600; }
.cart-remove { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 0.2rem; }
.cart-remove:hover { color: var(--err); }
.cart-empty { color: var(--muted); text-align: center; padding: 1rem 0; }
.cart-note { color: var(--muted); font-size: 0.8rem; margin: 0.6rem 0 0; }
.cart-footer {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; margin-top: 1.25rem;
}
.cart-total { font-size: 1.05rem; }

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  z-index: 60;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 0.7rem 1.1rem; font-size: 0.92rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  max-width: min(92vw, 480px);
}

/* --- Admin --- */
.admin-wrap { max-width: 960px; margin: 2rem auto; padding: 0 1.25rem; }
.section {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem;
}
.section h2 { margin-top: 0; }
.stats { display: flex; flex-wrap: wrap; gap: 1rem; }
.stat { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 1rem; min-width: 110px; }
.stat .num { font-size: 1.5rem; font-weight: 700; }
.stat .label { color: var(--muted); font-size: 0.8rem; }
table.data { width: 100%; border-collapse: collapse; margin-top: 1rem; }
table.data th, table.data td { border-bottom: 1px solid var(--border); padding: 0.55rem 0.5rem; text-align: left; font-size: 0.9rem; }
table.data th { color: var(--muted); font-weight: 600; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; margin-top: 1rem; }
.inline-form .field { margin: 0; min-width: 150px; }
.badge { padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; }
.badge.admin { background: #3a2a12; color: #f0b25b; }
.badge.user { background: #1f2a3a; color: #6fa8ff; }
.dropzone {
  border: 2px dashed var(--border); border-radius: 10px; padding: 1.5rem;
  text-align: center; color: var(--muted); margin-top: 1rem;
}
.dropzone.drag { border-color: var(--accent-2); color: var(--text); }
.row-actions { display: flex; gap: 0.5rem; }
.spinner {
  display: inline-block; width: 14px; height: 14px; border: 2px solid var(--muted);
  border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
