/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Inter via system stack — no external font request needed */
:root {
  /* ── Brand ─────────────────────────────────────────────── */
  --accent-blue:   #2563EB;
  --accent-cyan:   #06B6D4;
  --accent-grad:   linear-gradient(135deg, #2563EB 0%, #06B6D4 100%);

  /* ── Page ───────────────────────────────────────────────── */
  --page-bg:       linear-gradient(145deg, #F0F6FF 0%, #EBF3FF 45%, #F5F9FF 100%);

  /* ── Card ───────────────────────────────────────────────── */
  --card-bg:       #FFFFFF;
  --card-border:   rgba(15, 23, 42, 0.08);
  --card-shadow:   0 8px 24px rgba(15, 23, 42, 0.07),
                   0 32px 72px rgba(15, 23, 42, 0.10);

  /* ── Header ─────────────────────────────────────────────── */
  --header-bg:     #FAFBFD;
  --header-border: #E8EDF5;

  /* ── Text ───────────────────────────────────────────────── */
  --text-main:     #172033;
  --text-muted:    #64748B;
  --text-on-accent:#FFFFFF;

  /* ── Bubbles ─────────────────────────────────────────────── */
  --bubble-bg:          #F1F5F9;
  --bubble-border:      #E2E8F0;
  --bubble-text:        #1E293B;

  --bubble-error-bg:    #FFF1F4;
  --bubble-error-border:#FECDD3;
  --bubble-error-text:  #9F1239;

  --bubble-success-bg:  #F0FDF9;
  --bubble-success-border:#A7F3D0;
  --bubble-success-text:#065F46;

  /* ── IP badge ─────────────────────────────────────────────── */
  --ip-bg:          #EFF6FF;
  --ip-border:      #BFDBFE;
  --ip-text:        #1D4ED8;

  --ip-error-bg:    #FFF1F4;
  --ip-error-border:#FECDD3;
  --ip-error-text:  #BE123C;

  /* ── Misc ─────────────────────────────────────────────────── */
  --radius-card:  22px;
  --radius-bubble:18px;
  --radius-btn:   16px;
  --status-green: #22C55E;

  /* ── Easings ──────────────────────────────────────────────── */
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont,
               'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--page-bg);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  /* clamp() keeps sensible padding on every viewport */
  padding: clamp(16px, 4vw, 48px) clamp(12px, 4vw, 32px);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  position: relative;
}

/* ============================================================
   BACKGROUND — subtle decorative blobs (light, non-intrusive)
   ============================================================ */
.bg-blobs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  /* Much lighter, desaturated — barely visible on white bg */
  filter: blur(100px);
  opacity: 0.28;
}

.blob-1 {
  width: 560px;
  height: 560px;
  background: #BFDBFE; /* blue-200 */
  top: -200px;
  left: -200px;
  animation: blobDrift1 22s ease-in-out infinite;
}

.blob-2 {
  width: 440px;
  height: 440px;
  background: #A5F3FC; /* cyan-200 */
  bottom: -140px;
  right: -140px;
  animation: blobDrift2 26s ease-in-out infinite;
}

.blob-3 {
  width: 320px;
  height: 320px;
  background: #DDD6FE; /* violet-200 */
  top: 50%;
  left: 60%;
  transform: translate(-50%, -50%);
  animation: blobDrift3 32s ease-in-out infinite;
  opacity: 0.18;
}

@keyframes blobDrift1 {
  0%, 100% { transform: translate(0, 0); }
  50%       { transform: translate(48px, 56px); }
}
@keyframes blobDrift2 {
  0%, 100% { transform: translate(0, 0); }
  50%       { transform: translate(-44px, -48px); }
}
@keyframes blobDrift3 {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50%       { transform: translate(-50%, -50%) scale(1.18); }
}

/* ============================================================
   CHAT WRAPPER  (page-level centering layer)
   ============================================================ */
.chat-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   CHAT CARD
   ============================================================ */
.chat-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: var(--card-shadow);
  /* min(100%, 580px) = full-width on small screens, capped at 580px */
  width: min(100%, 580px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: cardRise 0.65s var(--ease-out) both;
}

@keyframes cardRise {
  from { opacity: 0; transform: translateY(28px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* ============================================================
   CHAT HEADER
   ============================================================ */
.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 24px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  flex-shrink: 0;
}

/* Header avatar — 48 px ring */
.header-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  /* Soft ring in brand colour */
  box-shadow: 0 0 0 2.5px #BFDBFE,
              0 4px 14px rgba(37, 99, 235, 0.18);
}

.header-avatar svg {
  width: 100%;
  height: 100%;
  display: block;
}

.header-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.header-name {
  font-size: 1.0625rem; /* 17 px */
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-main);
  line-height: 1.2;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8125rem; /* 13 px */
  color: var(--text-muted);
  font-weight: 400;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-green);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.22);
  animation: statusPulse 2.8s ease-in-out infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1;    transform: scale(1); }
  50%       { opacity: 0.6; transform: scale(0.82); }
}

/* ============================================================
   CHAT MESSAGES  (scrollable body)
   ============================================================ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* Cap height so card never becomes a full-screen column */
  max-height: 420px;
  scroll-behavior: smooth;

  /* Thin, understated scrollbar */
  scrollbar-width: thin;
  scrollbar-color: #CBD5E1 transparent;
}

.chat-messages::-webkit-scrollbar       { width: 4px; }
.chat-messages::-webkit-scrollbar-track  { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb  {
  background: #CBD5E1;
  border-radius: 4px;
}

/* ============================================================
   MESSAGE ROW  (avatar + bubble side-by-side)
   ============================================================ */
.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  /* Each new row slides up & fades in */
  animation: msgSlideIn 0.38s var(--ease-out) both;
}

@keyframes msgSlideIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* In-message avatar — 36 px, stays at bottom of bubble */
.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  align-self: flex-end;
  box-shadow: 0 0 0 2px #BFDBFE,
              0 2px 8px rgba(37, 99, 235, 0.14);
}

.msg-avatar svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ============================================================
   MESSAGE BUBBLE
   ============================================================ */
.msg-bubble {
  background: var(--bubble-bg);
  border: 1px solid var(--bubble-border);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 5px;   /* "tail" corner */
  padding: 13px 16px;
  font-size: 0.9375rem; /* 15 px */
  line-height: 1.6;
  color: var(--bubble-text);
  /* Never overflow, always wraps */
  max-width: calc(100% - 52px);
  word-break: break-word;
  min-width: 48px;
}

/* Error variant */
.msg-bubble.bubble-error {
  background: var(--bubble-error-bg);
  border-color: var(--bubble-error-border);
  color: var(--bubble-error-text);
}

/* Success variant */
.msg-bubble.bubble-success {
  background: var(--bubble-success-bg);
  border-color: var(--bubble-success-border);
  color: var(--bubble-success-text);
}

/*
 * Pulse animation — applied by JS when the user retries a VPN check but all
 * IP providers still fail. Instead of stacking a duplicate error bubble, the
 * existing one pulses to confirm the app did try again.
 */
.msg-bubble.bubble-pulse {
  animation: bubblePulse 0.5s ease both;
}

@keyframes bubblePulse {
  0%   { transform: scale(1);    box-shadow: none; }
  35%  { transform: scale(1.03); box-shadow: 0 0 0 4px rgba(159, 18, 57, 0.14); }
  70%  { transform: scale(0.98); box-shadow: none; }
  100% { transform: scale(1);    box-shadow: none; }
}

/* ============================================================
   TYPING INDICATOR  (three bouncing dots)
   ============================================================ */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  /* Same height as a one-liner bubble so layout doesn't jump */
  padding: 15px 18px;
}

.typing-indicator span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94A3B8;   /* slate-400 — visible on light bubble */
  animation: dotBounce 1.3s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.18s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.36s; }

@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.45; }
  30%           { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   TYPEWRITER CURSOR
   ============================================================ */
.cursor {
  display: inline-block;
  width: 2px;
  height: 0.9em;
  background: var(--accent-blue);
  margin-left: 1px;
  vertical-align: text-bottom;
  border-radius: 1px;
  animation: cursorBlink 0.8s step-end infinite;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ============================================================
   IP BADGE  (monospace tag shown inside bubble)
   ============================================================ */
.ip-tag {
  display: inline-block;
  background: var(--ip-bg);
  border: 1px solid var(--ip-border);
  border-radius: 8px;
  padding: 1px 9px;
  font-family: 'SFMono-Regular', 'Menlo', 'Consolas', 'Liberation Mono', monospace;
  font-size: 0.825em;
  color: var(--ip-text);
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.ip-tag.tag-error {
  background: var(--ip-error-bg);
  border-color: var(--ip-error-border);
  color: var(--ip-error-text);
}

/* ============================================================
   CHAT ACTIONS  (button zone below messages)
   ============================================================ */
.chat-actions {
  padding: 16px 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
  /* Top separator, only visible when there are buttons */
  border-top: 1px solid #F1F5F9;
  transition: padding 0.25s;
}

/* Collapse separator when zone is empty */
.chat-actions:empty {
  padding: 0;
  border-top: none;
}

/* ============================================================
   BASE BUTTON
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: none;
  border-radius: var(--radius-btn);
  font-size: 1rem;       /* 16 px */
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  /* Comfortable tap target — at least 52 px tall */
  padding: 15px 24px;
  min-height: 52px;
  width: 100%;           /* full-width by default */
  text-decoration: none;
  position: relative;
  overflow: hidden;
  transition:
    transform   0.22s var(--ease-spring),
    box-shadow  0.22s ease,
    opacity     0.18s ease,
    filter      0.22s ease;
  /* Appear from below */
  animation: btnFadeUp 0.38s var(--ease-out) both;
}

@keyframes btnFadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Ripple overlay on hover */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: transparent;
  transition: background 0.2s ease;
}
.btn:hover:not(:disabled)::after  { background: rgba(255, 255, 255, 0.12); }
.btn:active:not(:disabled)::after { background: rgba(0,   0,   0,   0.06); }

.btn:active:not(:disabled) { transform: translateY(1px) scale(0.985); }

/* Keyboard focus — always visible */
.btn:focus-visible {
  outline: 3px solid var(--accent-blue);
  outline-offset: 3px;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none !important;
  filter: none !important;
}

/* ── Primary — VPN check ─────────────────────────────────── */
.btn-primary {
  background: var(--accent-grad);
  color: var(--text-on-accent);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.28),
              0 1px  4px rgba(37, 99, 235, 0.18);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(37, 99, 235, 0.38),
              0 2px  8px rgba(37, 99, 235, 0.22);
}

/* ── Success — Читать дальше ─────────────────────────────── */
.btn-success {
  background: linear-gradient(135deg, #059669 0%, #06B6D4 100%);
  color: var(--text-on-accent);
  box-shadow: 0 4px 16px rgba(5, 150, 105, 0.28),
              0 1px  4px rgba(5, 150, 105, 0.18);
}

.btn-success:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(5, 150, 105, 0.38),
              0 2px  8px rgba(5, 150, 105, 0.22);
}

/* ── Ghost — retry / secondary ───────────────────────────── */
.btn-ghost {
  background: #F8FAFC;
  border: 1.5px solid #E2E8F0;
  color: var(--text-muted);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
  font-weight: 600;
}

.btn-ghost:hover:not(:disabled) {
  background: #F1F5F9;
  border-color: #CBD5E1;
  color: var(--text-main);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.09);
}

/* ── Button loading spinner ──────────────────────────────── */
.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spinnerRotate 0.7s linear infinite;
  flex-shrink: 0;
}

/* Ghost spinner uses darker ring */
.btn-ghost .btn-spinner {
  border-color: rgba(100, 116, 139, 0.35);
  border-top-color: var(--text-muted);
}

@keyframes spinnerRotate {
  to { transform: rotate(360deg); }
}

/* ============================================================
   CHECKING HINT TEXT  (below button while fetching)
   ============================================================ */
.checking-text {
  text-align: center;
  font-size: 0.8125rem; /* 13 px */
  color: var(--text-muted);
  padding-top: 2px;
  animation: fadeInSoft 0.3s ease both;
}

@keyframes fadeInSoft {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ============================================================
   RESPONSIVE  — Tablet  (≤ 700 px)
   ============================================================ */
@media (max-width: 700px) {
  body {
    /* Push card toward top; gives breathing room at top */
    align-items: flex-start;
    padding: 16px 14px 32px;
  }

  .chat-card {
    /* Fill available width, but card still has border-radius */
    width: 100%;
    border-radius: 20px;
    margin-top: 4px;
  }

  .chat-messages {
    max-height: 46dvh;
    padding: 18px 16px 10px;
    gap: 14px;
  }

  .chat-header {
    padding: 16px 18px;
  }

  .chat-actions {
    padding: 14px 16px 20px;
  }

  .header-avatar {
    width: 42px;
    height: 42px;
  }

  .msg-bubble {
    font-size: 0.9375rem; /* keep 15 px — do not shrink */
    padding: 12px 14px;
  }

  .btn {
    font-size: 1rem;
    min-height: 52px;
    padding: 14px 20px;
  }
}

/* ============================================================
   RESPONSIVE  — Small phones  (≤ 430 px, e.g. iPhone SE, 12 mini)
   ============================================================ */
@media (max-width: 430px) {
  body {
    padding: 10px 10px 24px;
  }

  .chat-card {
    border-radius: 18px;
    margin-top: 0;
  }

  .chat-header {
    padding: 14px 16px;
    gap: 12px;
  }

  .header-avatar {
    width: 40px;
    height: 40px;
  }

  .header-name {
    font-size: 0.9375rem; /* 15 px */
  }

  .header-status {
    font-size: 0.75rem;
  }

  .chat-messages {
    padding: 16px 14px 8px;
    max-height: 52dvh;
    gap: 12px;
  }

  .msg-avatar {
    width: 32px;
    height: 32px;
  }

  .msg-bubble {
    font-size: 0.9rem;
    line-height: 1.55;
    padding: 11px 13px;
    max-width: calc(100% - 44px);
  }

  .chat-actions {
    padding: 12px 14px 18px;
    gap: 9px;
  }

  .btn {
    font-size: 0.9375rem;
    min-height: 50px;
    padding: 13px 18px;
  }

  .checking-text {
    font-size: 0.75rem;
  }
}

/* ============================================================
   RESPONSIVE  — Landscape small phones  (height ≤ 500 px)
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    align-items: flex-start;
    padding: 8px 14px 16px;
  }

  .chat-messages {
    max-height: 38dvh;
  }

  .chat-header {
    padding: 12px 18px;
  }

  .header-avatar {
    width: 38px;
    height: 38px;
  }
}

/* ============================================================
   RESPONSIVE  — Large screens  (≥ 900 px)
   Give the card more room and ensure it's vertically centred.
   ============================================================ */
@media (min-width: 900px) {
  body {
    align-items: center;
    padding: 48px 32px;
  }

  .chat-card {
    /* Slightly wider on big screens */
    width: min(100%, 600px);
  }

  .chat-messages {
    max-height: 400px;
  }
}
