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

:root {
  --bg:         #000;
  --surface:    #1c1c1e;
  --surface2:   #2c2c2e;
  --blue:       #0a84ff;
  --red:        #ff453a;
  --orange:     #ff9f0a;
  --green:      #30d158;
  --text:       #fff;
  --text2:      #ebebf5cc;
  --text3:      #8e8e93;
  --border:     #38383a;
  --safe-top:   env(safe-area-inset-top,    0px);
  --safe-bot:   env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ─── Login ────────────────────────────────────────────────────────────────── */
#login-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-box {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.login-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 8px;
}

.login-icon svg { width: 100%; height: 100%; border-radius: 16px; }

h1 {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}

.login-box input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px 16px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color .15s;
}

.login-box input:focus { border-color: var(--blue); }

.login-box button {
  background: var(--blue);
  border: none;
  border-radius: 12px;
  padding: 15px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity .15s;
}

.login-box button:active { opacity: .8; }

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

/* ─── Header ───────────────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: var(--surface);
  border-bottom: .5px solid var(--border);
  flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 10px; }

.header-avatar {
  width: 38px;
  height: 38px;
  background: var(--blue);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  position: absolute;
  bottom: 0;
  right: 0;
}

.dot.online  { background: var(--green); }
.dot.offline { background: var(--text3); }

.header-name   { font-size: 16px; font-weight: 600; }
.header-status { font-size: 12px; color: var(--text3); transition: color .3s; }
.header-status.online { color: var(--green); }

#logout-btn {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

#logout-btn:active { background: var(--surface2); }
#logout-btn svg { width: 20px; height: 20px; }

/* ─── Messages ─────────────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-overflow-scrolling: touch;
}

.date-divider {
  text-align: center;
  color: var(--text3);
  font-size: 12px;
  font-weight: 500;
  margin: 10px 0 6px;
  position: sticky;
  top: 0;
}

.msg-group { display: flex; flex-direction: column; gap: 2px; margin: 2px 0; }
.msg-group.me    { align-items: flex-end; }
.msg-group.them  { align-items: flex-start; }

.bubble {
  max-width: 72vw;
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-group.me   .bubble {
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.msg-group.them .bubble {
  background: var(--surface2);
  color: var(--text);
  border-bottom-left-radius: 5px;
}

.msg-meta {
  font-size: 11px;
  color: var(--text3);
  padding: 0 4px;
  margin-top: 1px;
}

.expire-tag { color: var(--orange); }

.bubble-deleted {
  background: transparent !important;
  color: var(--text3) !important;
  border: 1px solid var(--border);
  font-style: italic;
}

/* ─── Input ────────────────────────────────────────────────────────────────── */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(var(--safe-bot) + 10px);
  background: var(--surface);
  border-top: .5px solid var(--border);
  flex-shrink: 0;
}

#msg-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 16px;
  resize: none;
  max-height: 130px;
  overflow-y: auto;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
  transition: border-color .15s;
}

#msg-input:focus { border-color: var(--blue); }

#send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--blue);
  border: none;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s, transform .1s;
}

#send-btn:disabled { background: var(--surface2); cursor: default; }
#send-btn:not(:disabled):active { transform: scale(.9); }
#send-btn svg { width: 18px; height: 18px; }

/* ─── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  gap: 8px;
  font-size: 14px;
}

.empty-state svg { width: 48px; height: 48px; opacity: .4; }

/* ─── Header icons ─────────────────────────────────────────────────────────── */
.header-right { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.icon-btn:active  { background: var(--surface2); }
.icon-btn svg     { width: 20px; height: 20px; }
.icon-btn.hidden  { display: none; }

/* ─── Face ID button ───────────────────────────────────────────────────────── */
.faceid-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 16px;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  transition: opacity .15s;
}
.faceid-btn:active { opacity: .7; }
.faceid-btn svg    { width: 22px; height: 22px; flex-shrink: 0; }
.faceid-btn.hidden { display: none; }

/* ─── Lock screen ──────────────────────────────────────────────────────────── */
#lock-screen {
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.lock-box {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}

.lock-avatar {
  width: 72px;
  height: 72px;
  margin: 0 auto 4px;
}
.lock-avatar svg { width: 100%; height: 100%; border-radius: 16px; }

.lock-name {
  text-align: center;
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

.lock-divider {
  text-align: center;
  color: var(--text3);
  font-size: 13px;
  position: relative;
}

.lock-divider.hidden { display: none; }

.lock-box input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px 16px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color .15s;
}
.lock-box input:focus { border-color: var(--blue); }
.lock-box input.hidden { display: none; }

.lock-box button.hidden { display: none; }

#lock-submit-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s;
}
#lock-submit-btn:active { opacity: .7; }

/* ─── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bot) + 90px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  white-space: nowrap;
  animation: fadeInOut 2.8s ease forwards;
  z-index: 999;
}
.toast-error { background: var(--red); }

@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateX(-50%) translateY(8px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ─── Install banner (Safari) ──────────────────────────────────────────────── */
.install-banner {
  position: fixed;
  bottom: calc(var(--safe-bot) + 12px);
  left: 12px; right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 100;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
}
.install-content { flex: 1; }
.install-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.install-steps {
  font-size: 13px;
  color: var(--text2);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.install-steps svg { width: 16px; height: 16px; flex-shrink: 0; }
.install-close {
  background: var(--surface2);
  border: none;
  color: var(--text3);
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding-bottom: var(--safe-bot);
}

.modal-box {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 28px 24px calc(var(--safe-bot) + 20px);
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.modal-icon {
  width: 64px; height: 64px;
  background: var(--surface2);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 4px;
}
.modal-icon svg { width: 32px; height: 32px; }
.modal-title { font-size: 20px; font-weight: 700; text-align: center; }
.modal-text  { font-size: 15px; color: var(--text2); text-align: center; line-height: 1.5; }

.modal-btn-primary {
  width: 100%;
  background: var(--blue);
  border: none;
  border-radius: 12px;
  padding: 15px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.modal-btn-secondary {
  width: 100%;
  background: none;
  border: none;
  color: var(--text3);
  font-size: 15px;
  cursor: pointer;
  padding: 8px;
}
