:root {
  --brand: #e45735;
  --brand-contrast: #ffffff;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e5e7eb;
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 10px 30px rgba(0,0,0,0.10);
}

[data-theme="dark"] {
  --bg: #0b0f16;
  --surface: #0f1420;
  --surface-2: #0b111a;
  --text: #e5e7eb;
  --text-muted: #97a0ad;
  --border: #1f2a37;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial; background: var(--bg); color: var(--text); }
img, video { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; }
input, textarea, select { font: inherit; color: inherit; }

.container { max-width: 960px; margin: 0 auto; padding: var(--s-4); }

/* Topbar */
.topbar { position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm); z-index: 30; }
.topbar__inner { display: flex; align-items: center; gap: var(--s-3); height: var(--topbar-h, 60px); }
.brand { font-weight: 700; color: var(--text); }
.topbar__right { margin-left: auto; display: inline-flex; align-items: center; gap: var(--s-2); }

/* Dropdown menu */
.menu__btn { background: transparent; border: 1px solid var(--border); border-radius: var(--r-sm); padding: 8px 10px; cursor: pointer; color: var(--text); position: relative; transition: transform .12s ease; }
.menu__btn:hover { transform: translateY(-1px); }
.menu__badge { position: absolute; top: -6px; right: -6px; background: #ef4444 !important; color: #fff !important; border-radius: 999px; min-width: 18px; height: 18px; padding: 0 6px; display: none; font-size: 11px; line-height: 18px; box-shadow: var(--shadow-sm); }
.menu__badge.is-visible { display: inline-block; }
.menu__panel { position: absolute; right: var(--s-4); top: calc(var(--topbar-h, 60px) + 8px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-md); width: 220px; z-index: 40; opacity: 0; transform: translateY(-6px); pointer-events: none; transition: opacity .18s ease, transform .18s ease; }
.menu__panel.is-open { opacity: 1; transform: translateY(0); pointer-events: auto; }
.menu__list { list-style: none; margin: 0; padding: 6px; }
.menu__item { display: grid; grid-template-columns: 24px 1fr; gap: 10px; align-items: center; padding: 10px 12px; border-radius: var(--r-sm); color: var(--text); font-size: 14px; line-height: 1.2; width: 100%; text-align: left; background: transparent; border: 0; cursor: pointer; appearance: none; -webkit-appearance: none; position: relative; overflow: hidden; }
.menu__item:hover { background: var(--surface-2); }
.menu__item:focus { outline: 2px solid var(--border); outline-offset: 2px; }
.ico { width: 18px; height: 18px; display:inline-block; }

/* Buttons */
.btn { background: var(--brand); color: var(--brand-contrast); border: none; padding: 10px 14px; border-radius: var(--r-md); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.btn { transition: transform .08s ease, box-shadow .12s ease, filter .12s ease; }
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); filter: brightness(.96); }
.btn--text { background: transparent; color: var(--text); padding: 8px 10px; }
.btn--outline { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.badge { background: var(--surface-2); border: 1px solid var(--border); padding: 2px 8px; border-radius: 999px; font-size: 12px; color: var(--text-muted); }
.badge--red { background: #ef4444 !important; color: #fff !important; border: none; min-width: 18px; height: 18px; padding: 0 6px; line-height: 18px; text-align: center; font-weight: 600; }
.badge--red { animation: pulse 1.6s ease-in-out infinite; }

/* Forms */
.form label { display: grid; gap: 6px; margin-bottom: var(--s-3); font-size: 14px; }
.form input, .form textarea, .form select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); color: var(--text); }
.form input::placeholder, .form textarea::placeholder { color: var(--text-muted); opacity: 1; }
.inline { display: inline-flex; gap: var(--s-2); align-items: center; }
.alert { padding: 10px 12px; border-radius: var(--r-sm); margin: var(--s-2) 0; }
.alert--error { background: #fee2e2; color: #991b1b; }
.alert--success { background: #dcfce7; color: #166534; }
.muted { color: var(--text-muted); font-size: 0.92em; }

/* Cards & lists */
.card { background: var(--surface); padding: var(--s-5); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); margin: var(--s-4) 0; }
.card { transition: box-shadow .18s ease, transform .12s ease; }
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card--center { max-width: 420px; margin: var(--s-8) auto; }
.list { display: grid; gap: var(--s-2); }
.list-item { background: var(--surface); border: 1px solid var(--border); padding: var(--s-3); border-radius: var(--r-md); display: grid; grid-template-columns: 1fr auto; gap: var(--s-2); align-items: center; }
.list-item { transition: background .12s ease, transform .08s ease; }
.list-item:hover { background: var(--surface-2); transform: translateY(-1px); }
.list-item img.avatar-32 { width: 28px; height: 28px; }

/* Toasts */
#toast-root { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--surface); border: 1px solid var(--border); padding: 10px 12px; border-radius: var(--r-md); box-shadow: var(--shadow-md); animation: fadeInUp .25s ease both; }
.toast--out { animation: fadeOutDown .2s ease both; }

/* Chat */
.chat { height: calc(100vh - var(--topbar-h, 60px) - 24px); display: grid; grid-template-rows: auto 1fr auto; gap: var(--s-2); }
.chat__header { display: flex; align-items: center; gap: var(--s-2); }
.chat__title { margin: 0; }
.chat__messages { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); min-height: 0; scroll-behavior: smooth; }
.bubble { max-width: 80%; padding: 8px 10px; border-radius: 16px; margin: 2px 0; box-shadow: var(--shadow-sm); word-wrap: break-word; background: var(--surface); color: var(--text); }
.bubble--me { background: var(--me-color, var(--brand)); color: #fff; margin-left: auto; border-bottom-right-radius: 8px; }
.bubble--other { background: var(--surface); color: var(--text); margin-right: auto; border-bottom-left-radius: 8px; }
.msg-meta { font-size: 11px; color: var(--text-muted); margin: 0 8px; }
.group { display: grid; gap: 2px; }
.chat__messages .group { animation: fadeInUp .2s ease both; }
.chat__meta { display:flex; align-items:center; justify-content: space-between; font-size: 12px; color: var(--text-muted); padding: 0 4px; }
.chat__input { display: grid; grid-template-columns: 1fr auto; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 4px; align-items: center; }
.chat__input textarea { resize: none; max-height: 24vh; border: none; background: transparent; outline: none; padding: 8px 10px; color: var(--text); caret-color: var(--text); }
.chat__input textarea::placeholder { color: var(--text-muted); opacity: 1; }
.chat__input .btn { height: 36px; padding: 8px 12px; }

/* Background ASCII cat */
.bgcat-hidden #bg-cat { display: none; }
#bg-cat { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#bg-cat .ascii { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); white-space: pre; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New"; line-height: 1.1; opacity: 0.08; color: var(--text); filter: grayscale(100%); }
[data-theme="dark"] #bg-cat .ascii { color: var(--text); opacity: 0.08; }

/* Modal animations (if modal markup exists) */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display:none; align-items: center; justify-content: center; z-index: 200; }
.modal--open { display: flex; animation: fadeIn .2s ease both; }
.modal__dialog { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--shadow-md); max-width: 480px; width: calc(100% - 32px); animation: scaleIn .18s ease both; }

/* Compact mode */
body.compact .chat__messages { padding: 4px; }
body.compact .bubble { padding: 6px 8px; border-radius: 14px; font-size: 0.95em; }
body.compact .chat__input { padding: 2px; gap: 6px; }
body.compact .chat__input .btn { height: 32px; padding: 6px 10px; }
body.compact .chat__input textarea { padding: 6px 8px; }

@media (max-width: 600px) {
  .container { padding: var(--s-3); }
  .list-item { padding: var(--s-2); }
  .chat { height: calc(100vh - var(--topbar-h, 56px) - 12px); gap: var(--s-1); }
  .chat__messages { padding: 4px; }
  .chat__input { gap: 6px; }
  .chat__input .btn { height: 32px; padding: 6px 10px; }
  .menu__panel { left: var(--s-3); right: var(--s-3); width: auto; }
}

/* Online dot subtle ping */
.dot--online { position: relative; }
.dot--online::after { content: ''; position: absolute; inset: -4px; border: 2px solid rgba(34,197,94,0.45); border-radius: 50%; animation: ping 1.6s cubic-bezier(0,0,.2,1) infinite; }

/* Ripple effect */
.ripple { position: absolute; top: 0; left: 0; width: 0; height: 0; border-radius: 50%; transform: translate(-50%, -50%) scale(0); background: currentColor; opacity: 0.18; pointer-events: none; animation: ripple .45s ease-out forwards; }

/* Animations */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }
@keyframes ping { 0% { transform: scale(.6); opacity: .6; } 80%,100% { transform: scale(1.6); opacity: 0; } }
@keyframes ripple { to { transform: translate(-50%, -50%) scale(1); opacity: 0; } }
@keyframes fadeOutDown { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

