/* Telegram (module relay): app skin. Rules moved verbatim from styles.css (C1); the variables are the app identity, posture themes re-map the shell only. */
/* P9 scheme tokens: light = the colours these rules always used, dark = Telegram in its own night theme. */
:root {
  --telegram-blue-line: #cfe3ff;
  --telegram-blue-text: #4d6a7d;
  --telegram-blue-text-2: #3a6d99;
  --telegram-blue-text-3: #0f6cbd;
  --telegram-blue-text-4: #229ed9;
  --telegram-line: #e9ecef;
  --telegram-line-2: #e3e7ec;
  --telegram-line-3: #e1dfdd;
  --telegram-surface: #fff;
  --telegram-surface-2: rgba(255, 255, 255, 0.7);
  --telegram-surface-3: #f1f3f5;
  --telegram-surface-4: #f3f2f1;
  --telegram-surface-5: #eaf3ff;
  --telegram-surface-6: #e8f1fb;
  --telegram-surface-7: #e9e7e4;
  --telegram-text: #707579;
}
[data-scheme="dark"] {
  --telegram-blue-line: #414c5b;
  --telegram-blue-text: #97b6cb;
  --telegram-blue-text-2: #81b0db;
  --telegram-blue-text-3: #67affd;
  --telegram-blue-text-4: #6ab3f3;
  --telegram-line: #444648;
  --telegram-line-2: #45484d;
  --telegram-line-3: #4d4b4a;
  --telegram-surface: #212121;
  --telegram-surface-2: rgba(33, 33, 33, 0.7);
  --telegram-surface-3: #2b2d2e;
  --telegram-surface-4: #2e2d2c;
  --telegram-surface-5: #292e35;
  --telegram-surface-6: #2b3036;
  --telegram-surface-7: #393835;
  --telegram-text: #aaaaaa;
}
.module-body[data-module="relay"] {
  --app-font: "Roboto", "Open Sans", Arial, sans-serif;
  --app-accent: #229ed9;
  --app-bg: #e1dfdd;
  --app-surface: #ffffff;
  --app-radius: 8px;
}

/* ---------- Relay ---------- */
.relay-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 540px; background: var(--telegram-surface); border: 1px solid var(--telegram-line-3); border-radius: 8px; overflow: hidden; }
.relay-channels { background: var(--telegram-surface-4); border-right: 1px solid var(--telegram-line-3); padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.relay-search { display: flex; align-items: center; gap: 7px; padding: 7px 9px; background: var(--telegram-surface); border: 1px solid var(--telegram-line-3); border-radius: 6px; margin-bottom: 8px; color: var(--muted); }
.relay-search input { flex: 1; border: none; outline: none; background: none; font-size: 12px; }
.relay-section-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--faint); padding: 4px 6px; }
.relay-channel { display: flex; align-items: center; gap: 8px; padding: 8px 9px; text-align: left; border-radius: 7px; border: 1px solid transparent; }
.relay-channel:hover { background: var(--telegram-surface-7); }
.relay-channel.is-active { background: var(--telegram-surface); border-color: var(--telegram-line-3); box-shadow: inset 3px 0 0 #229ed9; }
.relay-hash { color: var(--telegram-blue-text-3); font-weight: 700; }
.relay-channel-copy { display: flex; flex-direction: column; line-height: 1.2; flex: 1; min-width: 0; }
.relay-channel-copy strong { font-size: 12px; }
.relay-channel-copy small { font-size: 10px; color: var(--muted); }
.relay-unread { background: #229ed9; color: #fff; font-size: 9.5px; font-weight: 700; border-radius: 999px; padding: 1px 5px; }
.relay-channels-note { margin-top: auto; padding: 10px 6px 2px; border-top: 1px solid var(--telegram-line-3); }
.relay-channels-note p:last-child { font-size: 10.5px; color: var(--faint); margin-top: 4px; }
.relay-chat { display: flex; flex-direction: column; min-width: 0; }
.relay-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--telegram-line-3); }
.relay-head h2 { font-size: 16px; }
.relay-head small { font-size: 11px; color: var(--muted); }
.relay-messages { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; background: var(--telegram-surface); }
.relay-msg { display: flex; gap: 9px; max-width: 78%; }
.relay-msg.self { margin-left: auto; flex-direction: row-reverse; }
.relay-bubble { padding: 9px 11px; background: var(--telegram-surface-3); border: 1px solid var(--telegram-line); border-radius: 10px; }
.relay-msg.self .relay-bubble { background: var(--telegram-surface-5); border-color: var(--telegram-blue-line); }
.relay-meta { display: flex; align-items: baseline; gap: 7px; margin-bottom: 2px; }
.relay-meta strong { font-size: 11.5px; }
.relay-meta span { font-family: var(--font-mono); font-size: 9px; color: var(--faint); }
.relay-bubble p { font-size: 12.5px; }
.relay-compose { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--telegram-line-3); background: var(--telegram-surface); }
.relay-compose input { flex: 1; padding: 9px 11px; font-size: 12.5px; background: var(--telegram-surface); border: 1px solid var(--telegram-line-3); border-radius: 6px; outline: none; }
.relay-compose input:focus { border-color: #229ed9; }
.relay-compose .btn-accent { background: #229ed9; }
@media (max-width: 1180px) {
  .broadcast-layout { grid-template-columns: 1fr; }
  .tv-side { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .relay-layout { grid-template-columns: 1fr; }
  .relay-channels { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--telegram-line-3); }
  .relay-channels-note, .relay-section-label { display: none; }
  .relay-search { min-width: 180px; margin: 0; }
  .relay-channel { min-width: 150px; }
}
@media (max-width: 720px) {
  .tv-side { grid-template-columns: 1fr; }
  .relay-msg { max-width: 92%; }
}

.persona-signout {
  margin-top: 4px;
  padding-top: 9px !important;
  border-top: 1px solid var(--border);
  border-radius: 0 !important;
  color: var(--muted) !important;
}
.persona-signout span { display: flex; flex-direction: column; line-height: 1.2; }
.persona-signout strong { font-size: 12px; }
.persona-signout small { font-size: 10.5px; color: var(--faint); }

/* ---------- Telegram additions ---------- */
.relay-layout.with-info { grid-template-columns: 210px minmax(0, 1fr) 250px; }
.relay-head-actions { display: flex; align-items: center; gap: 4px; }
.relay-msg-search { display: flex; align-items: center; gap: 5px; padding: 5px 8px; background: var(--telegram-surface-4); border: 1px solid var(--telegram-line-3); border-radius: 6px; color: var(--muted); }
.relay-msg-search input { width: 120px; border: none; outline: none; background: none; font-size: 11.5px; }
.relay-pinned { display: flex; align-items: center; gap: 7px; padding: 8px 16px; font-size: 11.5px; color: var(--telegram-blue-text-3); background: var(--telegram-surface-5); border-bottom: 1px solid var(--telegram-blue-line); }
.relay-pinned span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relay-msg { position: relative; }
.relay-msg-actions { position: absolute; top: -12px; right: 6px; z-index: 2; display: flex; gap: 2px; padding: 1px; background: var(--telegram-surface); border: 1px solid var(--telegram-line-2); border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.08); opacity: 0; transition: opacity .12s; }
.relay-msg:hover .relay-msg-actions, .relay-msg:focus-within .relay-msg-actions { opacity: 1; }
.relay-msg-actions button { width: 24px; height: 22px; display: grid; place-items: center; color: var(--faint); border-radius: 4px; }
.relay-msg-actions button:hover { background: var(--telegram-surface); color: var(--text); }
.relay-quote { margin-bottom: 5px; padding: 5px 8px; border-left: 2px solid #229ed9; background: rgba(34,158,217,0.08); border-radius: 4px; }
.relay-quote strong { display: block; font-size: 10.5px; color: var(--telegram-blue-text-3); }
.relay-quote span { font-size: 10.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.relay-compose { flex-direction: column; align-items: stretch; gap: 6px; }
.relay-compose-row { display: flex; align-items: center; gap: 8px; }
.relay-compose-row input { flex: 1; }
.relay-reply-bar { display: flex; align-items: center; gap: 7px; padding: 5px 8px; font-size: 11px; background: var(--telegram-surface-5); border-left: 2px solid #229ed9; border-radius: 4px; }
.relay-reply-bar span { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relay-info { border-left: 1px solid var(--telegram-line-3); background: var(--telegram-surface); padding: 14px; overflow-y: auto; }
.relay-info-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.relay-info-head h3 { font-size: 14px; }
.relay-info-avatar { width: 58px; height: 58px; margin: 0 auto 8px; display: grid; place-items: center; border-radius: 50%; background: var(--telegram-surface-5); color: var(--telegram-blue-text-3); font-size: 24px; font-weight: 700; }
.relay-info h4 { text-align: center; font-size: 15px; }
.relay-info > p { text-align: center; font-size: 11.5px; color: var(--muted); margin: 4px 0 14px; }
.relay-info-btn { width: 100%; margin-top: 12px; }
.relay-info-note { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--telegram-line-3); }
.relay-info-note p:last-child { font-size: 10.5px; color: var(--faint); margin-top: 4px; }
@media (max-width: 1180px) {
  .relay-layout.with-info { grid-template-columns: 200px minmax(0, 1fr); }
  .relay-info { grid-column: 1 / -1; border-left: none; border-top: 1px solid var(--telegram-line-3); }
}
@media (max-width: 900px) {
  .relay-layout.with-info { grid-template-columns: 1fr; }
}

/* --- C8 Telegram: chat list (pinned, dm, time), day separators, forwards, edits, read ticks, typing, forward picker, members */
.relay-channel time { font-size: 10px; color: var(--faint); align-self: flex-start; margin-top: 2px; }
.relay-channel .avatar-img { width: 30px; height: 30px; border-radius: 50%; flex: none; }
.relay-channel-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
.relay-channel-copy strong svg { vertical-align: -1px; color: var(--faint); }
.relay-day { display: flex; justify-content: center; margin: 10px 0 4px; }
.relay-day span { font-size: 10.5px; color: var(--telegram-blue-text); background: var(--telegram-surface-2); border-radius: 999px; padding: 2px 9px; }
.relay-fwd { font-size: 10.5px; color: var(--muted); margin-bottom: 3px; }
.relay-fwd strong { color: var(--telegram-blue-text-3); font-weight: 600; }
.relay-quote { display: block; width: 100%; text-align: left; }
.relay-quote:hover span { text-decoration: underline; }
.relay-file { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--telegram-blue-text-3); }
.relay-edited { font-size: 10px; color: var(--faint); }
.relay-foot { display: flex; justify-content: flex-end; min-height: 10px; margin-top: 2px; }
.relay-ticks { display: inline-flex; color: var(--faint); }
.relay-ticks.is-read { color: var(--telegram-blue-text-4); }
.relay-ticks svg + svg { margin-left: -5px; }
.relay-typing { color: var(--telegram-blue-text-4); font-style: italic; }
.relay-forward-panel { border-top: 1px solid var(--telegram-line-3); background: var(--telegram-surface-4); padding: 8px 12px; max-height: 180px; overflow-y: auto; }
.relay-forward-panel header { display: flex; justify-content: space-between; align-items: center; font-size: 12px; margin-bottom: 4px; }
.relay-forward-panel .relay-channel { width: 100%; background: var(--telegram-surface); margin-bottom: 3px; }
.relay-members { list-style: none; padding: 0; margin: 4px 0 12px; display: grid; gap: 6px; font-size: 12px; }
.relay-members li { display: flex; align-items: center; gap: 8px; }
.relay-members-label { margin-top: 10px; }
@media (max-width: 480px) {
  .relay-channel time { display: none; }
  .relay-msg-actions { opacity: 1; }
}

/* --- T1 fidelity: channel posts with views, reactions and a clock time in the bubble corner -------------------- */
.relay-face { flex: none; align-self: flex-end; }
.relay-foot { display: flex; justify-content: flex-end; align-items: center; gap: 6px; font-size: 12px; color: #8a9aa9; }
.relay-msg.self .relay-foot { color: #4fae4e; }
.relay-views { display: inline-flex; align-items: center; gap: 3px; }
.relay-time { font-size: 12px; color: inherit; }
.relay-reacts { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 2px; }
.relay-react { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--telegram-surface-6); color: var(--telegram-blue-text-2); font-size: 13px; font-weight: 600; }
.relay-kind { vertical-align: -2px; margin-right: 4px; color: var(--telegram-text); }
.relay-channel time { font-size: 12px; color: var(--telegram-text); }

/* P9 dark scheme: the module tokens above, Telegram in its own night theme */
[data-scheme="dark"] .module-body[data-module="relay"] {
  --app-accent: #6ab3f3;
  --app-bg: #0e1621;
  --app-surface: #17212b;
}

/* P9 contrast: the accent button and unread badge (white on #229ed9 was 3:1); dark keeps Telegram's night blue with dark ink */
:root { --telegram-button: #1a7ab0; --telegram-on-button: #fff; }
[data-scheme="dark"] { --telegram-button: #6ab3f3; --telegram-on-button: #0e1621; }
.relay-compose .btn-accent, .module-body[data-module="relay"] .btn-accent { background: var(--telegram-button); color: var(--telegram-on-button); }
.relay-unread { background: var(--telegram-button); color: var(--telegram-on-button); }
