:root {
    --cc-bg: #030712;
    --cc-panel: #0f172a;
    --cc-border: rgba(56, 189, 248, 0.22);
    --cc-accent: #38bdf8;
    --cc-muted: #94a3b8;
    --cc-text: #e2e8f0;
    --cc-caution: #fbbf24;
    --cc-mono: "JetBrains Mono", ui-monospace, monospace;
    --cc-sans: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--cc-sans);
    background: var(--cc-bg);
    color: var(--cc-text);
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(56, 189, 248, 0.12), transparent),
        linear-gradient(180deg, #030712 0%, #0a1628 100%);
}

.cc-app {
    max-width: 920px;
    margin: 0 auto;
    padding: 1.25rem 1rem 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.cc-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-wrap: wrap;
}

.cc-header__title h1 {
    margin: 0.35rem 0 0;
    font-size: 1.35rem;
    letter-spacing: 0.08em;
}

.cc-tag {
    font-family: var(--cc-mono);
    font-size: 0.58rem;
    letter-spacing: 0.2em;
    color: var(--cc-muted);
}

.cc-you {
    margin: 0.35rem 0 0;
    font-size: 0.68rem;
    color: var(--cc-accent);
}

.cc-header__actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.cc-nav-link {
    color: var(--cc-muted);
    text-decoration: none;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.cc-nav-link:hover {
    color: var(--cc-accent);
}

.cc-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.72);
    overflow: hidden;
}

.cc-panel__head {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0.65rem 0.75rem 0;
}

.community-tabs {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.community-tabs__spacer {
    width: 1.25rem;
    flex-shrink: 0;
}

.community-tabs button.community-sos-tab {
    margin-right: 0;
    padding: 0.42rem 0.85rem;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    border-radius: 4px;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%);
    border: 1px solid rgba(252, 165, 165, 0.85);
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.35);
}

.community-tabs button.community-sos-tab:hover {
    filter: brightness(1.08);
    box-shadow: 0 3px 14px rgba(239, 68, 68, 0.45);
}

.community-tabs button:not(.community-sos-tab) {
    font-family: inherit;
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 0.35rem 0.65rem;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(2, 6, 23, 0.5);
    color: var(--cc-muted);
    cursor: pointer;
}

.community-tabs button.active {
    color: var(--cc-accent);
    border-color: rgba(56, 189, 248, 0.35);
    background: rgba(56, 189, 248, 0.08);
}

.community-msg__event {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.35rem;
}

.community-msg__event-badge {
    font-family: var(--cc-mono);
    font-size: 0.58rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.2rem 0.45rem;
    border-radius: 999px;
    border: 1px solid rgba(56, 189, 248, 0.35);
    color: var(--cc-accent);
    background: rgba(56, 189, 248, 0.08);
}

.community-msg__event-badge--critical {
    border-color: rgba(248, 113, 113, 0.55);
    color: #fecaca;
    background: rgba(239, 68, 68, 0.15);
}

.community-msg__event-meta {
    font-family: var(--cc-mono);
    font-size: 0.58rem;
    color: var(--cc-muted);
}

.sos-modal {
    position: fixed;
    inset: 0;
    z-index: 1300;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(2, 6, 23, 0.82);
    backdrop-filter: blur(4px);
}

.sos-modal[hidden] {
    display: none;
}

.sos-modal__dialog {
    position: relative;
    width: min(520px, 100%);
    max-height: min(92vh, 760px);
    overflow: auto;
    border-radius: 12px;
    border: 1px solid rgba(248, 113, 113, 0.35);
    background: linear-gradient(180deg, #1f0a0a 0%, #0f172a 100%);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.sos-modal__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1rem 0.5rem;
    border-bottom: 1px solid rgba(248, 113, 113, 0.18);
}

.sos-modal__title {
    margin: 0;
    font-size: 1.1rem;
    color: #fecaca;
}

.sos-modal__sub {
    margin: 0.25rem 0 0;
    font-size: 0.62rem;
    color: var(--cc-muted);
}

.sos-modal__close {
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: transparent;
    color: var(--cc-muted);
    border-radius: 6px;
    padding: 0.35rem 0.55rem;
    cursor: pointer;
}

.sos-modal__form {
    padding: 0.85rem 1rem 1rem;
}

.sos-fieldset {
    margin: 0 0 0.85rem;
    border: 0;
    padding: 0;
}

.sos-fieldset legend {
    font-size: 0.78rem;
    font-weight: 600;
    margin-bottom: 0.45rem;
}

.sos-options {
    display: grid;
    gap: 0.35rem;
}

.sos-options--inline {
    grid-template-columns: 1fr 1fr;
}

.sos-option {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.55rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(2, 6, 23, 0.45);
    font-size: 0.78rem;
    cursor: pointer;
}

.sos-option:has(input:checked) {
    border-color: rgba(248, 113, 113, 0.55);
    background: rgba(239, 68, 68, 0.12);
}

.sos-option--full {
    display: block;
    width: 100%;
    cursor: text;
}

.sos-option--full input[type="tel"] {
    width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
}

.sos-context {
    margin: 0.75rem 0;
    padding: 0.65rem 0.75rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(2, 6, 23, 0.35);
}

.sos-context__label {
    margin: 0 0 0.45rem;
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--cc-muted);
}

.sos-context__grid {
    margin: 0;
    display: grid;
    grid-template-columns: minmax(6rem, 38%) 1fr;
    gap: 0.25rem 0.65rem;
    font-size: 0.68rem;
}

.sos-context__grid dt {
    color: var(--cc-muted);
}

.sos-context__grid dd {
    margin: 0;
    color: var(--cc-text);
    word-break: break-word;
}

.sos-modal__msg {
    margin: 0 0 0.65rem;
    font-size: 0.68rem;
    color: #fecaca;
}

.sos-modal__msg--ok {
    color: #86efac;
}

.sos-guidance {
    margin: 0 0 0.75rem;
    padding: 0.65rem 0.7rem;
    border-radius: 8px;
    border: 1px solid rgba(253, 230, 138, 0.35);
    background: rgba(69, 26, 3, 0.35);
    font-size: 0.78rem;
    line-height: 1.45;
    color: #fde68a;
}

.sos-actions {
    display: grid;
    gap: 0.55rem;
}

.sos-btn {
    display: block;
    width: 100%;
    text-align: center;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-decoration: none;
    cursor: pointer;
    border: none;
}

.sos-btn--call {
    background: #fff;
    color: #991b1b;
}

.sos-btn--ghost {
    background: transparent;
    color: var(--cc-muted);
    border: 1px solid rgba(148, 163, 184, 0.35);
}

/* Inline panel — does not cover the SOS form so alert + call stay available */
.sos-call-confirm {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    margin: 0.15rem 0 0;
    padding: 1rem 1rem 1.1rem;
    border-top: 1px solid rgba(248, 113, 113, 0.35);
    background: transparent;
}

.sos-call-confirm[hidden] {
    display: none;
}

.sos-call-confirm__tip {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.4;
    color: #fde68a;
}

.sos-call-confirm__title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #fecaca;
}

.sos-call-confirm__body {
    margin: 0;
    font-size: 0.84rem;
    line-height: 1.45;
    color: #e2e8f0;
}

.sos-call-confirm__number {
    margin: 0.15rem 0;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #fff;
}

.sos-call-confirm__gps-hint {
    margin: 0.35rem 0 0;
    font-size: 0.78rem;
    line-height: 1.4;
    color: #fde68a;
}

.sos-call-confirm__gps {
    margin: 0;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid rgba(253, 230, 138, 0.35);
    font-size: 0.9rem;
    font-weight: 700;
    color: #fef3c7;
    word-break: break-word;
}

.sos-call-confirm__actions {
    display: grid;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.sos-btn--alert {
    background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%);
    color: #fff;
    border: 1px solid rgba(254, 202, 202, 0.45);
}

.sos-hub-disclaimer {
    margin: 0.35rem 0 0.15rem;
    padding: 0 0.25rem;
    font-size: 0.68rem;
    font-weight: 400;
    line-height: 1.4;
    letter-spacing: 0.01em;
    text-align: center;
    text-transform: none;
    color: var(--cc-muted);
}

.sos-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.community-intro {
    margin: 0;
    padding: 0.45rem 0.75rem 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--cc-muted);
}

.community-hint {
    margin: 0.35rem 0.75rem 0;
    padding: 0.35rem 0.5rem;
    font-size: 0.68rem;
    color: var(--cc-caution);
    border-left: 2px solid var(--cc-caution);
}

.community-global,
.community-dm-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.community-global {
    padding-bottom: 0.25rem;
}

.community-messages {
    flex: 1;
    min-height: min(52vh, 480px);
    max-height: min(62vh, 560px);
    overflow-y: auto;
    margin: 0.65rem 0.75rem 0;
    padding: 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    background: rgba(2, 6, 23, 0.45);
}

.community-msg {
    margin-bottom: 0.65rem;
}

.community-msg--self .community-msg__name {
    color: var(--cc-accent);
}

.community-msg__head {
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    margin-bottom: 0.12rem;
}

.community-msg__name {
    font-size: 0.72rem;
    font-weight: 700;
    color: #94a3b8;
}

.community-msg__time {
    font-size: 0.58rem;
    color: var(--cc-muted);
}

.community-msg__body {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--cc-text);
    white-space: pre-wrap;
    word-break: break-word;
}

.community-compose {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.45rem;
    padding: 0.65rem 0.75rem 0.75rem;
}

.community-loc-btn {
    font-family: inherit;
    font-size: 1rem;
    line-height: 1;
    padding: 0.45rem 0.55rem;
    border-radius: 6px;
    border: 1px solid rgba(56, 189, 248, 0.28);
    background: rgba(56, 189, 248, 0.08);
    cursor: pointer;
}

.community-loc-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.community-loc-btn.is-active {
    border-color: rgba(56, 189, 248, 0.55);
    background: rgba(56, 189, 248, 0.18);
}

.community-compose input {
    font-family: inherit;
    font-size: 0.82rem;
    padding: 0.55rem 0.65rem;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(2, 6, 23, 0.65);
    color: var(--cc-text);
}

.community-compose input:focus {
    outline: none;
    border-color: rgba(56, 189, 248, 0.45);
}

.community-compose button {
    font-family: inherit;
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.55rem 0.85rem;
    border-radius: 6px;
    border: 1px solid rgba(56, 189, 248, 0.35);
    background: rgba(56, 189, 248, 0.12);
    color: var(--cc-accent);
    cursor: pointer;
}

.community-compose button:disabled,
.community-compose input:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.community-dm {
    display: grid;
    grid-template-columns: minmax(140px, 200px) 1fr;
    gap: 0;
    min-height: min(58vh, 520px);
    flex: 1;
}

.community-dm-sidebar {
    padding: 0.5rem 0.5rem 0.5rem 0.75rem;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(2, 6, 23, 0.25);
}

.community-dm-label {
    margin: 0 0 0.35rem;
    font-size: 0.58rem;
    letter-spacing: 0.12em;
    color: var(--cc-muted);
}

.community-dm-threads {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-height: min(52vh, 480px);
    overflow-y: auto;
}

.community-thread {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    width: 100%;
    text-align: left;
    padding: 0.4rem 0.45rem;
    border-radius: 4px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--cc-text);
    cursor: pointer;
    font-family: inherit;
}

.community-thread.is-active,
.community-thread:hover {
    border-color: rgba(56, 189, 248, 0.25);
    background: rgba(56, 189, 248, 0.06);
}

.community-thread__head {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
}

.community-thread__envelope {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 999px;
    border: 1px solid rgba(56, 189, 248, 0.5);
    background: rgba(56, 189, 248, 0.14);
    color: #38bdf8;
    font-size: 0.72rem;
    line-height: 1;
    text-decoration: none;
    flex-shrink: 0;
}

.community-thread__envelope:hover {
    background: rgba(56, 189, 248, 0.28);
}

.community-thread__name {
    font-size: 0.72rem;
    font-weight: 700;
}

.community-thread__preview {
    font-size: 0.62rem;
    color: var(--cc-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.community-dm-to {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.45rem 0.55rem;
    align-items: start;
    padding: 0.5rem 0.75rem 0;
}

.community-dm-to label {
    font-size: 0.62rem;
    color: var(--cc-muted);
    padding-top: 0.45rem;
}

.community-dm-recipients {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.community-dm-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
}

.community-dm-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.22rem 0.45rem;
    border-radius: 999px;
    border: 1px solid rgba(56, 189, 248, 0.35);
    background: rgba(56, 189, 248, 0.1);
    color: var(--cc-text);
    font-size: 0.68rem;
}

.community-dm-chip button {
    border: none;
    background: transparent;
    color: var(--cc-muted);
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    padding: 0;
}

.community-dm-recipients input {
    flex: 1 1 8rem;
    min-width: 6rem;
    font-family: inherit;
    font-size: 0.78rem;
    padding: 0.4rem 0.55rem;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(2, 6, 23, 0.65);
    color: var(--cc-text);
}

.community-dm-recipients > button {
    font-family: inherit;
    font-size: 0.62rem;
    padding: 0.4rem 0.55rem;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(2, 6, 23, 0.5);
    color: var(--cc-accent);
    cursor: pointer;
    flex-shrink: 0;
}

.community-dm-hint {
    grid-column: 2;
    margin: 0;
    font-size: 0.58rem;
    color: var(--cc-muted);
    line-height: 1.4;
}

.community-dm-members {
    margin: 0;
    padding: 0.35rem 0.75rem 0;
    font-size: 0.62rem;
    color: var(--cc-muted);
}

.community-thread__badge {
    display: inline-block;
    margin-right: 0.25rem;
    font-size: 0.55rem;
    letter-spacing: 0.08em;
    color: var(--cc-accent);
    opacity: 0.85;
}

.cc-footer {
    margin-top: 1rem;
    font-size: 0.62rem;
    color: var(--cc-muted);
    letter-spacing: 0.08em;
}

@media (max-width: 720px) {
    .community-dm {
        grid-template-columns: 1fr;
    }

    .community-dm-sidebar {
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }

    .community-dm-threads {
        max-height: 120px;
    }
}
