:root {
  --green: #0e7c66;
  --green-dark: #0a5c4c;
  --it-1: #1e88e5;
  --it-2: #1565c0;
  --bn-1: #2e7d32;
  --bn-2: #1b5e20;
  --bg: #f3f6f5;
  --card: #ffffff;
  --ink: #14201d;
  --muted: #6b7c77;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  --radius: 22px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans Bengali", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 26px; }
.brand-name { font-size: 22px; font-weight: 700; letter-spacing: 0.5px; }
.icon-btn {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: #fff;
  font-size: 20px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
}

/* Feed */
.feed {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.welcome { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.welcome-big { font-size: 22px; font-weight: 600; color: var(--ink); margin: 0 0 10px; }
.welcome-sub { font-size: 17px; margin: 0; }

/* Bolle conversazione */
.bubble {
  max-width: 88%;
  padding: 14px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--card);
  animation: pop 0.18s ease-out;
}
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.bubble.it { align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble.bn { align-self: flex-start; border-bottom-left-radius: 6px; }

.bubble .src { font-size: 15px; color: var(--muted); margin: 0 0 6px; }
.bubble .dst { font-size: 24px; font-weight: 600; line-height: 1.35; margin: 0; }
.bubble.bn .dst { font-family: "Noto Sans Bengali", system-ui, sans-serif; }

.bubble-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.bubble-actions button {
  border: none;
  border-radius: 14px;
  padding: 9px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.act-speak { background: #eef3f1; color: var(--green-dark); }
.act-wa { background: #25d366; color: #fff; }

.bubble.pending .dst { color: var(--muted); font-style: italic; font-weight: 400; }

/* Domanda di chiarimento: chi ha parlato deve rispondere meglio */
.bubble.clarify {
  align-self: center;
  max-width: 94%;
  background: #fff8e1;
  border: 2px solid #ffca28;
}
.bubble.clarify .dst { color: #8a6d00; font-size: 21px; }

/* Status */
.status {
  text-align: center;
  font-size: 15px;
  color: var(--green-dark);
  padding: 6px 0;
  font-weight: 600;
}

/* Mic buttons */
.mics {
  display: flex;
  gap: 14px;
  padding: 14px;
}
.mic {
  flex: 1;
  border: none;
  border-radius: 26px;
  padding: 20px 10px;
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow);
  transition: transform 0.08s;
  min-height: 120px;
}
.mic:active { transform: scale(0.97); }
.mic-it { background: linear-gradient(135deg, var(--it-1), var(--it-2)); }
.mic-bn { background: linear-gradient(135deg, var(--bn-1), var(--bn-2)); }
.mic .flag { font-size: 46px; line-height: 1; }
.mic-label { font-size: 18px; font-weight: 700; text-align: center; line-height: 1.2; }

.mic.listening { animation: pulse 1s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(14, 124, 102, 0.5); }
  70% { box-shadow: 0 0 0 18px rgba(14, 124, 102, 0); }
  100% { box-shadow: 0 0 0 0 rgba(14, 124, 102, 0); }
}
.mic[disabled] { opacity: 0.5; }

/* Type row */
.type-row {
  display: flex;
  gap: 8px;
  padding: 0 14px 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  align-items: center;
}
.type-row select {
  border: 1px solid #d4ddda;
  border-radius: 14px;
  padding: 12px 8px;
  font-size: 16px;
  background: var(--card);
}
.type-row input {
  flex: 1;
  border: 1px solid #d4ddda;
  border-radius: 14px;
  padding: 13px 14px;
  font-size: 17px;
  min-width: 0;
}
.send-btn {
  border: none;
  background: var(--green);
  color: #fff;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Settings panel */
.panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
.panel-card {
  background: var(--card);
  width: 100%;
  max-width: 640px;
  border-radius: 24px 24px 0 0;
  padding: 24px 22px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  animation: slideUp 0.2s ease-out;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.panel-card h2 { margin: 0 0 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; font-size: 15px; color: var(--muted); }
.field input[type="tel"] {
  border: 1px solid #d4ddda;
  border-radius: 12px;
  padding: 12px;
  font-size: 17px;
  color: var(--ink);
}
.field.check { flex-direction: row; align-items: center; gap: 10px; font-size: 16px; color: var(--ink); }
.field.check input { width: 22px; height: 22px; }
.hint { font-size: 13px; color: var(--muted); margin: -8px 0 18px; }
.primary-btn {
  width: 100%;
  border: none;
  background: var(--green);
  color: #fff;
  padding: 15px;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}

/* ===== Nuova interfaccia: un riquadro + un microfono ===== */
.bubble.pending { align-self: center; }
.bubble .src, .bubble .dst { cursor: pointer; }
.bubble .src:active, .bubble .dst:active { opacity: 0.6; }

.bubble-actions .act {
  border: none;
  border-radius: 14px;
  padding: 9px 13px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.act-speak { background: #eef3f1; color: var(--green-dark); }
.act-copy { background: #e8eef7; color: #1565c0; }
.act-wa { background: #25d366; color: #fff; }

/* versione in lettere latine (Banglish) */
.roman-block {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed #cdd8d4;
}
.roman-label {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
}
.roman {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink);
  cursor: pointer;
}
.roman:active { opacity: 0.6; }
.roman-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.input-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
}
.input-bar input {
  flex: 1;
  min-width: 0;
  border: 1px solid #d4ddda;
  border-radius: 24px;
  padding: 14px 18px;
  font-size: 17px;
  background: var(--card);
}
.mic-btn {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: #fff;
  font-size: 26px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.mic-btn.listening { animation: pulse 1s infinite; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  background: #14201d;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 15px;
  font-weight: 600;
  z-index: 30;
  box-shadow: var(--shadow);
}

[hidden] { display: none !important; }
