/* MikeChat web — follows the osmike-web design system (Fraunces + Manrope, warm light
   palette, coral accent, gradient brand mark, ink pill buttons). Theme-driven via CSS
   variables that app.js swaps for light / dark / sepia + accent + text size. */
:root {
  --bg: #FBFAF7; --ink: #17130E; --muted: #6c6458; --faint: #9a9082;
  --line: #ece6dc; --card: #ffffff; --pane: #fdfcfa; --hover: #fff7f0;
  --coral: #FF8A5B; --rose: #FF6FA5; --peri: #7C7CFF; --sky: #4FC4E8;
  --accent: #E8553F; --bubble-mine: #17130E; --bubble-mine-ink: #FBFAF7;
  --disp: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --grad: linear-gradient(100deg, var(--coral), var(--rose) 42%, var(--peri) 82%);
  --msg-size: 15px;
}
body[data-theme="dark"] {
  --bg: #14120f; --ink: #F4EFE7; --muted: #a79f92; --faint: #7c7466;
  --line: #2b2620; --card: #1d1a15; --pane: #171410; --hover: #241f18;
  --bubble-mine-ink: #14120f;
}
body[data-theme="sepia"] {
  --bg: #F4ECD8; --ink: #4A3B28; --muted: #7d6a4f; --faint: #a2916f;
  --line: #e2d5b8; --card: #fbf5e6; --pane: #f7efdc; --hover: #f0e6cc;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); }
.hidden { display: none !important; }
.mark { width: 26px; height: 26px; border-radius: 8px; background: var(--grad); display: inline-block; flex: 0 0 26px; }

/* Sign-in gate */
.gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; }
.gate-card { text-align: center; background: var(--card); border: 1px solid var(--line);
  padding: 48px 44px; border-radius: 26px; max-width: 380px; width: 100%;
  box-shadow: 0 26px 60px -34px rgba(23,19,14,.35); }
.gate-card .brand { display: inline-flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.gate-card h1 { font-family: var(--disp); font-weight: 400; font-size: 40px; margin: 6px 0 6px; letter-spacing: -.01em; }
.gate-card p { color: var(--muted); margin: 4px 0 24px; }
.err { color: var(--accent); min-height: 18px; font-size: 14px; }

.btn { display: inline-block; border: 0; font-weight: 600; font-size: 16px; border-radius: 999px;
  padding: 14px 28px; background: var(--ink); color: var(--bg); cursor: pointer; text-decoration: none;
  transition: transform .2s, box-shadow .2s; box-shadow: 0 10px 30px -12px rgba(23,19,14,.5); }
.btn:hover { transform: translateY(-2px); box-shadow: 0 16px 36px -12px rgba(23,19,14,.55); }
.btn.send { padding: 12px 22px; }
.btn.sm { padding: 9px 18px; font-size: 14px; box-shadow: none; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1;
  padding: 4px 6px; border-radius: 8px; }
.icon-btn:hover { color: var(--accent); background: var(--hover); }

/* App layout */
.app { display: flex; height: 100vh; }
.sidebar { width: 350px; min-width: 300px; border-right: 1px solid var(--line); display: flex;
  flex-direction: column; background: var(--bg); }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px;
  border-bottom: 1px solid var(--line); }
.side-top .who { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.side-top .who span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-actions { display: flex; gap: 2px; flex: 0 0 auto; }
.search-wrap { padding: 12px; }
#search { width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink); padding: 11px 16px; font-size: 15px; outline: none; font-family: var(--sans); }
#search:focus { border-color: var(--accent); }
.results { border-bottom: 1px solid var(--line); }
.results .label, .empty small { color: var(--faint); font-size: 12px; padding: 8px 18px 2px; display: block;
  text-transform: uppercase; letter-spacing: .04em; }

.convos { flex: 1; overflow-y: auto; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; cursor: pointer;
  border-bottom: 1px solid var(--line); }
.row:hover { background: var(--hover); }
.row.active { background: var(--card); }
.avatar { width: 44px; height: 44px; border-radius: 50%; flex: 0 0 44px; display: flex;
  align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 18px; }
.avatar.sm { width: 30px; height: 30px; flex-basis: 30px; font-size: 13px; }
.row .meta { min-width: 0; flex: 1; }
.row .name { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.row .name .when { font-weight: 400; font-size: 11px; color: var(--faint); flex: 0 0 auto; }
.row .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: flex; align-items: center; gap: 6px; }
.row .sub .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread { flex: 0 0 auto; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 999px; display: inline-flex; align-items: center;
  justify-content: center; padding: 0 6px; }

/* Thread */
.thread-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--pane); }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); background: var(--card); font-weight: 600; }
.thread-head .peer-id { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.thread-head .peer-id > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 2px; }
/* chat wallpaper (chat_wallpaper setting) — subtle, stays readable in light & dark */
body[data-wallpaper="None"] .messages { background: var(--bg); }
body[data-wallpaper="Dark"] .messages { background: #0f0d0b; }
body[data-wallpaper="Gradient"] .messages {
  background: linear-gradient(160deg, rgba(255,138,91,.12), rgba(255,111,165,.08) 45%, rgba(124,124,255,.12)); }
/* compact density (appear_compact) — tighter list + thread */
body.compact .messages { padding: 12px 16px; }
body.compact .msg { margin-top: 3px; }
body.compact .bubble { padding: 6px 11px; }
body.compact .row { padding: 7px 16px; }
body.compact .avatar { width: 38px; height: 38px; flex-basis: 38px; font-size: 16px; }
.messages .empty { margin: auto; color: var(--muted); text-align: center; }
.day-sep { align-self: center; color: var(--faint); font-size: 12px; background: var(--card);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; margin: 12px 0 8px; }

.msg { display: flex; flex-direction: column; max-width: 72%; margin-top: 6px; position: relative; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.peer { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 8px 12px; border-radius: 18px; word-wrap: break-word; overflow-wrap: anywhere;
  white-space: pre-wrap; line-height: 1.35; font-size: var(--msg-size); position: relative; }
.msg.mine .bubble { background: var(--bubble-mine); color: var(--bubble-mine-ink); border-bottom-right-radius: 5px; }
.msg.peer .bubble { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble.media { padding: 4px; overflow: hidden; }
.bubble .time { font-size: 11px; margin-left: 8px; opacity: .6; white-space: nowrap; }
.bubble .meta-row { display: inline-flex; align-items: center; gap: 3px; float: right; margin: 6px 0 0 10px; }
.bubble.big-emoji { font-size: 44px; background: none !important; border: 0 !important; padding: 0 4px; }
.tick { font-size: 12px; opacity: .7; }
.tick.read { color: var(--sky); opacity: 1; }
.edited { font-size: 10px; opacity: .55; font-style: italic; }
.deleted-note { font-style: italic; opacity: .6; }

/* reply quote */
.reply-quote { border-left: 3px solid var(--accent); padding: 2px 8px; margin: 2px 0 6px; opacity: .85;
  font-size: 13px; background: rgba(232,85,63,.08); border-radius: 6px; cursor: pointer; }
.reply-quote .rq-who { font-weight: 600; font-size: 12px; color: var(--accent); }
.reply-quote .rq-body { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }

/* media */
.media-img { max-width: 260px; max-height: 320px; border-radius: 14px; display: block; cursor: pointer; }
.album { display: grid; gap: 3px; border-radius: 14px; overflow: hidden; max-width: 270px; }
.album.n2 { grid-template-columns: 1fr 1fr; }
.album.n3, .album.n4 { grid-template-columns: 1fr 1fr; }
.album .cell { position: relative; aspect-ratio: 1; overflow: hidden; cursor: pointer; background: var(--line); }
.album .cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album .cell .more { position: absolute; inset: 0; background: rgba(0,0,0,.5); color: #fff; font-size: 22px;
  font-weight: 700; display: flex; align-items: center; justify-content: center; }
.voice { display: flex; align-items: center; gap: 10px; padding: 6px 8px; min-width: 190px; }
.voice .play { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 15px; }
.voice .wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 30px; }
.voice .wave i { flex: 1; background: currentColor; opacity: .45; border-radius: 2px; min-height: 3px; }
.voice .wave i.on { opacity: 1; }
.voice .dur { font-size: 12px; opacity: .7; flex: 0 0 auto; }
.circle video { width: 220px; height: 220px; border-radius: 50%; object-fit: cover; background: #000; cursor: pointer; }

/* reactions */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { display: inline-flex; align-items: center; gap: 3px; background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 1px 8px; font-size: 13px; cursor: pointer; }
.chip.mine { border-color: var(--accent); background: rgba(232,85,63,.12); }
.chip .cnt { font-size: 11px; color: var(--muted); }

/* hover action affordance */
.msg .acts { position: absolute; top: -4px; display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.msg.mine .acts { left: -66px; }
.msg.peer .acts { right: -66px; }
.msg:hover .acts { opacity: 1; }
.msg .acts button { background: var(--card); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
  font-size: 14px; width: 28px; height: 28px; color: var(--muted); }
.msg .acts button:hover { color: var(--accent); }

/* floating menus */
.msg-menu, .react-bar { position: fixed; z-index: 60; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 18px 48px -20px rgba(0,0,0,.4); overflow: hidden; }
.msg-menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 10px 18px;
  font-size: 14px; color: var(--ink); cursor: pointer; font-family: var(--sans); }
.msg-menu button:hover { background: var(--hover); }
.msg-menu button.danger { color: var(--accent); }
.react-bar { display: flex; gap: 2px; padding: 5px 8px; border-radius: 999px; }
.react-bar button { background: none; border: 0; font-size: 22px; cursor: pointer; padding: 2px 4px; border-radius: 8px; }
.react-bar button:hover { background: var(--hover); transform: scale(1.2); }

/* context bar (reply/edit) */
.context-bar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-top: 1px solid var(--line);
  background: var(--card); }
.context-bar .ctx-body { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; }
.context-bar .ctx-label { color: var(--accent); font-weight: 600; margin-right: 8px; }
.context-bar #ctx-text { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* composer */
.composer { display: flex; gap: 8px; align-items: center; padding: 12px 14px; border-top: 1px solid var(--line);
  background: var(--card); }
.composer .attach { font-size: 24px; display: inline-flex; align-items: center; }
.composer.recording #draft, .composer.recording .attach { opacity: .4; pointer-events: none; }
#draft { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; color: var(--ink);
  padding: 13px 18px; font-size: 15px; outline: none; font-family: var(--sans); }
#draft:focus { border-color: var(--accent); }
.rec-dot { color: var(--accent); font-weight: 600; font-size: 13px; }
.only-mobile { display: none; }

/* fullscreen viewer */
.viewer { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.92); display: flex;
  align-items: center; justify-content: center; }
.viewer img { max-width: 94vw; max-height: 92vh; border-radius: 8px; }
.viewer-close { position: absolute; top: 18px; right: 22px; background: none; border: 0; color: #fff;
  font-size: 30px; cursor: pointer; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.12);
  color: #fff; border: 0; font-size: 34px; width: 54px; height: 72px; cursor: pointer; border-radius: 12px; }
.viewer-nav.prev { left: 18px; } .viewer-nav.next { right: 18px; }

/* settings drawer */
.drawer-scrim { position: fixed; inset: 0; z-index: 70; background: rgba(23,19,14,.4); display: flex; justify-content: flex-end; }
.drawer { width: 420px; max-width: 100%; height: 100%; background: var(--bg); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; animation: slidein .18s ease; }
@keyframes slidein { from { transform: translateX(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px;
  border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-family: var(--disp); font-weight: 400; font-size: 26px; margin: 0; }
.drawer-body { padding: 8px 22px 30px; overflow-y: auto; }
.set-group { padding: 16px 0; border-bottom: 1px solid var(--line); }
.set-group h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); margin: 0 0 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 14px; }
.field > span { color: var(--muted); }
.field input[type="text"] { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px; font-size: 15px; color: var(--ink); font-family: var(--sans); outline: none; }
.field input[type="text"]:focus { border-color: var(--accent); }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; font-size: 15px; cursor: pointer; }
.toggle input { width: 42px; height: 24px; appearance: none; background: var(--line); border-radius: 999px;
  position: relative; cursor: pointer; transition: background .15s; flex: 0 0 auto; }
.toggle input:checked { background: var(--accent); }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; transition: transform .15s; }
.toggle input:checked::after { transform: translateX(18px); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; align-self: flex-start; }
.seg button { background: var(--card); border: 0; padding: 8px 16px; font-size: 14px; cursor: pointer; color: var(--muted);
  font-family: var(--sans); }
.seg button.on { background: var(--accent); color: #fff; }
.swatches { display: flex; gap: 10px; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatches button.on { border-color: var(--ink); }
.hint { color: var(--faint); font-size: 13px; margin: 8px 0 0; }

@media (max-width: 720px) {
  .sidebar { width: 100%; }
  .app.in-thread .sidebar { display: none; }
  .app:not(.in-thread) .thread-pane { display: none; }
  .only-mobile { display: inline; }
  .msg { max-width: 84%; }
  .msg .acts { display: none; }
  .drawer { width: 100%; }
}
