/* =========================================================
   RESET & BASE
   ========================================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-void: #050505;
  --bg-panel: #0c0c0e;
  --bg-key: #121214;
  --red: #ff0033;
  --red-dim: #7a0019;
  --red-glow: rgba(255, 0, 51, 0.55);
  --text-main: #f2f2f2;
  --text-dim: #8a8a8f;
  --border: rgba(255, 0, 51, 0.25);
  --font-mono: "Courier New", "SFMono-Regular", Consolas, monospace;
}

html,
body {
  height: 100%;
}

body {
  background: radial-gradient(
    ellipse at 50% 0%,
    #170305 0%,
    var(--bg-void) 55%
  );
  color: var(--text-main);
  font-family: var(--font-mono);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  position: relative;
  padding: 24px 16px;
}

/* Bruit / scanlines cyberpunk en fond */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 0, 51, 0.035) 0px,
    rgba(255, 0, 51, 0.035) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
  opacity: 0.6;
}

.scanlines::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at 50% 50%,
    transparent 40%,
    rgba(0, 0, 0, 0.75) 100%
  );
}

/* =========================================================
   ÉCRAN PIN
   ========================================================= */
.pin-screen {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.pin-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.pin-icon {
  color: var(--red);
  filter: drop-shadow(0 0 8px var(--red-glow));
  margin-bottom: 4px;
  animation: pulseIcon 2.4s ease-in-out infinite;
}

@keyframes pulseIcon {
  0%,
  100% {
    filter: drop-shadow(0 0 6px var(--red-glow));
    opacity: 0.9;
  }
  50% {
    filter: drop-shadow(0 0 14px var(--red-glow));
    opacity: 1;
  }
}

.pin-title {
  font-size: 1.05rem;
  letter-spacing: 0.22em;
  color: var(--text-main);
  text-shadow: 0 0 12px var(--red-glow);
  text-transform: uppercase;
}

.pin-subtitle {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  text-transform: uppercase;
  transition: color 0.2s ease;
}

.pin-subtitle.is-error {
  color: var(--red);
}

/* =========================================================
   INDICATEURS (DOTS)
   ========================================================= */
.dots {
  display: flex;
  gap: 18px;
}

.dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--red-dim);
  background: transparent;
  box-shadow: inset 0 0 6px rgba(255, 0, 51, 0.15);
  transition:
    background 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease;
}

.dot.filled {
  background: var(--red);
  border-color: var(--red);
  box-shadow:
    0 0 10px 2px var(--red-glow),
    0 0 22px 4px rgba(255, 0, 51, 0.35);
  transform: scale(1.05);
}

.dots.shake {
  animation: shake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.dots.shake .dot {
  border-color: var(--red);
}

.dots.error-flash .dot.filled {
  background: #ff0033;
  box-shadow: 0 0 14px 4px rgba(255, 0, 51, 0.85);
}

@keyframes shake {
  10%,
  90% {
    transform: translateX(-2px);
  }
  20%,
  80% {
    transform: translateX(4px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-8px);
  }
  40%,
  60% {
    transform: translateX(8px);
  }
}

/* =========================================================
   PAVÉ NUMÉRIQUE
   ========================================================= */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 18px;
  justify-content: center;
}

.key {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-key), #0a0a0b);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: var(--font-mono);
  -webkit-user-select: none;
  user-select: none;
  position: relative;
  transition:
    background 0.12s ease,
    box-shadow 0.12s ease,
    transform 0.08s ease,
    border-color 0.12s ease;
}

.key-num {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.key-sub {
  font-size: 0.55rem;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  margin-top: 2px;
}

.key:active,
.key.is-pressed {
  background: radial-gradient(
    circle,
    rgba(255, 0, 51, 0.28),
    rgba(10, 10, 11, 0.9)
  );
  border-color: var(--red);
  box-shadow: 0 0 18px 2px var(--red-glow);
  transform: scale(0.94);
}

.key-empty {
  background: transparent;
  border: none;
  cursor: default;
  pointer-events: none;
}

.key-action {
  border: none;
  background: transparent;
  color: var(--text-dim);
  box-shadow: none;
}

.key-action:active,
.key-action.is-pressed {
  background: transparent;
  color: var(--red);
  box-shadow: none;
  border: none;
  transform: scale(0.9);
}

/* =========================================================
   LIGNE DE STATUT SYSTÈME
   ========================================================= */
.status-line {
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  color: var(--red-dim);
  text-transform: uppercase;
  opacity: 0.75;
  text-align: center;
  min-height: 14px;
  transition:
    color 0.2s ease,
    opacity 0.2s ease;
}

.status-line.busy {
  color: var(--red);
  opacity: 1;
  animation: blink 0.9s steps(2, start) infinite;
}

.status-line.error {
  color: var(--red);
  opacity: 1;
}

.status-line.success {
  color: #33ff77;
  opacity: 1;
}

@keyframes blink {
  50% {
    opacity: 0.25;
  }
}

/* =========================================================
   RESPONSIVE — TABLETTE / DESKTOP
   ========================================================= */
@media (min-width: 480px) {
  .pin-screen {
    max-width: 380px;
    gap: 34px;
  }

  .pin-title {
    font-size: 1.2rem;
  }

  .keypad {
    grid-template-columns: repeat(3, 80px);
    gap: 22px;
  }

  .key {
    width: 80px;
    height: 80px;
  }

  .key-num {
    font-size: 1.7rem;
  }
}

@media (min-width: 900px) {
  body {
    padding: 40px;
  }

  .pin-screen {
    padding: 40px 32px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: linear-gradient(
      180deg,
      rgba(20, 4, 7, 0.55),
      rgba(5, 5, 5, 0.75)
    );
    box-shadow:
      0 0 40px rgba(255, 0, 51, 0.08),
      inset 0 0 60px rgba(255, 0, 51, 0.03);
    backdrop-filter: blur(6px);
  }
}

/* Réduction des animations si l'utilisateur le demande */
@media (prefers-reduced-motion: reduce) {
  .pin-icon,
  .status-line.busy {
    animation: none;
  }
  .dots.shake {
    animation: none;
  }
}

/* Context menu and inline editor */
.bubble-row {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.bubble-row .bubble {
  -webkit-user-select: none;
  user-select: none;
}

.chat-context-menu {
  position: absolute;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-main);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  z-index: 9999;
  min-width: 140px;
  border-radius: 6px;
  overflow: hidden;
}
.chat-context-item {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 0.9rem;
}
.chat-context-item:hover {
  background: rgba(255, 0, 51, 0.06);
}
.chat-context-delete {
  color: var(--red);
}

.bubble-editor {
  margin-top: 8px;
}
.bubble-editor textarea {
  width: 100%;
  resize: vertical;
  min-height: 48px;
  max-height: 160px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
}
.bubble-editor-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.bubble-editor-actions button {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
}
.bubble-editor-actions button:first-child {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.bubble-editor-actions button:last-child {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.bubble.edited .bubble-time::after {
  content: " (modifié)";
  color: var(--text-dim);
  font-size: 0.85em;
  margin-left: 6px;
}
