
/* HCPA WhatsApp Inbox - minimal modern UI (RTL) */
:root{
  --primary: #1976B9;
  --secondary: #B59962;
  --bg: #0b1220;
  --panel: #0f1a2b;
  --panel2: #111f35;
  --text: #e8eefc;
  --muted: #9fb0d0;
  --border: rgba(255,255,255,.10);
  --bubble-in: rgba(255,255,255,.08);
  --bubble-out: rgba(25,118,185,.22);
  --shadow: 0 10px 30px rgba(0,0,0,.25);
  --radius: 18px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Cairo", "Tahoma", Arial, sans-serif;
}

html[data-theme="light"]{
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel2: #ffffff;
  --text: #101828;
  --muted: #5b6b82;
  --border: rgba(16,24,40,.10);
  --bubble-in: rgba(16,24,40,.05);
  --bubble-out: rgba(25,118,185,.12);
  --shadow: 0 10px 30px rgba(16,24,40,.10);
}

*{ box-sizing:border-box; }
body{
  margin:0; background: var(--bg); color: var(--text);
  font-family: var(--font);
}

code{ background: rgba(255,255,255,.08); padding:2px 6px; border-radius:10px; }
html[data-theme="light"] code{ background: rgba(16,24,40,.06); }

a{ color: var(--primary); text-decoration: none; }
a:hover{ text-decoration: underline; }

.app-shell{ min-height:100vh; display:flex; flex-direction:column; }

/* Topbar */
.topbar{
  display:flex; justify-content:space-between; align-items:center;
  padding:10px 14px; border-bottom:1px solid var(--border);
  background: linear-gradient(90deg, rgba(0,0,0,0), rgba(181,153,98,.08));
  position: sticky; top:0; z-index: 10;
  backdrop-filter: blur(8px);
}
.topbar-left, .topbar-right{ display:flex; align-items:center; gap:10px; }
.logo{ width:42px; height:42px; border-radius:12px; object-fit:contain; box-shadow: var(--shadow); background: #fff; }
.brand-title{ font-weight:800; letter-spacing: .2px; }
.brand-sub{ color: var(--muted); font-size: 12px; }

.user-pill{
  display:flex; align-items:center; gap:10px;
  padding:6px 10px; border:1px solid var(--border);
  border-radius: 999px; background: rgba(255,255,255,.04);
}

/* Layout */
.layout{
  flex:1; display:flex; gap:0;
  height: calc(100vh - 70px);
}
.sidebar{
  width: 360px; max-width: 100%;
  border-left:1px solid var(--border);
  background: var(--panel);
  display:flex; flex-direction:column;
}
.sidebar-head{ padding:12px; border-bottom:1px solid var(--border); }
.search{
  width:100%;
  padding:10px 12px;
  border-radius: 14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  outline:none;
}
html[data-theme="light"] .search{ background: rgba(16,24,40,.04); }
.hint{ margin-top:8px; color: var(--muted); font-size: 12px; }

.thread-list{ overflow:auto; padding:6px; }
.thread{
  display:flex; gap:12px; align-items:flex-start;
  padding:10px 10px; border-radius: 16px;
  cursor:pointer;
  transition: background .15s ease, transform .15s ease;
}
.thread:hover{ background: rgba(255,255,255,.06); transform: translateY(-1px); }
html[data-theme="light"] .thread:hover{ background: rgba(16,24,40,.04); }
.thread.active{ background: rgba(25,118,185,.16); }
.avatar-sm{
  width:40px; height:40px; border-radius: 14px;
  display:grid; place-items:center;
  background: radial-gradient(circle at 30% 30%, rgba(25,118,185,.35), rgba(181,153,98,.18));
  border:1px solid var(--border);
}
.thread-main{ flex:1; min-width:0; }
.thread-top{ display:flex; justify-content:space-between; gap:10px; align-items:center; }
.thread-title{ font-weight:700; }
.thread-time{ font-size:12px; color: var(--muted); white-space:nowrap; }
.thread-preview{
  margin-top:4px;
  color: var(--muted);
  font-size: 13px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.thread-badges{ margin-top:6px; display:flex; gap:6px; flex-wrap:wrap; }

.chat{
  flex:1;
  background: linear-gradient(180deg, rgba(25,118,185,.06), rgba(181,153,98,.04));
  display:flex; flex-direction:column;
}
.chat-empty{
  flex:1; display:grid; place-items:center;
  padding:20px;
}
.empty-card{
  width:min(520px, 92%);
  border:1px solid var(--border);
  border-radius: 24px;
  background: var(--panel);
  padding: 26px;
  box-shadow: var(--shadow);
  text-align:center;
}
.empty-title{ font-size: 22px; font-weight: 800; }
.empty-sub{ color: var(--muted); margin-top:6px; }

.chat-panel{ flex:1; display:flex; flex-direction:column; height:100%;overflow:hidden;}
.chat-panel.hidden{ display:none; }

.chat-head{
  display:flex; justify-content:space-between; align-items:center;
  padding:10px 14px;
  border-bottom:1px solid var(--border);
  background: var(--panel2);
  position: sticky;
  top: 0;
  z-index: 5;
}
.chat-contact{ display:flex; align-items:center; gap:12px; }
.avatar{
  width:46px; height:46px; border-radius: 18px;
  display:grid; place-items:center;
  background: radial-gradient(circle at 30% 30%, rgba(181,153,98,.28), rgba(25,118,185,.20));
  border:1px solid var(--border);
}
.contact-wa{ font-weight:800; }
.contact-meta{ color: var(--muted); font-size: 12px; }

.chat-body{
  flex:1;
  overflow:auto;
  padding: 14px;
  display:flex; flex-direction:column; gap:10px;
}
.msg-row{
  display:flex; gap:10px; align-items:flex-end;
}
.msg-row.in{ justify-content:flex-start; }
.msg-row.out{ justify-content:flex-end; }

.bubble{
  max-width: min(720px, 86%);
  padding:10px 12px;
  border-radius: var(--radius);
  border:1px solid var(--border);
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
  position:relative;
  line-height:1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.bubble.in{ background: var(--bubble-in); border-top-right-radius: 8px; }
.bubble.out{ background: var(--bubble-out); border-top-left-radius: 8px; }
.bubble .meta{
  margin-top:6px;
  display:flex; gap:10px; justify-content:space-between;
  font-size: 11px; color: var(--muted);
}
.bubble .status{ white-space:nowrap; }

.bubble img.media{
  max-width: 320px;
  border-radius: 14px;
  display:block;
  margin: 6px 0;
  border:1px solid var(--border);
}

.composer{
  padding:10px 12px;
  border-top:1px solid var(--border);
  background: var(--panel);
  position: sticky;
  bottom: 0;
  z-index: 5;
}
.composer-row{ display:flex; gap:10px; align-items:center; }
.composer-input{
  flex:1;
  padding:12px 14px;
  border-radius: 999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  outline:none;
}
html[data-theme="light"] .composer-input{ background: rgba(16,24,40,.04); }
.composer-foot{ margin-top:8px; color: var(--muted); font-size: 12px; }

.templates{
  margin-top:10px;
  border:1px solid var(--border);
  border-radius: 18px;
  padding:12px;
  background: rgba(255,255,255,.03);
}
.templates.hidden{ display:none; }
.templates-title{ font-weight:800; }
.templates-sub{ color: var(--muted); font-size:12px; margin-top:4px; }
.templates-row{ display:flex; gap:10px; align-items:center; margin-top:10px; }
.select{
  flex:1;
  padding:10px 12px;
  border-radius: 14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
}
html[data-theme="light"] .select{ background: rgba(16,24,40,.04); }
.template-vars{ margin-top:10px; display:flex; flex-direction:column; gap:8px; }
.template-preview{
  margin-top:10px;
  padding:10px 12px;
  border-radius: 14px;
  border:1px dashed var(--border);
  color: var(--muted);
  background: rgba(0,0,0,.08);
}
html[data-theme="light"] .template-preview{ background: rgba(16,24,40,.03); }

.btn{
  border:1px solid var(--border);
  border-radius: 999px;
  padding:10px 14px;
  cursor:pointer;
  background: rgba(255,255,255,.04);
  color: var(--text);
  font-weight:700;
  transition: transform .12s ease, background .12s ease;
}
.btn:hover{ transform: translateY(-1px); background: rgba(255,255,255,.06); }
.btn:active{ transform: translateY(0); }
.btn-small{ padding:6px 10px; font-size: 12px; }
.btn-primary{ background: linear-gradient(135deg, var(--primary), rgba(181,153,98,.80)); border-color: transparent; }
.btn-primary:hover{ background: linear-gradient(135deg, rgba(25,118,185,.95), rgba(181,153,98,.90)); }
.btn-danger{ background: rgba(255, 72, 72, .18); border-color: rgba(255,72,72,.35); }
.btn-ghost{ background: rgba(255,255,255,.02); }
.icon-btn{ width:42px; height:42px; border-radius: 16px; border:1px solid var(--border); background: rgba(255,255,255,.04); color: var(--text); cursor:pointer; }

.badge{
  display:inline-flex; align-items:center; gap:6px;
  padding:4px 10px; border-radius: 999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  font-size: 12px;
  color: var(--text);
}

/* Auth */
.auth{ min-height:100vh; display:grid; place-items:center; padding: 22px; }
.auth-card{
  width:min(460px, 96%);
  background: var(--panel);
  border:1px solid var(--border);
  border-radius: 26px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.auth-brand{ display:flex; gap:12px; align-items:center; margin-bottom: 14px; }
.auth-brand img{ width:56px; height:56px; border-radius: 18px; background:#fff; }
.auth-brand h1{ margin:0; font-size: 20px; }
.auth-brand p{ margin:4px 0 0; color: var(--muted); font-size: 12px; }
.field{ display:flex; flex-direction:column; gap:6px; margin: 10px 0; }
.field span{ color: var(--muted); font-size: 12px; }
.field input, .field select, .field textarea{
  padding:10px 12px;
  border-radius: 14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  outline:none;
}
html[data-theme="light"] .field input, html[data-theme="light"] .field select, html[data-theme="light"] .field textarea{
  background: rgba(16,24,40,.04);
}
.alert{
  padding:10px 12px;
  border-radius: 16px;
  border:1px solid var(--border);
  margin: 10px 0;
}
.alert-danger{ background: rgba(255,72,72,.12); border-color: rgba(255,72,72,.28); }
.alert-success{ background: rgba(46,204,113,.12); border-color: rgba(46,204,113,.28); }
.auth-foot{ margin-top: 10px; color: var(--muted); font-size: 12px; display:flex; gap:8px; align-items:center; }

/* Admin */
.admin{ padding:16px; max-width: 1100px; margin: 0 auto; width:100%; }
.card{
  background: var(--panel);
  border:1px solid var(--border);
  border-radius: 24px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card h2{ margin: 0 0 10px; }
.grid{ display:grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap:12px; }
@media (max-width: 900px){ .grid{ grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 620px){ .grid{ grid-template-columns: 1fr; } }

.table-wrap{ overflow:auto; border-radius: 18px; border:1px solid var(--border); }
.table{
  width:100%;
  border-collapse:collapse;
  min-width: 820px;
}
.table th, .table td{
  padding: 10px 12px;
  border-bottom:1px solid var(--border);
  text-align:right;
  vertical-align:top;
}
.table th{ color: var(--muted); font-weight: 800; font-size: 12px; background: rgba(255,255,255,.03); }
.inline{ display:inline-flex; gap:8px; align-items:center; }
.inline .mini{ padding:6px 10px; border-radius: 12px; border:1px solid var(--border); background: rgba(255,255,255,.04); color: var(--text); }
.mt{ margin-top: 10px; }
.row{ display:flex; gap:10px; align-items:center; margin-top: 10px; }
.muted{ color: var(--muted); }

/* Responsive: sidebar overlay on mobile */
@media (max-width: 980px){
  .sidebar{
    position: fixed;
    top: 70px;
    bottom: 0;
    right: 0;
    transform: translateX(0);
    z-index: 20;
    box-shadow: var(--shadow);
  }
  .sidebar.hidden{
    transform: translateX(110%);
  }
  .layout{ height: calc(100vh - 70px); }
}
.hidden{ display:none; }

.loading{ padding:12px; color: var(--muted); text-align:center; }
