/* ============================================================
   Velour — theme tokens are injected as CSS variables per-request
   from includes/theme_head.php (admin-editable). Static accents
   below (the hairline gold divider, shadows) are fixed design
   choices, independent of the admin color settings.
   ============================================================ */

:root {
  --gold: #c9a15a;
  --surface-2: color-mix(in srgb, var(--color-surface) 80%, black 20%);
  --border-soft: color-mix(in srgb, var(--color-text) 12%, transparent);
  --radius: 10px;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  --bottom-nav-h: calc(66px + env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-family);
  background: radial-gradient(120% 140% at 10% -10%, var(--surface-2) 0%, var(--color-bg) 55%);
  color: var(--color-text);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, h4 { font-weight: 600; letter-spacing: 0.2px; margin: 0; }

::selection { background: var(--color-primary); color: #fff; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.btn {
  font-family: var(--font-family);
  border: none;
  border-radius: var(--radius);
  padding: 12px 22px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--border-soft);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #fff;
  border: none;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--color-primary) 45%, transparent);
}
.btn-primary:hover { box-shadow: 0 10px 26px color-mix(in srgb, var(--color-primary) 55%, transparent); }

.btn-ghost { background: transparent; border: 1px solid var(--border-soft); }
.btn-danger { background: transparent; border: 1px solid #7a2b3d; color: #e28ba0; }
.btn-danger:hover { background: rgba(200, 60, 90, 0.12); }
.btn-icon {
  width: 42px; height: 42px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; font-size: 18px;
}
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

input, select, textarea {
  font-family: var(--font-family);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  color: var(--color-text);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14.5px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--color-primary);
}
input[type="checkbox"], input[type="radio"], input[type="color"], input[type="file"], input[type="range"] {
  width: auto;
}
label { font-size: 13px; color: color-mix(in srgb, var(--color-text) 70%, transparent); display: block; margin-bottom: 6px; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow-x: auto;
}

.hairline {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0.5;
  border: none;
}

/* ---------------- Auth (login) ---------------- */

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}
.auth-screen::before {
  content: '';
  position: absolute;
  width: 520px; height: 520px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--color-primary) 35%, transparent) 0%, transparent 70%);
  top: -180px; right: -160px;
  filter: blur(10px);
}
.auth-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 44px 38px 38px;
  text-align: center;
}
.auth-mark {
  width: 54px; height: 54px;
  margin: 0 auto 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #fff; font-weight: 700;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--color-primary) 50%, transparent);
}
.auth-card h1 {
  font-size: 26px;
  margin-bottom: 6px;
}
.auth-sub {
  color: color-mix(in srgb, var(--color-text) 60%, transparent);
  font-size: 14px;
  margin-bottom: 30px;
}
.code-input {
  width: 100%;
  text-align: center;
  font-size: 20px;
  letter-spacing: 4px;
  padding: 16px 14px;
  text-transform: uppercase;
}
.auth-error {
  color: #ef8fa6;
  font-size: 13.5px;
  margin-top: 14px;
}
.auth-foot {
  margin-top: 26px;
  font-size: 12.5px;
  color: color-mix(in srgb, var(--color-text) 45%, transparent);
}

/* ---------------- App shell ---------------- */

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}
.app-shell.single-pane { grid-template-columns: 1fr; }

.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.sidebar-head {
  padding: 22px 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-dot {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  flex-shrink: 0;
}
.brand-name { font-size: 17px; font-weight: 700; }
.sidebar-head .spacer { flex: 1; }

.contact-list { overflow-y: auto; flex: 1; min-height: 0; padding: 6px 10px; }
.contact-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 2px;
  position: relative;
  border-bottom: 1px solid var(--border-soft);
}
.contact-item:last-child { border-bottom: none; }
.contact-item:hover { background: var(--surface-2); }
.contact-item.active { background: color-mix(in srgb, var(--color-primary) 18%, var(--surface-2)); }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px; flex-shrink: 0;
  color: var(--color-primary);
  border: 1px solid var(--border-soft);
  object-fit: cover;
  position: relative;
}
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #555; border: 2px solid var(--color-surface);
  position: absolute; right: -2px; bottom: -2px;
}
.status-dot.online { background: #4fd689; }
.contact-meta { min-width: 0; flex: 1; }
.contact-name { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-sub { font-size: 12.5px; color: color-mix(in srgb, var(--color-text) 55%, transparent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-empty { padding: 30px 20px; text-align: center; color: color-mix(in srgb, var(--color-text) 50%, transparent); font-size: 13.5px; line-height: 1.6; }

.sidebar-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-foot .me-name { font-size: 13.5px; font-weight: 600; flex: 1; }
.sidebar-foot a.small-link { font-size: 12.5px; color: color-mix(in srgb, var(--color-text) 55%, transparent); }
.sidebar-foot a.small-link:hover { color: var(--color-primary); }

/* ---------------- Chat pane ---------------- */

.chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-soft);
}
.chat-header .contact-meta { flex: 1; }
.chat-actions { display: flex; gap: 10px; }
.back-btn { display: none; font-size: 19px; flex-shrink: 0; }

.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: color-mix(in srgb, var(--color-text) 45%, transparent);
  gap: 10px; text-align: center; padding: 20px;
}
.chat-empty .auth-mark { opacity: 0.5; }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 4px; }
.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }
.bubble {
  max-width: 62%;
  padding: 11px 16px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.5;
  margin: 3px 0;
  word-wrap: break-word;
}
.msg-row.mine .bubble {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-row.theirs .bubble {
  background: var(--color-surface);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: 4px;
}
.bubble .meta { display: inline-block; font-size: 10.5px; opacity: 0.65; margin-top: 5px; }
.ticks {
  display: inline-block;
  font-size: 11px;
  margin-top: 5px;
  margin-left: 4px;
  letter-spacing: -1.5px;
}
.ticks.sent, .ticks.delivered { color: currentColor; opacity: 0.65; }
.ticks.read { color: #4fd689; opacity: 1; }

.reply-preview {
  border-left: 2.5px solid rgba(255,255,255,0.5);
  padding: 3px 0 3px 9px;
  margin-bottom: 6px;
  font-size: 12.5px;
  opacity: 0.85;
  line-height: 1.4;
  display: block;
}
.msg-row.theirs .reply-preview { border-left-color: var(--color-primary); }
.reply-preview .reply-name { display: block; font-weight: 700; font-size: 11.5px; }

.deleted-text { font-style: italic; opacity: 0.65; font-size: 13.5px; }

.bubble-text { white-space: pre-wrap; }

.attachment-wrap { position: relative; margin-bottom: 4px; border-radius: 10px; overflow: hidden; }
.msg-image { display: block; max-width: 240px; max-height: 300px; width: 100%; object-fit: cover; border-radius: 10px; cursor: zoom-in; }
.msg-video { display: block; max-width: 260px; max-height: 300px; border-radius: 10px; background: #000; }
.save-btn {
  position: absolute; top: 8px; right: 8px;
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(0,0,0,0.55); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; cursor: pointer;
}
.attachment-placeholder {
  font-size: 13px; opacity: 0.7; font-style: italic;
  padding: 4px 0;
}

/* ---------------- Reply bar / composer extras ---------------- */

.reply-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px;
  border-top: 1px solid var(--border-soft);
  background: var(--surface-2);
  font-size: 12.5px;
}
.reply-bar-text { flex: 1; min-width: 0; }
.reply-bar-text .reply-name { display: block; font-weight: 700; color: var(--color-primary); font-size: 11.5px; }

.upload-progress { height: 3px; background: var(--surface-2); }
.upload-progress-bar { height: 100%; background: var(--color-primary); transition: width 0.15s ease; }

/* ---------------- Long-press context menu ---------------- */

.msg-menu {
  position: fixed;
  z-index: 55;
  background: var(--color-surface);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 150px;
}
.msg-menu button {
  display: block; width: 100%;
  text-align: left;
  padding: 12px 16px;
  background: none; border: none;
  color: var(--color-text);
  font-family: var(--font-family);
  font-size: 14px;
  cursor: pointer;
}
.msg-menu button:hover { background: var(--surface-2); }

/* ---------------- Lightbox ---------------- */

.lightbox {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center;
  padding: 30px;
}
.lightbox-inner img, .lightbox-inner video { max-width: 100%; max-height: 90vh; border-radius: 8px; }
#lightboxClose {
  position: absolute; top: 20px; right: 20px;
  background: rgba(255,255,255,0.12); color: #fff;
}

/* ---------------- Privacy blur (app-switch obscuring — see README) ---------------- */

body.privacy-blur .messages,
body.privacy-blur .contact-list {
  filter: blur(24px);
  transition: filter 0.15s ease;
}

.composer {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-soft);
}
.composer input { flex: 1; border-radius: 24px; padding: 13px 20px; }
.composer .btn-icon { flex-shrink: 0; }

/* ---------------- Call UI ---------------- */

.call-screen {
  height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  background: radial-gradient(120% 140% at 50% 0%, var(--surface-2) 0%, var(--color-bg) 60%);
}
.call-video-remote {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000;
}
.call-video-local {
  position: absolute; bottom: 110px; right: 26px;
  width: 160px; height: 210px; object-fit: cover;
  border-radius: 14px; border: 2px solid var(--border-soft);
  box-shadow: var(--shadow);
  background: #000;
}
.call-info { position: relative; z-index: 2; text-align: center; }
.call-avatar-big {
  width: 120px; height: 120px; border-radius: 50%;
  margin: 0 auto 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 42px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--color-primary) 15%, transparent);
}
.call-name { font-size: 24px; margin-bottom: 8px; }
.call-status { color: color-mix(in srgb, var(--color-text) 60%, transparent); font-size: 14.5px; letter-spacing: 0.3px; }
.call-controls {
  position: absolute; bottom: 44px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 18px; z-index: 3;
}
.call-controls .btn-icon { width: 58px; height: 58px; font-size: 22px; }
.call-controls .btn-hangup { background: #d13a56; color: #fff; }
.call-controls .btn-toggle.off { background: color-mix(in srgb, var(--color-text) 20%, var(--color-surface)); }

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-primary) 55%, transparent); }
  100% { box-shadow: 0 0 0 26px transparent; }
}
.ringing .call-avatar-big { animation: pulse-ring 1.6s ease-out infinite; }

/* ---------------- Admin ---------------- */

.admin-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.admin-nav {
  background: var(--color-surface);
  border-right: 1px solid var(--border-soft);
  padding: 24px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.admin-nav .brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 22px; }
.admin-nav a {
  padding: 11px 14px; border-radius: 8px; font-size: 14px; color: color-mix(in srgb, var(--color-text) 75%, transparent);
}
.admin-nav a:hover { background: var(--surface-2); }
.admin-nav a.active { background: color-mix(in srgb, var(--color-primary) 16%, var(--surface-2)); color: var(--color-text); font-weight: 600; }
.admin-nav .nav-bottom { margin-top: auto; }

.admin-main { padding: 34px 42px; max-width: 980px; }
.admin-main h1 { font-size: 24px; margin-bottom: 4px; }
.page-sub { color: color-mix(in srgb, var(--color-text) 55%, transparent); font-size: 14px; margin-bottom: 28px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 32px; }
.stat-card { padding: 22px; }
.stat-num { font-size: 30px; font-weight: 700; margin-bottom: 4px; }
.stat-label { font-size: 13px; color: color-mix(in srgb, var(--color-text) 55%, transparent); }

table.data-table { width: 100%; min-width: 480px; border-collapse: collapse; }
table.data-table th {
  text-align: left; font-size: 12.5px; font-weight: 600;
  color: color-mix(in srgb, var(--color-text) 55%, transparent);
  padding: 10px 14px; border-bottom: 1px solid var(--border-soft);
}
table.data-table td { padding: 13px 14px; border-bottom: 1px solid var(--border-soft); font-size: 14px; vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
.code-pill {
  font-family: 'Courier New', monospace;
  background: var(--surface-2);
  padding: 4px 10px; border-radius: 6px; font-size: 13px; letter-spacing: 1px;
}
.code-cell { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tag { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.tag-admin { background: color-mix(in srgb, var(--color-primary) 22%, transparent); color: var(--color-primary); }
.tag-active { background: rgba(79, 214, 137, 0.15); color: #4fd689; }
.tag-inactive { background: rgba(200, 60, 90, 0.15); color: #e28ba0; }

.form-grid { display: grid; gap: 18px; max-width: 480px; }
.form-row-flex { display: flex; gap: 12px; align-items: flex-end; }
.actions-cell { text-align: right; white-space: nowrap; }
.swatch-row { display: flex; gap: 10px; align-items: center; }
.swatch-row input[type=color] { width: 46px; height: 40px; padding: 3px; cursor: pointer; }
.toast {
  position: fixed; top: 20px; right: 20px; z-index: 50;
  background: var(--color-surface); border: 1px solid var(--border-soft);
  padding: 13px 20px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 14px;
}
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 40;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal { width: 100%; max-width: 420px; padding: 28px; }
.modal h3 { margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.incoming-call-toast {
  position: fixed; top: 22px; left: 50%; transform: translateX(-50%);
  z-index: 60; padding: 16px 22px; display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow);
}
.incoming-call-toast .actions { display: flex; gap: 8px; }

/* ---------------- Bottom navbar (phone view) ---------------- */
/* Floating pill bar, active tab gets a soft rounded highlight —
   matches the WhatsApp-style reference the app is themed after. */

.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--color-surface) 96%, black 4%);
  border-top: 1px solid var(--border-soft);
  z-index: 45;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.3);
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 6px;
  font-size: 10.5px;
  font-weight: 600;
  color: color-mix(in srgb, var(--color-text) 50%, transparent);
  position: relative;
  transition: color 0.15s ease;
}
.bottom-nav a .nav-icon-wrap { position: relative; display: flex; }
.bottom-nav a .nav-icon { width: 22px; height: 22px; stroke: currentColor; }
.bottom-nav a.active { color: var(--color-primary); }
.bottom-nav a.active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 26px; height: 2.5px;
  border-radius: 0 0 3px 3px;
  background: var(--color-primary);
}
.bottom-nav a .nav-badge {
  position: absolute;
  top: -6px; right: -9px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px;
  background: var(--color-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid color-mix(in srgb, var(--color-surface) 90%, black 10%);
}

@media (max-width: 860px) {
  html, body { overscroll-behavior-y: contain; }

  .bottom-nav { display: flex; }

  /* ---- Chat app: full-screen list <-> full-screen conversation ---- */
  .app-shell {
    grid-template-columns: 1fr;
    height: calc(100vh - var(--bottom-nav-h));
    height: calc(100dvh - var(--bottom-nav-h));
  }
  .sidebar { display: flex; width: 100%; }
  .chat-pane { display: none; }
  body.chat-open .sidebar { display: none; }
  body.chat-open .chat-pane { display: flex; }
  .back-btn { display: inline-flex; }

  /* ---- Admin: stacked layout, side nav replaced by bottom nav ---- */
  .admin-shell { grid-template-columns: 1fr; min-height: calc(100vh - var(--bottom-nav-h)); }
  .admin-nav { display: none; }
  .admin-main { padding: 22px 18px calc(30px + var(--bottom-nav-h)); }
  .admin-main h1 { font-size: 21px; }
  .stat-grid { grid-template-columns: 1fr; }
  .form-row-flex { flex-direction: column; align-items: stretch; gap: 14px; }
  .actions-cell {
    text-align: left; white-space: normal;
    display: flex; flex-wrap: wrap; gap: 8px;
  }
  .actions-cell form { display: inline-flex; }
  table.data-table { min-width: 0; }
  .swatch-row { flex-wrap: wrap; }

  /* ---- Misc mobile polish ---- */
  .auth-card { padding: 36px 26px 30px; }
  .composer input, .code-input, table.data-table { font-size: 16px; } /* prevents iOS auto-zoom on focus */
  .call-video-local { width: 120px; height: 160px; right: 16px; bottom: 96px; }
  .admin-main .form-grid { max-width: 100%; }
}