:root {
  --bg: #e6ebee;
  --feed-bg: #c9d8e2;
  --side-bg: #ffffff;
  --border: rgba(0, 0, 0, .09);
  --text: #0f1419;
  --muted: #707579;
  --bubble: #ffffff;
  --accent: #3390ec;
  --accent-text: #ffffff;
  --chat-on: #3390ec;
  --chat-on-text: #ffffff;
  --hover: rgba(0, 0, 0, .05);
  --code-bg: rgba(0, 0, 0, .06);
  --live: #1f9d55;
  --warn: #d97706;
  --shadow: 0 1px 1px rgba(0, 0, 0, .12);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1621;
    --feed-bg: #0e1621;
    --side-bg: #17212b;
    --border: rgba(255, 255, 255, .07);
    --text: #e9eef2;
    --muted: #7d8b99;
    --bubble: #182533;
    --accent: #5eb5f7;
    --accent-text: #0e1621;
    --chat-on: #2b5278;
    --chat-on-text: #ffffff;
    --hover: rgba(255, 255, 255, .05);
    --code-bg: rgba(255, 255, 255, .08);
    --live: #4cc477;
    --warn: #f0b354;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
button { font: inherit; color: inherit; }

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

/* Lateral */
.side {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--side-bg);
  border-right: 1px solid var(--border);
}
.side-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; }
.side-top .status { flex: 1; }
.logout { margin: 0; }
.logout button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.logout button:hover { background: var(--hover); }

.status { font-size: 12px; color: var(--warn); white-space: nowrap; }
.status.live { color: var(--live); }

.chat-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.chat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.chat:hover { background: var(--hover); }
.chat.on { background: var(--chat-on); color: var(--chat-on-text); }
.chat.on .chat-preview { color: inherit; opacity: .8; }
.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 17px;
  color: #fff;
}
.chat-body { flex: 1; min-width: 0; }
.chat-head { display: flex; align-items: baseline; gap: 6px; }
.chat-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { font-size: 12px; color: var(--muted); }
.chat.on .chat-time { color: inherit; opacity: .8; }
.chat-foot { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.chat-preview {
  flex: 1;
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 11px;
  min-width: 22px;
  padding: 1px 7px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

/* Feed */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--feed-bg);
}
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--side-bg);
  border-bottom: 1px solid var(--border);
}
.top-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back {
  display: none;
  background: none;
  border: 0;
  padding: 0 6px 0 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 15px;
}
.feed { flex: 1; display: flex; flex-direction: column; overflow-y: auto; padding: 10px 14px 14px; overscroll-behavior: contain; }
.more { margin-top: auto; text-align: center; font-size: 12px; color: var(--muted); padding: 6px 0 10px; min-height: 1em; }
.messages { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 760px; margin: 0 auto; }
.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.msg {
  align-self: flex-start;
  max-width: min(85%, 560px);
  background: var(--bubble);
  border-radius: 12px;
  padding: 6px 10px 5px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
  transition: background-color .6s;
}
.msg.flash { background: var(--chat-on); color: var(--chat-on-text); }
.who { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.text { white-space: pre-wrap; }
.text a { color: var(--accent); }
.text code, .text pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--code-bg);
  border-radius: 4px;
}
.text code { padding: 0 3px; }
.text pre { display: block; margin: 4px 0; padding: 6px 8px; white-space: pre-wrap; }
.spoiler { background: var(--muted); color: transparent; border-radius: 3px; cursor: pointer; }
.spoiler * { color: transparent !important; }
.spoiler.revealed { background: none; color: inherit; cursor: auto; }
.spoiler.revealed * { color: inherit !important; }
.meta {
  float: right;
  margin: 6px 0 -3px 12px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.meta .edited { margin-right: 4px; font-style: italic; }
.reply {
  border-left: 3px solid var(--accent);
  background: var(--hover);
  border-radius: 4px;
  padding: 2px 8px;
  margin: 2px 0 4px;
  font-size: 13px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-name { color: var(--accent); font-weight: 600; }
.photo {
  display: block;
  width: min(100%, 420px);
  height: auto;
  margin: 4px 0 2px;
  border-radius: 8px;
  background: var(--code-bg);
  cursor: zoom-in;
  object-fit: cover;
}
.marker { margin: 2px 0; }
.marker a { color: var(--accent); }

.new-btn {
  position: absolute;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
  cursor: pointer;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  cursor: zoom-out;
}
.overlay img { max-width: 100%; max-height: 100%; object-fit: contain; }

[hidden] { display: none !important; }

/* Celular */
@media (max-width: 700px) {
  .side { width: 100%; border-right: 0; }
  .main { display: none; }
  body.show-feed .side { display: none; }
  body.show-feed .main { display: flex; }
  .back { display: inline-block; }
  .feed { padding: 8px 8px 12px; }
  .msg { max-width: 92%; }
}
