/* QABILTU Wali Portal — mobile-first */
:root {
  --qb-green: #0f6b4f;
  --qb-green-dark: #0a4d39;
  --qb-green-soft: #e6f2ed;
  --qb-gold: #c9a24b;
  --qb-bg: #f5f7f6;
  --qb-card: #ffffff;
  --qb-text: #1c2b25;
  --qb-muted: #6b7c74;
  --qb-line: #e3e9e6;
  --qb-bubble-in: #ffffff;
  --qb-bubble-out: #d9f0e6;
  --qb-topbar-h: 56px;
  --qb-nav-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bs-primary: #0f6b4f;
  --bs-primary-rgb: 15, 107, 79;
  --bs-body-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

* { -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { background: var(--qb-bg); color: var(--qb-text); overscroll-behavior: none; }

.btn-primary { --bs-btn-bg: var(--qb-green); --bs-btn-border-color: var(--qb-green);
  --bs-btn-hover-bg: var(--qb-green-dark); --bs-btn-hover-border-color: var(--qb-green-dark);
  --bs-btn-active-bg: var(--qb-green-dark); --bs-btn-active-border-color: var(--qb-green-dark);
  --bs-btn-disabled-bg: var(--qb-green); --bs-btn-disabled-border-color: var(--qb-green); }
.btn-outline-primary { --bs-btn-color: var(--qb-green); --bs-btn-border-color: var(--qb-green);
  --bs-btn-hover-bg: var(--qb-green); --bs-btn-hover-border-color: var(--qb-green);
  --bs-btn-active-bg: var(--qb-green); --bs-btn-active-border-color: var(--qb-green); }
.form-control:focus, .form-select:focus { border-color: var(--qb-green); box-shadow: 0 0 0 .2rem rgba(15,107,79,.18); }
a { color: var(--qb-green); }
.text-muted, .text-secondary { color: var(--qb-muted) !important; }

/* ---------- shell ---------- */
.app-shell { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-top) + 8px) 16px 8px; min-height: calc(var(--qb-topbar-h) + var(--safe-top));
  background: var(--qb-green); color: #fff; z-index: 20;
}
.topbar.d-none { display: none !important; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .04em; }
.brand img { border-radius: 8px; }
.brand-text small { font-weight: 500; opacity: .8; letter-spacing: .02em; margin-left: 2px; }
.topnav { margin-left: 24px; gap: 4px; flex: 1; }
.topnav a { color: rgba(255,255,255,.85); text-decoration: none; padding: 8px 14px; border-radius: 10px; font-weight: 600; display: inline-flex; gap: 8px; align-items: center; }
.topnav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.topnav a.active { background: rgba(255,255,255,.2); color: #fff; }
.topbar > .dropdown { margin-left: auto; }
.avatar-btn { width: 38px; height: 38px; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); background: var(--qb-gold); color: #fff; font-weight: 700; }

.view { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; outline: none; }
.view.no-pad-bottom { overflow: hidden; }

.bottomnav {
  flex: 0 0 auto; display: flex; background: var(--qb-card); border-top: 1px solid var(--qb-line);
  padding-bottom: var(--safe-bottom); z-index: 20;
}
.bottomnav.d-none { display: none !important; }
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--qb-nav-h); color: var(--qb-muted); text-decoration: none; font-size: .72rem; font-weight: 600; position: relative;
}
.bottomnav a.active { color: var(--qb-green); }
.bottomnav a.active::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--qb-green); }
.icon { width: 22px; height: 22px; display: inline-block; flex: 0 0 auto; }
.icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-badge { position: absolute; top: 6px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #d64545; color: #fff; font-size: .68rem; line-height: 18px; text-align: center; }
.topnav .nav-badge { position: static; }

.page { max-width: 880px; margin: 0 auto; padding: 16px; }
.page-title { font-size: 1.25rem; font-weight: 700; margin: 4px 0 14px; }
.card-qb { background: var(--qb-card); border: 1px solid var(--qb-line); border-radius: 16px; box-shadow: 0 1px 2px rgba(16,40,30,.04); }

/* ---------- avatars ---------- */
.avatar { width: 46px; height: 46px; border-radius: 50%; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; overflow: hidden; background: var(--qb-green); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 84px; height: 84px; font-size: 1.8rem; }
.avatar.sm { width: 34px; height: 34px; font-size: .85rem; }

/* ---------- auth / landing ---------- */
.auth-wrap { min-height: 100%; display: flex; align-items: flex-start; justify-content: center; padding: calc(var(--safe-top) + 24px) 16px 32px; background: linear-gradient(180deg, var(--qb-green) 0, var(--qb-green) 190px, var(--qb-bg) 190px); }
.auth-card { width: 100%; max-width: 440px; padding: 24px; }
.auth-logo { text-align: center; color: #fff; margin-bottom: 18px; }
.auth-logo img { width: 64px; height: 64px; border-radius: 16px; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.auth-logo h1 { font-size: 1.35rem; margin: 10px 0 0; letter-spacing: .12em; font-weight: 800; }
.auth-logo p { margin: 2px 0 0; opacity: .85; font-size: .85rem; }
.nav-pills .nav-link { color: var(--qb-muted); font-weight: 600; }
.nav-pills .nav-link.active { background: var(--qb-green); color: #fff; }
.quote { border-left: 4px solid var(--qb-gold); background: #faf6ea; padding: 10px 14px; border-radius: 8px; font-style: italic; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--qb-green-soft); color: var(--qb-green-dark); font-size: .78rem; font-weight: 600; }
.chip.gold { background: #f7eed3; color: #7a5c12; }
.chip.red { background: #fbe4e4; color: #9b2c2c; }
.chip.gray { background: #eceff0; color: #55646b; }

/* ---------- chats ---------- */
.chat-layout { height: 100%; display: flex; min-height: 0; }
.chat-list { flex: 1 1 100%; overflow-y: auto; background: var(--qb-card); min-height: 0; }
.chat-thread { display: none; flex: 1 1 100%; min-width: 0; min-height: 0; flex-direction: column; background: #eef2f0; }
.chat-layout[data-mode="thread"] .chat-list { display: none; }
.chat-layout[data-mode="thread"] .chat-thread { display: flex; }
.list-head { padding: 14px 16px 6px; position: sticky; top: 0; background: var(--qb-card); z-index: 2; }
.filter-pill { display: inline-flex; gap: 6px; align-items: center; }
.conv-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--qb-line); text-decoration: none; color: inherit; align-items: center; }
.conv-item:hover { background: #f7faf9; }
.conv-item.active { background: var(--qb-green-soft); }
.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: .74rem; color: var(--qb-muted); flex: 0 0 auto; }
.conv-sub { font-size: .76rem; color: var(--qb-green-dark); }
.conv-last { font-size: .86rem; color: var(--qb-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item.unread .conv-last { color: var(--qb-text); font-weight: 600; }
.unread-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--qb-green); flex: 0 0 auto; }

.thread-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--qb-card); border-bottom: 1px solid var(--qb-line); }
.back-btn { border: 0; background: transparent; padding: 6px; color: var(--qb-text); border-radius: 50%; }
.thread-title { font-weight: 700; line-height: 1.2; }
.thread-sub { font-size: .76rem; color: var(--qb-muted); }
.readonly-bar { display: flex; align-items: center; gap: 8px; padding: 6px 14px; background: #fff8e5; color: #7a5c12; font-size: .78rem; border-bottom: 1px solid #f0e2b4; }
.messages { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 12px 18px; display: flex; flex-direction: column; gap: 4px; -webkit-overflow-scrolling: touch; }
.day-sep { align-self: center; margin: 10px 0 6px; font-size: .72rem; color: var(--qb-muted); background: rgba(255,255,255,.85); padding: 3px 12px; border-radius: 999px; }
.msg { max-width: min(82%, 520px); padding: 7px 11px 5px; border-radius: 14px; background: var(--qb-bubble-in); box-shadow: 0 1px 1px rgba(0,0,0,.06); word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.from-member { align-self: flex-end; background: var(--qb-bubble-out); border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
.msg .who { display: block; font-size: .7rem; font-weight: 700; color: var(--qb-green-dark); margin-bottom: 1px; }
.msg .time { display: block; text-align: right; font-size: .66rem; color: var(--qb-muted); margin-top: 2px; }
.msg.deleted { font-style: italic; color: var(--qb-muted); background: rgba(255,255,255,.6); }
.msg .edited { font-size: .66rem; color: var(--qb-muted); }
.typing-hint { height: 20px; padding: 0 16px; font-size: .74rem; color: var(--qb-muted); }
.thread-empty { flex: 1; display: none; align-items: center; justify-content: center; text-align: center; color: var(--qb-muted); padding: 24px; }
.new-pill { position: absolute; right: 16px; bottom: 16px; border-radius: 999px; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.thread-body { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* ---------- members / invitations ---------- */
.member-card { display: flex; gap: 14px; padding: 14px; align-items: center; text-decoration: none; color: inherit; margin-bottom: 10px; }
.member-card:hover { border-color: #cfe0d9; }
.kv { display: grid; grid-template-columns: 1fr; gap: 10px 20px; }
.kv dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--qb-muted); margin: 0; }
.kv dd { margin: 0; font-weight: 500; }
.gallery { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.gallery img { height: 150px; width: 120px; object-fit: cover; border-radius: 12px; flex: 0 0 auto; }
.empty { text-align: center; color: var(--qb-muted); padding: 48px 20px; }
.empty .icon { width: 44px; height: 44px; opacity: .45; margin-bottom: 8px; }
.invite-card { padding: 16px; margin-bottom: 12px; }
.skeleton { background: linear-gradient(90deg, #eef2f0 25%, #f7faf9 37%, #eef2f0 63%); background-size: 400% 100%; animation: sk 1.3s ease infinite; border-radius: 12px; }
@keyframes sk { 0% { background-position: 100% 50% } 100% { background-position: 0 50% } }

/* ---------- desktop ---------- */
@media (min-width: 576px) {
  .kv { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 992px) {
  .page { padding: 28px 24px; }
  .view.chat-view { padding: 16px 24px 24px; }
  .chat-layout { border: 1px solid var(--qb-line); border-radius: 18px; overflow: hidden; background: var(--qb-card); max-width: 1180px; margin: 0 auto; box-shadow: 0 2px 8px rgba(16,40,30,.05); }
  .chat-list { flex: 0 0 360px; border-right: 1px solid var(--qb-line); }
  .chat-thread, .chat-layout[data-mode="thread"] .chat-thread, .chat-layout[data-mode="list"] .chat-thread { display: flex; flex: 1 1 auto; }
  .chat-layout[data-mode="thread"] .chat-list { display: block; }
  .back-btn { display: none; }
  .msg { max-width: min(70%, 560px); }
}
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

.min-w-0 { min-width: 0; }
.card-qb p { white-space: pre-wrap; }
