/* ═══════════════════════════════════════════════════════════
   app.css — Clinicer WhatsApp Dashboard
   WhatsApp Green Theme + iPad Responsive
   ═══════════════════════════════════════════════════════════ */

/* ── Tokens ───────────────────────────────────────────────── */
:root {
  /* Brand */
  --wa-green:         #00a884;
  --wa-green-dark:    #008069;
  --wa-green-light:   #d9fdd3;
  --wa-incoming-bg:   #ffffff;
  --wa-outgoing-bg:   #d9fdd3;

  /* UI */
  --bg-app:           #efeae2;
  --bg-sidebar:       #ffffff;
  --bg-header:        #f0f2f5;
  --bg-input:         #f0f2f5;
  --bg-hover:         #f5f6f6;
  --bg-selected:      #e9edef;

  /* Text */
  --text-primary:     #111b21;
  --text-secondary:   #667781;
  --text-white:       #ffffff;

  /* Borders */
  --border:           #e9edef;
  --border-input:     #ccc;

  /* Status */
  --status-sent:      #8696a0;
  --status-delivered: #8696a0;
  --status-read:      #53bdeb;

  /* Sizes */
  --sidebar-width:    360px;
  --header-height:    60px;
  --chat-max-width:   65%;

  /* Motion */
  --ease:             cubic-bezier(0.4, 0, 0.2, 1);
  --duration-fast:    120ms;
  --duration-base:    220ms;

  /* Radius */
  --radius-sm:        6px;
  --radius-md:        8px;
  --radius-lg:        12px;
  --radius-xl:        16px;
  --radius-pill:      999px;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(0,0,0,.08);
  --shadow-md:  0 2px 8px rgba(0,0,0,.12);
  --shadow-lg:  0 8px 24px rgba(0,0,0,.18);
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; font-size: 16px; }

body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; background: none; font: inherit; }
input, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }

/* ── Utilities ────────────────────────────────────────────── */
.hidden           { display: none !important; }
.visually-hidden  { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ── Screens ──────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ══════════════════════════════════════════════════════════
   LOGIN
   ══════════════════════════════════════════════════════════ */
#loginScreen {
  background: linear-gradient(135deg, #00a884 0%, #008069 50%, #005c4b 100%);
  padding: 24px;
}

.login-card {
  background: var(--bg-sidebar);
  border-radius: var(--radius-xl);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: slideUp var(--duration-base) var(--ease);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

.login-logo {
  width: 72px;
  height: 72px;
  background: var(--wa-green);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 36px;
  color: var(--text-white);
  box-shadow: 0 4px 16px rgba(0,168,132,.35);
}

.login-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.form-field { display: flex; flex-direction: column; gap: 6px; }

.form-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.text-input,
.form-field input {
  height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-sidebar);
  transition: border-color var(--duration-fast) var(--ease);
  width: 100%;
}

.text-input:focus,
.form-field input:focus {
  outline: none;
  border-color: var(--wa-green);
}

.password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrapper input { padding-right: 44px; width: 100%; }

.toggle-password {
  position: absolute;
  right: 12px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
  padding: 4px;
}

.toggle-password:hover { color: var(--text-primary); }

.login-error {
  font-size: 13px;
  color: #e53935;
  min-height: 18px;
  text-align: center;
}

.btn-login {
  height: 46px;
  background: var(--wa-green);
  color: var(--text-white);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background var(--duration-fast) var(--ease),
              transform var(--duration-fast) var(--ease);
  margin-top: 4px;
}

.btn-login:hover  { background: var(--wa-green-dark); }
.btn-login:active { transform: scale(0.98); }

.btn-spinner { display: flex; align-items: center; }

/* ══════════════════════════════════════════════════════════
   APP LAYOUT
   ══════════════════════════════════════════════════════════ */
#appScreen {
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
}

.app-layout {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ── Sidebar backdrop (mobile/iPad) ───────────────────────── */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  animation: fadeIn var(--duration-fast) var(--ease);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Global Spinner ───────────────────────────────────────── */
.global-spinner {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.spinner-ring {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--wa-green);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

/* ══════════════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  z-index: 101;
  transition: transform var(--duration-base) var(--ease);
}

/* ── Sidebar Header ───────────────────────────────────────── */
.sidebar-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--wa-green);
  color: var(--text-white);
  font-weight: 600;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Icon Buttons ─────────────────────────────────────────── */
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 16px;
  transition: background var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ── Account Menu ─────────────────────────────────────────── */
.account-menu { position: relative; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-sidebar);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 200;
  overflow: hidden;
  animation: dropDown var(--duration-fast) var(--ease);
}

@keyframes dropDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown-info {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.dropdown-info strong {
  color: var(--text-primary);
  font-size: 14px;
}

.dropdown-divider {
  height: 1px;
  background: var(--border);
}

.dropdown-item {
  width: 100%;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-primary);
  text-align: left;
  transition: background var(--duration-fast) var(--ease);
}

.dropdown-item:hover { background: var(--bg-hover); }

.dropdown-item i { color: var(--text-secondary); width: 16px; }

/* ── Search ───────────────────────────────────────────────── */
.sidebar-search {
  padding: 8px 12px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-secondary);
  font-size: 13px;
}

.search-input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 36px;
  background: var(--bg-input);
  border: none;
  border-radius: var(--radius-pill);
  font-size: 14px;
  color: var(--text-primary);
  transition: background var(--duration-fast) var(--ease);
}

.search-input:focus {
  outline: none;
  background: #e8e8e8;
}

.search-input::placeholder { color: var(--text-secondary); }

/* ── Chat List ────────────────────────────────────────────── */
.chat-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-track { background: transparent; }
.chat-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: var(--radius-pill); }

/* ── Chat Item ────────────────────────────────────────────── */
.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--duration-fast) var(--ease);
  user-select: none;
}

.chat-item:hover   { background: var(--bg-hover); }
.chat-item.active  { background: var(--bg-selected); }

.chat-item-avatar {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 50%;
  background: var(--wa-green);
  color: var(--text-white);
  font-size: 17px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}

.chat-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

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

.chat-item-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-item-time {
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.chat-item-time.unread { color: var(--wa-green); font-weight: 500; }

.chat-item-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.unread-badge {
  background: var(--wa-green);
  color: var(--text-white);
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Search empty state ───────────────────────────────────── */
.search-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 24px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}

.search-empty i {
  font-size: 28px;
  opacity: .4;
}

/* ══════════════════════════════════════════════════════════
   CHAT WINDOW
   ══════════════════════════════════════════════════════════ */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg-app);
}

/* ── Empty State ──────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-secondary);
  text-align: center;
  padding: 40px;
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  background: var(--wa-green-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: var(--wa-green);
  margin-bottom: 8px;
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 14px;
  max-width: 280px;
  line-height: 1.6;
}

/* ── Chat Panel ───────────────────────────────────────────── */
.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

/* ── Chat Header ──────────────────────────────────────────── */
.chat-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-btn { display: none; } /* shown on mobile */

.chat-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: var(--wa-green);
  color: var(--text-white);
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}

.chat-header-info { display: flex; flex-direction: column; gap: 1px; }

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

.chat-header-phone {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Message Container ────────────────────────────────────── */
.message-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 8%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg-app);
  background-image: url("data:image/svg+xml,%3Csvg width='80' height='80' viewBox='0 0 80 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ccc' fill-opacity='0.08'%3E%3Cpath d='M50 50c0-5.523 4.477-10 10-10s10 4.477 10 10-4.477 10-10 10c0 5.523-4.477 10-10 10s-10-4.477-10-10 4.477-10 10-10zM10 10c0-5.523 4.477-10 10-10s10 4.477 10 10-4.477 10-10 10c0 5.523-4.477 10-10 10S0 25.523 0 20s4.477-10 10-10zm10 8c4.418 0 8-3.582 8-8s-3.582-8-8-8-8 3.582-8 8 3.582 8 8 8zm40 40c4.418 0 8-3.582 8-8s-3.582-8-8-8-8 3.582-8 8 3.582 8 8 8z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.message-container::-webkit-scrollbar { width: 6px; }
.message-container::-webkit-scrollbar-track { background: transparent; }
.message-container::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: var(--radius-pill); }

.scroll-sentinel { height: 1px; flex-shrink: 0; }

/* ── Date Separator ───────────────────────────────────────── */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px 0 8px;
}

.date-separator span {
  background: rgba(225,221,216,.92);
  backdrop-filter: blur(4px);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
}

/* ── Messages ─────────────────────────────────────────────── */
.message {
  display: flex;
  max-width: var(--chat-max-width);
  animation: msgIn var(--duration-fast) var(--ease);
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.incoming { align-self: flex-start; }
.message.outgoing { align-self: flex-end; flex-direction: row-reverse; }

.message-bubble {
  padding: 7px 10px 6px;
  border-radius: var(--radius-md);
  position: relative;
  box-shadow: var(--shadow-sm);
  min-width: 80px;
  max-width: 100%;
}

.incoming .message-bubble {
  background: var(--wa-incoming-bg);
  border-top-left-radius: 2px;
}

.outgoing .message-bubble {
  background: var(--wa-outgoing-bg);
  border-top-right-radius: 2px;
}

/* Bubble tails */
.incoming .message-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  border: 8px solid transparent;
  border-top-color: var(--wa-incoming-bg);
  border-right: 0;
}

.outgoing .message-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  right: -8px;
  border: 8px solid transparent;
  border-top-color: var(--wa-outgoing-bg);
  border-left: 0;
}

/* Message Text */
.message-text {
  font-size: 14.2px;
  line-height: 1.45;
  color: var(--text-primary);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message-text strong { font-weight: 600; }
.message-text em { font-style: italic; }

/* Reply quote */
.message-quote {
  border-left: 3px solid var(--wa-green);
  padding: 4px 8px;
  margin-bottom: 6px;
  border-radius: 2px;
  background: rgba(0,0,0,.04);
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Metadata row */
.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
  height: 16px;
}

.message-time-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Status ticks */
.message-ticks {
  font-size: 13px;
  color: var(--status-sent);
  line-height: 1;
}

.message-ticks.delivered { color: var(--status-delivered); }
.message-ticks.read      { color: var(--status-read); }

/* ── Button-type message ──────────────────────────────────── */
.message-button-label {
  display: inline-block;
  background: rgba(0,168,132,.1);
  color: var(--wa-green-dark);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 500;
}

/* ── Media Messages ───────────────────────────────────────── */
.media-wrapper {
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
}

.msg-image {
  max-width: 260px;
  max-height: 200px;
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
  object-fit: cover;
  transition: opacity var(--duration-fast) var(--ease);
}

.msg-image:hover { opacity: .92; }

.msg-video {
  max-width: 260px;
  max-height: 200px;
  border-radius: var(--radius-sm);
  display: block;
}

/* Document */
.doc-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  cursor: pointer;
  max-width: 240px;
}

.doc-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: rgba(0,168,132,.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--wa-green-dark);
  flex-shrink: 0;
}

.doc-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.doc-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.doc-type {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
}

/* Media caption */
.media-caption {
  font-size: 13.5px;
  color: var(--text-primary);
  margin-top: 4px;
  word-wrap: break-word;
}

/* Loading messages progress */
.messages-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  color: var(--text-secondary);
  font-size: 13px;
  gap: 8px;
}

/* ── Chat Footer ──────────────────────────────────────────── */
.chat-footer {
  background: var(--bg-input);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Reply Bar */
.reply-bar {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  gap: 8px;
  background: #fafafa;
  border-bottom: 1px solid var(--border);
  animation: slideDown var(--duration-fast) var(--ease);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.reply-bar-content {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.reply-bar-indicator {
  width: 3px;
  height: 36px;
  background: var(--wa-green);
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

.reply-bar-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.reply-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--wa-green);
}

.reply-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Message Input Row */
.message-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.attach-btn {
  color: var(--text-secondary);
  font-size: 18px;
  flex-shrink: 0;
}

.message-input {
  flex: 1;
  height: 42px;
  padding: 0 16px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 15px;
  color: var(--text-primary);
  transition: border-color var(--duration-fast) var(--ease);
}

.message-input::placeholder { color: var(--text-secondary); }

.message-input:focus {
  outline: none;
  border-color: var(--wa-green);
}

.send-btn {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 50%;
  background: var(--wa-green);
  color: var(--text-white);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast) var(--ease),
              transform var(--duration-fast) var(--ease);
  flex-shrink: 0;
}

.send-btn:hover  { background: var(--wa-green-dark); }
.send-btn:active { transform: scale(0.94); }

/* ══════════════════════════════════════════════════════════
   MODALS
   ══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 16px;
  animation: fadeIn var(--duration-fast) var(--ease);
}

.modal-card {
  background: var(--bg-sidebar);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  animation: slideUp var(--duration-base) var(--ease);
  max-height: 90vh;
  overflow: hidden;
}

.modal-card--sm { max-width: 340px; }

.modal-header {
  height: 56px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.btn-primary, .btn-secondary {
  height: 40px;
  padding: 0 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--duration-fast) var(--ease);
}

.btn-primary {
  background: var(--wa-green);
  color: var(--text-white);
}

.btn-primary:hover  { background: var(--wa-green-dark); }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-secondary:hover { background: #e4e6e8; }

/* ── Media Drop Zone ──────────────────────────────────────── */
.media-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  transition: border-color var(--duration-fast) var(--ease),
              background var(--duration-fast) var(--ease);
}

.media-drop-zone:hover, .media-drop-zone.drag-over {
  border-color: var(--wa-green);
  background: var(--wa-green-light);
  color: var(--wa-green-dark);
}

.media-drop-zone i { font-size: 32px; margin-bottom: 4px; }

.drop-hint { font-size: 12px; }

.media-preview-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.media-preview-area img,
.media-preview-area video {
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius-md);
  object-fit: contain;
}

.media-preview-area .doc-preview-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: 100%;
}

.caption-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-sidebar);
  transition: border-color var(--duration-fast) var(--ease);
}

.caption-input:focus { outline: none; border-color: var(--wa-green); }

.form-hint { font-size: 12px; color: var(--text-secondary); }

/* ══════════════════════════════════════════════════════════
   MEDIA VIEWER (fullscreen)
   ══════════════════════════════════════════════════════════ */
.media-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn var(--duration-fast) var(--ease);
}

.viewer-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 1;
}

.viewer-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background var(--duration-fast) var(--ease);
}

.viewer-btn:hover { background: rgba(255,255,255,.25); }

.viewer-content img,
.viewer-content video {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}

/* ══════════════════════════════════════════════════════════
   CONTEXT MENU
   ══════════════════════════════════════════════════════════ */
.context-menu {
  position: fixed;
  background: var(--bg-sidebar);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 350;
  min-width: 160px;
  overflow: hidden;
  animation: dropDown var(--duration-fast) var(--ease);
  padding: 4px 0;
}

.context-menu-item {
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background var(--duration-fast) var(--ease);
}

.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item.danger { color: #e53935; }
.context-menu-item i { width: 16px; color: var(--text-secondary); }
.context-menu-item.danger i { color: #e53935; }

/* ══════════════════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  z-index: 600;
  box-shadow: var(--shadow-md);
  animation: toastIn var(--duration-base) var(--ease);
  white-space: nowrap;
  max-width: 90vw;
  text-overflow: ellipsis;
  overflow: hidden;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.toast.error { background: #c62828; }
.toast.success { background: var(--wa-green-dark); }

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — iPad / Mobile
   ══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  :root { --sidebar-width: 300px; }
}

@media (max-width: 768px) {
  /* On mobile/iPad, sidebar overlaps the chat */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: min(var(--sidebar-width), 85vw);
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .chat-window {
    width: 100%;
  }

  /* Show the chat when active */
  .back-btn { display: flex !important; }

  .empty-state { display: flex; }

  /* Chat occupies full screen */
  .chat-panel { width: 100vw; }

  /* Wider message bubbles on mobile */
  :root { --chat-max-width: 82%; }

  /* Slightly less padding on small screens */
  .message-container { padding: 16px 4%; }
}

@media (max-width: 480px) {
  :root { --chat-max-width: 88%; }

  .modal-card { margin: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 95vh; }
  .modal-overlay { align-items: flex-end; padding: 0; }

  .login-card { padding: 32px 24px; }
}
