/* Brand identity: AG Hotel Consulting (aghotelconsulting.it)
   arancio #ea6838 · marrone #423a38 · greige #f0eeec/#dfdcdc · taupe #5f564f
   Playfair Display (titoli) + Open Sans (testo) */

:root {
  --bg: #f0eeec;
  --panel: #ffffff;
  --panel-2: #f7f5f3;
  --line: #dfdcdc;
  --text: #423a38;
  --muted: #6f6761;
  --accent: #ea6838;
  --accent-dark: #c9532a;
  --ok: #4c8f6a;
  --no: #b0413e;
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; width: 100%; }
html { background: var(--bg); }
body {
  touch-action: manipulation; /* niente zoom da doppio tap: il layout resta inchiodato */
  font-family: "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

h1, h3, .header-title strong { font-family: "Playfair Display", Georgia, serif; }

.hidden { display: none !important; }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand-logo { height: 34px; display: block; }
.header-title { display: flex; flex-direction: column; line-height: 1.15; }
.header-title strong { font-size: 18px; letter-spacing: .3px; }
#status-line { font-size: 12px; color: var(--muted); }
nav { margin-left: auto; display: flex; gap: 6px; }
.tab {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  padding: 7px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
  font-family: inherit;
}
.tab.active { background: var(--bg); color: var(--text); border-color: var(--line); }
.badge {
  background: var(--accent); color: white; border-radius: 999px;
  font-size: 11px; padding: 1px 7px; margin-left: 4px;
}
.tab.help {
  text-decoration: none; font-weight: 700; color: var(--accent);
  border: 1px solid var(--line); display: flex; align-items: center;
}

/* ---------- logo M (fallback e PIN) ---------- */
.logo-dot {
  width: 56px; height: 56px; border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 28px; color: white;
  font-family: "Playfair Display", Georgia, serif;
}

/* ---------- chat ---------- */
main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#messages {
  flex: 1; overflow-y: auto; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 7px;
  overscroll-behavior: contain;
}
.msg {
  max-width: 88%; padding: 8px 12px; border-radius: 14px;
  font-size: 15px; line-height: 1.42; white-space: pre-wrap; word-wrap: break-word;
}
.msg.user {
  align-self: flex-end; background: var(--accent); color: white;
  border-bottom-right-radius: 5px;
}
.msg.miranda {
  align-self: flex-start; background: var(--panel);
  border: 1px solid var(--line); border-bottom-left-radius: 5px;
}
.msg.thinking { color: var(--muted); font-style: italic; }
.msg.error { align-self: center; background: #f7e4e2; color: var(--no); font-size: 13px; }

/* ---------- composer ---------- */
#composer {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--panel); border-top: 1px solid var(--line);
}
#text-input {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 999px; padding: 11px 16px; font-size: 15px; outline: none;
  font-family: inherit;
}
#text-input::placeholder { color: var(--muted); }
#text-input:focus { border-color: var(--accent); }
#composer button {
  width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
#mic-btn { background: var(--panel-2); color: var(--accent); border: 1px solid var(--line); transition: transform .15s ease, background .15s ease; }
#mic-btn.recording {
  background: var(--no); color: white; border-color: var(--no);
  transform: scale(1.35);
  animation: ring 1.4s ease-out infinite;
}
@keyframes ring {
  0%   { box-shadow: 0 0 0 0 rgba(176, 65, 62, .45); }
  70%  { box-shadow: 0 0 0 14px rgba(176, 65, 62, 0); }
  100% { box-shadow: 0 0 0 0 rgba(176, 65, 62, 0); }
}
#send-btn { background: var(--accent); color: white; }
#send-btn:active { background: var(--accent-dark); }

/* barra di registrazione stile WhatsApp: sostituisce il campo testo mentre registri */
#rec-bar {
  flex: 1; display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; background: var(--panel-2);
  border: 1px solid var(--no); border-radius: 999px;
}
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--no);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
#rec-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--no); font-size: 15px; }
.rec-hint { margin-left: auto; color: var(--muted); font-size: 13px; }
#composer.rec-mode #text-input, #composer.rec-mode #send-btn { display: none; }
#composer.rec-mode #rec-bar { display: flex; }

/* ---------- risposte rapide ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-self: flex-start; max-width: 82%; }
.chip {
  background: var(--panel); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.chip:active { background: var(--accent); color: white; }

/* card di approvazione dentro la chat */
.approval.inline { align-self: flex-start; max-width: 88%; border-left: 3px solid var(--accent); }
.decision-note { font-size: 13px; font-weight: 600; color: var(--muted); }
.decision-note.ok { color: var(--ok); }
.decision-note.no { color: var(--no); }

/* storico approvazioni */
.section-title {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 16px; color: var(--muted);
  margin: 6px 2px 0;
}
.approval.history { opacity: .85; }
.approval.history .body { max-height: 90px; }

/* ---------- approvazioni ---------- */
#approvals-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.empty { color: var(--muted); text-align: center; margin-top: 40px; }
.approval {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.approval .kind { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--accent); font-weight: 700; }
.approval h3 { font-size: 17px; margin: 6px 0 2px; }
.approval .to { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.approval .body {
  font-size: 14px; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; margin-bottom: 12px;
  max-height: 180px; overflow-y: auto;
}
.approval .actions { display: flex; gap: 10px; }
.approval button {
  flex: 1; padding: 10px; border-radius: 10px; border: none;
  font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-approve { background: var(--accent); color: white; }
.btn-approve:active { background: var(--accent-dark); }
.btn-reject { background: transparent; color: var(--muted); border: 1px solid var(--line) !important; }

/* ---------- PIN overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.pin-card { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 280px; text-align: center; }
.pin-card .brand-logo { height: 48px; margin-bottom: 4px; }
.pin-card h1 { font-size: 26px; }
.pin-card p { color: var(--muted); font-size: 14px; }
.pin-card input {
  width: 100%; text-align: center; letter-spacing: 8px; font-size: 22px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px; outline: none;
}
.pin-card input:focus { border-color: var(--accent); }
.pin-card input.cred { letter-spacing: normal; font-size: 16px; text-align: left; }
.pin-card button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.pin-card button.linklike {
  background: none; border: none; color: var(--accent-dark);
  font-size: 14px; text-decoration: underline; cursor: pointer; padding: 0;
}
.pin-card .info-msg { color: var(--muted) !important; }
.pin-card .ok-msg { color: var(--ok) !important; }
.pin-card button {
  width: 100%; padding: 12px; border-radius: 12px; border: none;
  background: var(--accent); color: white; font-size: 16px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.pin-error { color: var(--no) !important; }
