:root {
  --background: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #182136;
  --muted: #68758b;
  --subtle: #97a3b5;
  --line: #e1e7f0;
  --line-strong: #d3dce8;
  --primary: #3478ed;
  --primary-dark: #2663cf;
  --primary-soft: #eaf2ff;
  --success: #15976a;
  --warning: #d68516;
  --danger: #d8495e;
  --shadow: 0 1px 3px rgba(28, 43, 70, .04), 0 16px 42px rgba(41, 62, 96, .08);
  --header-height: 72px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--background);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% -8%, rgba(64, 126, 244, .11), transparent 31rem),
    var(--background);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }
svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
button:focus-visible, input:focus-visible, .feed-scroller:focus-visible { outline: 3px solid rgba(52,120,237,.23); outline-offset: 2px; }

.eyebrow { margin: 0 0 5px; color: var(--subtle); font-size: .67rem; font-weight: 780; letter-spacing: .12em; text-transform: uppercase; }
.logo { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 17px; color: #fff; background: linear-gradient(145deg, #5792ff, #2f6fe6); box-shadow: 0 13px 30px rgba(49,111,229,.28); }
.logo svg { width: 30px; height: 30px; }
.logo-small { width: 41px; height: 41px; border-radius: 13px; box-shadow: 0 8px 20px rgba(49,111,229,.2); }
.logo-small svg { width: 24px; height: 24px; }

.login-view { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 22px; }
.login-card { width: min(100%, 470px); padding: 34px; border: 1px solid rgba(218,226,237,.9); border-radius: 26px; background: rgba(255,255,255,.94); box-shadow: 0 28px 80px rgba(38,57,91,.16); backdrop-filter: blur(18px); }
.login-card .logo { margin-bottom: 26px; }
.login-card h1 { margin: 0; font-size: clamp(1.8rem, 6vw, 2.25rem); line-height: 1.08; letter-spacing: -.045em; }
.login-copy { margin: 12px 0 25px; color: var(--muted); font-size: .94rem; line-height: 1.65; }
.login-card label { display: block; margin-bottom: 8px; color: #354056; font-size: .8rem; font-weight: 720; }
.token-row { display: grid; grid-template-columns: minmax(0,1fr) 48px; gap: 8px; }
.token-row input { width: 100%; height: 49px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 13px; color: var(--text); background: #fbfcfe; }
.token-row input:focus { border-color: var(--primary); outline: 0; box-shadow: 0 0 0 4px rgba(52,120,237,.09); background: #fff; }
.icon-button, .toolbar-button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); color: #526078; background: #fff; cursor: pointer; }
.icon-button { width: 48px; height: 49px; border-radius: 13px; }
.icon-button svg { width: 20px; height: 20px; }
.form-error { margin: 8px 2px 0; color: var(--danger); font-size: .78rem; font-weight: 650; }
.primary-button, .secondary-button { min-height: 45px; padding: 0 17px; border-radius: 12px; font-weight: 750; cursor: pointer; }
.primary-button { border: 1px solid var(--primary); color: #fff; background: linear-gradient(145deg, #4487f4, #2d6ddd); box-shadow: 0 8px 20px rgba(45,109,221,.2); }
.primary-button:hover { background: linear-gradient(145deg, #3d7de6, #275fc5); }
.primary-button:disabled, .secondary-button:disabled { cursor: wait; opacity: .6; }
.login-card > form > .primary-button { width: 100%; margin-top: 13px; }
.secondary-button { border: 1px solid var(--line-strong); color: #536077; background: #fff; box-shadow: none; }
.secondary-button:hover, .icon-button:hover, .toolbar-button:hover { border-color: #bdcadb; color: var(--primary-dark); background: #f4f8ff; }
.login-note { margin-top: 22px; padding: 14px 15px; border: 1px solid var(--line); border-radius: 13px; color: var(--muted); background: var(--surface-soft); font-size: .78rem; line-height: 1.55; }

.app { height: 100vh; height: 100dvh; display: grid; grid-template-rows: var(--header-height) minmax(0,1fr); }
.topbar { z-index: 20; border-bottom: 1px solid rgba(216,225,237,.9); background: rgba(255,255,255,.9); backdrop-filter: blur(18px); }
.topbar-inner { width: min(100%, 1280px); height: 100%; display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: 0 auto; padding: 0 24px; }
.brand { display: flex; align-items: center; min-width: 0; gap: 11px; }
.brand > div:last-child { min-width: 0; display: grid; gap: 2px; }
.brand strong { overflow: hidden; font-size: .96rem; text-overflow: ellipsis; white-space: nowrap; }
.brand span { color: var(--muted); font-size: .7rem; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.status-pill { height: 38px; display: inline-flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--surface-soft); font-size: .75rem; font-weight: 720; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); }
.status-pill[data-state="live"] .status-dot { background: var(--success); box-shadow: 0 0 0 4px rgba(21,151,106,.12); }
.status-pill[data-state="offline"] .status-dot { background: var(--danger); }
.toolbar-button { min-width: 42px; height: 42px; gap: 7px; padding: 0 12px; border-radius: 12px; font-size: .74rem; font-weight: 720; }
.toolbar-button svg { width: 18px; height: 18px; }
.toolbar-button b { min-width: 20px; height: 20px; display: inline-grid; place-items: center; padding: 0 5px; border-radius: 999px; color: #fff; background: var(--primary); font-size: .65rem; }
.toolbar-icon { width: 42px; padding: 0; }

.page { width: min(100%, 1280px); min-height: 0; display: grid; grid-template-rows: auto minmax(0,1fr); gap: 16px; margin: 0 auto; padding: 18px 24px 22px; }
.filter-card, .feed-card { border: 1px solid rgba(216,224,235,.9); border-radius: 20px; background: rgba(255,255,255,.9); box-shadow: var(--shadow); }
.filter-card { padding: 17px 20px 14px; }
.filter-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.filter-heading h1 { margin: 0; font-size: 1rem; letter-spacing: -.02em; }
.text-button { border: 0; padding: 4px 0; color: var(--primary); background: transparent; cursor: pointer; font-size: .75rem; font-weight: 740; }
.text-button:hover { text-decoration: underline; }
.filter-form { display: grid; grid-template-columns: minmax(0,1fr) auto auto; gap: 8px; margin-top: 12px; }
.filter-input { position: relative; }
.filter-input svg { position: absolute; top: 50%; left: 13px; width: 18px; height: 18px; color: #8f9bae; transform: translateY(-50%); pointer-events: none; }
.filter-input input { width: 100%; height: 45px; padding: 0 13px 0 40px; border: 1px solid var(--line-strong); border-radius: 12px; color: var(--text); background: #fff; font: .78rem ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.filter-input input:focus { border-color: var(--primary); outline: 0; box-shadow: 0 0 0 4px rgba(52,120,237,.08); }
.filter-submit, .filter-form .secondary-button { min-height: 45px; }
.filter-status { min-height: 17px; margin: 7px 2px 0; color: var(--success); font-size: .72rem; }
.filter-status.error { color: var(--danger); }
.filter-help { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; padding: 11px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); }
.filter-help code { padding: 5px 7px; border-radius: 7px; color: #2f5c9e; background: var(--primary-soft); font-size: .69rem; }
.filter-help p { flex-basis: 100%; margin: 2px 0 0; color: var(--muted); font-size: .72rem; line-height: 1.5; }

.feed-card { min-height: 0; display: grid; grid-template-rows: auto minmax(0,1fr); overflow: hidden; }
.feed-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 21px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.94); }
.feed-title-row { display: flex; align-items: center; gap: 9px; }
.feed-title-row h1 { margin: 0; font-size: 1.48rem; letter-spacing: -.035em; }
.feed-title-row span { padding: 5px 8px; border-radius: 999px; color: #225fc2; background: var(--primary-soft); font-size: .68rem; font-weight: 760; }
#syncText { color: var(--subtle); font-size: .72rem; }
.feed-scroller { min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; background: linear-gradient(180deg, #f8fafc, #f5f8fc); }
.feed-inner { width: min(100%, 900px); min-height: 100%; margin: 0 auto; padding: 20px 24px 36px; }
.older-button { display: block; margin: 0 auto 16px; padding: 9px 14px; border: 1px solid var(--line-strong); border-radius: 999px; color: #506078; background: #fff; cursor: pointer; font-size: .72rem; font-weight: 720; }
.older-button:hover { color: var(--primary); border-color: #b9c9df; }
.archive-divider { display: flex; align-items: center; gap: 10px; margin: 2px 0 16px; color: var(--subtle); font-size: .66rem; font-weight: 740; letter-spacing: .05em; text-transform: uppercase; }
.archive-divider::before, .archive-divider::after { height: 1px; flex: 1; content: ""; background: var(--line); }
.message-list { display: grid; gap: 12px; }
.message-card { position: relative; padding: 17px 18px 14px; border: 1px solid var(--line); border-left: 3px solid transparent; border-radius: 17px; background: rgba(255,255,255,.98); box-shadow: 0 1px 2px rgba(28,43,70,.025); transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease; }
.message-card:hover { border-color: #d2dbe7; box-shadow: 0 10px 28px rgba(36,54,85,.08); transform: translateY(-1px); }
.message-card.unread { border-left-color: var(--primary); background: linear-gradient(90deg, #f2f7ff, #fff 28%); }
.message-card.arriving { animation: card-in .36s ease both; }
.message-card.focused { animation: focus-ring 1.2s ease; }
.message-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.message-heading { min-width: 0; display: flex; gap: 11px; }
.avatar { width: 39px; height: 39px; display: grid; flex: 0 0 auto; place-items: center; border-radius: 12px; color: var(--primary-dark); background: var(--primary-soft); font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.message-heading-text { min-width: 0; }
.message-heading h2 { margin: 0; color: #1d2739; font-size: .93rem; line-height: 1.35; overflow-wrap: anywhere; }
.message-subline { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 3px; color: var(--muted); font-size: .71rem; }
.source-chip { padding: 2px 6px; border-radius: 999px; color: #496c9f; background: #eff4fb; font-size: .63rem; font-weight: 720; }
.message-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 3px; }
.message-time { color: var(--subtle); font-size: .67rem; white-space: nowrap; }
.copy-button { width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 8px; color: var(--subtle); background: transparent; cursor: pointer; }
.copy-button:hover { color: var(--primary); background: var(--primary-soft); }
.copy-button svg { width: 15px; height: 15px; }
.message-body { margin: 13px 0 15px 50px; color: #344057; font-size: .91rem; line-height: 1.62; overflow-wrap: anywhere; }
.message-body > :first-child { margin-top: 0; }
.message-body > :last-child { margin-bottom: 0; }
.message-body p { margin: .55em 0; }
.message-body h1, .message-body h2, .message-body h3, .message-body h4, .message-body h5, .message-body h6 { margin: .95em 0 .4em; color: #202a3d; line-height: 1.25; letter-spacing: -.015em; }
.message-body h1 { font-size: 1.34rem; }.message-body h2 { font-size: 1.18rem; }.message-body h3 { font-size: 1.06rem; }.message-body h4, .message-body h5, .message-body h6 { font-size: .98rem; }
.message-body ul, .message-body ol { margin: .55em 0; padding-left: 1.45rem; }
.message-body li + li { margin-top: .22em; }
.message-body blockquote { margin: .7em 0; padding: .2em 0 .2em 12px; border-left: 3px solid #b9cff3; color: #56627a; }
.message-body code { padding: .14em .35em; border: 1px solid #e0e5ed; border-radius: 6px; color: #ac3156; background: #f7f8fa; font: .87em ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.message-body pre { max-width: 100%; margin: .75em 0; padding: 13px 14px; overflow: auto; border-radius: 11px; color: #e4ebf5; background: #202938; }
.message-body pre code { padding: 0; border: 0; color: inherit; background: transparent; white-space: pre; }
.message-body a { color: #2767cc; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.message-body hr { height: 1px; margin: 1em 0; border: 0; background: var(--line); }
.message-body table { width: 100%; display: block; overflow-x: auto; border-collapse: collapse; margin: .75em 0; font-size: .84rem; }
.message-body th, .message-body td { padding: 7px 9px; border: 1px solid var(--line); text-align: left; white-space: nowrap; }
.message-body th { background: #f4f7fa; }
.message-body .task { list-style: none; margin-left: -1.15rem; }
.message-body .task input { margin-right: 7px; pointer-events: none; }
.message-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-left: 50px; color: var(--subtle); font-size: .65rem; }
.message-meta { display: flex; flex-wrap: wrap; gap: 7px; }
.delivery { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.delivery::before { width: 6px; height: 6px; content: ""; border-radius: 50%; background: var(--warning); }
.delivery.sent::before { background: var(--success); }.delivery.failed::before { background: var(--danger); }
.unread-divider { display: flex; align-items: center; gap: 10px; color: var(--primary); font-size: .67rem; font-weight: 760; text-transform: uppercase; letter-spacing: .05em; }
.unread-divider::before, .unread-divider::after { height: 1px; flex: 1; content: ""; background: #bad0f5; }
.empty-state { min-height: 360px; display: grid; align-content: center; justify-items: center; text-align: center; }
.empty-icon { width: 66px; height: 66px; display: grid; place-items: center; margin-bottom: 15px; border-radius: 21px; color: var(--primary); background: var(--primary-soft); }
.empty-icon svg { width: 34px; height: 34px; }
.empty-state h2 { margin: 0 0 7px; font-size: 1rem; }.empty-state p { max-width: 340px; margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.55; }
.jump-button { position: fixed; z-index: 30; right: 28px; bottom: 25px; height: 43px; display: inline-flex; align-items: center; gap: 6px; padding: 0 16px; border: 0; border-radius: 999px; color: #fff; background: linear-gradient(145deg, #4487f4, #2d6ddd); box-shadow: 0 13px 30px rgba(45,109,221,.3); cursor: pointer; font-size: .74rem; }
.toast { position: fixed; z-index: 50; right: 20px; bottom: 20px; max-width: min(360px, calc(100vw - 40px)); padding: 12px 15px; border-radius: 12px; color: #fff; background: rgba(28,39,58,.95); box-shadow: 0 14px 36px rgba(20,32,52,.24); font-size: .77rem; font-weight: 650; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.noscript { position: fixed; z-index: 100; inset: 0 0 auto; padding: 12px; color: #fff; text-align: center; background: #a82f43; }
@keyframes card-in { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: translateY(0); } }
@keyframes focus-ring { 0%,100% { box-shadow: none; } 35% { box-shadow: 0 0 0 4px rgba(52,120,237,.18); } }

@media (max-width: 720px) {
  :root { --header-height: 64px; }
  .topbar-inner { padding: 0 11px 0 14px; }
  .brand span, .toolbar-button > span, .status-pill > span:last-child { display: none; }
  .status-pill { width: 39px; justify-content: center; padding: 0; }
  .toolbar-button { width: 40px; min-width: 40px; padding: 0; }
  .toolbar-button b { position: absolute; margin: -28px 0 0 25px; }
  .page { gap: 0; padding: 0; }
  .filter-card, .feed-card { border-right: 0; border-left: 0; border-radius: 0; box-shadow: none; }
  .filter-card { padding: 12px 13px 11px; }
  .filter-heading h1 { font-size: .92rem; }
  .filter-form { grid-template-columns: minmax(0,1fr) auto; }
  .filter-form .secondary-button { grid-column: 1 / -1; min-height: 36px; }
  .feed-header { padding: 13px 15px; }
  #syncText { display: none; }
  .feed-inner { padding: 15px 11px max(28px, env(safe-area-inset-bottom)); }
  .message-card { padding: 15px 13px 13px; }
  .message-body, .message-footer { margin-left: 0; }
  .jump-button { right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); }
}

@media (max-width: 450px) {
  .login-view { padding: 13px; align-items: end; }
  .login-card { padding: 27px 21px calc(23px + env(safe-area-inset-bottom)); border-radius: 24px; }
  .filter-form { grid-template-columns: 1fr; }
  .filter-form .secondary-button { grid-column: auto; }
  .message-time { max-width: 82px; overflow: hidden; text-overflow: ellipsis; }
  .delivery span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
