/* Jokko theme: a bright, lively palette (violet, teal, coral) with soft cards, gradient
   accents and colourful avatars. Light by default, with a tasteful dark-mode swap that
   keeps the same vivid accents. */

:root {
  --violet: #6d28d9; --violet2: #7c3aed; --indigo: #4f46e5;
  --teal: #0d9488; --teal2: #14b8a6;
  --coral: #fb7185; --orange: #f97316; --amber: #f59e0b;
  --green: #16a34a; --red: #e11d48;

  --grad: linear-gradient(135deg, #7c3aed 0%, #6d28d9 42%, #0d9488 100%);
  --grad-warm: linear-gradient(135deg, #f97316 0%, #fb7185 100%);
  --grad-soft: linear-gradient(160deg, #f5f3ff 0%, #eefdfb 60%, #fff7f6 100%);

  --bg: #f4f5fb; --panel: #ffffff; --panel2: #f1f2f9; --line: #e6e8f2;
  --ink: #1e2130; --dim: #6b7280;
  --accent: var(--violet); --me: var(--violet); --them: #ffffff;
  --me-grad: linear-gradient(135deg, #7c3aed, #6d28d9);
  --shadow: 0 8px 28px rgba(31, 41, 80, .12);
  --shadow-sm: 0 2px 10px rgba(31, 41, 80, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1220; --panel: #171a2b; --panel2: #1e2236; --line: #2a2f4a;
    --ink: #e8eaf5; --dim: #9aa2c0; --them: #1e2236;
    --shadow: 0 10px 34px rgba(0, 0, 0, .5); --shadow-sm: 0 2px 12px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 600px at 12% -8%, rgba(124, 58, 237, .18), transparent 60%),
    radial-gradient(900px 520px at 110% 10%, rgba(13, 148, 136, .16), transparent 55%),
    radial-gradient(700px 500px at 50% 120%, rgba(251, 113, 133, .12), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
.hidden { display: none !important; }
.screen { height: 100dvh; }

/* Brand */
.brand { display: flex; align-items: center; gap: .6rem; }
.logo {
  width: 2.4rem; height: 2.4rem; border-radius: 30%; background: var(--grad); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 1.2rem;
  box-shadow: 0 6px 16px rgba(109, 40, 217, .4);
}
.logo.sm { width: 1.7rem; height: 1.7rem; font-size: .9rem; border-radius: 28%; }

/* Auth + unlock cards */
#auth, #unlock { display: grid; place-items: center; padding: 1rem; }
.card {
  width: min(24rem, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 1.7rem; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; background: var(--grad); }
.card h1 { margin: 0; color: var(--ink); letter-spacing: .3px; font-size: 1.6rem; }
.tag { color: var(--dim); margin: .5rem 0 1rem; }
.whoami-big { font-weight: 700; color: var(--violet); margin: .2rem 0 .4rem; font-size: 1.1rem; }
.card label { display: block; margin: .8rem 0 .25rem; font-size: .82rem; color: var(--dim); font-weight: 600; }
.card input {
  width: 100%; padding: .68rem .8rem; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--panel2); color: var(--ink); font-size: 1rem; transition: border-color .15s, box-shadow .15s;
}
.card input:focus { outline: none; border-color: var(--violet2); box-shadow: 0 0 0 4px rgba(124, 58, 237, .16); }

button {
  cursor: pointer; border: none; border-radius: 12px; background: var(--grad);
  color: #fff; padding: .58rem .95rem; font-size: .95rem; font-weight: 600;
  transition: transform .08s ease, filter .15s, box-shadow .15s; box-shadow: var(--shadow-sm);
}
button:hover { filter: brightness(1.06); box-shadow: var(--shadow); }
button:active { transform: translateY(1px); }
#btn-register, #btn-unlock { margin-top: 1.1rem; width: 100%; padding: .78rem; font-size: 1rem; }
.linkbtn { background: none; box-shadow: none; color: var(--dim); text-decoration: underline; padding: .4rem; margin-top: .8rem; width: 100%; font-weight: 500; }
.linkbtn:hover { filter: none; color: var(--red); box-shadow: none; }
.note { color: var(--dim); font-size: .8rem; }
.err { color: var(--red); font-size: .85rem; min-height: 1.2em; margin: .4rem 0 0; }

/* App layout */
#app { display: grid; grid-template-columns: 18rem 1fr; }
@media (max-width: 640px) {
  #app { grid-template-columns: 1fr; }
  #app.chatting #sidebar { display: none; }
  #app:not(.chatting) #chat { display: none; }
}
#sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#sidebar header { display: flex; align-items: center; gap: .5rem; padding: .8rem; background: var(--grad); color: #fff; }
#sidebar header strong { font-size: 1.05rem; letter-spacing: .3px; }
.whoami { color: #ffffffcc; font-size: .78rem; margin-left: auto; font-weight: 600; }
#sidebar header button { background: #ffffff2e; padding: .32rem .5rem; backdrop-filter: blur(4px); }
#sidebar header button:hover { background: #ffffff45; }
#contacts { list-style: none; margin: 0; padding: .4rem; overflow-y: auto; flex: 1; }
#contacts li { padding: .6rem .7rem; border-radius: 14px; cursor: pointer; display: flex; align-items: center; gap: .7rem; transition: background .12s; }
#contacts li:hover { background: var(--panel2); }
#contacts li.active { background: linear-gradient(135deg, rgba(124, 58, 237, .14), rgba(13, 148, 136, .12)); box-shadow: inset 3px 0 0 var(--violet2); }
.c-meta small { color: var(--dim); }
.avatar { width: 2.3rem; height: 2.3rem; border-radius: 50%; background: var(--violet); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; box-shadow: var(--shadow-sm); }
.avatar.peer { width: 2rem; height: 2rem; font-size: .9rem; }

/* Chat */
#chat { display: flex; flex-direction: column; min-height: 0; }
#chat-head { display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem; border-bottom: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow-sm); z-index: 2; }
#peer-name { font-weight: 700; }
.backbtn { display: none; background: none; box-shadow: none; color: var(--violet); font-size: 1.6rem; line-height: 1; padding: 0 .3rem 0 0; }
.backbtn:hover { filter: none; box-shadow: none; }
@media (max-width: 640px) { #app.chatting .backbtn { display: inline-block; } }
#call-actions { margin-left: auto; display: flex; gap: .2rem; }
#call-actions button { background: var(--panel2); color: var(--ink); font-size: 1.2rem; padding: .3rem .45rem; box-shadow: none; }
#call-actions button:hover { background: linear-gradient(135deg, rgba(124, 58, 237, .16), rgba(13, 148, 136, .14)); }
#messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .45rem; }
.bubble { max-width: 74%; padding: .55rem .75rem; border-radius: 16px; white-space: pre-wrap; word-break: break-word; box-shadow: var(--shadow-sm); }
.bubble.me { align-self: flex-end; background: var(--me-grad); color: #fff; border-bottom-right-radius: 5px; }
.bubble.them { align-self: flex-start; background: var(--them); color: var(--ink); border: 1px solid var(--line); border-bottom-left-radius: 5px; border-left: 3px solid var(--teal2); }
.bubble .meta { display: block; font-size: .66rem; opacity: .78; margin-top: .25rem; }
.bubble.them .meta { color: var(--dim); }
.sys { align-self: center; color: var(--dim); font-size: .82rem; text-align: center; padding: .6rem; }
.e2ee-bar { text-align: center; font-size: .72rem; color: var(--teal); padding: .35rem; background: linear-gradient(90deg, rgba(13, 148, 136, .12), rgba(124, 58, 237, .1)); }
#composer { display: flex; gap: .5rem; padding: .7rem; border-top: 1px solid var(--line); background: var(--panel); }
#composer input { flex: 1; padding: .65rem .9rem; border-radius: 22px; border: 1.5px solid var(--line); background: var(--panel2); color: var(--ink); }
#composer input:focus { outline: none; border-color: var(--violet2); box-shadow: 0 0 0 4px rgba(124, 58, 237, .14); }
#composer button { border-radius: 22px; padding: .65rem 1.2rem; }
#attach { display: grid; place-items: center; width: 2.6rem; border-radius: 22px; cursor: pointer; font-size: 1.2rem; background: var(--panel2); }
#attach:hover { background: linear-gradient(135deg, rgba(124, 58, 237, .16), rgba(13, 148, 136, .14)); }

/* Media messages */
.media-img { max-width: 100%; border-radius: 12px; display: block; }
.bubble audio { width: 15rem; max-width: 60vw; }
.bubble.me a { color: #fff; }
.bubble.them a { color: var(--violet); }

/* Call overlay */
#call-overlay { position: fixed; inset: 0; background: rgba(12, 10, 30, .62); backdrop-filter: blur(8px); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.call-box {
  width: min(30rem, 94vw); border-radius: 22px; padding: 1.4rem; text-align: center; color: #fff;
  background: linear-gradient(160deg, #2b2170 0%, #3b2a8c 45%, #0e6f68 100%);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .5); border: 1px solid #ffffff22;
}
.call-box.ended { padding: 2rem 1.4rem; }
.call-peer { font-size: 1.4rem; font-weight: 800; }
.call-status { color: #ffffffcc; margin: .25rem 0 .9rem; min-height: 1.2em; font-weight: 600; }
.call-status.err { color: #fecdd3; }
.call-videos { position: relative; background: #000; border-radius: 14px; overflow: hidden; aspect-ratio: 4/3; }
.call-videos.audio { aspect-ratio: auto; height: 8rem; display: grid; place-items: center; background: linear-gradient(135deg, #4c1d95, #0f766e); }
.call-videos.audio #remote-video { display: none; }
.call-avatar { position: absolute; inset: 0; margin: auto; width: 4.5rem; height: 4.5rem; border-radius: 50%; background: #ffffff26; display: none; place-items: center; font-size: 2rem; font-weight: 800; }
.call-videos.audio .call-avatar { display: grid; }
#remote-video { width: 100%; height: 100%; object-fit: cover; background: #000; }
#local-video.pip { position: absolute; right: .6rem; bottom: .6rem; width: 28%; border-radius: 10px; border: 2px solid #ffffff66; background: #000; }
.call-route { font-size: .72rem; color: #ffffff9c; margin-top: .55rem; }
.call-p2p { font-size: .72rem; color: #a7f3d0; margin: .35rem 0 .6rem; }
.call-actions { display: flex; gap: .7rem; justify-content: center; margin-top: .7rem; }
.call-actions button { padding: .65rem 1.6rem; border-radius: 26px; font-weight: 700; }
.call-actions .answer { background: linear-gradient(135deg, #22c55e, #16a34a); }
.call-actions .hangup { background: linear-gradient(135deg, #fb7185, #e11d48); }
.call-actions .close-btn { background: #ffffff26; }

/* Store + wallet overlay */
#store-overlay { position: fixed; inset: 0; background: rgba(12, 10, 30, .55); backdrop-filter: blur(8px); display: grid; place-items: center; z-index: 60; padding: 1rem; }
.store-box { width: min(34rem, 96vw); max-height: 90dvh; overflow-y: auto; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 20px; padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.store-box::-webkit-scrollbar { width: 8px; } .store-box::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.store-box header { display: flex; align-items: center; gap: .6rem; padding-bottom: .5rem; }
.store-box header strong { font-size: 1.15rem; }
.store-box header .wallet { margin-left: auto; color: #fff; background: var(--grad-warm); padding: .3rem .7rem; border-radius: 20px; font-weight: 700; font-size: .85rem; }
.store-box header button { background: var(--panel2); color: var(--ink); box-shadow: none; }
.sandbox-note { font-size: .78rem; color: var(--dim); background: var(--panel2); padding: .4rem .6rem; border-radius: 10px; }
.store-box h4 { margin: 1rem 0 .4rem; }
.store-item { display: flex; align-items: center; gap: .7rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.si-emoji { font-size: 1.7rem; width: 2.6rem; height: 2.6rem; display: grid; place-items: center; background: var(--panel2); border-radius: 14px; }
.si-body { flex: 1; } .si-body small { color: var(--dim); }
.si-buy { display: flex; gap: .4rem; flex-wrap: wrap; }
.si-buy button { padding: .42rem .7rem; font-size: .8rem; }
.si-buy button[data-m="wave"] { background: linear-gradient(135deg, #38bdf8, #0ea5e9); }
.si-buy button[data-m="orange_money"] { background: var(--grad-warm); }
.store-orders { display: flex; flex-direction: column; gap: .5rem; }
.order-row { background: var(--panel2); border-radius: 12px; padding: .55rem .75rem; font-size: .88rem; }
.oactions { display: flex; gap: .4rem; margin-top: .4rem; flex-wrap: wrap; }
.oactions .answer { background: linear-gradient(135deg, #22c55e, #16a34a); }
.oactions .hangup { background: linear-gradient(135deg, #fb7185, #e11d48); }
.oactions .paybtn, .oactions button { padding: .38rem .75rem; border-radius: 10px; font-size: .8rem; text-decoration: none; color: #fff; }
.oactions .paybtn { background: var(--grad); display: inline-block; }
.otrace { font-size: .72rem; color: var(--dim); margin-top: .35rem; }
.note { color: var(--dim); }
