/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue-dark:   #03045e;
  --blue:        #0077b6;
  --blue-mid:    #0096c7;
  --blue-light:  #90e0ef;
  --bg:          #f0f4f8;
  --surface:     #ffffff;
  --text:        #1a1a2e;
  --text-muted:  #6b7280;
  --border:      #e2e8f0;
  --bubble-user: #0077b6;
  --bubble-ai:   #ffffff;
  --header-h:    56px;
  --reports-h:   52px;
  --input-h:     64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── PIN Screen ───────────────────────────────────────────── */
.pin-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: linear-gradient(160deg, var(--blue-dark) 0%, var(--blue) 100%);
  padding: 24px;
}

.pin-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 32px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.pin-logo  { font-size: 48px; margin-bottom: 12px; }
.pin-title { font-size: 22px; font-weight: 700; color: var(--blue-dark); }
.pin-subtitle {
  font-size: 14px; color: var(--text-muted);
  margin: 4px 0 28px;
}

.pin-card input {
  width: 100%;
  padding: 14px 16px;
  font-size: 18px;
  letter-spacing: 4px;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 12px;
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}
.pin-card input:focus { border-color: var(--blue); }

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--blue-mid); }
.btn-primary:active { transform: scale(0.98); }

.pin-error {
  margin-top: 10px;
  color: #dc2626;
  font-size: 14px;
}

/* ── Chat Screen ─────────────────────────────────────────── */
.chat-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

/* Header */
.header {
  height: var(--header-h);
  background: linear-gradient(90deg, var(--blue-dark), var(--blue));
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 100%;
  padding: 0 16px;
}
.header-logo  { font-size: 24px; }
.header-text  { flex: 1; }
.header-title { display: block; color: #fff; font-size: 16px; font-weight: 700; }
.header-sub   { display: block; color: var(--blue-light); font-size: 11px; }
.btn-logout {
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 18px;
  padding: 6px 10px;
  cursor: pointer;
  line-height: 1;
}
.btn-logout:hover { background: rgba(255,255,255,0.25); }

/* Reports bar */
.reports-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}
.reports-bar::-webkit-scrollbar { display: none; }

.report-btn {
  white-space: nowrap;
  padding: 8px 14px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--blue);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.report-btn:hover  { background: var(--blue); color: #fff; border-color: var(--blue); }
.report-btn:active { transform: scale(0.97); }

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

.welcome-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.6;
  padding: 24px 12px;
}
.welcome-icon { font-size: 36px; margin-bottom: 12px; }
.welcome-msg p { margin-bottom: 6px; }

/* Message bubbles */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.msg-row.user  { justify-content: flex-end; }
.msg-row.ai    { justify-content: flex-start; }

.msg-bubble {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.user .msg-bubble {
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-row.ai .msg-bubble {
  background: var(--bubble-ai);
  color: var(--text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 4px;
  flex-shrink: 0;
}

/* Typing / streaming cursor */
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--blue);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}

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

.chat-input {
  flex: 1;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  border: 1.5px solid var(--border);
  border-radius: 22px;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.45;
  transition: border-color 0.2s;
}
.chat-input:focus { border-color: var(--blue); }
.chat-input::placeholder { color: var(--text-muted); }

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}
.btn-send:hover   { background: var(--blue-mid); }
.btn-send:active  { transform: scale(0.93); }
.btn-send:disabled {
  background: var(--border);
  cursor: not-allowed;
  transform: none;
}

/* ── Desktop tweak ───────────────────────────────────────── */
@media (min-width: 720px) {
  .chat-screen {
    border-left:  1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 40px rgba(0,0,0,0.06);
  }
}
