/* ─── Variabili ────────────────────────────────────────────────────────────── */
:root {
  --giallo:     #ffd601;
  --blu:        #142b6f;
  --crema:      #f9f6ea;
  --blu-light:  #1e3d99;
  --grigio:     #e5e5e5;
  --grigio-mid: #999;
  --testo:      #1a1a1a;
  --bianco:     #ffffff;

  --font-main: 'Baskerville', 'Baskerville Old Face', Georgia, serif;
  --radius:    8px;
  --sidebar-w: 200px;
}

/* ─── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-main);
  background: var(--crema);
  color: var(--testo);
  height: 100vh;
  overflow: hidden;
}

/* ─── Layout shell ───────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--blu);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-logo {
  padding: 24px 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo-icon { font-size: 22px; }

.logo-text {
  color: var(--giallo);
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 1px;
}

.nav-menu {
  list-style: none;
  padding: 16px 0;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: var(--bianco);
}

.nav-item.active {
  background: rgba(255,214,1,0.15);
  color: var(--giallo);
  border-left-color: var(--giallo);
}

.nav-icon { font-size: 18px; }
.nav-label { font-size: 14px; }

.sidebar-footer {
  padding: 16px;
  text-align: center;
  color: rgba(255,255,255,0.3);
  font-size: 11px;
}

/* nascosto su desktop, visibile solo su mobile */
.mobile-header { display: none; }
.btn-back      { display: none; }

/* ─── Main content ───────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
}

/* ─── Utility ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 14px;
  transition: opacity 0.2s;
}
.btn:hover { opacity: 0.85; }

.btn-primary   { background: var(--blu);    color: var(--bianco); }
.btn-secondary { background: var(--giallo); color: var(--blu); font-weight: bold; }
.btn-ghost     { background: transparent;   color: var(--blu); border: 1px solid var(--blu); }
.btn-danger    { background: #e53935;       color: var(--bianco); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: bold;
}
.badge-unread  { background: var(--giallo); color: var(--blu); }
.badge-ai      { background: #7c3aed;       color: var(--bianco); }
.badge-ok      { background: #22c55e;       color: var(--bianco); }
.badge-pending { background: var(--grigio); color: var(--grigio-mid); }

.logo-img {
  width: 100%;
  max-width: 160px;
  padding: 0 8px;
  object-fit: contain;
}

.logo-text {
  color: var(--giallo);
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 1px;
  line-height: 1.3;
  text-align: center;
  display: block;
  width: 100%;
}

/* ─── Chat shell ─────────────────────────────────────────────────────────────── */
.chat-shell {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ─── Lista conversazioni ────────────────────────────────────────────────────── */
.conv-list {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--grigio);
  display: flex;
  flex-direction: column;
  background: var(--bianco);
}

.conv-list-header {
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--grigio);
}

.conv-list-header h2 {
  font-size: 16px;
  color: var(--blu);
  font-weight: bold;
}

.conv-items {
  flex: 1;
  overflow-y: auto;
}

.conv-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--grigio);
  transition: background 0.15s;
}

.conv-item:hover  { background: var(--crema); }
.conv-item.active { background: rgba(20,43,111,0.07); border-left: 3px solid var(--blu); }

.conv-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--blu);
  color: var(--giallo);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 16px;
  flex-shrink: 0;
}

.conv-info { flex: 1; min-width: 0; }

.conv-name-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
}

.conv-name {
  font-weight: bold;
  font-size: 14px;
  color: var(--testo);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 11px;
  color: var(--grigio-mid);
  flex-shrink: 0;
}

.conv-preview-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2px;
}

.conv-preview {
  font-size: 12px;
  color: var(--grigio-mid);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.conv-pet {
  font-size: 11px;
  color: var(--blu);
  margin-top: 3px;
  opacity: 0.7;
}

.conv-empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--grigio-mid);
  font-size: 13px;
}

/* ─── Area chat ──────────────────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  transition: background 0.4s ease;
  overflow: hidden;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--grigio-mid);
  font-size: 15px;
}

/* ─── Header chat ────────────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bianco);
  border-bottom: 1px solid var(--grigio);
  flex-wrap: wrap;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--blu);
  color: var(--giallo);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 15px;
  flex-shrink: 0;
}

.chat-header-name {
  font-weight: bold;
  font-size: 15px;
  color: var(--blu);
}

.chat-header-phone {
  font-size: 12px;
  color: var(--grigio-mid);
}

.chat-pet-info {
  font-size: 12px;
  color: var(--blu);
  background: rgba(20,43,111,0.08);
  padding: 4px 10px;
  border-radius: 12px;
}

/* ─── Pulsante AI ────────────────────────────────────────────────────────────── */
.btn-ai-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 13px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-ai-toggle.ai-active {
  background: #7c3aed;
  color: var(--bianco);
}

.btn-ai-toggle.ai-paused {
  background: var(--grigio);
  color: var(--grigio-mid);
}

.ai-icon { font-size: 15px; }

/* ─── Banner AI pausa ────────────────────────────────────────────────────────── */
.ai-pausa-banner {
  background: rgba(124,58,237,0.12);
  color: #7c3aed;
  font-size: 12px;
  padding: 6px 20px;
  text-align: center;
  border-bottom: 1px solid rgba(124,58,237,0.2);
}

/* ─── Lista messaggi ─────────────────────────────────────────────────────────── */
.msg-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-loading {
  text-align: center;
  color: var(--grigio-mid);
  font-size: 13px;
  padding: 20px;
}

/* ─── Bolle messaggi ─────────────────────────────────────────────────────────── */
.bolla {
  display: flex;
  flex-direction: column;
  max-width: 65%;
  gap: 3px;
}

.bolla-customer {
  align-self: flex-start;
}

.bolla-seripet {
  align-self: flex-end;
}

.bolla-ai {
  align-self: flex-end;
}

.bolla-content {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}

.bolla-customer .bolla-content {
  background: var(--bianco);
  color: var(--testo);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.bolla-seripet .bolla-content {
  background: var(--blu);
  color: var(--bianco);
  border-bottom-right-radius: 4px;
}

.bolla-ai .bolla-content {
  background: #7c3aed;
  color: var(--bianco);
  border-bottom-right-radius: 4px;
}

.bolla-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--grigio-mid);
}

.bolla-seripet .bolla-meta,
.bolla-ai .bolla-meta {
  justify-content: flex-end;
}

.bolla-sender {
  background: #7c3aed;
  color: var(--bianco);
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
}

/* ─── Input messaggio ────────────────────────────────────────────────────────── */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 20px;
  background: var(--bianco);
  border-top: 1px solid var(--grigio);
}

.chat-input {
  flex: 1;
  border: 1px solid var(--grigio);
  border-radius: 20px;
  padding: 10px 16px;
  font-family: var(--font-main);
  font-size: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  max-height: 120px;
  overflow-y: auto;
}

.chat-input:focus {
  border-color: var(--blu);
}

.btn-invia {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--blu);
  color: var(--giallo);
  border: none;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.btn-invia:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-invia:not(:disabled):hover {
  opacity: 0.85;
}

/* ─── Barra modalità ─────────────────────────────────────────────────────────── */
.chat-mode-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 20px;
  background: var(--blu);
  color: var(--bianco);
  font-size: 12px;
}

.mode-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-customer { background: #60a5fa; }
.dot-seripet  { background: var(--giallo); }
.dot-ai       { background: #4ade80; }

.mode-label {
  margin-left: 8px;
  color: rgba(255,255,255,0.7);
  font-style: italic;
}

/* ─── Mobile (iPhone) ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {

  .app-shell {
    flex-direction: column;
  }

  /* Sidebar diventa tab bar in basso */
  .sidebar {
    width: 100%;
    height: 56px;
    flex-direction: row;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
  }

  .sidebar-logo { display: none; }
  .sidebar-footer { display: none; }

  .nav-menu {
    display: flex;
    flex-direction: row;
    width: 100%;
    padding: 0;
  }

  .nav-item {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 6px 0;
    gap: 2px;
    border-left: none;
    border-top: 3px solid transparent;
  }

  .nav-item.active {
    border-left: none;
    border-top-color: var(--giallo);
  }

  .nav-icon { font-size: 20px; }
  .nav-label { font-size: 10px; }

  /* Main content sopra la tab bar */
  .main-content {
    height: calc(100vh - 56px);
    padding-bottom: 0;
  }

  /* Chat shell — colonna singola */
  .chat-shell {
    flex-direction: column;
  }

  .conv-list {
    width: 100%;
    height: 100%;
    border-right: none;
  }

  .chat-area {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 56px;
    z-index: 50;
    display: none;
  }

  .chat-area.mobile-visible {
    display: flex;
  }

  /* Header chat — pulsante back */
  .chat-header {
    padding: 10px 12px;
  }

  .btn-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--crema);
    border: none;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
  }

  /* Bolle più larghe su mobile */
  .bolla { max-width: 85%; }

  /* Safe area iPhone */
  .sidebar {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(56px + env(safe-area-inset-bottom));
  }
  .mobile-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--blu);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 101;
    border-bottom: 2px solid var(--giallo);
  }

  .mobile-logo {
    height: 36px;
    width: auto;
  }

  .mobile-title {
    color: var(--giallo);
    font-size: 16px;
    font-weight: bold;
  }

  .main-content {
    margin-top: 54px;
    height: calc(100vh - 54px - 56px);
  }
}
