/* Bizzi Mobile PWA V1 — style mobile-first
 * Charte : noir + or (#ffd23f), fonts Syne / Outfit / DM Mono
 * Pas de framework, vanilla CSS.
 */

:root {
  --bg: #0a0a0f;
  --bg-soft: #14141a;
  --bg-elev: #1a1a23;
  --bg-bubble-agent: #1d1d26;
  --accent: #ffd23f;
  --accent-soft: #ffe57a;
  --accent-dim: #b88f17;
  --w: #fff8e0;
  --muted: #8a8a96;
  --muted-soft: #5a5a6a;
  --border: #2a2a36;
  --border-soft: #1f1f29;
  --error: #ff6b6b;
  --success: #6bff8c;
  --warn: #ffaa3f;
  --bubble-radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --bottom-nav-h: 60px;
}

@import url('https://fonts.googleapis.com/css2?family=Syne:wght@600;800&family=Outfit:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--w);
  font-family: 'Outfit', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

input, textarea, button { font-family: inherit; font-size: inherit; color: inherit; }
button { background: transparent; border: none; cursor: pointer; }

/* ───────────────────────── LAYOUT GLOBAL ───────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 100%;
  position: relative;
}

/* ───────────────────────── SIDEBAR AGENTS ───────────────────────── */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  z-index: 60;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

.sidebar.open { transform: translateX(0); }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 55;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

.sidebar__header {
  display: flex;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar__title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 18px;
  color: var(--accent);
  flex: 1;
}

.sidebar__close {
  margin-left: auto;
}

.agents-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.agent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  text-align: left;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--w);
  transition: all 0.15s ease;
  cursor: pointer;
}

.agent-item:hover { background: var(--bg-elev); }

.agent-item.active {
  background: rgba(255, 210, 63, 0.1);
  border-color: var(--accent-dim);
}

.agent-item__emoji {
  font-size: 22px;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.agent-item__name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-item__badge {
  font-size: 10px;
  padding: 2px 6px;
  background: var(--bg-elev);
  border-radius: 6px;
  color: var(--muted);
  font-family: 'DM Mono', monospace;
}

.agent-item--add {
  border: 1px dashed var(--border);
  color: var(--accent);
  margin-top: 8px;
}

.agent-item--add:hover {
  background: rgba(255, 210, 63, 0.08);
  border-color: var(--accent);
}

/* ───────────────────────── HEADER ───────────────────────── */

.header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.header__agent {
  flex: 1;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--accent);
  letter-spacing: -0.3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header__status {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.header__status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
}

.header__status.offline::before { background: var(--error); }

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--w);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-icon:active { transform: scale(0.95); background: var(--border); }
.btn-icon:hover { background: var(--bg-elev); }

/* ───────────────────────── VIEWS (chat / agents / memory / settings) ───────────────────────── */

.view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
}

.view.active { display: flex; }

.view--chat { padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom)); }

.view__title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: var(--accent);
  padding: 18px 16px 4px;
  letter-spacing: -0.5px;
}

.view__sub {
  color: var(--muted);
  font-size: 13px;
  padding: 0 16px 16px;
}

/* ───────────────────────── MESSAGES ───────────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--bubble-radius);
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.45;
  animation: bubble-in 0.18s ease-out;
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.bubble--user {
  background: var(--accent);
  color: #0a0a0f;
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  font-weight: 500;
}

.bubble--agent {
  background: var(--bg-bubble-agent);
  color: var(--w);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  border: 1px solid var(--border);
}

.bubble--system {
  background: transparent;
  color: var(--muted);
  align-self: center;
  font-size: 12px;
  font-style: italic;
  text-align: center;
  max-width: 100%;
}

/* ───────────────────────── METACOGNITION ───────────────────────── */

.metacog {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: 'DM Mono', monospace;
}

.metacog__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.metacog__label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.metacog__bar {
  flex: 1;
  height: 6px;
  background: var(--border-soft);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.metacog__bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.conf--high .metacog__bar-fill { background: var(--success); }
.conf--mid .metacog__bar-fill { background: var(--warn); }
.conf--low .metacog__bar-fill { background: var(--error); }
.conf--unknown .metacog__bar-fill { background: var(--muted); width: 0; }

.metacog__score {
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.metacog__score.conf--high { color: var(--success); }
.metacog__score.conf--mid { color: var(--warn); }
.metacog__score.conf--low { color: var(--error); }
.metacog__score.conf--unknown { color: var(--muted); }

.metacog__details {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 10px;
  color: var(--muted);
}

.metacog__src { color: var(--accent-soft); }
.metacog__model { font-style: italic; }
.metacog__cost { color: var(--accent-dim); }

.metacog__breakdown {
  font-size: 10px;
  color: var(--muted-soft);
  cursor: help;
}

.metacog__warn {
  margin-top: 4px;
  font-size: 11px;
  color: var(--warn);
  font-family: 'Outfit', sans-serif;
  font-style: italic;
}

/* ───────────────────────── TENANT RECO CARD ───────────────────────── */

.tenant-reco {
  align-self: flex-start;
  max-width: 90%;
  background: linear-gradient(135deg, rgba(255, 210, 63, 0.08), rgba(255, 210, 63, 0.02));
  border: 1px solid var(--accent-dim);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: bubble-in 0.25s ease-out;
}

.tenant-reco__header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tenant-reco__emoji {
  font-size: 28px;
  flex-shrink: 0;
}

.tenant-reco__info { flex: 1; }

.tenant-reco__name {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 15px;
  color: var(--accent);
}

.tenant-reco__tagline {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.tenant-reco__cta {
  align-self: flex-start;
  background: var(--accent);
  color: #0a0a0f;
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  transition: transform 0.15s ease;
}

.tenant-reco__cta:active { transform: scale(0.96); }

/* ───────────────────────── THINKING DOTS ───────────────────────── */

.thinking {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 18px;
  padding: 0 4px;
}

.thinking span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-pulse 1.2s infinite ease-in-out;
}
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.85); }
  30% { opacity: 1; transform: scale(1.1); }
}

/* ───────────────────────── COMPOSER (chat input) ───────────────────────── */

.composer {
  padding: 10px 12px 10px;
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  z-index: 10;
}

.composer__input-wrap {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  min-height: 44px;
  transition: border-color 0.15s ease;
}

.composer__input-wrap:focus-within { border-color: var(--accent); }

.composer__input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--w);
  font-size: 16px;
  resize: none;
  max-height: 96px;
  line-height: 1.4;
  font-family: inherit;
}

.composer__input::placeholder { color: var(--muted); }

.btn-mic, .btn-send {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--w);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.btn-send {
  background: var(--accent);
  color: #0a0a0f;
  border-color: var(--accent);
}

.btn-send:disabled {
  background: var(--border);
  border-color: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

.btn-mic.listening {
  background: var(--accent);
  color: #0a0a0f;
  border-color: var(--accent);
  animation: mic-pulse 1.2s infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 210, 63, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(255, 210, 63, 0); }
}

.btn-send:active, .btn-mic:active { transform: scale(0.92); }

/* ───────────────────────── AGENTS GRID (vue agents) ───────────────────────── */

.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding: 0 16px 24px;
  overflow-y: auto;
}

.agent-card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  transition: all 0.15s ease;
  position: relative;
}

.agent-card.active {
  border-color: var(--accent);
  background: rgba(255, 210, 63, 0.06);
}

.agent-card__header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.agent-card__emoji { font-size: 28px; flex-shrink: 0; }

.agent-card__name {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-card__badge {
  font-size: 9px;
  font-family: 'DM Mono', monospace;
  background: var(--bg-elev);
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 6px;
}

.agent-card__persona {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  flex: 1;
}

.agent-card__actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.btn-sm {
  padding: 6px 10px !important;
  font-size: 12px !important;
}

.agent-card--add {
  border: 1px dashed var(--border);
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  color: var(--accent);
}

.agent-card--add:hover {
  border-color: var(--accent);
  background: rgba(255, 210, 63, 0.05);
}

/* ───────────────────────── MEMORY VIEW ───────────────────────── */

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 16px 16px;
}

.quick-action {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 8px;
  text-decoration: none;
  color: var(--w);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.quick-action:hover { background: var(--bg-elev); border-color: var(--accent-dim); }
.quick-action:active { transform: scale(0.96); }

.quick-action__emoji { font-size: 26px; }
.quick-action__label { font-size: 11px; color: var(--muted); text-align: center; }

.memory-section {
  margin: 8px 16px 16px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.memory-section__title {
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.badge-collective {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  background: var(--accent);
  color: #0a0a0f;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
}

.memory-section__body {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.memory-stat {
  flex: 1;
  min-width: 120px;
  background: var(--bg);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
}

.memory-stat__value {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 24px;
  color: var(--accent);
}

.memory-stat__label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.memory-disclaimer {
  width: 100%;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  margin-top: 10px;
  line-height: 1.5;
}

/* ───────────────────────── SETTINGS VIEW ───────────────────────── */

.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.setting-row label {
  flex: 1;
  cursor: pointer;
}

.setting-row__title { font-size: 14px; font-weight: 500; }
.setting-row__sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.setting-row--user .setting-row__title {
  font-size: 14px;
  color: var(--accent);
  font-family: 'DM Mono', monospace;
}

.setting-row--meta { padding-top: 24px; }

.toggle {
  appearance: none;
  width: 44px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.toggle:checked { background: var(--accent); }

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.toggle:checked::after { transform: translateX(20px); }

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

/* ───────────────────────── BOTTOM NAV ───────────────────────── */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 50;
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
  transition: color 0.15s ease;
  padding: 6px 4px;
}

.bottom-nav__item.active { color: var(--accent); }
.bottom-nav__item svg { width: 22px; height: 22px; }

/* ───────────────────────── BUTTONS ───────────────────────── */

.btn-primary {
  background: var(--accent);
  color: #0a0a0f;
  border: none;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-elev);
  color: var(--w);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-secondary:active { transform: scale(0.98); }
.btn-secondary:hover { border-color: var(--accent-dim); }

/* ───────────────────────── INSTALL PROMPT ───────────────────────── */

.install-banner {
  position: fixed;
  bottom: calc(var(--safe-bottom) + var(--bottom-nav-h) + 12px);
  left: 12px;
  right: 12px;
  background: var(--accent);
  color: #0a0a0f;
  padding: 12px 16px;
  border-radius: 12px;
  display: none;
  align-items: center;
  gap: 12px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 80;
  animation: slide-up 0.25s ease-out;
}

.install-banner.show { display: flex; }

.install-banner button {
  background: #0a0a0f;
  color: var(--accent);
  border: none;
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.install-banner button.dismiss {
  background: transparent;
  color: #0a0a0f;
  padding: 6px 8px;
  font-size: 18px;
  line-height: 1;
}

@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ───────────────────────── LOGIN ───────────────────────── */

.login {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100dvh;
  padding: 24px;
  gap: 20px;
}

.login__logo {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  margin-bottom: 8px;
}

.login__title {
  font-family: 'Syne', sans-serif;
  font-size: 36px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -1px;
}

.login__subtitle {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  margin-top: -16px;
  max-width: 320px;
  line-height: 1.5;
}

.login__form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.input-field {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--w);
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s ease;
}

.input-field:focus { border-color: var(--accent); }

.login__error {
  color: var(--error);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

.login__hint {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  margin-top: 24px;
  line-height: 1.6;
  font-family: 'DM Mono', monospace;
  max-width: 320px;
}

/* ───────────────────────── BREAKPOINT TABLET / DESKTOP ───────────────────────── */

@media (min-width: 600px) {
  .app, .login {
    max-width: 720px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
  body { background: #050507; }
}

@media (min-width: 900px) {
  /* Sidebar permanente sur desktop */
  .app {
    max-width: 1100px;
    display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "sidebar header"
      "sidebar main"
      "sidebar bottom-nav";
  }
  .sidebar {
    position: relative;
    transform: none !important;
    grid-area: sidebar;
    border-right: 1px solid var(--border);
  }
  .sidebar-backdrop { display: none !important; }
  .header { grid-area: header; }
  .view { grid-area: main; padding-bottom: 0; }
  .bottom-nav { position: relative; grid-area: bottom-nav; }
  #btnMenu { display: none; }
}

/* ───────────────────────── SCROLLBAR ───────────────────────── */

.messages::-webkit-scrollbar,
.agents-list::-webkit-scrollbar,
.agents-grid::-webkit-scrollbar,
.view::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb,
.agents-list::-webkit-scrollbar-thumb,
.agents-grid::-webkit-scrollbar-thumb,
.view::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.messages::-webkit-scrollbar-track,
.agents-list::-webkit-scrollbar-track,
.agents-grid::-webkit-scrollbar-track,
.view::-webkit-scrollbar-track { background: transparent; }
