:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --accent: #0f6ab4;
    --accent-soft: #e3f0fa;
    --good: #16a34a;
    --warn: #d97706;
    --bad: #dc2626;
}

* { box-sizing: border-box; }

/* Rótulos de campos de pesquisa que já têm placeholder visível: acessível a leitores de ecrã
   sem duplicar texto visualmente (ver inputs type="search" nas páginas de listagem). */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

html, body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}

h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
h1:focus { outline: none; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .75rem; color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand { display: flex; align-items: baseline; gap: .5rem; }
.brand a { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand a:hover { text-decoration: none; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); align-self: center; }
.brand-sub { color: var(--muted); font-size: .8rem; }

.topbar nav { display: flex; gap: .25rem; }
.topbar nav a {
    padding: .4rem .8rem;
    border-radius: 6px;
    color: var(--muted);
    font-weight: 500;
}
.topbar nav a:hover { background: var(--accent-soft); text-decoration: none; }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }

.content { padding: 1.5rem; max-width: 1200px; width: 100%; margin: 0 auto; }

/* Ecrãs estreitos (telemóvel/PWA): a barra passa a duas linhas e o menu desliza na horizontal. */
@media (max-width: 720px) {
    .topbar { height: auto; flex-wrap: wrap; padding: .5rem .75rem; row-gap: .25rem; }
    .topbar nav { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    .topbar nav::-webkit-scrollbar { display: none; }
    .topbar nav a { white-space: nowrap; }
    .content { padding: 1rem .75rem; }
}

.page-sub { color: var(--muted); margin: 0 0 1.25rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem; margin-bottom: 1.5rem; }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .9rem 1rem;
}
.card .card-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.card .card-value { font-size: 1.5rem; font-weight: 700; margin-top: .15rem; }
.card .card-value.good { color: var(--good); }
.card .card-value.warn { color: var(--warn); }
.card .card-value.bad { color: var(--bad); }
.card .card-detail { color: var(--muted); font-size: .78rem; margin-top: .15rem; }
@media (min-width: 1180px) {
    .home-cards { grid-template-columns: repeat(8, minmax(0, 1fr)); }
    .home-cards .card { padding: .8rem .75rem; }
    .home-cards .card .card-label { font-size: .72rem; }
    .home-cards .card .card-value { font-size: 1.28rem; }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 1.25rem;
}
.panel-title { font-weight: 600; margin-bottom: .5rem; }

.chart { width: 100%; height: 320px; }
.chart-tall { width: 100%; height: 420px; }

table.data {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
table.data th, table.data td { padding: .5rem .75rem; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { background: #f8fafc; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
table.data th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.data th.sortable:hover { color: var(--accent); }
table.data .sort-arrow { color: var(--accent); }

.has-help { cursor: help; }
.card .card-label.has-help { border-bottom: 1px dotted var(--muted); display: inline-block; }

/* Tooltips estilizados: balão abaixo do elemento, via atributo data-tip */
[data-tip] { position: relative; }
[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    top: calc(100% + 9px);
    left: 0;
    z-index: 60;
    width: max-content;
    max-width: 300px;
    background: #1e293b;
    color: #f1f5f9;
    padding: .55rem .75rem;
    border-radius: 8px;
    font-size: .78rem;
    font-weight: 400;
    line-height: 1.45;
    letter-spacing: normal;
    text-transform: none;
    white-space: normal;
    text-align: left;
    box-shadow: 0 10px 28px rgba(15, 23, 42, .28);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity .15s ease, transform .15s ease;
    pointer-events: none;
}
[data-tip]::before {
    content: "";
    position: absolute;
    top: calc(100% - 3px);
    left: 16px;
    z-index: 61;
    border: 6px solid transparent;
    border-bottom-color: #1e293b;
    opacity: 0;
    visibility: hidden;
    transition: opacity .15s ease;
    pointer-events: none;
}
[data-tip]:hover::after, [data-tip]:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
/* Colunas numéricas encostam à direita: alinhar o balão pela direita para não sair do ecrã */
th.num[data-tip]::after { left: auto; right: 0; }
th.num[data-tip]::before { left: auto; right: 16px; }

.lang-switch { display: flex; gap: .35rem; align-items: center; color: var(--muted); font-size: .8rem; margin-left: 1rem; }
.lang-switch a { color: var(--muted); cursor: pointer; }
.lang-switch a.active { color: var(--accent); font-weight: 700; }
table.data tr:last-child td { border-bottom: none; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

.delay-pos { color: var(--bad); font-weight: 600; }
.delay-neg { color: var(--good); font-weight: 600; }
.delay-zero { color: var(--muted); }

/* Espera do utente (sempre ≥ 0): verde curta, amarelo média, vermelho longa. Não scoped, para
   servir tanto os card-value como as células de tabela. */
.wait-good { color: var(--good); font-weight: 600; }
.wait-warn { color: var(--warn); font-weight: 600; }
.wait-bad { color: var(--bad); font-weight: 600; }

.toolbar { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar label { color: var(--muted); font-size: .85rem; }
.toolbar select, .toolbar input {
    padding: .35rem .6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    font: inherit;
    color: var(--text);
}
.toolbar .spacer { flex: 1; }
.period-nav { display: inline-flex; align-items: center; gap: .5rem; }
.period-nav .navbtn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--accent);
    border-radius: 6px;
    padding: .3rem .55rem;
    font: inherit;
    line-height: 1;
    cursor: pointer;
}
.period-nav .navbtn:hover:not(:disabled) { background: var(--accent-soft); }
.period-nav .navbtn:disabled { color: var(--border); cursor: default; }
.period-nav .period-range { color: var(--muted); font-size: .85rem; min-width: 8ch; text-align: center; }

/* Fita de percurso (diagrama linear com calor por troço) */
/* Agrupa as fitas da mesma linha (ex.: os 2 sentidos) num só bloco sombreado — sempre a
   mesma cor em todos os grupos; a margem+contorno garantem separação nítida do grupo seguinte. */
.ribbon-group {
    /* Tom claramente distinto do fundo da página (--bg: #f4f6f9) — a tentativa anterior
       (#eef2f6) era quase idêntica ao fundo e por isso invisível. */
    background: #e2e8f0;
    border: 1px solid #b9c4d1;
    border-radius: 10px;
    padding: .6rem .8rem .35rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
    position: relative;
}
.ribbon-status {
    position: absolute;
    top: .55rem;
    right: .15rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    cursor: help;
}
.ribbon-status.live {
    background: var(--good);
    box-shadow: 0 0 0 0 rgba(22, 163, 74, .6);
    animation: live-pulse 1.6s ease-out infinite;
}
.ribbon-status.partial {
    background: #facc15;
    box-shadow: 0 0 0 0 rgba(250, 204, 21, .65);
    animation: live-pulse 1.6s ease-out infinite;
}
.ribbon-status.offline {
    background: transparent;
    border: 2px solid #94a3b8;
}
.ribbon {
    position: relative;
    padding-right: 1.1rem;
    margin-bottom: .35rem;
}
.ribbon-title { font-size: .85rem; font-weight: 600; margin-bottom: .1rem; }
.ribbon-headsign { color: var(--muted); font-weight: 400; }
.ribbon-headsign-arrow { color: #dc2626; font-weight: 600; margin: 0 .22rem; }
.ribbon-headsign-destination { color: #dc2626; }
.ribbon-len { color: var(--muted); font-weight: 400; font-size: .78rem; margin-left: .5rem; }
.ribbon-buscount { color: var(--muted); font-weight: 400; font-size: .78rem; margin-left: .5rem; }
.ribbon-svg { width: 100%; height: 30px; display: block; }
.ribbon-svg line { cursor: pointer; }
.ribbon-stop { fill: #fff; stroke: #334155; stroke-width: 1.6; cursor: pointer; }
.ribbon-stop:hover { fill: var(--accent); }
/* Marcadores ao vivo: linha vertical + círculos nas extremidades para continuarem legíveis
   mesmo sobre troços amarelos/vermelhos. A cor vive no <g> (currentColor), para linha e
   extremidades mudarem juntas e o hover não ficar dessincronizado. */
.ribbon-bus, .ribbon-bus-approx, .ribbon-bus-late, .ribbon-bus-ghost {
    cursor: pointer;
    opacity: 1;
    filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 1.5px #fff);
}
.ribbon-bus { color: #15803d; }
/* Reserva para um eventual estado intermédio sem GPS confirmado: âmbar escuro. Testado em
   fundo simulado local contra verde/vermelho/azul; distinguiu-se melhor do que slate escuro
   (confundia-se com o contorno das paragens) e do que castanho escuro (mais próximo do vermelho). */
.ribbon-bus-approx { color: #a16207; }
/* Autocarro atualmente atrasado (>1 min face ao horário, mesmo critério de DelayCss) —
   vermelho bem saturado, para ser imediatamente visível. */
.ribbon-bus-late { color: #dc2626; }
.ribbon-bus-ghost {
    color: #6d28d9;
    opacity: .8;
}
.ribbon-bus-line {
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}
.ribbon-bus-cap {
    fill: currentColor;
    stroke: #fff;
    stroke-width: .8;
}
.ribbon-bus-cap-line {
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}
.ribbon-bus-cap-pill {
    fill: currentColor;
    stroke: #fff;
    stroke-width: .8;
}
.ribbon-bus-triangle {
    fill: currentColor;
    stroke: #fff;
    stroke-width: .8;
    stroke-linejoin: round;
}
.ribbon-bus:hover .ribbon-bus-line,
.ribbon-bus-approx:hover .ribbon-bus-line,
.ribbon-bus-late:hover .ribbon-bus-line,
.ribbon-bus-ghost:hover .ribbon-bus-line {
    stroke-width: 2.8;
}
.ribbon-bus:hover .ribbon-bus-cap-line,
.ribbon-bus-approx:hover .ribbon-bus-cap-line,
.ribbon-bus-late:hover .ribbon-bus-cap-line,
.ribbon-bus-ghost:hover .ribbon-bus-cap-line {
    stroke-width: 2.8;
}
.ribbon-bus:hover .ribbon-bus-cap-pill,
.ribbon-bus-approx:hover .ribbon-bus-cap-pill,
.ribbon-bus-late:hover .ribbon-bus-cap-pill,
.ribbon-bus-ghost:hover .ribbon-bus-cap-pill {
    stroke-width: 1;
}
.ribbon-bus:hover .ribbon-bus-cap,
.ribbon-bus-approx:hover .ribbon-bus-cap,
.ribbon-bus-late:hover .ribbon-bus-cap,
.ribbon-bus-ghost:hover .ribbon-bus-cap {
    r: 3.2;
}
.ribbon-bus:hover .ribbon-bus-triangle,
.ribbon-bus-approx:hover .ribbon-bus-triangle,
.ribbon-bus-late:hover .ribbon-bus-triangle,
.ribbon-bus-ghost:hover .ribbon-bus-triangle {
    stroke-width: 1;
}
.ribbon-bus-ghost .ribbon-bus-line { stroke-dasharray: 2 2; }
.ribbon-bus-ghost:hover { color: #5b21b6; opacity: 1; }
.ribbon-tip {
    position: fixed;
    z-index: 80;
    max-width: 320px;
    background: #1e293b;
    color: #f1f5f9;
    padding: .5rem .7rem;
    border-radius: 8px;
    font-size: .78rem;
    line-height: 1.45;
    box-shadow: 0 10px 28px rgba(15, 23, 42, .28);
    pointer-events: none;
}
.ribbon-legend { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .78rem; margin: .4rem 0 .8rem; }
.ribbon-legend .grad { width: 140px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #16a34a, #facc15, #dc2626); }
/* Amostras de cor da legenda "ao vivo/atrasado/etc" — substituem o carácter Unicode fino
   (▏) que tinha a cor certa mas era pequeno e fino demais para se notar (mesmo problema dos
   marcadores na fita, ver .ribbon-bus). Um bloco sólido é sempre visível, seja qual for o ecrã. */
.ribbon-legend .legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    vertical-align: middle;
    margin-right: 2px;
}
.ribbon-legend .legend-swatch-bus {
    width: 2px;
    height: 16px;
    border-radius: 999px;
    margin-right: 6px;
    position: relative;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .9);
}
.ribbon-legend .legend-swatch-bus::before,
.ribbon-legend .legend-swatch-bus::after {
    content: "";
    position: absolute;
    left: 50%;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: inherit;
    transform: translateX(-50%);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .9);
}
.ribbon-legend .legend-swatch-bus::before { top: -1px; }
.ribbon-legend .legend-swatch-bus::after { bottom: -1px; }
.ribbon-legend .legend-swatch-bus-tri {
    width: 2px;
    height: 16px;
    border-radius: 0;
    margin-left: 3px;
    margin-right: 9px;
    background: currentColor !important;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .9);
}
.ribbon-legend .legend-swatch-bus-line::before,
.ribbon-legend .legend-swatch-bus-line::after {
    width: 8px;
    height: 6px;
    border-radius: 999px;
}
.ribbon-legend .legend-swatch-bus-tri::before,
.ribbon-legend .legend-swatch-bus-tri::after {
    width: 0;
    height: 0;
    background: transparent;
    box-shadow: none;
    left: 50%;
    transform: translateX(-50%);
}
.ribbon-legend .legend-swatch-bus-tri::before {
    top: -1px;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 0;
    border-top: 6px solid currentColor;
}
.ribbon-legend .legend-swatch-bus-tri::after {
    bottom: -1px;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 0;
    border-bottom: 6px solid currentColor;
}
.ribbon-legend .legend-swatch-ghost {
    opacity: .8;
}
.ribbon-legend .legend-swatch-ghost::before,
.ribbon-legend .legend-swatch-ghost::after {
    opacity: 1;
}
.ribbon-totals {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    margin-left: .75rem;
    padding: .22rem .55rem;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: #f8fafc;
    color: #475569;
}
.ribbon-totals-label { font-weight: 600; color: #334155; }

.live-badge { display: inline-flex; align-items: center; gap: .4rem; color: var(--good); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 rgba(22,163,74,.6); animation: live-pulse 1.6s ease-out infinite; }
@keyframes live-pulse {
    0% { box-shadow: 0 0 0 0 rgba(22,163,74,.5); }
    70% { box-shadow: 0 0 0 7px rgba(22,163,74,0); }
    100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); }
}
.btn {
    display: inline-block;
    padding: .4rem .9rem;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    border: none;
    font: inherit;
    cursor: pointer;
}
.btn:hover { text-decoration: none; opacity: .92; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-sm { padding: .2rem .55rem; font-size: .8rem; }

/* Alternador binário: pílula que mostra a opção ativa; clicar troca */
.btn-toggle {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .35rem .85rem;
    border: 1px solid var(--accent);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font: inherit;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .12s ease, transform .06s ease;
    user-select: none;
}
.btn-toggle:hover { background: #d3e7f7; }
.btn-toggle:active { transform: scale(.97); }
.btn-toggle .toggle-icon { font-size: .8rem; opacity: .65; }

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 3rem 1rem;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 10px;
}

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none;
    left: 0;
    padding: .6rem 1.25rem .7rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
    border-radius: 8px;
}
.blazor-error-boundary::after { content: "Ocorreu um erro." }
