:root {
  --tag-navy: #1a367e;
  --tag-navy-deep: #142c66;
  --tag-navy-mid: #2a4a9a;
  --tag-coral: #f05a5b;
  --tag-coral-deep: #d4484a;
  --wa-green: var(--tag-navy);
  --wa-green-deep: var(--tag-navy-deep);
  --wa-unread: var(--tag-coral);
  --wa-app-bg: #c5d0e4;
  --wa-header: var(--tag-navy);
  --wa-panel: #ffffff;
  --wa-hover: #eef2f8;
  --wa-active: #e4ebf6;
  --wa-border: #d7deea;
  --wa-chat-bg: #e8eef6;
  --wa-in: #ffffff;
  --wa-out: #d6e2f5;
  --wa-text: #111b21;
  --wa-secondary: #5b6b80;
  --wa-icon: #dce4f4;
  --wa-composer: #f4f6fb;
  --wa-shadow: 0 1px 1px rgba(26,54,126,.08), 0 2px 8px rgba(26,54,126,.12);
  --sidebar-width: 400px;
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}
.wa-body {
  background: var(--wa-app-bg);
  color: var(--wa-text);
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.login-shell { min-height: 100%; position: relative; background: #0e1a3d; }
.login-banner { height: 222px; background: linear-gradient(135deg, #2a4a9a 0%, var(--tag-navy) 48%, var(--tag-navy-deep) 100%); }
.login-card {
  width: min(860px, calc(100% - 32px));
  margin: -140px auto 40px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 17px 50px rgba(14,26,61,.28);
  padding: 48px 56px 40px;
}
.login-brand { display: flex; gap: 16px; align-items: center; margin-bottom: 28px; }
.login-logo { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; box-shadow: 0 2px 8px rgba(26,54,126,.28); }
.login-brand h1 { margin: 0; font-size: 28px; font-weight: 300; color: var(--tag-navy); }
.login-brand p { margin: 4px 0 0; color: var(--wa-secondary); }
.login-form { display: grid; gap: 16px; max-width: 420px; }
.login-form label, .modal-card label { display: grid; gap: 6px; font-size: 13px; color: var(--wa-secondary); }
.login-form input, .modal-card input, .modal-card textarea, .modal-card select, #forwardSearch {
  border: 0; border-bottom: 2px solid var(--tag-navy); padding: 10px 4px; font-size: 15px; outline: none; font-family: inherit; background: transparent; color: var(--wa-text);
}
.login-form input:focus, .modal-card input:focus, .modal-card textarea:focus, .modal-card select:focus {
  border-bottom-color: var(--tag-coral);
}
.login-error { background: #fdecec; color: #b3261e; padding: 10px 12px; border-radius: 6px; }
.login-hint { margin-top: 24px; color: var(--wa-secondary); font-size: 13px; }
.btn-primary {
  background: var(--tag-coral); color: #fff; border: 0; border-radius: 24px; padding: 12px 28px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-primary:hover { background: var(--tag-coral-deep); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-outline {
  background: #fff; color: var(--tag-navy); border: 1px solid var(--tag-navy); border-radius: 24px;
  padding: 12px 20px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-outline:hover { background: var(--wa-hover); }
.btn-outline:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; border: 0; color: var(--tag-navy); font-weight: 600; cursor: pointer; padding: 12px 16px; }

.app {
  display: grid;
  grid-template-columns: minmax(280px, var(--sidebar-width)) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  background: var(--wa-panel);
  box-shadow: var(--wa-shadow);
  overflow: hidden;
}

.sidebar,
.conversation {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--wa-border);
  background: var(--wa-panel);
  position: relative;
}
.sidebar-header, .thread-header {
  min-height: 59px; height: auto; padding: 10px 16px; background: var(--tag-navy); display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center; gap: 12px; position: relative; flex-shrink: 0; color: #fff;
}
.thread-header {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
}
.thread-header .avatar {
  grid-column: 1;
  grid-row: 1;
  box-shadow: 0 0 0 2px rgba(255,255,255,.35);
}
.thread-person-copy {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.thread-header .icon-row {
  grid-column: 3;
  grid-row: 1;
  margin-left: 0;
}
.btn-back { display: none; }
.brand { display: grid; place-items: center; flex: none; }
.brand-logo, .intro-logo {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover; display: block;
  box-shadow: 0 0 0 2px rgba(255,255,255,.28);
}
.intro-logo { width: 96px; height: 96px; box-shadow: 0 8px 24px rgba(26,54,126,.28); }
.me-avatar, .avatar, .chat-avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; flex: none; text-transform: uppercase;
}
.me-copy { flex: 1; min-width: 0; }
.me-name, .thread-name { font-weight: 600; font-size: 16px; line-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.chat-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-role, .thread-sub { font-size: 12px; line-height: 16px; color: rgba(255,255,255,.78); }
.chat-preview, .chat-time { font-size: 12px; color: var(--wa-secondary); }
.icon-row { display: flex; gap: 2px; margin-left: auto; align-items: center; }
.icon-btn {
  width: 40px; height: 40px; border: 0; background: transparent; border-radius: 50%; cursor: pointer; color: var(--wa-icon); display: grid; place-items: center;
}
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
.icon-btn:hover { background: rgba(255,255,255,.12); }
.composer .icon-btn, .reply-bar .icon-btn { color: var(--tag-navy); }
.composer .icon-btn:hover, .reply-bar .icon-btn:hover { background: rgba(26,54,126,.08); }
.composer .send-btn { color: var(--tag-coral); }

.menu-pop, .attach-menu, .ctx-menu {
  position: absolute; background: #fff; box-shadow: 0 2px 5px rgba(11,20,26,.2), 0 8px 24px rgba(11,20,26,.16); border-radius: 3px; z-index: 20; min-width: 200px; padding: 6px 0;
}
.menu-pop { top: 52px; right: 10px; }
.attach-menu { bottom: 58px; left: 52px; }
.menu-pop button, .attach-menu button, .ctx-menu button, .menu-pop form button, .menu-pop a {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: 12px 22px; font-size: 14.5px; cursor: pointer; color: var(--wa-text); font-family: inherit; text-decoration: none; box-sizing: border-box;
}
.menu-pop button:hover, .attach-menu button:hover, .ctx-menu button:hover, .menu-pop a:hover { background: var(--wa-hover); }

.search-wrap { padding: 7px 12px; background: var(--wa-panel); border-bottom: 1px solid var(--wa-border); flex-shrink: 0; }
.search-box { display: flex; align-items: center; gap: 12px; background: #eef2f8; border-radius: 8px; padding: 0 12px; height: 35px; }
.search-box svg { width: 20px; height: 20px; fill: #5b6b80; flex: none; }
.search-box input, .thread-search input {
  border: 0; background: transparent; outline: none; width: 100%; font-size: 14px; color: var(--wa-text); font-family: inherit;
}

.chat-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.chat-empty { padding: 32px 24px; color: var(--wa-secondary); text-align: center; flex-shrink: 0; }
.chat-item {
  display: grid; grid-template-columns: 49px 1fr; gap: 13px; padding: 12px 14px 12px 13px; cursor: pointer; border-bottom: 1px solid var(--wa-border); align-items: center;
}
.chat-item:hover { background: var(--wa-hover); }
.chat-item.active { background: var(--wa-active); }
.chat-top, .chat-bottom { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.chat-preview-line { display: flex; align-items: center; gap: 4px; min-width: 0; flex: 1; }
.chat-preview { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-ticks { flex: none; font-size: 13px; line-height: 1; }
.unread { background: var(--wa-unread); color: #fff; min-width: 20px; height: 20px; border-radius: 10px; font-size: 11px; font-weight: 600; display: grid; place-items: center; padding: 0 6px; }

.conversation { display: flex; flex-direction: column; background: var(--wa-chat-bg); position: relative; }
.intro { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; background: #f4f6fb; border-bottom: 6px solid var(--tag-coral); padding: 24px; }
.intro h2 { font-weight: 300; font-size: 32px; margin: 16px 0 8px; color: var(--tag-navy); }
.intro p { color: var(--wa-secondary); line-height: 1.5; }
.intro-lock { margin-top: 28px; color: var(--wa-secondary); font-size: 13px; display: flex; gap: 8px; align-items: center; }

.thread { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.thread-search { width: 220px; background: #fff; border-radius: 8px; padding: 4px 10px; display: none; }
.thread-search.open { display: block; }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 20px 6%;
  background-color: var(--wa-chat-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260' opacity='.06'%3E%3Cpath fill='%23000' d='M40 20c8 0 12 10 6 16s-16 2-14-6 4-10 8-10zm90 40c6-8 20-2 18 8s-14 12-20 4-2-8 2-12zm-80 90c10 2 12 18 2 22s-16-10-8-18 2-5 6-4zm140-20c8 6 2 20-8 18s-10-16 0-20 6 0 8 2zM30 180c12 0 14 16 4 20s-18-8-10-18 2-2 6-2zm170 20c8-6 20 4 14 14s-20 6-22-4 2-8 8-10z'/%3E%3C/svg%3E");
}

.day-chip { display: flex; justify-content: center; margin: 12px 0; }
.day-chip span { background: #ffffffd9; color: var(--wa-secondary); font-size: 12.5px; padding: 5px 12px; border-radius: 7px; box-shadow: 0 1px 0.5px rgba(11,20,26,.13); text-transform: uppercase; }

.bubble-row { display: flex; margin: 2px 0; }
.bubble-row.in { justify-content: flex-start; }
.bubble-row.out { justify-content: flex-end; }
.bubble {
  max-width: min(75%, 560px); padding: 6px 7px 8px 9px; border-radius: 7.5px; box-shadow: 0 1px 0.5px rgba(11,20,26,.13); position: relative; word-wrap: break-word;
}
.bubble-row.in .bubble { background: var(--wa-in); border-top-left-radius: 0; }
.bubble-row.out .bubble { background: var(--wa-out); border-top-right-radius: 0; }
.bubble.tail-in::before, .bubble.tail-out::before {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px;
}
.bubble.tail-in::before { left: -8px; background: radial-gradient(circle at 0 13px, transparent 8px, var(--wa-in) 8.2px); }
.bubble.tail-out::before { right: -8px; background: radial-gradient(circle at 8px 13px, transparent 8px, var(--wa-out) 8.2px); }
.fwd { font-size: 12px; color: var(--wa-secondary); font-style: italic; margin-bottom: 2px; }
.quote {
  border-left: 4px solid var(--tag-coral); background: rgba(26,54,126,.06); border-radius: 6px; padding: 6px 8px; margin-bottom: 4px; font-size: 13px; color: var(--wa-secondary);
}
.msg-text { font-size: 14.2px; line-height: 19px; white-space: pre-wrap; }
.msg-text strong { font-weight: 700; }
.msg-text em { font-style: italic; }
.msg-text s { text-decoration: line-through; }
.msg-text .wa-mono {
  font-family: "Menlo", "Consolas", "Courier New", monospace;
  font-size: 12.6px;
  background: rgba(26,54,126,.08);
  padding: 0 4px;
  border-radius: 3px;
  white-space: pre-wrap;
}
.msg-text a { color: #1a367e; text-decoration: none; }
.msg-text a:hover { text-decoration: underline; }
.msg-meta { display: flex; justify-content: flex-end; gap: 4px; align-items: center; margin-top: 2px; float: right; margin-left: 8px; }
.msg-time { font-size: 11px; color: var(--wa-secondary); }
.ticks { font-size: 14px; letter-spacing: -1px; color: var(--wa-secondary); }
.ticks.read { color: #53bdeb; }
.ticks.failed { color: var(--tag-coral); font-weight: 700; }
.edited { font-size: 11px; color: var(--wa-secondary); font-style: italic; margin-right: 4px; }
.bubble.has-header-media { padding-top: 0; min-width: min(75%, 240px); }
.msg-header-video {
  margin: 0 -7px 8px -9px;
  overflow: hidden;
  border-radius: 7.5px 7.5px 0 0;
  background: #000;
}
.bubble.tail-out.has-header-media .msg-header-video { border-top-right-radius: 0; }
.bubble.tail-in.has-header-media .msg-header-video { border-top-left-radius: 0; }
.msg-header-video video {
  display: block;
  width: 100%;
  max-height: 280px;
  background: #000;
}
.msg-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px solid rgba(11, 20, 26, .08);
}
.msg-footer-text {
  font-size: 12.5px;
  color: var(--wa-secondary);
  line-height: 16px;
  min-width: 0;
}
.msg-footer .msg-meta { float: none; margin: 0; flex: none; }
.msg-media img, .msg-media video { max-width: 280px; max-height: 320px; border-radius: 6px; display: block; cursor: pointer; }
.msg-media audio { width: 240px; }
.doc-chip { display: flex; gap: 10px; align-items: center; background: rgba(11,20,26,.04); padding: 8px 10px; border-radius: 6px; text-decoration: none; color: inherit; min-width: 180px; }
.contact-card {
  display: flex; align-items: center; gap: 10px; background: rgba(26,54,126,.06);
  border-radius: 8px; padding: 8px 10px; min-width: 220px; margin-bottom: 4px;
}
.contact-card-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--tag-navy); color: #fff;
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.contact-card-name { font-weight: 600; font-size: 14px; }
.contact-card-line { font-size: 12.5px; color: var(--wa-secondary); }
.doc-icon.xls { background: #1d6f42; }
.doc-icon.doc { background: #2b579a; }

.reply-bar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--wa-composer); border-left: 4px solid var(--tag-coral); flex-shrink: 0; }
.reply-bar-label { color: var(--tag-navy); font-size: 13px; font-weight: 600; }
.reply-bar-text { font-size: 13px; color: var(--wa-secondary); }

.emoji-panel {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; max-height: 220px; overflow: auto; padding: 10px; background: #fff; border-top: 1px solid var(--wa-border); flex-shrink: 0; overscroll-behavior: contain;
}
.emoji-panel button { font-size: 22px; background: none; border: 0; cursor: pointer; padding: 4px; border-radius: 6px; }
.emoji-panel button:hover { background: var(--wa-hover); }

.composer { display: flex; align-items: flex-end; gap: 4px; padding: 5px 10px 8px; background: var(--wa-composer); position: relative; flex-shrink: 0; }
.composer-input-wrap { flex: 1; background: #fff; border-radius: 8px; padding: 9px 12px; }
.composer-input-wrap textarea {
  width: 100%; border: 0; resize: none; outline: none; font: inherit; font-size: 15px; max-height: 140px; line-height: 20px; color: var(--wa-text);
}
.send-btn { color: var(--tag-coral); }

.modal { position: fixed; inset: 0; background: rgba(11,20,26,.85); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal[hidden], [hidden] { display: none !important; }
.modal-card { background: #fff; width: min(480px, 100%); border-radius: 8px; padding: 24px; max-height: 90vh; overflow: auto; }
.modal-card h3 { margin: 0 0 16px; font-weight: 500; }
.modal-card form { display: grid; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.forward-list { max-height: 320px; overflow: auto; margin: 12px 0; }
.modal-wide { width: min(680px, 100%); }
.modal-hint { margin: 0 0 12px; color: var(--wa-secondary); font-size: 13px; }
.modal-error { color: #b3261e; white-space: pre-wrap; padding: 12px; }
.broadcast-panel { margin-top: 8px; border-top: 1px solid var(--wa-border); padding-top: 12px; }
.broadcast-panel h4 { margin: 0 0 8px; font-weight: 500; font-size: 14px; }
.broadcast-toolbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin: 6px 0; }
.broadcast-toolbar select { flex: 1; min-width: 160px; }
.broadcast-count { margin-left: auto; color: var(--wa-secondary); font-size: 13px; }
.recipient-list { max-height: 180px; overflow: auto; margin: 8px 0; border: 1px solid var(--wa-border); border-radius: 8px; overscroll-behavior: contain; }
.recipient-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--wa-border); background: #fff; padding: 8px 12px; cursor: pointer; font: inherit; color: var(--wa-text); }
.recipient-row:hover, .recipient-row.checked { background: var(--wa-hover); }
.recipient-row input { width: 16px; height: 16px; accent-color: var(--tag-coral); flex-shrink: 0; }
.recipient-row span { min-width: 0; }
.recipient-row small { display: block; color: var(--wa-secondary); font-size: 12px; }
.broadcast-save { display: flex; gap: 8px; align-items: center; }
.broadcast-save input { flex: 1; }
.broadcast-result { margin-top: 10px; font-size: 13px; max-height: 140px; overflow: auto; border: 1px solid var(--wa-border); border-radius: 8px; padding: 10px 12px; }
.broadcast-result .ok { color: var(--tag-navy); }
.broadcast-result .fail { color: var(--tag-coral-deep); }
.template-list { max-height: 240px; overflow: auto; margin: 12px 0; border: 1px solid var(--wa-border); border-radius: 8px; }
.template-item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--wa-border); background: #fff; padding: 12px 14px; cursor: pointer; font: inherit; }
.template-item:hover, .template-item.active { background: var(--wa-hover); }
.template-item small { display: block; color: var(--wa-secondary); margin-top: 4px; }
.template-preview { background: var(--wa-out); border-radius: 8px; padding: 12px; white-space: pre-wrap; font-size: 14px; margin: 8px 0 12px; line-height: 1.45; }
.template-preview strong { font-weight: 700; }
.template-preview em { font-style: italic; }
.template-preview s { text-decoration: line-through; }
.template-preview .wa-mono { font-family: "Menlo", "Consolas", "Courier New", monospace; font-size: 12.6px; }
#templateFields { display: grid; gap: 10px; margin-bottom: 8px; }

.lightbox { position: fixed; inset: 0; background: #0b141a; z-index: 50; display: grid; place-items: center; }
.lightbox img { max-width: 92vw; max-height: 92vh; }
.lightbox-close { position: absolute; top: 16px; right: 16px; background: transparent; color: #fff; border: 0; font-size: 24px; cursor: pointer; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #111b21; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; font-size: 14px;
}
.token-banner {
  flex: none;
  background: #fff3cd;
  color: #664d03;
  padding: 8px 16px;
  text-align: center;
  font-size: 13px;
  z-index: 30;
}

.ctx-menu { z-index: 35; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .intro { display: none !important; }
  .conversation { display: none; }
  .conversation.is-open { display: flex; }
  .sidebar.hidden-mobile { display: none; }
  .btn-back { display: grid; }
  .thread-header {
    grid-template-columns: 40px 40px minmax(0, 1fr) auto;
  }
  .thread-header .btn-back { grid-column: 1; grid-row: 1; }
  .thread-header .avatar { grid-column: 2; }
  .thread-person-copy { grid-column: 3; }
  .thread-header .icon-row { grid-column: 4; }
  :root { --sidebar-width: 100%; }
}
