/* TodoWay - app do participante.
 *
 * Linguagem: minimalismo utilitario, monocromatico quente. A cor e escassa e
 * so carrega significado: vermelho = SOS/acao sem volta, verde = conectado,
 * ambar = reconectando, azul = aviso informativo. Todo o resto e preto, branco
 * e cinzas quentes.
 *
 * Usado quase sempre no celular, no meio de um evento: alvos de toque grandes,
 * menu na base da tela (alcance do polegar) e o SOS como o botao mais forte.
 *
 * Fontes do sistema de proposito (SF no iPhone, Segoe no Windows): nao custam
 * download e a CSP (font-src 'self') nao precisa liberar terceiros. Os titulos
 * usam a serifa do sistema (Iowan/Palatino/Georgia) para o tom editorial.
 */

:root {
    color-scheme: light;

    --canvas: #f7f6f3;
    --surface: #ffffff;
    --surface-2: #fbfbfa;
    --surface-3: #f1f0ec;
    --ink: #111111;
    --ink-2: #2f3437;
    --muted: #787774;
    --line: #eaeaea;
    --line-strong: #dcdbd7;

    --primary: #111111;
    --primary-hover: #333333;

    /* Pasteis para estados; texto escuro do mesmo tom. */
    --red-bg: #fdebec;
    --red-ink: #9f2f2d;
    --blue-bg: #e1f3fe;
    --blue-ink: #1f6c9f;
    --green-bg: #edf3ec;
    --green-ink: #346538;
    --yellow-bg: #fbf3db;
    --yellow-ink: #956400;

    /* O unico vermelho cheio da tela: o SOS. */
    --sos: #b3261e;
    --sos-hover: #8f1d17;

    --sans: "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    --mono: "SF Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;

    --radius-lg: 12px;
    --radius: 8px;
    --radius-btn: 6px;

    --nav-h: 64px;
    --ease: cubic-bezier(0.16, 1, 0.3, 1);

    /* Escala de camadas: nada de z-index 9999. */
    --z-header: 20;
    --z-nav: 30;

    /* Curvas de nivel em SVG (data: e permitido pelo img-src da CSP). */
    --contours: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='560' height='560' viewBox='0 0 560 560'%3E%3Cg fill='none' stroke='%23111111' stroke-opacity='0.06' stroke-width='1'%3E%3Cpath d='M-20 120c80-40 150 30 240 0s140-90 240-50 120 60 120 60'/%3E%3Cpath d='M-20 170c90-40 160 40 250 6s150-92 250-40 100 54 100 54'/%3E%3Cpath d='M-20 230c100-34 160 46 260 14s140-80 240-36 100 50 100 50'/%3E%3Cpath d='M-20 300c90-30 170 50 270 20s130-70 230-30 100 44 100 44'/%3E%3Cpath d='M-20 380c100-26 170 52 270 24s130-64 230-26 100 40 100 40'/%3E%3Cpath d='M-20 450c90-22 170 50 270 26s140-58 240-22 90 34 90 34'/%3E%3Cpath d='M-20 520c100-20 170 46 270 24s130-52 230-18 100 30 100 30'/%3E%3Cellipse cx='400' cy='300' rx='46' ry='30'/%3E%3Cellipse cx='400' cy='300' rx='82' ry='56'/%3E%3C/g%3E%3C/svg%3E");
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    color: var(--ink-2);
    background: var(--canvas);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

h1,
h2 {
    color: var(--ink);
    font-family: var(--serif);
    font-weight: 600;
    text-wrap: balance;
}

button,
input,
textarea {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.hidden {
    display: none !important;
}

.skip-link {
    position: absolute;
    left: 12px;
    top: -60px;
    z-index: var(--z-nav);
    border-radius: var(--radius-btn);
    padding: 10px 14px;
    color: #ffffff;
    background: var(--primary);
    font-weight: 600;
}

.skip-link:focus {
    top: 12px;
}

/* --- Botoes ------------------------------------------------------------- */

button {
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: var(--radius-btn);
    padding: 10px 16px;
    color: #ffffff;
    background: var(--primary);
    cursor: pointer;
    font-weight: 500;
    line-height: 1.3;
    transition:
        background-color 200ms var(--ease),
        border-color 200ms var(--ease),
        color 200ms var(--ease),
        transform 120ms var(--ease);
    -webkit-tap-highlight-color: transparent;
}

button:hover {
    background: var(--primary-hover);
}

button:active {
    transform: scale(0.98);
}

button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    transform: none;
}

/* Requisicao em andamento (busy() no JS): o botao "respira" e nao aceita
   toque repetido -- um SOS em dobro ou a mesma mensagem enviada duas vezes. */
button[aria-busy="true"] {
    cursor: progress;
    pointer-events: none;
    animation: busy 1.1s ease-in-out infinite;
}

@keyframes busy {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* Retorno junto da acao. Vazio nao ocupa espaco. */
.inline-message {
    margin: 0;
    color: var(--red-ink);
    font-size: 14px;
    line-height: 1.45;
}

.inline-message:empty {
    display: none;
}

.inline-message[data-kind="success"] {
    color: var(--green-ink);
}

.inline-message[data-kind="info"] {
    color: var(--ink-2);
}

/* Acoes secundarias: contorno, para nao competir com a acao principal. */
.panel-actions button,
#watch-location-button,
#logout-button {
    border-color: var(--line-strong);
    color: var(--ink);
    background: var(--surface);
}

.panel-actions button:hover,
#watch-location-button:hover,
#logout-button:hover {
    border-color: #c9c8c3;
    background: var(--surface-3);
}

/* Acoes sem volta: pastel vermelho, nunca com a cara do botao principal. */
#close-group-button,
#delete-account-button {
    border-color: transparent;
    color: var(--red-ink);
    background: var(--red-bg);
}

#close-group-button:hover,
#delete-account-button:hover {
    border-color: transparent;
    color: #ffffff;
    background: var(--red-ink);
}

.link-button {
    min-height: 44px;
    margin-top: 6px;
    border: 0;
    padding: 0;
    color: var(--ink);
    background: none;
    font-weight: 500;
    text-decoration: underline;
    text-decoration-color: var(--line-strong);
    text-underline-offset: 4px;
}

.link-button:hover {
    color: var(--ink);
    background: none;
    text-decoration-color: var(--ink);
}

/* --- Formularios -------------------------------------------------------- */

label {
    display: grid;
    gap: 6px;
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 500;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-btn);
    padding: 11px 12px;
    color: var(--ink);
    background: var(--surface);
    font-size: 16px; /* 16px evita o zoom automatico do iOS ao focar */
    font-weight: 400;
    transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}

input {
    min-height: 46px;
}

textarea {
    resize: vertical;
}

input::placeholder,
textarea::placeholder {
    color: #a3a29e;
}

input:focus,
textarea:focus {
    border-color: var(--ink);
    outline: none;
    box-shadow: 0 0 0 3px rgba(17, 17, 17, 0.07);
}

.auth-form,
.join-form,
.message-form {
    display: grid;
    gap: 14px;
}

.message {
    min-height: 20px;
    margin: 8px 0 0;
    color: var(--red-ink);
    font-size: 14px;
}

.message[data-kind="info"] {
    color: var(--ink-2);
}

.message[data-kind="success"] {
    color: var(--green-ink);
}

/* --- Tela de acesso ----------------------------------------------------- */

/* Fundo claro com curvas de nivel em SVG. A foto do Unsplash que havia aqui
   era bloqueada pela CSP em producao e entregava o IP do visitante a um
   terceiro. */
.auth-view {
    display: grid;
    min-height: 100dvh;
    place-items: center;
    padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
    background: var(--contours) center / 560px 560px, var(--canvas);
}

.auth-panel {
    width: min(100%, 420px);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 32px 28px 24px;
    background: var(--surface);
    animation: rise 600ms var(--ease) both;
}

.brand-line {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}

.brand-line.compact {
    margin-bottom: 24px;
}

/* So o texto ao lado do selo: `.brand-line span` pegava tambem o proprio
   .brand-mark (entao um span com "TW"), tirava o grid e pintava o selo de cinza. */
.brand-line div > strong,
.brand-line div > span {
    display: block;
}

.brand-line strong {
    color: var(--ink);
    font-family: var(--serif);
    font-size: 21px;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
}

.brand-line div > span {
    color: var(--muted);
    font-size: 13px;
}

/* Icone do TodoWay (app/static/todoway-icon.svg); os cantos arredondados ja
   vem do proprio desenho. */
.brand-mark {
    display: block;
    flex: none;
    width: 40px;
    height: 40px;
}

/* Abas como controle segmentado: a aba ativa e a unica branca. */
.auth-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    margin-bottom: 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 3px;
    background: var(--canvas);
}

.auth-tabs button {
    min-height: 38px;
    border: 1px solid transparent;
    color: var(--muted);
    background: transparent;
}

.auth-tabs button:hover {
    color: var(--ink);
    background: transparent;
}

.auth-tabs button.active {
    border-color: var(--line);
    color: var(--ink);
    background: var(--surface);
}

.auth-form button[type="submit"] {
    margin-top: 4px;
}

/* --- Avatares e foto de perfil ------------------------------------------- */

/* Quadrado arredondado em vez de circulo: combina com os cantos do resto da
   interface. Sem foto, as iniciais. */
.avatar {
    display: inline-grid;
    flex: none;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 10px;
    object-fit: cover;
    background: var(--surface-3);
}

.avatar-initials {
    color: var(--ink-2);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.avatar-lg {
    width: 72px;
    height: 72px;
    border-radius: 16px;
    font-size: 24px;
}

.list-item.person {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
}

.list-item.person > div {
    display: grid;
    gap: 1px;
    min-width: 0;
}

/* Marcador do mapa: foto (ou iniciais) com borda branca. O Leaflet poe a
   classe map-person no proprio icone. */
.map-person {
    background: none;
    border: 0;
}

.avatar-map {
    width: 42px;
    height: 42px;
    border: 3px solid #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(17, 17, 17, 0.25);
    font-size: 13px;
}

.profile-photo {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin: 14px 20px 6px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 18px;
}

.profile-photo-body {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.profile-photo-body strong {
    color: var(--ink);
    font-weight: 600;
}

.profile-photo-hint {
    max-width: 44ch;
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.profile-photo-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.profile-photo-actions button {
    min-height: 38px;
    padding: 7px 12px;
    border-color: var(--line-strong);
    color: var(--ink);
    background: var(--surface);
    font-size: 14px;
}

.profile-photo-actions button:hover {
    background: var(--surface-3);
}

/* O <input type=file> fica escondido; o rotulo faz o papel de botao e continua
   alcancavel pelo teclado (o foco do input aparece no rotulo). */
.file-button {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    border-radius: var(--radius-btn);
    padding: 7px 14px;
    color: #ffffff;
    background: var(--primary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 200ms var(--ease), transform 120ms var(--ease);
}

.file-button:hover {
    background: var(--primary-hover);
}

.file-button:active {
    transform: scale(0.98);
}

.file-button:focus-within {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}

.file-button[aria-busy="true"] {
    cursor: progress;
    pointer-events: none;
    animation: busy 1.1s ease-in-out infinite;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

/* --- Pagina 404 ---------------------------------------------------------- */

.not-found h1 {
    margin: 4px 0 10px;
    font-size: 30px;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.not-found p {
    max-width: 44ch;
    margin: 0 0 22px;
}

.not-found .brand-mark {
    margin-bottom: 26px;
}

.not-found-code {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: 0.08em;
}

/* Link com cara de botao principal. */
.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border-radius: var(--radius-btn);
    padding: 10px 18px;
    color: #ffffff;
    background: var(--primary);
    font-weight: 500;
    transition: background-color 200ms var(--ease), transform 120ms var(--ease);
}

.button-link:hover {
    background: var(--primary-hover);
}

.button-link:active {
    transform: scale(0.98);
}

/* --- Area de trabalho --------------------------------------------------- */

.workspace-view {
    display: grid;
    grid-template-columns: 236px minmax(0, 1fr);
    min-height: 100dvh;
}

.workspace-nav {
    position: sticky;
    top: 0;
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    gap: 8px;
    height: 100dvh;
    border-right: 1px solid var(--line);
    padding: 24px 16px 20px;
    background: var(--surface-2);
}

.workspace-nav nav {
    display: grid;
    align-content: start;
    gap: 2px;
}

.workspace-nav a {
    position: relative;
    border-radius: var(--radius-btn);
    padding: 9px 12px;
    color: var(--muted);
    font-weight: 500;
    transition: background-color 200ms var(--ease), color 200ms var(--ease);
}

.workspace-nav a:hover {
    color: var(--ink);
    background: var(--surface-3);
}

.workspace-nav a.current {
    color: var(--ink);
    background: var(--surface-3);
    font-weight: 600;
}

.workspace-main {
    width: min(1180px, 100%);
    padding: 32px clamp(16px, 4vw, 48px) 64px;
}

.toolbar,
.map-section,
.panel,
.event-log {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
}

/* Entrada suave dos blocos quando a area de trabalho aparece. */
.toolbar,
.map-section,
.grid-two,
.event-log {
    animation: rise 600ms var(--ease) both;
}

.map-section {
    animation-delay: 80ms;
}

.grid-two:nth-of-type(2) {
    animation-delay: 160ms;
}

.grid-two:nth-of-type(3) {
    animation-delay: 240ms;
}

.grid-two:nth-of-type(4),
.event-log {
    animation-delay: 320ms;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.toolbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    padding: 20px;
}

.join-block {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.join-hint {
    max-width: 52ch;
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.join-form {
    grid-template-columns: minmax(200px, 320px) auto;
    align-items: end;
}

.join-form input {
    font-family: var(--mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

#map-message {
    margin: -4px 0 12px;
}

#message-feedback {
    margin-top: -4px;
}

/* Falha do SOS em destaque: fundo pastel vermelho, nao so texto. */
.sos-message {
    margin: 12px 20px 0;
    border-radius: var(--radius);
    padding: 10px 12px;
    background: var(--red-bg);
    font-weight: 500;
}

.sos-message[data-kind="success"] {
    background: var(--green-bg);
}

.panel-message {
    margin: 10px 20px 0;
}

.status-stack {
    display: grid;
    justify-items: end;
    gap: 6px;
    text-align: right;
}

.status-stack span {
    color: var(--ink);
    font-family: var(--serif);
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* Indicador de conexao: o tom vem de setConnectionStatus() no JS. */
/* Link para a pagina de videos (fora do menu de secoes da propria tela). */
.nav-extra {
    border-radius: var(--radius-btn);
    padding: 9px 12px;
    color: var(--muted);
    font-weight: 500;
    transition: background-color 200ms var(--ease), color 200ms var(--ease);
}

.nav-extra:hover {
    color: var(--ink);
    background: var(--surface-3);
}

.auth-footer {
    margin: 18px 0 0;
    border-top: 1px solid var(--line);
    padding-top: 10px;
}

.auth-footer .arrow-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    color: var(--ink-2);
    font-size: 14px;
    font-weight: 500;
}

.auth-footer .arrow-link::after {
    content: "\2192";
}

#connection-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border-radius: 9999px;
    padding: 3px 10px 3px 9px;
    color: var(--muted);
    background: var(--surface-3);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
}

#connection-status::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #a3a29e;
}

#connection-status[data-tone="live"] {
    color: var(--green-ink);
    background: var(--green-bg);
}

#connection-status[data-tone="live"]::before {
    background: var(--green-ink);
    animation: pulse 2s ease-in-out infinite;
}

#connection-status[data-tone="pending"] {
    color: var(--yellow-ink);
    background: var(--yellow-bg);
}

#connection-status[data-tone="pending"]::before {
    background: var(--yellow-ink);
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.3;
    }
}

/* Aviso de que a localizacao ainda nao esta autorizada. Fica no topo da area
   de trabalho porque, sem consentimento, o envio de posicao e recusado pela
   API -- o participante precisa entender isso antes de tentar. */
.consent-banner {
    display: grid;
    gap: 10px;
    margin-top: 16px;
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    color: var(--blue-ink);
    background: var(--blue-bg);
}

.consent-banner strong {
    font-weight: 600;
}

.consent-banner p {
    max-width: 68ch;
    margin: 0;
    color: var(--ink-2);
    font-size: 14px;
    white-space: pre-line;
}

.consent-banner button {
    justify-self: start;
}

.map-section {
    margin-top: 16px;
    padding: 20px;
}

.map-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}

.map-header h1 {
    margin: 0 0 2px;
    font-size: 30px;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.map-header p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.map-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.map-canvas {
    position: relative;
    height: 420px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background:
        linear-gradient(90deg, rgba(17, 17, 17, 0.04) 1px, transparent 1px) 0 0 / 40px 40px,
        linear-gradient(rgba(17, 17, 17, 0.04) 1px, transparent 1px) 0 0 / 40px 40px,
        var(--surface-3);
}

.grid-two {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.panel {
    padding-bottom: 6px;
}

.panel-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 12px;
    padding: 20px 20px 0;
}

.panel-heading h2,
.event-log h2 {
    margin: 0;
    font-size: 20px;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.panel-heading .panel-actions button {
    min-height: 36px;
    padding: 7px 12px;
    font-size: 14px;
}

/* Listas como linhas separadas por fio, sem caixa em volta de cada item. */
.list {
    display: grid;
    padding: 8px 20px 14px;
}

.list-item {
    display: grid;
    gap: 2px;
    border-bottom: 1px solid var(--line);
    padding: 12px 0;
}

.list-item:last-child {
    border-bottom: 0;
}

.list-item strong {
    color: var(--ink);
    font-size: 15px;
    font-weight: 500;
}

.list-item span {
    color: var(--muted);
    font-size: 14px;
}

.list-item small {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 12px;
}

.list-item.empty {
    place-items: center;
    margin-top: 6px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    padding: 18px 14px;
    text-align: center;
}

.privacy-state {
    margin: 12px 20px;
    color: var(--ink);
    font-size: 15px;
}

.privacy-note {
    max-width: 62ch;
    margin: 12px 20px 14px;
    color: var(--muted);
    font-size: 13px;
}

#privacidade .panel-actions,
.panel > .panel-actions {
    margin: 12px 20px 4px;
}

#access-log-list {
    margin-top: 4px;
}

.invite-box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 18px;
    margin: 16px 20px 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    background: var(--surface-2);
}

.invite-qr svg {
    display: block;
    width: 132px;
    height: 132px;
    border-radius: 4px;
    background: #ffffff;
}

.invite-meta {
    display: grid;
    flex: 1;
    gap: 8px;
    min-width: 200px;
}

.invite-meta input {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 13px;
}

.message-form {
    padding: 16px 20px 0;
}

.message-form button {
    justify-self: start;
}

/* O SOS e o botao mais importante da tela: largo, alto e o unico vermelho cheio. */
.sos-panel #sos-button {
    width: calc(100% - 40px);
    min-height: 56px;
    margin: 16px 20px 0;
    border-radius: var(--radius);
    background: var(--sos);
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.sos-panel #sos-button:hover {
    background: var(--sos-hover);
}

.event-log {
    margin-top: 16px;
    padding: 20px;
}

#event-log {
    display: grid;
    max-height: 200px;
    overflow: auto;
    margin-top: 8px;
}

.event-entry {
    display: grid;
    grid-template-columns: 100px minmax(0, 1fr);
    gap: 12px;
    border-bottom: 1px solid var(--line);
    padding: 9px 0;
    font-size: 14px;
}

.event-entry:last-child {
    border-bottom: 0;
}

.event-entry strong {
    color: var(--ink);
    font-weight: 500;
}

.event-entry time {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.9;
}

#last-location {
    font-variant-numeric: tabular-nums;
}

/* --- Tablet e celular --------------------------------------------------- */

@media (max-width: 960px) {
    .workspace-view {
        grid-template-columns: 1fr;
        /* Sem isto, com pouco conteudo o grid repartia a sobra de altura e o
           cabecalho esticava. */
        grid-template-rows: auto 1fr;
    }

    /* A lateral vira um cabecalho compacto; o menu desce para a base da tela. */
    .workspace-nav {
        position: sticky;
        top: 0;
        z-index: var(--z-header);
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: max(10px, env(safe-area-inset-top)) 16px 10px;
        /* Fundo solido, SEM backdrop-filter: filtro (como transform) faz deste
           cabecalho o bloco de referencia do menu `position: fixed` que mora
           dentro dele -- o menu de baixo ia parar no topo e cobria o cabecalho. */
        background: var(--surface-2);
    }

    .workspace-nav .brand-line {
        min-width: 0;
        margin: 0;
    }

    .workspace-nav .brand-line > div {
        min-width: 0;
    }

    .workspace-nav .brand-line strong {
        font-size: 18px;
    }

    .workspace-nav .brand-line div > span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .workspace-nav .brand-mark {
        width: 34px;
        height: 34px;
    }

    #logout-button {
        flex: none;
        min-height: 36px;
        padding: 7px 14px;
    }

    .nav-extra {
        margin-left: auto;
        padding: 8px 10px;
        font-size: 14px;
    }

    .workspace-nav nav {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: var(--z-nav);
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 0;
        height: calc(var(--nav-h) + env(safe-area-inset-bottom));
        border-top: 1px solid var(--line);
        padding: 6px 6px env(safe-area-inset-bottom);
        background: rgba(255, 255, 255, 0.94);
        backdrop-filter: blur(12px);
    }

    .workspace-nav a {
        display: grid;
        place-items: center;
        border-radius: 0;
        padding: 6px 2px;
        font-size: 12px;
        text-align: center;
    }

    .workspace-nav a:hover {
        background: transparent;
    }

    .workspace-nav a.current {
        background: transparent;
        box-shadow: inset 0 2px 0 var(--ink);
    }

    .workspace-main {
        width: 100%;
        padding-top: 20px;
        padding-bottom: calc(var(--nav-h) + 32px + env(safe-area-inset-bottom));
    }

    .grid-two {
        grid-template-columns: 1fr;
    }

    /* A ancora da secao nao pode ficar escondida sob o cabecalho fixo. */
    .map-section,
    .panel {
        scroll-margin-top: 76px;
    }
}

@media (max-width: 640px) {
    .workspace-main {
        padding-right: 12px;
        padding-left: 12px;
    }

    .toolbar,
    .map-header {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar {
        gap: 16px;
        padding: 16px;
    }

    .join-form {
        grid-template-columns: 1fr;
    }

    .status-stack {
        order: -1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        text-align: left;
    }

    .map-section {
        padding: 16px;
    }

    .map-header h1 {
        font-size: 26px;
    }

    .map-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .map-canvas {
        height: clamp(300px, 52dvh, 520px);
    }

    .panel-heading,
    .event-log {
        padding-right: 16px;
        padding-left: 16px;
    }

    .list {
        padding-right: 16px;
        padding-left: 16px;
    }

    .event-entry {
        grid-template-columns: 1fr;
        gap: 0;
    }
}

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