/* ── Variables ─────────────────────────────────────────────── */
:root {
  --bg:           #fdf0f4;
  --bg2:          #fce8ef;
  --surface:      #ffffff;
  --surface2:     #fff5f8;
  --border:       #f0c8d5;
  --border2:      #e8b0c2;
  --accent:       #e8386d;
  --accent-h:     #cc2458;
  --accent-soft:  #f9d0de;
  --accent-glow:  rgba(232, 56, 109, 0.15);
  --text:         #2a1020;
  --text-sub:     #6b3550;
  --text-muted:   #b08090;
  --me-bubble:    #e8386d;
  --me-bubble2:   #c41f55;
  --other-bubble: #ffffff;
  --danger:       #e53935;
  --online:       #22c55e;
  --shadow-sm:    0 2px 10px rgba(200, 60, 100, 0.08);
  --shadow-md:    0 6px 30px rgba(200, 60, 100, 0.13);
  --shadow-lg:    0 16px 60px rgba(200, 60, 100, 0.16);
  --radius:       20px;
  --radius-sm:    12px;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; height: -webkit-fill-available; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overscroll-behavior: none;
}
a { color: inherit; text-decoration: none; }

/* ── Login page ────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse at 15% 15%, rgba(255, 180, 200, 0.45) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 80%, rgba(255, 150, 180, 0.35) 0%, transparent 55%),
    radial-gradient(ellipse at 50% 50%, rgba(255, 220, 230, 0.2) 0%, transparent 70%),
    linear-gradient(160deg, #fff0f5 0%, #fce8ef 50%, #fdf4f7 100%);
}

/* floating decorative petals */
.login-page::before,
.login-page::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}
.login-page::before {
  width: 300px; height: 300px;
  top: -80px; right: -80px;
  background: radial-gradient(circle, rgba(255,180,200,0.3), transparent 70%);
  animation: float1 8s ease-in-out infinite;
}
.login-page::after {
  width: 220px; height: 220px;
  bottom: -60px; left: -60px;
  background: radial-gradient(circle, rgba(255,160,190,0.25), transparent 70%);
  animation: float2 10s ease-in-out infinite;
}
@keyframes float1 {
  0%, 100% { transform: translate(0,0) scale(1); }
  50%       { transform: translate(-20px, 20px) scale(1.08); }
}
@keyframes float2 {
  0%, 100% { transform: translate(0,0) scale(1); }
  50%       { transform: translate(15px,-15px) scale(1.05); }
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 390px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 200, 215, 0.6);
  border-radius: 28px;
  padding: 2.8rem 2.2rem 2.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255,255,255,0.7) inset;
}

.login-logo {
  margin-bottom: 0.6rem;
  filter: drop-shadow(0 4px 16px rgba(232, 56, 109, 0.4));
  animation: heartbeat 2.6s ease-in-out infinite;
}
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  14%       { transform: scale(1.12); }
  28%       { transform: scale(1); }
  42%       { transform: scale(1.07); }
  56%       { transform: scale(1); }
}

.login-title {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #e8386d 0%, #ff6b9d 50%, #c41f55 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-sub {
  font-size: 0.83rem;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
  letter-spacing: 0.01em;
}

.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-top: 0.6rem;
}

.field-input {
  width: 100%;
  padding: 0.75rem 1.1rem;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  -webkit-appearance: none;
}
.field-input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 4px var(--accent-glow);
}
.field-input::placeholder { color: var(--text-muted); }

.btn-primary {
  margin-top: 1.2rem;
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, #ff6b9d, #e8386d, #c41f55);
  background-size: 200% 200%;
  animation: gradShift 4s ease infinite;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.97rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 6px 24px rgba(232, 56, 109, 0.4);
}
@keyframes gradShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
.btn-primary:hover  { box-shadow: 0 8px 30px rgba(232, 56, 109, 0.5); transform: translateY(-1px); }
.btn-primary:active { transform: scale(0.98) translateY(0); }

.error-banner {
  background: rgba(229, 57, 53, 0.08);
  border: 1.5px solid rgba(229, 57, 53, 0.35);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  font-size: 0.84rem;
  text-align: center;
}

/* ── Chat page layout ──────────────────────────────────────── */
.chat-page {
  display: grid;
  grid-template-rows: 64px 1fr auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 0% 0%,   rgba(255, 190, 210, 0.3) 0%, transparent 45%),
    radial-gradient(ellipse at 100% 100%, rgba(255, 170, 200, 0.2) 0%, transparent 45%),
    linear-gradient(180deg, #fff0f4 0%, #fce8ef 100%);
}

/* ── Header ────────────────────────────────────────────────── */
.chat-header {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  padding-left:  calc(1rem + env(safe-area-inset-left));
  padding-right: calc(1rem + env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  box-shadow: 0 1px 16px rgba(200, 60, 100, 0.07);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff8fb3, #e8386d);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 3px 12px rgba(232, 56, 109, 0.35);
}

.chat-with {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s, box-shadow 0.3s;
}
.status-dot.online {
  background: var(--online);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}
.status-dot.offline { background: #d4aab5; }

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.my-name {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: none;
}

.btn-logout {
  font-size: 0.76rem;
  padding: 0.32rem 0.75rem;
  border: 1.5px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text-sub);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  font-weight: 500;
}
.btn-logout:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.btn-clear {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border2);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.btn-clear:hover {
  color: var(--danger);
  border-color: rgba(229, 57, 53, 0.5);
  background: rgba(229, 57, 53, 0.07);
}

/* ── Messages area ─────────────────────────────────────────── */
.messages-area {
  overflow-y: auto;
  padding: 1rem 0.75rem 0.5rem;
  padding-left:  calc(0.75rem + env(safe-area-inset-left));
  padding-right: calc(0.75rem + env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.messages-inner {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}

/* Date divider */
.date-divider {
  text-align: center;
  font-size: 0.69rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 1rem 0 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.date-divider::before,
.date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border2), transparent);
}

/* Message bubbles */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: 85%;
  animation: fadeUp 0.2s ease;
}
.msg-row.mine   { align-self: flex-end;   flex-direction: row-reverse; }
.msg-row.theirs { align-self: flex-start; }

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

.msg-bubble {
  padding: 0.65rem 1.05rem;
  border-radius: 20px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 0.91rem;
  max-width: 100%;
}

.msg-row.mine .msg-bubble {
  background: linear-gradient(135deg, #ff6b9d, #e8386d);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 18px rgba(232, 56, 109, 0.35);
}

.msg-row.theirs .msg-bubble {
  background: #ffffff;
  color: var(--text);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.msg-time {
  font-size: 0.64rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-bottom: 3px;
  flex-shrink: 0;
}

/* Typing indicator */
.typing-indicator {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.2rem;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.6;
  animation: bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-6px); }
}

/* ── Footer / input ────────────────────────────────────────── */
.chat-footer {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 0.65rem 0.75rem;
  padding-left:   calc(0.75rem + env(safe-area-inset-left));
  padding-right:  calc(0.75rem + env(safe-area-inset-right));
  padding-bottom: calc(0.65rem + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  box-shadow: 0 -1px 16px rgba(200, 60, 100, 0.06);
}

.msg-input {
  flex: 1;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  padding: 0.65rem 1.1rem;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  font-family: inherit;
  -webkit-appearance: none;
}
.msg-input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 4px var(--accent-glow);
}
.msg-input::placeholder { color: var(--text-muted); }

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6b9d, #e8386d);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  box-shadow: 0 4px 18px rgba(232, 56, 109, 0.45);
}
.btn-send:disabled {
  opacity: 0.35;
  cursor: default;
  box-shadow: none;
}
.btn-send:not(:disabled):hover  { transform: scale(1.06); box-shadow: 0 6px 24px rgba(232, 56, 109, 0.55); }
.btn-send:not(:disabled):active { transform: scale(0.93); }

/* ── Confirm dialog ────────────────────────────────────────── */
.dialog-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(40, 10, 20, 0.35);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.dialog-backdrop.open { display: flex; }

.dialog {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 2rem 1.75rem 1.5rem;
  width: 100%;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: popIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

.dialog-icon { font-size: 2.2rem; line-height: 1; }

.dialog-msg {
  font-size: 0.92rem;
  color: var(--text-sub);
  line-height: 1.6;
}

.dialog-actions {
  display: flex;
  gap: 0.75rem;
  width: 100%;
  margin-top: 0.25rem;
}

.dialog-btn {
  flex: 1;
  padding: 0.68rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: transform 0.1s, box-shadow 0.15s;
}
.dialog-btn:active { transform: scale(0.97); }
.dialog-btn.cancel {
  background: var(--surface2);
  color: var(--text-sub);
  border: 1.5px solid var(--border2);
}
.dialog-btn.cancel:hover { background: var(--accent-soft); }
.dialog-btn.confirm {
  background: linear-gradient(135deg, #ff6b9d, #e8386d);
  color: #fff;
  box-shadow: 0 4px 16px rgba(232, 56, 109, 0.4);
}
.dialog-btn.confirm:hover { box-shadow: 0 6px 20px rgba(232, 56, 109, 0.5); }

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── Desktop ───────────────────────────────────────────────── */
@media (min-width: 640px) {
  .my-name { display: inline; }
  .msg-row { max-width: 65%; }
  .chat-header  { padding: 0 1.5rem; }
  .messages-area { padding: 1.25rem 1.25rem 0.5rem; }
  .chat-footer  { padding: 0.8rem 1.25rem; }
  .msg-input    { font-size: 0.92rem; }
}

/* ── Tiny phones ───────────────────────────────────────────── */
@media (max-width: 420px) {
  .login-card {
    border: none;
    border-radius: 0;
    min-height: 100vh;
    min-height: 100dvh;
    justify-content: center;
    padding: 2rem 1.5rem;
    background: transparent;
    box-shadow: none;
  }
  .login-page { padding: 0; }
}
