:root {
  --green: #1D9E75;
  --green-dark: #0F6E56;
  --green-light: #E1F5EE;
  --text: #1A1A1A;
  --text-sec: #6B6B6B;
  --border: #E5E5E5;
  --bg: #F7F7F5;
  --white: #FFFFFF;
  --red: #D85A30;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#auth-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0F6E56, #1D9E75, #5DCAA5);
  padding: 16px;
}

.auth-card {
  background: white;
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 64px rgba(0,0,0,.18);
}

.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo .bridge { font-size: 48px; display: block; margin-bottom: 8px; }
.auth-logo h1 { font-size: 26px; font-weight: 600; color: var(--green-dark); }
.auth-logo p { font-size: 13px; color: var(--text-sec); margin-top: 4px; }

.badge {
  background: var(--green-light);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--green-dark);
  text-align: center;
}

.tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text-sec);
  font-family: inherit;
}

.tab.active { background: var(--green); color: white; font-weight: 500; }

.fg { margin-bottom: 14px; }

.fg label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-sec);
  margin-bottom: 5px;
}

.fg input, .fg select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  outline: none;
}

.fg input:focus, .fg select:focus { border-color: var(--green); }

.btn {
  width: 100%;
  padding: 14px;
  background: var(--green);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  margin-top: 8px;
}

.btn:hover { background: var(--green-dark); }
.btn:disabled { opacity: .6; }

#app-screen { display: none; flex: 1; overflow: hidden; }

.layout { display: grid; grid-template-columns: 280px 1fr; height: 100dvh; }

.sidebar {
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sb-header { padding: 20px 16px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }

.brand-icon {
  width: 36px;
  height: 36px;
  background: var(--green);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.brand-name { font-size: 17px; font-weight: 600; }
.brand-sub { font-size: 11px; color: var(--text-sec); }

.user-box {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.uname { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ulang { font-size: 11px; color: var(--text-sec); }

.lang-sel {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-sec);
  font-family: inherit;
}

.sb-section {
  padding: 12px 16px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: .8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.add-btn { background: none; border: none; color: var(--green); font-size: 18px; cursor: pointer; }

.contacts { flex: 1; overflow-y: auto; padding: 4px 8px; }

.contact {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
}

.contact:hover { background: var(--bg); }
.contact.active { background: var(--green-light); }

.cavatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}

.cinfo { flex: 1; min-width: 0; }
.cname { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clang { font-size: 12px; color: var(--text-sec); }

.sb-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.fbtn {
  flex: 1;
  padding: 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-sec);
  cursor: pointer;
  font-family: inherit;
}

.fbtn:hover { border-color: var(--green); color: var(--green); }

.chat {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  height: 100dvh;
  overflow: hidden;
  min-height: 0;
}

.chat-hdr {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.chat-hdr-info { flex: 1; }
.chat-hdr-name { font-size: 16px; font-weight: 600; }
.chat-hdr-sub { font-size: 12px; color: var(--text-sec); }

.sec-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--green-light);
  padding: 6px 12px;
  border-radius: 100px;
  font-size: 12px;
  color: var(--green-dark);
  white-space: nowrap;
}

.msgs {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mg { display: flex; flex-direction: column; gap: 4px; }
.mg.mine { align-items: flex-end; }
.mg.theirs { align-items: flex-start; }

.msender { font-size: 11px; color: var(--text-sec); padding: 0 4px; }

.bubble { max-width: 60%; padding: 12px 16px; border-radius: 18px; }
.mine .bubble { background: var(--green); color: white; border-bottom-right-radius: 4px; }
.theirs .bubble { background: var(--white); color: var(--text); border-bottom-left-radius: 4px; box-shadow: 0 2px 12px rgba(0,0,0,.08); }

.orig { font-size: 11px; opacity: .7; margin-bottom: 4px; font-style: italic; }
.mtxt { font-size: 15px; line-height: 1.5; }

.mmeta { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.mtime { font-size: 11px; opacity: .6; }

.rbtn {
  background: rgba(255,255,255,.2);
  border: none;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  color: white;
  cursor: pointer;
  font-family: inherit;
}

.theirs .rbtn { background: var(--green-light); color: var(--green-dark); }

.controls {
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-shrink: 0;
}

.recbtn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--green);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(29,158,117,.5);
  transition: all .2s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.recbtn.rec { background: var(--red); animation: pulse 1s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.rec-info { text-align: center; }
.rec-main { font-size: 14px; font-weight: 500; }
.rec-sub { font-size: 12px; color: var(--text-sec); margin-top: 3px; }

.tbar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: var(--green-light);
  font-size: 13px;
  color: var(--green-dark);
  flex-shrink: 0;
}

.tbar.show { display: flex; }

.spin {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(15,110,86,.3);
  border-top-color: var(--green-dark);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}

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

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-sec);
  padding: 40px;
}

.welcome .icon { font-size: 56px; opacity: .4; }
.welcome h3 { font-size: 18px; font-weight: 500; color: var(--text); }
.welcome p { font-size: 14px; text-align: center; max-width: 280px; line-height: 1.6; }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 64px rgba(0,0,0,.2);
}

.modal h3 { font-size: 18px; font-weight: 600; margin-bottom: 20px; }

.mfooter { display: flex; gap: 10px; margin-top: 20px; }

.mbtn {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: none;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-sec);
}

.gbtn {
  flex: 1;
  padding: 12px;
  background: var(--green);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1A1A1A;
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 999;
  transition: transform .3s;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
}

.toast.show { transform: translateX(-50%) translateY(0); }

.online-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22C55E;
  border: 2px solid white;
  position: absolute;
  bottom: 0;
  right: 0;
}

.offline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #9CA3AF;
  border: 2px solid white;
  position: absolute;
  bottom: 0;
  right: 0;
}

.cavatar-wrap { position: relative; flex-shrink: 0; }

.backbtn { display: none !important; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: 100dvh; }
  body.chat-open .sidebar { display: none; }
  body:not(.chat-open) .chat { display: none; }
  .backbtn { display: block !important; }
  .controls { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .bubble { max-width: 85%; }
  .sec-badge { display: none; }
}

@media (max-width: 480px) {
  .auth-card { padding: 32px 20px; }
  .recbtn { width: 64px; height: 64px; font-size: 28px; }
  .bubble { max-width: 90%; }
}
