/* Phone123 SMS app — mobile-first */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root { --blue: #0b3d91; --blue2: #1a5ac9; --bg: #f4f6fa; --card: #ffffff; --border: #dfe4ec; --text: #1c2733; --muted: #6b7684; --green: #1e8e3e; --red: #c5221f; --unread: #dce9ff; --active: #b3ccff; }
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; padding-right: 10px; }
.hidden { display: none !important; }
.view { height: 100%; }
.btn { border: 1px solid var(--border); background: var(--card); color: var(--text); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.error { color: var(--red); font-size: 13px; margin-top: 8px; }
.muted { color: var(--muted); }
.small-status { font-size: 12px; min-height: 16px; padding: 2px 12px; }

/* login */
#view-login { display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 28px 24px; width: 100%; max-width: 380px; box-shadow: 0 6px 24px rgba(0,0,0,.06); }
.login-card h1 { color: var(--blue); font-size: 26px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); margin-bottom: 18px; }
#login-form input { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; font-size: 15px; }
#login-form .btn { width: 100%; padding: 12px; font-size: 16px; }
/* Turnstile widget (2026-09-03): centered above Sign In like the portals;
   the widget itself is pinned to light so it matches the white login card. */
#turnstile-box { margin: 2px 0 12px; text-align: center; }

/* topbar */
.topbar { background: var(--card); border-bottom: 1px solid var(--border); padding: 10px 12px; position: sticky; top: 0; z-index: 5; }
.topbar-row { display: flex; gap: 8px; align-items: center; }
.topbar-row + .topbar-row { margin-top: 8px; }
.topbar select { flex: 1; min-width: 0; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); font-size: 14px; }

/* split layout */
#view-main { display: flex; flex-direction: column; height: 100%; }
.topbar { flex-shrink: 0; }
.split { display: flex; flex: 1 1 auto; min-height: 0; }
.pane { overflow-y: auto; }
#threads-pane { width: 100%; max-width: 380px; border-right: 1px solid var(--border); background: var(--card); }
#chat-pane { flex: 1; display: flex; flex-direction: column; }


/* threads */
.threads-top { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.thread-list { padding: 4px 0; }
.thread { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.thread.active { background: var(--active); }
.thread.unread { background: var(--unread); }
.thread.unread.active { background: var(--active); }
.thread .t-contact { font-weight: 600; }
.thread .t-preview { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread .t-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; font-size: 12px; color: var(--muted); }
.badge { background: var(--blue2); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 12px; }

/* chat */
.chat-header { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: var(--card); border-bottom: 1px solid var(--border); }
.back-btn { display: none; }
.chat-title { display: flex; flex-direction: column; min-width: 0; }
.chat-did { font-size: 12px; color: var(--muted); }
.chat-contact { font-weight: 600; }
.message-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 78%; padding: 9px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--border); white-space: pre-wrap; word-break: break-word; }
.msg.out { align-self: flex-end; background: #dce9ff; border-color: #c3d7f7; }
.msg .m-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.msg .m-img { max-width: 100%; border-radius: 10px; margin-top: 6px; display: block; }
.msg .m-video { max-width: 100%; border-radius: 10px; margin-top: 6px; }
.msg .m-audio { max-width: 100%; margin-top: 6px; }
.msg .m-file { display: inline-block; margin-top: 6px; color: var(--blue2); text-decoration: underline; }
.send-form { display: flex; gap: 6px; align-items: flex-end; padding: 10px 12px; background: var(--card); border-bottom: 1px solid var(--border); }
textarea { font-family: inherit; }
#send-input { flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; resize: none; height: 40px; transition: height .15s ease; }
#send-input:focus { height: 220px; }

/* new message overlay */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 60; }
.new-msg-card { background: var(--card); border-radius: 14px; padding: 18px; width: 92%; max-width: 430px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.new-msg-card h2 { font-size: 18px; margin-bottom: 10px; color: var(--blue); }
#new-to-input, #new-msg-input { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; }
#new-to-input { margin-bottom: 8px; }
.new-msg-row { display: flex; gap: 6px; align-items: flex-start; }
.new-msg-row #new-msg-input { flex: 1; resize: none; height: 40px; transition: height .15s ease; }
.new-msg-row #new-msg-input:focus { height: 220px; }

/* toast */
.toast { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); background: #222c38; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 70; max-width: 90%; }

/* context menu (right-click / press-hold) */
.ctx-menu { position: fixed; background: var(--card); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,.15); z-index: 2000; padding: 4px 0; min-width: 170px; }
.ctx-item { padding: 10px 14px; cursor: pointer; font-size: 14px; color: var(--text); white-space: nowrap; }
.ctx-item:hover { background: var(--bg); }
/* deleted message placeholder */
.msg.deleted { font-style: italic; color: var(--muted); background: #f2f4f8; }

@media (max-width: 768px) {
  body { font-size: 16px; }
  .topbar select { font-size: 16px; padding: 10px; }
  .btn { font-size: 15px; padding: 10px 14px; }
  .btn.small { font-size: 14px; padding: 8px 12px; }
  .split { display: block; }
  #threads-pane { max-width: none; border-right: none; height: 100%; }
  #chat-pane { display: none; height: 100%; }
  body.chat-open #threads-pane { display: none; }
  body.chat-open #chat-pane { display: flex; }
  .back-btn { display: inline-flex; align-items: center; gap: 2px; font-size: 15px; font-weight: 600; padding: 8px 14px; color: var(--blue); }
  .chat-contact { font-size: 16px; }
  .thread { padding: 14px; margin: 8px 10px; border: 1px solid var(--border); border-radius: 12px; }
  .thread .t-contact { font-size: 16px; }
  .thread .t-meta { font-size: 13px; margin-top: 6px; }
  .thread-list { padding: 4px 0 8px; }
  .msg { max-width: 85%; font-size: 16px; padding: 10px 14px; }
  .msg .m-meta { font-size: 12px; }
  #send-input { font-size: 16px; padding: 12px; }
  .send-form { padding: 8px 10px; }
  .message-list { padding: 10px; }
  /* new message takes the whole page */
  .overlay { padding: 0; }
  .new-msg-card { width: 100%; max-width: none; height: 100%; border-radius: 0; display: flex; flex-direction: column; overflow-y: auto; padding: 20px 16px; }
  .new-msg-card h2 { font-size: 20px; }
  #new-to-input, #new-msg-input { font-size: 16px; padding: 12px; }
}
