:root {
  --bg: #0a1020;
  --bg2: #0f172c;
  --card: #121c33;
  --card2: #182443;
  --line: rgba(255, 255, 255, .08);
  --text: #e9eefb;
  --muted: #8fa0c2;
  --green: #22c55e;
  --green2: #4ade80;
  --red: #f87171;
  --amber: #fbbf24;
  --r: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'Cairo', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(900px 500px at 85% -10%, rgba(34, 197, 94, .14), transparent 60%),
    radial-gradient(700px 400px at 0% 100%, rgba(59, 130, 246, .10), transparent 60%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 800; line-height: 1.3; }
p { margin: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
/* Prices always read left-to-right, even inside RTL text. */
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(10, 16, 32, .85);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; }
.brand .logo-sm { font-size: 22px; }
.tabs {
  display: flex; gap: 4px; padding: 4px; border-radius: 999px;
  background: rgba(255, 255, 255, .05);
}
.tabs button {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 700; padding: 5px 14px; border-radius: 999px; cursor: pointer;
  transition: .15s;
}
.tabs button.on { background: var(--green); color: #052e16; }
.who { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }
.chip {
  background: rgba(255, 255, 255, .06); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 12px; font-size: 13px; font-weight: 700;
}
/* On a phone the bar is brand + user on one row and the tabs full-width below,
   instead of three stacked rows. */
@media (max-width: 600px) {
  .who { order: 2; }
  .tabs { order: 3; width: 100%; }
  .tabs button { flex: 1; }
}
.main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 70px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.head h2 { font-size: 24px; }

/* ---------- buttons ---------- */
.btn {
  border: 0; font: inherit; font-weight: 800; padding: 10px 18px; border-radius: 12px;
  cursor: pointer; transition: .15s; background: rgba(255, 255, 255, .08); color: var(--text);
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--green); color: #052e16; box-shadow: 0 6px 18px rgba(34, 197, 94, .3); }
.btn.ghost { background: rgba(255, 255, 255, .07); }
.btn.danger { background: rgba(248, 113, 113, .15); color: var(--red); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }

/* ---------- forms ---------- */
label { display: flex; flex-direction: column; gap: 6px; text-align: start; font-weight: 700; font-size: 14px; }
.opt { color: var(--muted); font-weight: 400; font-size: 12px; font-style: normal; }
input, textarea {
  font: inherit; color: var(--text); width: 100%;
  background: rgba(255, 255, 255, .06); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; outline: 0; transition: .15s;
}
input::placeholder, textarea::placeholder { color: rgba(143, 160, 194, .6); }
input:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
input[inputmode="decimal"] { direction: ltr; text-align: right; }
textarea { resize: vertical; min-height: 80px; }
.err { color: var(--red); font-size: 14px; min-height: 1.4em; }
.hint { color: var(--green2); font-size: 12px; font-weight: 800; min-height: 1.2em; direction: ltr; text-align: right; }
.hint.down { color: var(--red); }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; text-align: center; display: flex; flex-direction: column; gap: 12px; }
.logo { font-size: 56px; line-height: 1; }
.login-card h1 { font-size: 28px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; box-shadow: var(--shadow);
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.post { display: flex; flex-direction: column; gap: 12px; animation: pop .3s ease both; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.post-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.post-head h3 { font-size: 20px; word-break: break-word; }
.post-head time { color: var(--muted); font-size: 12px; white-space: nowrap; padding-top: 5px; }
.entry {
  display: flex; justify-content: space-between; align-items: center;
  background: rgba(34, 197, 94, .10); border: 1px solid rgba(34, 197, 94, .25);
  border-radius: 12px; padding: 8px 14px;
}
.entry span { color: var(--green2); font-weight: 700; }
.entry b { font-size: 22px; }
.targets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.target {
  background: var(--card2); border-radius: 12px; padding: 8px 6px;
  display: flex; flex-direction: column; align-items: center; text-align: center; line-height: 1.4;
}
.target span { font-size: 12px; color: var(--muted); font-weight: 700; }
.target b { font-size: 17px; }
.target em { font-style: normal; font-size: 12px; font-weight: 800; }
.up { color: var(--green2); }
.down { color: var(--red); }
.note {
  background: rgba(255, 255, 255, .04); border-inline-start: 3px solid var(--amber);
  border-radius: 8px; padding: 8px 12px; white-space: pre-wrap; word-break: break-word;
}
.post-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: auto; font-size: 13px; }
.actions { display: flex; gap: 6px; }
.empty { text-align: center; padding: 60px 16px; }
.empty .big { font-size: 52px; }
.empty p:first-of-type { font-size: 18px; font-weight: 700; }

/* ---------- modal / sheet ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: end center; animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; overflow: auto;
  display: flex; flex-direction: column; gap: 12px; animation: up .25s ease;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (min-width: 700px) {
  .modal { place-items: center; }
  .sheet { border-radius: 20px; }
}
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 420px) { .row3 { grid-template-columns: 1fr; } }
.sheet-btns { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- members ---------- */
.add-member { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; margin-bottom: 14px; }
.add-member .err { grid-column: 1 / -1; min-height: 0; }
@media (max-width: 640px) { .add-member { grid-template-columns: 1fr; } }
.list { padding: 4px 16px; }
.mem { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.mem:last-child { border-bottom: 0; }
.mem .grow { flex: 1; min-width: 0; }
.mem .name { font-weight: 800; word-break: break-word; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, #22c55e, #0ea5e9);
  display: grid; place-items: center; font-weight: 800; color: #052e16; font-size: 16px;
}
.badge { font-size: 11px; font-weight: 800; padding: 1px 8px; border-radius: 999px; background: rgba(255, 255, 255, .08); color: var(--muted); }
.badge.owner { background: rgba(251, 191, 36, .15); color: var(--amber); }

/* ---------- chat ---------- */
.small { font-size: 12px; }
.tabs .dot {
  background: var(--red); color: #fff; font-size: 11px; line-height: 18px;
  border-radius: 999px; padding: 0 6px; margin-inline-start: 5px; vertical-align: 1px;
}
.chat {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 14px;
  height: calc(100vh - var(--tb, 70px) - 40px); height: calc(100dvh - var(--tb, 70px) - 40px);
  min-height: 420px;
}
.threads { padding: 8px; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.thread {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: start;
  background: transparent; border: 0; color: var(--text); font: inherit;
  padding: 10px; border-radius: 12px; cursor: pointer; transition: .15s;
}
.thread:hover { background: rgba(255, 255, 255, .05); }
.thread.on { background: rgba(34, 197, 94, .12); }
.thread .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.4; }
.thread .name { font-weight: 800; }
.thread .last { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-n {
  background: var(--green); color: #052e16; font-weight: 800; font-size: 12px;
  min-width: 22px; height: 22px; border-radius: 999px; padding: 0 6px;
  display: grid; place-items: center; flex: none;
}
.sect { font-size: 12px; font-weight: 700; padding: 10px 10px 2px; }
.convo { padding: 0; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.convo .empty { margin: auto; }
.convo-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.convo-head .grow { flex: 1; min-width: 0; line-height: 1.4; }
.convo-head .name { font-weight: 800; }
.back { display: none; }
.msgs { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msgs > .center { margin: auto; }
.msg {
  max-width: 78%; align-self: flex-start;
  background: var(--card2); border-radius: 14px; border-end-start-radius: 4px;
  padding: 7px 12px; display: flex; flex-direction: column; animation: pop .2s ease both;
}
.msg.mine { align-self: flex-end; background: rgba(34, 197, 94, .18); border-end-start-radius: 14px; border-end-end-radius: 4px; }
.msg .who { font-size: 12px; font-weight: 800; color: var(--green2); }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.msg .meta { font-size: 11px; color: var(--muted); align-self: flex-end; display: flex; gap: 6px; align-items: center; }
.msg .del { background: none; border: 0; cursor: pointer; font-size: 12px; opacity: .45; padding: 0; line-height: 1; }
.msg .del:hover { opacity: 1; }
.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
}
.composer textarea { min-height: 44px; max-height: 140px; resize: none; line-height: 1.5; }
@media (max-width: 800px) {
  .chat { grid-template-columns: 1fr; height: calc(100vh - var(--tb, 111px) - 20px); height: calc(100dvh - var(--tb, 111px) - 20px); min-height: 0; }
  .chat .convo { display: none; }
  .chat.open .convo { display: flex; }
  .chat.open .threads { display: none; }
  .back { display: inline-block; }
}

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .25s;
  background: #1f2b4a; color: var(--text); border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 18px; box-shadow: var(--shadow); font-weight: 700; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { border-color: rgba(248, 113, 113, .5); color: var(--red); }
