/* ============================
   WhatsApp iPhone Clone - dicKI
   Pixel-perfect iOS WhatsApp
   ============================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --wa-green: #075E54;
  --wa-green-light: #25D366;
  --wa-teal: #128C7E;
  --wa-teal-dark: #075E54;
  --wa-blue: #34B7F1;
  --wa-chat-bg: #ECE5DD;
  --wa-bubble-out: #DCF8C6;
  --wa-bubble-in: #FFFFFF;
  --wa-header-bg: #F6F6F6;
  --wa-input-bg: #FFFFFF;
  --wa-text-primary: #111B21;
  --wa-text-secondary: #667781;
  --wa-text-timestamp: #667781;
  --wa-border: #E9EDEF;
  --wa-ios-blue: #007AFF;
  --wa-ios-header-bg: #F6F6F6;
  --wa-ios-separator: #C6C6C8;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, 'SF Pro Text', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 16px;
  background: #000;
  color: var(--wa-text-primary);
}

/* ---- Screen management ---- */
.screen {
  display: none;
  height: 100%;
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

/* ---- Login Screen ---- */
#login-screen {
  background: linear-gradient(135deg, #075E54 0%, #128C7E 50%, #25D366 100%);
  align-items: center;
  justify-content: center;
}

.login-container {
  text-align: center;
  padding: 40px 30px;
  width: 100%;
}

.login-icon {
  margin-bottom: 24px;
}

.login-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.3);
  object-fit: cover;
}

.login-container h2 {
  color: white;
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.ki-highlight {
  color: #FFD700;
  font-weight: 700;
}

.login-subtitle {
  color: rgba(255,255,255,0.8);
  font-size: 15px;
  margin-bottom: 32px;
}

#access-code {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0 auto 16px;
  padding: 14px 20px;
  border: none;
  border-radius: 24px;
  font-size: 17px;
  text-align: center;
  background: rgba(255,255,255,0.95);
  outline: none;
  letter-spacing: 2px;
}

#login-btn {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0 auto 16px;
  padding: 14px 20px;
  border: none;
  border-radius: 24px;
  font-size: 17px;
  font-weight: 600;
  background: white;
  color: var(--wa-green);
  cursor: pointer;
  transition: transform 0.15s;
}

#login-btn:active {
  transform: scale(0.97);
}

.error-text {
  color: #FF6B6B;
  font-size: 14px;
  min-height: 20px;
}

.disclaimer {
  color: rgba(255,255,255,0.5);
  font-size: 11px;
  margin-top: 40px;
}

/* ---- WhatsApp Header (iOS style) ---- */
.wa-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: max(env(safe-area-inset-top, 0px), 10px);
  background: var(--wa-ios-header-bg);
  border-bottom: 0.5px solid var(--wa-ios-separator);
  min-height: 60px;
  flex-shrink: 0;
  z-index: 10;
}

.wa-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.wa-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}

.wa-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.wa-header-info {
  display: flex;
  flex-direction: column;
}

.wa-header-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--wa-text-primary);
  line-height: 1.2;
}

.wa-header-status {
  font-size: 12px;
  color: var(--wa-text-secondary);
  line-height: 1.3;
}

.wa-header-right {
  display: flex;
  gap: 20px;
}

.wa-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--wa-ios-blue);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Chat Area ---- */
.wa-chat {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--wa-chat-bg);
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.wa-chat-bg {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg width='200' height='200' viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23000' fill-opacity='0.4'%3E%3Ccircle cx='20' cy='20' r='2'/%3E%3Ccircle cx='60' cy='40' r='1.5'/%3E%3Ccircle cx='100' cy='20' r='2'/%3E%3Ccircle cx='140' cy='50' r='1'/%3E%3Ccircle cx='180' cy='30' r='1.5'/%3E%3Ccircle cx='40' cy='80' r='1'/%3E%3Ccircle cx='80' cy='100' r='2'/%3E%3Ccircle cx='120' cy='80' r='1.5'/%3E%3Ccircle cx='160' cy='110' r='1'/%3E%3Ccircle cx='20' cy='140' r='1.5'/%3E%3Ccircle cx='60' cy='160' r='2'/%3E%3Ccircle cx='100' cy='140' r='1'/%3E%3Ccircle cx='140' cy='170' r='1.5'/%3E%3Ccircle cx='180' cy='150' r='2'/%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
}

.wa-messages {
  position: relative;
  padding: 8px 12px 8px;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  justify-content: flex-end;
}

/* Date separator */
.wa-date-separator {
  text-align: center;
  margin: 12px 0;
}

.wa-date-separator span {
  background: #E1F2FA;
  color: var(--wa-text-secondary);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  display: inline-block;
  font-weight: 500;
  box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

/* Message Bubbles */
.wa-bubble {
  max-width: 78%;
  padding: 6px 7px 4px 9px;
  border-radius: 8px;
  margin: 1px 0;
  position: relative;
  line-height: 1.35;
  word-wrap: break-word;
  clear: both;
}

.wa-bubble.incoming {
  background: var(--wa-bubble-in);
  align-self: flex-start;
  border-top-left-radius: 0;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.08);
}

.wa-bubble.outgoing {
  background: var(--wa-bubble-out);
  align-self: flex-end;
  border-top-right-radius: 0;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.08);
}

.wa-bubble-text {
  font-size: 15.5px;
  color: var(--wa-text-primary);
  white-space: pre-wrap;
}

.wa-bubble-text a {
  color: #027EB5;
  text-decoration: none;
}

.wa-bubble-media {
  margin: -2px -3px 2px -5px;
  border-radius: 6px;
  overflow: hidden;
  max-width: 300px;
}

.wa-bubble-media img,
.wa-bubble-media video {
  display: block;
  max-width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: 6px;
}

.wa-bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 1px;
  float: right;
  margin-left: 8px;
  padding-left: 6px;
}

.wa-bubble-time {
  font-size: 11px;
  color: var(--wa-text-timestamp);
}

.wa-bubble-check {
  display: inline-flex;
}

.wa-bubble-check svg {
  width: 16px;
  height: 11px;
}

/* First message in group gets tail */
.wa-bubble.incoming.first-in-group {
  border-top-left-radius: 0;
}

.wa-bubble.outgoing.first-in-group {
  border-top-right-radius: 0;
}

.wa-bubble.incoming.first-in-group::before {
  content: '';
  position: absolute;
  top: 0;
  left: -7px;
  width: 0;
  height: 0;
  border-top: 0 solid transparent;
  border-right: 7px solid var(--wa-bubble-in);
  border-bottom: 8px solid transparent;
}

.wa-bubble.outgoing.first-in-group::after {
  content: '';
  position: absolute;
  top: 0;
  right: -7px;
  width: 0;
  height: 0;
  border-top: 0 solid transparent;
  border-left: 7px solid var(--wa-bubble-out);
  border-bottom: 8px solid transparent;
}

/* Spacing between message groups */
.wa-bubble.first-in-group {
  margin-top: 8px;
}

/* Typing indicator */
.wa-typing {
  align-self: flex-start;
  background: var(--wa-bubble-in);
  border-radius: 8px;
  border-top-left-radius: 0;
  padding: 10px 14px;
  display: none;
  margin-top: 8px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.08);
}

.wa-typing.visible {
  display: flex;
}

.wa-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.wa-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8696A0;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.wa-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.wa-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---- Input Bar ---- */
.wa-input-bar {
  background: var(--wa-ios-header-bg);
  border-top: 0.5px solid var(--wa-ios-separator);
  padding: 6px 8px;
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 6px);
  flex-shrink: 0;
}

.wa-input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.wa-plus-btn {
  color: var(--wa-ios-blue);
  flex-shrink: 0;
  width: 36px;
  height: 36px;
}

.wa-input-container {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--wa-input-bg);
  border: 1px solid var(--wa-ios-separator);
  border-radius: 20px;
  padding: 6px 12px;
  min-height: 36px;
  max-height: 120px;
  position: relative;
}

.wa-input {
  flex: 1;
  font-size: 16px;
  line-height: 1.35;
  max-height: 100px;
  overflow-y: auto;
  outline: none;
  word-break: break-word;
  color: var(--wa-text-primary);
}

.wa-input:empty::before {
  content: attr(data-placeholder);
  color: var(--wa-text-secondary);
  pointer-events: none;
}

.wa-emoji-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--wa-text-secondary);
  padding: 0;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: 4px;
}

.wa-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--wa-ios-blue);
  border: none;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.wa-send-btn.visible {
  display: flex;
}

.wa-send-btn:active {
  transform: scale(0.9);
}

.wa-mic-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--wa-ios-blue);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.wa-mic-btn.hidden {
  display: none;
}

/* ---- Admin Dashboard ---- */
.admin-header {
  background: #1a1a2e;
  color: white;
  padding: 20px;
  padding-top: max(env(safe-area-inset-top, 0px), 20px);
  text-align: center;
  flex-shrink: 0;
}

.admin-header h2 {
  font-size: 20px;
  margin-bottom: 4px;
}

.admin-subtitle {
  font-size: 13px;
  opacity: 0.6;
}

.admin-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f5f5f5;
}

.admin-msg {
  background: white;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.admin-msg.from-mudrack {
  border-left: 3px solid var(--wa-teal);
}

.admin-msg.from-ai {
  border-left: 3px solid var(--wa-ios-blue);
}

.admin-msg.is-deleted {
  opacity: 0.4;
}

.admin-msg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.admin-msg-sender {
  font-weight: 600;
  font-size: 13px;
}

.admin-msg-time {
  font-size: 11px;
  color: var(--wa-text-secondary);
}

.admin-msg-text {
  font-size: 14px;
  margin-bottom: 8px;
  white-space: pre-wrap;
}

.admin-msg-media img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  margin-bottom: 8px;
}

.admin-msg-actions {
  display: flex;
  gap: 8px;
}

.admin-btn {
  font-size: 12px;
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}

.admin-btn.edit {
  background: #E3F2FD;
  color: #1565C0;
}

.admin-btn.delete {
  background: #FFEBEE;
  color: #C62828;
}

.admin-btn.edit:hover { background: #BBDEFB; }
.admin-btn.delete:hover { background: #FFCDD2; }

/* ---- Responsive ---- */
@media (min-width: 431px) {
  .screen {
    border-left: 1px solid #ddd;
    border-right: 1px solid #ddd;
  }
  body {
    background: #8696A0;
  }
}

/* Image preview overlay */
.media-preview-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.9);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.media-preview-overlay img {
  max-width: 90%;
  max-height: 70vh;
  border-radius: 8px;
}

.media-preview-actions {
  margin-top: 20px;
  display: flex;
  gap: 16px;
}

.media-preview-actions button {
  padding: 10px 28px;
  border: none;
  border-radius: 24px;
  font-size: 16px;
  cursor: pointer;
  font-weight: 600;
}

.preview-send {
  background: var(--wa-ios-blue);
  color: white;
}

.preview-cancel {
  background: rgba(255,255,255,0.2);
  color: white;
}
