/* Flora Messenger — Styles | Prefix: fm- */
:root {
  --fm-green: #2E7D32;
  --fm-green-light: #4CAF50;
  --fm-green-pale: #E8F5E9;
  --fm-blue: #1565C0;
  --fm-blue-light: #42A5F5;
  --fm-text: #1a1a1a;
  --fm-text-secondary: #666;
  --fm-border: #e0e0e0;
  --fm-bg: #f5f5f5;
  --fm-white: #fff;
  --fm-bubble-own: #DCF8C6;
  --fm-bubble-other: #fff;
  --fm-radius: 16px;
  --fm-radius-sm: 10px;
  --fm-shadow: 0 2px 8px rgba(0,0,0,.08);
  --fm-safe-top: env(safe-area-inset-top, 0px);
  --fm-safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  color: var(--fm-text);
  background: var(--fm-bg);
  -webkit-font-smoothing: antialiased;
}
#app { height: 100%; display: flex; flex-direction: column; }

/* ===== AUTH SCREEN ===== */
.fm-auth {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; padding: 24px; text-align: center; background: var(--fm-white);
}
.fm-auth-logo {
  width: 80px; height: 80px; background: #fff; border-radius: 20px;
  border: 2px solid #4CAF50;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 24px; overflow: hidden;
}
.fm-auth-logo img {
  width: 60px; height: 60px; object-fit: contain;
}
.fm-auth h1 { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.fm-auth p { color: var(--fm-text-secondary); margin-bottom: 32px; font-size: 14px; }
.fm-auth-form { width: 100%; max-width: 320px; }
.fm-input-group { position: relative; margin-bottom: 16px; }
.fm-input {
  width: 100%; padding: 14px 16px; border: 2px solid var(--fm-border); border-radius: var(--fm-radius-sm);
  font-size: 18px; outline: none; transition: border .2s; background: var(--fm-white);
  -webkit-appearance: none;
}
.fm-input:focus { border-color: var(--fm-green); }
.fm-input::placeholder { color: #aaa; }
.fm-input:-webkit-autofill,
.fm-input:-webkit-autofill:hover,
.fm-input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px white inset !important;
  -webkit-text-fill-color: var(--fm-text) !important;
  transition: background-color 5000s ease-in-out 0s;
}
.fm-btn {
  width: 100%; padding: 14px; border: none; border-radius: var(--fm-radius-sm);
  font-size: 16px; font-weight: 600; cursor: pointer; transition: all .2s;
}
.fm-btn-primary { background: var(--fm-green); color: white; }
.fm-btn-primary:hover { background: var(--fm-green-light); }
.fm-btn-primary:disabled { background: #ccc; cursor: default; }
.fm-otp-inputs { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.fm-otp-input {
  width: 48px; height: 56px; text-align: center; font-size: 24px; font-weight: 600;
  border: 2px solid var(--fm-border); border-radius: var(--fm-radius-sm); outline: none;
  -webkit-appearance: none;
}
.fm-otp-input:focus { border-color: var(--fm-green); }
.fm-auth-timer { color: var(--fm-text-secondary); font-size: 14px; margin-top: 12px; }
.fm-auth-timer a { color: var(--fm-green); text-decoration: none; cursor: pointer; }
.fm-auth-error { color: #d32f2f; font-size: 14px; margin-top: 8px; }
.fm-auth-step { display: none; }
.fm-auth-step.active { display: block; }
.fm-vpn-warning {
  background: #FFF8E1; border: 2px solid #FFB300; border-radius: 12px;
  padding: 16px 20px; margin-bottom: 24px; text-align: left; max-width: 360px;
}
.fm-vpn-icon { font-size: 28px; margin-bottom: 8px; }
.fm-vpn-title { font-size: 16px; font-weight: 700; color: #E65100; margin-bottom: 8px; }
.fm-vpn-text { font-size: 13px; line-height: 1.5; color: #5D4037; }

/* ===== HEADER ===== */
.fm-header {
  display: flex; align-items: center; padding: 12px 16px;
  padding-top: calc(12px + var(--fm-safe-top));
  background: var(--fm-green); color: white; flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,.15); z-index: 100;
}
.fm-header-back {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; margin-right: 8px; border: none; background: none; color: white;
  font-size: 20px; border-radius: 50%; flex-shrink: 0;
}
.fm-header-back:hover { background: rgba(255,255,255,.15); }
.fm-header-title { font-size: 17px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fm-header-subtitle { font-size: 12px; opacity: .8; }
.fm-header-info { flex: 1; min-width: 0; }
.fm-header-actions { display: flex; gap: 8px; }

/* ===== TABS ===== */
.fm-tabs {
  display: flex; background: var(--fm-white); border-bottom: 1px solid var(--fm-border); flex-shrink: 0;
}
.fm-tab {
  flex: 1; padding: 12px; text-align: center; font-size: 14px; font-weight: 500;
  color: var(--fm-text-secondary); cursor: pointer; border-bottom: 2px solid transparent; transition: all .2s;
  background: none; border-top: none; border-left: none; border-right: none;
}
.fm-tab.active { color: var(--fm-green); border-bottom-color: var(--fm-green); }
.fm-tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--fm-green); color: white; font-size: 11px; font-weight: 600; margin-left: 6px;
}

/* ===== CONVERSATION LIST ===== */
.fm-conv-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.fm-conv-item {
  display: flex; align-items: center; padding: 14px 16px; gap: 12px;
  border-bottom: 1px solid #f0f0f0; cursor: pointer; transition: background .15s;
}
.fm-conv-item:hover { background: #fafafa; }
.fm-conv-item:active { background: #f0f0f0; }
.fm-avatar {
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 600; color: white; overflow: hidden;
}
.fm-avatar img { width: 100%; height: 100%; object-fit: cover; }
.fm-avatar-green { background: var(--fm-green); }
.fm-avatar-blue { background: var(--fm-blue); }
.fm-conv-info { flex: 1; min-width: 0; }
.fm-conv-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fm-conv-preview {
  font-size: 13px; color: var(--fm-text-secondary); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; margin-top: 2px;
}
.fm-conv-meta { text-align: right; flex-shrink: 0; }
.fm-conv-time { font-size: 12px; color: var(--fm-text-secondary); }
.fm-conv-unread {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--fm-green); color: white; font-size: 12px; font-weight: 600; margin-top: 4px;
}

/* ===== EMPTY STATE ===== */
.fm-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; text-align: center; padding: 24px; color: var(--fm-text-secondary);
}
.fm-empty-icon { font-size: 48px; margin-bottom: 16px; opacity: .5; }
.fm-empty h3 { font-size: 18px; margin-bottom: 8px; color: var(--fm-text); }

/* ===== CHAT VIEW ===== */
.fm-chat { display: flex; flex-direction: column; height: 100%; }
.fm-messages {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 16px; display: flex; flex-direction: column; gap: 4px;
  background: #ECE5DD;
}
.fm-msg {
  max-width: 80%; padding: 8px 12px; border-radius: var(--fm-radius-sm);
  position: relative; word-wrap: break-word; overflow-wrap: break-word;
  line-height: 1.4; font-size: 15px;
}
.fm-msg-own { align-self: flex-end; background: var(--fm-bubble-own); border-bottom-right-radius: 4px; }
.fm-msg-other { align-self: flex-start; background: var(--fm-bubble-other); border-bottom-left-radius: 4px; box-shadow: var(--fm-shadow); }
.fm-msg-system {
  align-self: center; background: rgba(0,0,0,.06); color: var(--fm-text-secondary);
  font-size: 13px; padding: 4px 12px; border-radius: 8px; max-width: 90%;
}
.fm-msg-sender { font-size: 13px; font-weight: 600; color: var(--fm-green); margin-bottom: 2px; }
.fm-msg-text { white-space: pre-wrap; }
.fm-msg-time {
  font-size: 11px; color: rgba(0,0,0,.4); text-align: right; margin-top: 2px;
  float: right; margin-left: 8px; position: relative; top: 4px;
}
.fm-msg-device { font-size: 10px; color: rgba(0,0,0,.3); margin-right: 4px; }
.fm-msg-read { font-size: 11px; color: rgba(0,0,0,.35); margin-left: 3px; letter-spacing: -2px; font-weight: 600; }
.fm-msg-read-seen { color: #4FC3F7; }
.fm-msg-date {
  align-self: center; background: rgba(0,0,0,.08); color: var(--fm-text-secondary);
  font-size: 12px; padding: 4px 12px; border-radius: 8px; margin: 8px 0;
}

/* Media in messages */
.fm-msg-media { margin: 4px -4px; border-radius: 8px; overflow: hidden; cursor: pointer; position: relative; }
.fm-msg-media img { display: block; max-width: 100%; max-height: 300px; object-fit: contain; border-radius: 8px; }
.fm-msg-media video { display: block; max-width: 100%; max-height: 300px; border-radius: 8px; background: #000; }
.fm-msg-media[data-type="video"]::after {
  content: "▶"; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 48px; height: 48px; background: rgba(0,0,0,.55); color: #fff; font-size: 20px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  pointer-events: none; padding-left: 3px;
}
.fm-msg-duration {
  position: absolute; bottom: 8px; right: 8px; background: rgba(0,0,0,.6);
  color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 4px;
  pointer-events: none; font-variant-numeric: tabular-nums;
}
/* Upload progress */
.fm-upload-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 999;
  display: flex; align-items: center; justify-content: center;
}
.fm-upload-card {
  background: #fff; border-radius: 16px; padding: 28px 32px; text-align: center;
  min-width: 260px; box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.fm-upload-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: #333; }
.fm-upload-bar { height: 6px; background: #e0e0e0; border-radius: 3px; overflow: hidden; }
.fm-upload-fill { height: 100%; background: var(--fm-green); border-radius: 3px; transition: width .2s; width: 0; }
.fm-upload-pct { font-size: 13px; color: #888; margin-top: 8px; }
.fm-msg-file {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: rgba(0,0,0,.04); border-radius: 8px; margin: 4px 0; cursor: pointer;
}
.fm-msg-file-icon { font-size: 24px; flex-shrink: 0; }
.fm-msg-file-info { flex: 1; min-width: 0; }
.fm-msg-file-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fm-msg-file-size { font-size: 12px; color: var(--fm-text-secondary); }

/* ===== REPLY — Quote block in message ===== */
.fm-quote {
  display: flex; align-items: stretch; gap: 0;
  margin: -2px -4px 6px -4px; padding: 8px 10px;
  border-radius: 8px; cursor: pointer;
  background: rgba(0,0,0,.05); transition: background .15s;
}
.fm-msg-own .fm-quote { background: rgba(0,0,0,.06); }
.fm-quote:active { background: rgba(0,0,0,.1); }
.fm-quote-bar {
  width: 3px; min-height: 100%; border-radius: 2px;
  background: var(--fm-blue); flex-shrink: 0; margin-right: 8px;
}
.fm-quote-bar-own { background: var(--fm-green); }
.fm-quote-body { flex: 1; min-width: 0; }
.fm-quote-name { font-size: 12px; font-weight: 600; color: var(--fm-blue); margin-bottom: 1px; }
.fm-quote-name-own { color: var(--fm-green); }
.fm-quote-text {
  font-size: 13px; color: var(--fm-text-secondary); line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.fm-quote-thumb {
  width: 40px; height: 40px; border-radius: 6px; object-fit: cover;
  flex-shrink: 0; margin-left: 8px;
}

/* ===== REPLY BAR above input ===== */
.fm-reply-bar {
  display: none; align-items: center; gap: 0; padding: 8px 12px;
  background: var(--fm-white); border-top: 1px solid var(--fm-border);
  flex-shrink: 0; animation: fm-reply-slide .2s ease;
}
@keyframes fm-reply-slide { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fm-reply-bar-accent {
  width: 3px; height: 36px; border-radius: 2px; background: var(--fm-blue);
  flex-shrink: 0; margin-right: 10px;
}
.fm-reply-accent-own { background: var(--fm-green); }
.fm-reply-bar-body { flex: 1; min-width: 0; }
.fm-reply-bar-name { font-size: 13px; font-weight: 600; color: var(--fm-blue); }
.fm-reply-name-own { color: var(--fm-green); }
.fm-reply-bar-text {
  font-size: 13px; color: var(--fm-text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fm-reply-bar-thumb {
  width: 36px; height: 36px; border-radius: 6px; object-fit: cover;
  flex-shrink: 0; margin-left: 8px;
}
.fm-reply-bar-close {
  width: 32px; height: 32px; border: none; background: none;
  color: var(--fm-text-secondary); font-size: 20px; cursor: pointer;
  border-radius: 50%; flex-shrink: 0; margin-left: 4px;
  display: flex; align-items: center; justify-content: center;
}
.fm-reply-bar-close:hover { background: rgba(0,0,0,.06); }

/* ===== Reply button (desktop hover) ===== */
.fm-msg-reply-btn {
  position: absolute; top: 2px; right: 2px; opacity: 0; pointer-events: none;
  width: 28px; height: 28px; border: none;
  background: rgba(255,255,255,.75); backdrop-filter: blur(4px);
  border-radius: 50%; cursor: pointer; font-size: 15px;
  color: var(--fm-text-secondary);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s; z-index: 2;
}
.fm-msg:hover .fm-msg-reply-btn { opacity: 1; pointer-events: auto; }
.fm-msg-reply-btn:hover { background: rgba(255,255,255,.9); color: var(--fm-text); }
.fm-msg-other .fm-msg-reply-btn { background: rgba(0,0,0,.05); }
.fm-msg-other .fm-msg-reply-btn:hover { background: rgba(0,0,0,.1); }

/* ===== Scroll-to highlight ===== */
@keyframes fm-msg-glow {
  0% { box-shadow: 0 0 0 0 rgba(255,193,7,.5); }
  40% { box-shadow: 0 0 0 4px rgba(255,193,7,.35); }
  100% { box-shadow: 0 0 0 0 rgba(255,193,7,0); }
}
.fm-msg-highlight { animation: fm-msg-glow 1.5s ease-out; }

/* Mobile: swipe to reply instead of hover button */
@media (max-width: 767px) {
  .fm-msg-reply-btn { display: none !important; }
}

/* Typing indicator */
.fm-typing {
  font-size: 13px; color: var(--fm-text-secondary); padding: 4px 16px 8px;
  font-style: italic; flex-shrink: 0;
}

/* ===== CHAT INPUT ===== */
.fm-input-bar {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px;
  padding-bottom: calc(8px + var(--fm-safe-bottom));
  background: var(--fm-white); border-top: 1px solid var(--fm-border); flex-shrink: 0;
}
.fm-input-attach {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border: none; background: none; color: var(--fm-text-secondary); font-size: 22px;
  cursor: pointer; border-radius: 50%; flex-shrink: 0;
}
.fm-input-attach:hover { background: #f0f0f0; }
.fm-input-text {
  flex: 1; min-height: 40px; max-height: 120px; padding: 10px 14px;
  border: 1px solid var(--fm-border); border-radius: 20px; outline: none;
  font-size: 15px; resize: none; line-height: 1.4; font-family: inherit;
}
.fm-input-text:focus { border-color: var(--fm-green); }
.fm-input-send {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border: none; background: var(--fm-green); color: white; font-size: 18px;
  cursor: pointer; border-radius: 50%; flex-shrink: 0; transition: background .2s;
}
.fm-input-send:hover { background: var(--fm-green-light); }
.fm-input-send:disabled { background: #ccc; cursor: default; }

/* ===== MEDIA VIEWER (fullscreen overlay) ===== */
.fm-viewer {
  position: fixed; inset: 0; background: rgba(0,0,0,.95); z-index: 1000;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
}
.fm-viewer-close {
  position: absolute; top: 16px; right: 16px; width: 40px; height: 40px;
  border: none; background: rgba(255,255,255,.2); color: white; font-size: 24px;
  border-radius: 50%; cursor: pointer; z-index: 1001;
  padding-top: env(safe-area-inset-top, 0);
}
.fm-viewer img, .fm-viewer video {
  max-width: 100%; max-height: 90vh; object-fit: contain;
}
.fm-viewer-download {
  margin-top: 16px; padding: 10px 24px; background: rgba(255,255,255,.2); color: white;
  border: none; border-radius: 20px; font-size: 14px; cursor: pointer;
}

/* ===== FAB ===== */
.fm-fab {
  position: fixed; bottom: calc(24px + var(--fm-safe-bottom)); right: 20px;
  width: 56px; height: 56px; border-radius: 50%; background: var(--fm-green);
  color: white; border: none; font-size: 28px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.2); z-index: 50; transition: transform .2s;
  display: flex; align-items: center; justify-content: center;
}
.fm-fab:hover { transform: scale(1.05); }

/* ===== PUSH BANNER ===== */
.fm-push-banner {
  position: fixed; top: 0; left: 0; right: 0; padding: 16px;
  padding-top: calc(16px + var(--fm-safe-top));
  background: var(--fm-green); color: white;
  box-shadow: 0 4px 12px rgba(0,0,0,.2); z-index: 300;
  display: flex; align-items: center; gap: 12px;
  animation: fm-slide-down .3s ease;
}
@keyframes fm-slide-down { from { transform: translateY(-100%); } to { transform: translateY(0); } }
.fm-push-banner-text { flex: 1; font-size: 14px; }
.fm-push-banner-text strong { display: block; font-size: 15px; margin-bottom: 2px; }
.fm-push-btn { background: white !important; color: var(--fm-green) !important; padding: 10px 20px; white-space: nowrap; }
.fm-push-banner .fm-install-close { color: rgba(255,255,255,.7); }

/* ===== INSTALL BANNER ===== */
.fm-install-banner {
  position: fixed; bottom: 0; left: 0; right: 0; padding: 16px;
  padding-bottom: calc(16px + var(--fm-safe-bottom));
  background: var(--fm-white); border-top: 1px solid var(--fm-border);
  box-shadow: 0 -4px 12px rgba(0,0,0,.1); z-index: 200;
  display: flex; align-items: center; gap: 12px;
}
.fm-install-banner-text { flex: 1; font-size: 14px; }
.fm-install-banner-text strong { display: block; font-size: 15px; margin-bottom: 2px; }
.fm-install-btn { padding: 10px 20px; }
.fm-install-close {
  width: 32px; height: 32px; border: none; background: none;
  font-size: 20px; color: var(--fm-text-secondary); cursor: pointer;
}

/* ===== LOADING ===== */
.fm-loading {
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.fm-spinner {
  width: 32px; height: 32px; border: 3px solid var(--fm-border);
  border-top-color: var(--fm-green); border-radius: 50%;
  animation: fm-spin .8s linear infinite;
}
@keyframes fm-spin { to { transform: rotate(360deg); } }

/* ===== SCROLLBAR ===== */
.fm-conv-list::-webkit-scrollbar, .fm-messages::-webkit-scrollbar { width: 4px; }
.fm-conv-list::-webkit-scrollbar-thumb, .fm-messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,.15); border-radius: 2px;
}

/* ===== DESKTOP ===== */
@media (min-width: 768px) {
  .fm-msg { max-width: 60%; }
  .fm-auth-form { max-width: 360px; }
}
