/* WhatsApp Inbox — dark theme */

:root {
  --bg:           #0b141a;
  --panel:        #111b21;
  --panel-2:      #202c33;
  --panel-3:      #2a3942;
  --border:       #222e35;
  --text:         #e9edef;
  --text-soft:    #aebac1;
  --text-muted:   #8696a0;
  --bubble-in:    #202c33;
  --bubble-out:   #005c4b;
  --accent:       #00a884;
  --accent-2:     #25d366;
  --danger:       #f15c6d;
  --link:         #53bdeb;
  --shadow:       0 1px 2px rgba(0,0,0,0.3);
}

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

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', 'Segoe UI', system-ui, sans-serif;
  overscroll-behavior: none;
  overflow: hidden;
}

.hidden { display: none !important; }

.screen {
  width: 100vw;
  height: 100vh;
  position: fixed;
  inset: 0;
}

/* ─────────── Login ─────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #0b141a 0%, #0e1a22 100%);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  width: min(92vw, 380px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.login-brand {
  text-align: center;
  margin-bottom: 12px;
}

.login-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  position: relative;
}
.login-logo::before {
  content: '💬';
  font-size: 32px;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.login-card .subtitle {
  opacity: 0.5;
  font-size: 13px;
  margin-top: 4px;
}

.login-card input {
  background: var(--panel-2);
  border: 1px solid transparent;
  color: var(--text);
  padding: 13px 16px;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}
.login-card input:focus {
  border-color: var(--accent);
}

.login-card button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 13px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 6px;
  transition: background 0.15s, transform 0.1s;
}
.login-card button:hover { background: var(--accent-2); }
.login-card button:active { transform: scale(0.98); }

.error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  min-height: 16px;
}

/* ─────────── Main layout ─────────── */
.layout {
  display: flex;
  width: 100%;
  height: 100%;
}

.contacts-pane {
  width: 380px;
  min-width: 380px;
  max-width: 30vw;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.chat-pane {
  flex: 1;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ─── Contacts header ─── */
.contacts-header {
  height: 60px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.me {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
}

.header-actions {
  display: flex;
  gap: 4px;
}

.header-actions button {
  background: transparent;
  border: none;
  color: var(--text-soft);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
}
.header-actions button:hover { background: var(--panel-3); }

#new-contact-btn { font-size: 24px; line-height: 1; }

/* ─── Search bar ─── */
.search-bar {
  padding: 8px 12px;
  background: var(--panel);
}

#search-input {
  width: 100%;
  background: var(--panel-2);
  border: none;
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
#search-input::placeholder {
  color: var(--text-muted);
}

/* ─── Contacts list ─── */
.contacts-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.contact-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.contact-row:hover { background: var(--panel-2); }
.contact-row.active { background: var(--panel-3); }

.contact-row .info {
  flex: 1;
  min-width: 0;
}

.contact-row .row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.contact-row .name {
  font-size: 15.5px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.contact-row .ts {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.contact-row .row-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.contact-row .preview {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.contact-row .preview .out-prefix {
  margin-right: 3px;
}

.contact-row .badge {
  background: var(--accent);
  color: #0b141a;
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
}

.contacts-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ─── Avatar ─── */
.avatar {
  width: 49px;
  height: 49px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  user-select: none;
  overflow: hidden;
  position: relative;
}
.avatar.small {
  width: 40px;
  height: 40px;
  font-size: 14px;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ─── Empty state ─── */
.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--panel);
  border-left: 1px solid var(--border);
}

.chat-empty-state .logo-large {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 30px;
  position: relative;
}
.chat-empty-state .logo-large::before {
  content: '💬';
  font-size: 100px;
  opacity: 0.3;
}

.chat-empty-state h2 {
  color: var(--text-soft);
  font-size: 32px;
  font-weight: 300;
  margin-bottom: 10px;
}

.chat-empty-state p {
  color: var(--text-muted);
  font-size: 14px;
}

/* ─── Conversation ─── */
.chat-conversation {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(rgba(11,20,26,0.95), rgba(11,20,26,0.95)),
    repeating-linear-gradient(45deg, transparent 0 8px, rgba(255,255,255,0.01) 8px 16px);
}

.chat-header {
  height: 60px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: var(--panel-2);
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-back {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 32px;
  width: 30px;
  cursor: pointer;
  display: none;
  line-height: 1;
}

.chat-contact-info {
  flex: 1;
  min-width: 0;
}

.chat-contact-name {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-contact-phone {
  font-size: 12px;
  color: var(--text-muted);
}

.window-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--panel-3);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.window-indicator .window-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.window-indicator.open .window-dot { background: var(--accent-2); }
.window-indicator.warn .window-dot { background: #ffaa00; }
.window-indicator.closed .window-dot { background: var(--danger); }
.window-indicator.open { color: var(--accent-2); }
.window-indicator.warn { color: #ffaa00; }
.window-indicator.closed { color: var(--danger); }

.mute-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-soft);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mute-toggle:hover { background: var(--panel-3); }
.mute-toggle.muted {
  background: rgba(241, 92, 109, 0.15);
  border-color: var(--danger);
  color: var(--danger);
}

@media (max-width: 600px) {
  .window-indicator { display: none; }
}

/* Template-only input */
#chat-input-area {
  flex-shrink: 0;
}

.chat-input-template {
  background: var(--panel-2);
  border-top: 1px solid var(--border);
  padding: 16px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.window-closed-notice {
  display: flex;
  gap: 12px;
  align-items: center;
  background: rgba(241, 92, 109, 0.08);
  border: 1px solid rgba(241, 92, 109, 0.25);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-soft);
}

.window-closed-notice .closed-icon { font-size: 22px; }
.window-closed-notice strong { color: var(--text); display: block; font-size: 14px; }
.window-closed-notice .closed-sub { font-size: 12px; opacity: 0.8; margin-top: 2px; }

.big-button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}
.big-button:hover { background: var(--accent-2); }

/* ─── Modals ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(92vw, 460px);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-card.large { width: min(94vw, 600px); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-soft);
  font-size: 26px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  line-height: 1;
}
.modal-close:hover { background: var(--panel-2); }

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn-primary:hover { background: var(--accent-2); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  background: var(--panel-3);
  color: var(--text);
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--border); }
.btn-secondary.small { padding: 6px 12px; font-size: 12px; }

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.form-field span {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-field input, .form-field textarea {
  background: var(--panel-2);
  border: 1px solid transparent;
  color: var(--text);
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.form-field input:focus, .form-field textarea:focus {
  border-color: var(--accent);
}
.form-field small {
  font-size: 11px;
  color: var(--text-muted);
}

.muted { color: var(--text-muted); font-size: 12px; }

/* ─── Template list ─── */
.template-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.template-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.template-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.1s;
}
.template-item:hover { background: var(--panel-3); }
.template-item.disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.template-item .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.template-item .name {
  font-size: 14px;
  font-weight: 500;
}
.template-item .meta {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 10px;
}
.template-item .meta.approved { background: rgba(0, 168, 132, 0.2); color: var(--accent-2); }
.template-item .meta.pending { background: rgba(255, 170, 0, 0.2); color: #ffaa00; }
.template-item .meta.rejected { background: rgba(241, 92, 109, 0.2); color: var(--danger); }
.template-item .meta.unknown { background: var(--panel-3); color: var(--text-muted); }
.template-item .preview {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.template-item .category-tag {
  font-size: 10px;
  background: var(--panel-3);
  padding: 1px 7px;
  border-radius: 8px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ─── Template preview ─── */
.template-status {
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
}
.template-status.approved { background: rgba(0, 168, 132, 0.1); color: var(--accent-2); }
.template-status.pending { background: rgba(255, 170, 0, 0.1); color: #ffaa00; }
.template-status.rejected { background: rgba(241, 92, 109, 0.1); color: var(--danger); }

.template-preview-body {
  background: var(--bubble-out);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  white-space: pre-wrap;
  line-height: 1.4;
}

.cost-warning {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(255, 170, 0, 0.1);
  border: 1px solid rgba(255, 170, 0, 0.3);
  border-radius: 8px;
  font-size: 12px;
  color: #ffcc66;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 5%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 65%;
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 14.5px;
  line-height: 1.36;
  word-wrap: break-word;
  position: relative;
  flex-shrink: 0;
  margin-bottom: 2px;
  box-shadow: var(--shadow);
}

.msg.in {
  align-self: flex-start;
  background: var(--bubble-in);
  color: var(--text);
  border-top-left-radius: 0;
}

.msg.out {
  align-self: flex-end;
  background: var(--bubble-out);
  color: var(--text);
  border-top-right-radius: 0;
}

.msg .body {
  white-space: pre-wrap;
}

.msg .meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-muted);
}

.msg.out .meta {
  color: rgba(255,255,255,0.5);
}

.msg .meta .ticks {
  font-size: 13px;
  letter-spacing: -2px;
}

.msg .meta .ticks.read {
  color: var(--link);
}

.msg.image, .msg.video {
  padding: 4px;
  width: min(380px, 70vw);
  max-width: min(380px, 70vw);
}

.msg.image img, .msg.video video {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  cursor: pointer;
}

.msg.image .body, .msg.video .body {
  padding: 6px 8px 4px;
  font-size: 14px;
}

.msg.image .meta, .msg.video .meta {
  padding: 0 8px 4px;
}

.msg.audio audio {
  display: block;
  width: 100%;
  margin: 4px 0;
}

.msg.template {
  border: 1px dashed var(--text-muted);
  font-style: italic;
  opacity: 0.85;
}

.msg.failed { opacity: 0.6; }
.msg.failed::after {
  content: ' ⚠️';
}

/* WhatsApp formatting */
.msg strong { font-weight: 700; }
.msg em { font-style: italic; }
.msg del { text-decoration: line-through; opacity: 0.7; }
.msg code {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 4px;
}
.msg a {
  color: var(--link);
  text-decoration: underline;
}

.msg-day-divider {
  align-self: center;
  background: var(--panel-2);
  color: var(--text-muted);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  margin: 14px 0;
  box-shadow: var(--shadow);
}

/* ─── Input row ─── */
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--panel-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-row textarea {
  flex: 1;
  background: var(--panel-3);
  border: none;
  color: var(--text);
  padding: 11px 16px;
  border-radius: 22px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 140px;
  line-height: 1.35;
  overflow-y: auto;
}

.chat-input-row button {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-input-row button:hover { background: var(--accent-2); }

.chat-attach {
  background: transparent !important;
  color: var(--text-soft) !important;
}
.chat-attach:hover { background: var(--panel-3) !important; }

/* ─── Image viewer ─── */
.image-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.93);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.image-viewer.hidden { display: none; }
.image-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.image-viewer .close-btn {
  position: absolute;
  top: calc(15px + env(safe-area-inset-top));
  right: 15px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
}

/* ─── Mobile ─── */
@media (max-width: 767px) {
  .contacts-pane {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
  }
  .chat-pane {
    position: fixed;
    inset: 0;
    z-index: 10;
    transform: translateX(100%);
    transition: transform 0.25s ease-out;
  }
  .chat-pane.active {
    transform: translateX(0);
  }
  .chat-back { display: block; }
  .chat-empty-state { display: none; }
  .msg { max-width: 80%; }
  .msg.image, .msg.video { width: min(85vw, 380px); max-width: min(85vw, 380px); }
}
