/* =========================================
   Telegram (dark theme) — channels mirror the
   Map Alerts demo's three sources.
   ========================================= */
:root {
    /* Telegram dark theme — colors copied from the desktop/mobile app palette */
    --tg-bg: #17212B;             /* main background (navy) */
    --tg-bg-elevated: #182533;    /* slight elevation for bars */
    --tg-bg-card: #182533;        /* incoming message bubble */
    --tg-bg-row-active: #2B5278;  /* selected chat row */
    --tg-text: #ffffff;
    --tg-text-secondary: #708499; /* muted gray-blue */
    --tg-text-tertiary: #5C7080;
    --tg-accent: #50A8E0;         /* link / accent blue */
    --tg-accent-soft: rgba(80, 168, 224, 0.18);
    --tg-divider: rgba(255,255,255,0.06);
    --tg-icon-btn-bg: rgba(255,255,255,0.07);
    --tg-pinned-bg: #1B2734;
    --tg-mute-bar-bg: rgba(23, 33, 43, 0.85);

    --phone-width: 390px;
    --phone-height: 844px;
    --phone-radius: 54px;
    --status-h: 54px;
    --tabbar-h: 84px;

    --sf: -apple-system, BlinkMacSystemFont, "SF Pro Text",
          "SF Pro Display", system-ui, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--sf);
    color: var(--tg-text);
    background: #14161a;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

[hidden] { display: none !important; }

/* ===== Phone frame (matches the Map Alerts demo) ===== */
.stage {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(80% 60% at 50% 0%,  rgba(80, 168, 224, 0.10), transparent 60%),
        radial-gradient(80% 60% at 50% 100%, rgba(34, 60, 93, 0.20), transparent 60%),
        #0d1218;
}
.phone {
    position: relative;
    width: var(--phone-width);
    height: var(--phone-height);
    border-radius: var(--phone-radius);
    background: #0b0c0e;
    padding: 14px;
    box-shadow:
        0 0 0 2px #2a2c30,
        0 30px 80px rgba(0,0,0,0.55),
        0 12px 28px rgba(0,0,0,0.4);
}
.phone::before, .phone::after { content: ""; position: absolute; background: #2a2c30; }
.phone::before { left: -3px; top: 130px; width: 3px; height: 64px; border-radius: 2px; }
.phone::after  { right: -3px; top: 200px; width: 3px; height: 88px; border-radius: 2px; }

.phone-screen {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--tg-bg);
    border-radius: calc(var(--phone-radius) - 12px);
    overflow: hidden;
}

/* ===== Status bar (light variant for dark theme) ===== */
.status-bar {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: var(--status-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 0;
    z-index: 70;
    color: #fff;
    pointer-events: none;
}
.status-time {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.2px;
    width: 90px;
    text-align: left;
    margin-left: 6px;
}
.status-island {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #000;
    padding: 6px 14px;
    border-radius: 22px;
    margin-top: 4px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.6px;
    color: #fff;
}
.island-icon { width: 14px; height: 14px; flex-shrink: 0; }
.status-icons {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 90px;
    justify-content: flex-end;
}
.icon-signal, .icon-wifi { width: 18px; height: 12px; fill: #fff; }
.icon-wifi { width: 17px; }
.icon-battery {
    display: flex;
    align-items: center;
    position: relative;
    margin-left: 1px;
}
.icon-battery .battery-body {
    width: 28px; height: 13px;
    border: 1.2px solid rgba(255,255,255,0.4);
    border-radius: 3px;
    padding: 1px;
    position: relative;
}
.icon-battery .battery-fill {
    height: 100%;
    width: 39%;
    background: #FFA500;       /* yellow when low */
    border-radius: 1.5px;
}
.icon-battery .battery-cap {
    width: 2px; height: 4px;
    background: rgba(255,255,255,0.4);
    border-radius: 0 1px 1px 0;
    margin-left: 1px;
}
.icon-battery .battery-pct {
    position: absolute;
    inset: 0 4px 0 4px;
    font-size: 9px;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ===== Screens ===== */
.screen-content {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.screen-content.active { display: flex; }

/* Hide tab bar when channel screen is active */
.tg-screen-channel.active ~ .tg-tabbar { display: none; }

/* ===== Chats screen ===== */
.tg-top-bar {
    position: relative;
    margin-top: var(--status-h);
    height: 44px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    flex-shrink: 0;
}
.tg-edit {
    background: transparent;
    border: none;
    color: var(--tg-accent);
    font-size: 17px;
    cursor: pointer;
    padding: 4px 0;
    font-family: inherit;
}
.tg-top-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 17px;
    font-weight: 600;
    margin: 0;
    color: #fff;
}
.tg-top-actions {
    margin-left: auto;
    display: flex;
    gap: 10px;
}
.tg-icon-btn {
    background: var(--tg-icon-btn-bg);
    border: none;
    width: 34px; height: 34px;
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}
.tg-icon-btn svg { width: 18px; height: 18px; }

/* Chat list */
.tg-chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0 calc(var(--tabbar-h) + 16px);
}
.tg-chat-row {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 8px 16px 8px 12px;
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background 0.12s ease;
}
.tg-chat-row:active { background: rgba(255,255,255,0.05); }
.tg-chat-avatar {
    width: 56px; height: 56px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-right: 12px;
    overflow: hidden;
    background: var(--tg-bg-elevated);
}
.tg-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.tg-chat-content {
    flex: 1;
    min-width: 0;
}
.tg-chat-row-top {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 2px;
}
.tg-chat-row-name {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.tg-chat-row-mute {
    width: 14px; height: 14px;
    color: var(--tg-text-tertiary);
    flex-shrink: 0;
    margin-left: 2px;
}
.tg-chat-row-time {
    margin-left: auto;
    font-size: 14px;
    color: var(--tg-text-secondary);
    flex-shrink: 0;
    padding-left: 8px;
}
.tg-chat-row-bottom {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.tg-chat-row-preview {
    flex: 1;
    font-size: 15px;
    color: var(--tg-text-secondary);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    min-width: 0;
}
.tg-chat-row-preview .tg-preview-emoji { margin-right: 2px; }
.tg-chat-row-unread {
    flex-shrink: 0;
    background: rgba(255,255,255,0.2);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 7px;
    margin-top: 2px;
}

/* ===== Channel detail screen ===== */
.tg-chan-header {
    margin-top: var(--status-h);
    padding: 6px 16px 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 0.5px solid var(--tg-divider);
    flex-shrink: 0;
}
.tg-back-btn {
    background: var(--tg-icon-btn-bg);
    border: none;
    width: 32px; height: 32px;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
}
.tg-back-btn svg { width: 14px; height: 14px; }
.tg-chan-info {
    flex: 1;
    text-align: center;
    min-width: 0;
}
.tg-chan-name {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.15;
}
.tg-chan-subs {
    font-size: 12px;
    color: var(--tg-text-secondary);
    line-height: 1.15;
    margin-top: 2px;
}
.tg-chan-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}
.tg-chan-avatar img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}

.tg-pinned {
    background: var(--tg-pinned-bg);
    padding: 8px 14px;
    border-bottom: 0.5px solid var(--tg-divider);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.tg-pinned-bar {
    width: 3px;
    height: 30px;
    background: var(--tg-accent);
    border-radius: 1.5px;
    flex-shrink: 0;
}
.tg-pinned-content { flex: 1; min-width: 0; }
.tg-pinned-title {
    color: var(--tg-accent);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
}
.tg-pinned-text {
    color: #fff;
    font-size: 14px;
    line-height: 1.3;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tg-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
}

.tg-msg {
    background: var(--tg-bg-card);
    border-radius: 14px;
    padding: 10px 12px 8px;
    max-width: 92%;
    align-self: flex-start;
    color: #fff;
    font-size: 15px;
    line-height: 1.35;
    position: relative;
}
.tg-msg-channel-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.tg-msg-channel-line .tg-channel-avatar-small {
    width: 18px; height: 18px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}
.tg-msg-channel-line .tg-channel-avatar-small img {
    width: 100%; height: 100%;
    object-fit: cover;
}
.tg-msg-channel-line .tg-msg-channel-name {
    color: var(--tg-accent);
    font-weight: 600;
    font-size: 14px;
}
.tg-msg-title {
    font-weight: 600;
    color: var(--tg-accent);
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
}
.tg-msg-text {
    white-space: pre-wrap;
    word-break: break-word;
}
.tg-msg-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 8px;
}
.tg-reaction {
    background: var(--tg-accent-soft);
    color: var(--tg-accent);
    padding: 2px 7px 2px 5px;
    border-radius: 11px;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    line-height: 1.4;
}
.tg-reaction .tg-reaction-emoji { font-size: 13px; }

.tg-msg-footer {
    margin-top: 6px;
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    color: var(--tg-text-secondary);
    font-size: 11px;
    align-items: center;
    line-height: 1;
}
.tg-msg-views {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.tg-msg-views svg { width: 14px; height: 12px; flex-shrink: 0; }

.tg-msg-comments {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 0.5px solid rgba(255,255,255,0.10);
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--tg-accent);
    font-size: 14px;
    cursor: pointer;
}
.tg-msg-comments .tg-msg-comments-count { font-weight: 600; }
.tg-msg-comments .tg-msg-comments-arrow {
    margin-left: auto;
    color: var(--tg-text-secondary);
    font-size: 18px;
    line-height: 1;
}
.tg-msg-comments .tg-msg-commenters {
    display: flex;
    margin-right: 4px;
}
.tg-msg-commenters .commenter {
    width: 16px; height: 16px;
    border-radius: 50%;
    border: 1.5px solid var(--tg-bg-card);
    margin-left: -6px;
    background-size: cover;
    background-position: center;
}
.tg-msg-commenters .commenter:first-child { margin-left: 0; }

/* Action bar (Unmute) */
.tg-action-bar {
    padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 28px);
    background: var(--tg-mute-bar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--tg-divider);
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}
.tg-mute-btn {
    color: var(--tg-accent);
    background: transparent;
    border: none;
    font-size: 17px;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 32px;
    font-family: inherit;
}

/* ===== Tab bar (rounded pill at the bottom) ===== */
.tg-tabbar {
    position: absolute;
    bottom: 18px;
    left: 12px;
    right: 12px;
    height: 56px;
    background: rgba(24, 37, 51, 0.92);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    border: 0.5px solid rgba(255,255,255,0.05);
    border-radius: 28px;
    display: flex;
    z-index: 60;
    padding: 4px 6px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.40);
}
.tg-tab {
    flex: 1;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    color: rgba(255,255,255,0.55);
    padding: 0;
    font-family: inherit;
    position: relative;
    z-index: 1;
}
.tg-tab svg { width: 22px; height: 22px; }
.tg-tab-label {
    font-size: 9.5px;
    font-weight: 500;
    line-height: 1;
    margin-top: 2px;
}
.tg-tab-search { flex: 0 0 48px; }
.tg-tab-search .tg-tab-label { display: none; }

.tg-tab-active { color: var(--tg-accent); }
.tg-tab-active .tg-tab-bg {
    position: absolute;
    inset: 4px 4px;
    background: var(--tg-accent-soft);
    border-radius: 22px;
    z-index: -1;
}

/* ===== Mobile (no phone frame) ===== */
@media (max-width: 480px) {
    body { background: var(--tg-bg); }
    .stage { padding: 0; min-height: 100vh; }
    .phone {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        padding: 0;
        box-shadow: none;
    }
    .phone::before, .phone::after { display: none; }
    .phone-screen { border-radius: 0; }
}

/* ===== Embed mode (used when ?embed=1 — landing page iframe) ===== */
html.embed, html.embed body, body.embed {
    background: transparent !important;
}
html.embed .stage, body.embed .stage {
    background: transparent !important;
    padding: 0 !important;
    min-height: auto;
}
/* Iframes can be ≤480px wide, which triggers the mobile media query above and
   strips the phone chrome. In embed mode we always want the native phone frame. */
html.embed .phone, body.embed .phone {
    width: 390px !important;
    height: 844px !important;
    border-radius: 54px !important;
    padding: 14px !important;
    box-shadow: none !important;
}
html.embed .phone::before, body.embed .phone::before,
html.embed .phone::after,  body.embed .phone::after { display: block !important; }
html.embed .phone-screen, body.embed .phone-screen {
    border-radius: 42px !important;
    /* Same Chrome backdrop-filter clipping bug as in style.css. */
    clip-path: inset(0 round 42px);
    isolation: isolate;
}
html.embed .phone, body.embed .phone {
    clip-path: inset(0 round 54px);
    isolation: isolate;
}
