*, *::before, *::after { box-sizing: border-box; }

:root {
    --bg:       #0f1117;
    --surface:  #161923;
    --surface2: #1e2130;
    --border:   #2a2e48;
    --border2:  #363b60;
    --accent:   #5b8dee;
    --accent2:  #8b6de8;
    --text:     #cdd2ee;
    --text2:    #a0a8cc;
    --muted:    #666e94;
    --success:  #4cba80;
    --warn:     #d8b34c;
    --danger:   #e05252;
    --mono: 'Cascadia Code', 'Fira Mono', 'Consolas', monospace;
}

body {
    color: var(--text);
    background-color: var(--bg);
    margin: 0;
    padding-bottom: 40px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.43;
}

#container {
    max-width: 1100px;
    margin-right: auto;
    margin-left: auto;
    padding: 0 20px;
}

#top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 20px 0;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

#top-header img {
    vertical-align: middle;
    height: 36px;
}

#title {
    font-size: 1.6em;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
}

.badge {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent);
    background: rgba(91, 141, 238, 0.12);
    border: 1px solid rgba(91, 141, 238, 0.25);
    border-radius: 999px;
    padding: 3px 10px;
}

#loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 80px 0;
    color: var(--text2);
    font-size: 0.9rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid var(--border2);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

#user-info {
    font-size: 0.85rem;
    color: var(--text2);
    margin-right: 4px;
}

.btn-icon, .btn-toggle {
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    transition: filter 0.15s, border-color 0.15s;
}
.btn-icon:hover, .btn-toggle:hover { filter: brightness(1.15); border-color: var(--border2); }
.btn-icon:active, .btn-toggle:active { transform: translateY(1px); }

.btn-toggle[aria-pressed="true"] {
    color: #0f1117;
    background: var(--success);
    border-color: var(--success);
}
.btn-toggle.is-off {
    color: var(--muted);
    background: var(--surface2);
}

.btn-logout {
    color: #f0a0a0;
    border-color: rgba(224, 82, 82, 0.3);
}
.btn-logout:hover { background: rgba(224, 82, 82, 0.1); }

#header-info {
    font-size: 100%;
    margin-bottom: 30px;
    background-color: var(--surface);
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: 10px;

    display: grid;
    grid-template-columns: auto auto auto;
    grid-template-rows: auto auto;
    row-gap: 4px;
}

#generator-name {
    font-weight: 600;
    color: var(--text);
}

#generator-version {
    color: var(--accent);
    font-family: var(--mono);
}

.header-time {
    color: var(--accent);
    font-family: var(--mono);
}

.ago-time {
    text-align: right;
    color: var(--muted);
}

.server-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.server-header > span {
    font-size: 90%;
    color: var(--muted);
    font-family: var(--mono);
}

h1 {
    margin-top: 32px;
    margin-bottom: 12px;
    font-size: 140%;
    font-weight: 700;
    font-family: var(--mono);
    color: var(--text);
}

/* from https://stackoverflow.com/a/55118265 */
section.warn h1 {
    padding-left: 1.8em;
    background-size: auto 100%;
    background-repeat: no-repeat;
    background-image: url(/icon-warn.svg);
}
section.danger h1 {
    padding-left: 1.8em;
    background-size: auto 100%;
    background-repeat: no-repeat;
    background-image: url(/icon-danger.svg);
}

section > div {
    background-color: var(--surface);
    padding: 16px 16px 8px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);

    display: grid;
    grid-template-columns: 3fr 5fr 2fr 2fr;  /* auto */
}

section.ok > div {
    border-color: rgba(76, 186, 128, 0.35);
    box-shadow: 0 4px 16px rgba(76, 186, 128, 0.08);
}

section.warn > div {
    border-color: rgba(216, 179, 76, 0.4);
    box-shadow: 0 4px 16px rgba(216, 179, 76, 0.1);
}

section.danger > div {
    border-color: rgba(224, 82, 82, 0.45);
    box-shadow: 0 4px 16px rgba(224, 82, 82, 0.12);
}

.st-header-cell {
    font-weight: 600;
    font-size: 90%;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.st-cell {
    border-top: 1px solid var(--border);
    padding-top: 8px;
    padding-bottom: 8px;
    padding-right: 8px;
}

.cname {
    display: grid;
    grid-template-columns: 2fr 3fr;
    grid-template-rows: 1fr;

    font-size: 105%;
    font-weight: 600;
}

.cname-ok {
    color: var(--success);
}
.cname-warn {
    color: var(--warn);
}
.cname-danger {
    color: var(--danger);
}

.cname-scheme {
    margin-top: auto;
    margin-bottom: auto;
}

.cname-port {
    font-family: var(--mono);
    color: var(--muted);
    margin-top: auto;
    margin-bottom: auto;
}

.attempt {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
}

.hsduration { color: var(--success); font-family: var(--mono); }
.hsok { color: var(--success); }
.hswarn { color: var(--warn); }
.hsdanger { color: var(--danger); }
.excname {
    color: var(--danger);
    font-weight: 700;
    font-family: var(--mono);
}

.hsinstant {
    color: var(--muted);
    font-size: 90%;
    font-family: var(--mono);
}

.hsnumattempts {
    color: var(--muted);
    font-size: 85%;
}

footer {
    font-size: 85%;
    color: var(--muted);
    margin-top: 40px;
    text-align: center;
}
footer > a {
    color: var(--accent);
}

@media (max-width: 700px) {
    #top-header { flex-direction: column; align-items: flex-start; }
    section > div { grid-template-columns: 1fr; }
}

/* Metrics dashboards (server list + per-server charts) */

a.btn-icon {
    text-decoration: none;
    display: inline-block;
}

select.btn-icon {
    appearance: none;
    -webkit-appearance: none;
}

.hint {
    color: var(--text2);
    font-size: 0.9rem;
    padding: 40px 0;
    text-align: center;
}

.server-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.server-list li {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.server-list a {
    display: block;
    padding: 16px 18px;
    color: var(--text);
    text-decoration: none;
    font-family: var(--mono);
    font-weight: 600;
}

.server-list a:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.server-list-sub {
    display: block;
    margin-top: 4px;
    font-family: inherit;
    font-weight: 400;
    font-size: 0.78rem;
    color: var(--text2);
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--kpi-color, var(--accent));
    border-radius: 10px;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: filter 0.15s ease, border-color 0.15s ease;
}

.kpi-card:hover {
    filter: brightness(1.1);
    border-color: var(--border2);
}

.kpi-card.active {
    border-color: var(--kpi-color, var(--accent));
    box-shadow: 0 0 0 1px var(--kpi-color, var(--accent));
}

.kpi-label {
    font-size: 0.82rem;
    color: var(--text2);
}

.kpi-value {
    font-size: 1.8rem;
    font-weight: 700;
    font-family: var(--mono);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.stats-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stats-item span {
    color: var(--text2);
    font-size: 0.85rem;
    font-family: var(--mono);
}

.servers-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.servers-table th, .servers-table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.servers-table th {
    color: var(--text2);
    font-weight: 600;
    font-size: 0.8rem;
}

.servers-table td:first-child {
    font-family: var(--mono);
}

.chart-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
}

.chart-card h3 {
    margin: 0 0 12px;
    font-size: 0.95rem;
    color: var(--text2);
    font-weight: 600;
}

/* Global (whole-network) dashboard: spacing + small-multiple charts */

/* Vertical rhythm between panels so cards never touch each other. */
.section-stack {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.chart-card .card-sub {
    margin: -6px 0 16px;
    font-size: 0.82rem;
    color: var(--muted);
}

/* One small chart per metric / per environment, instead of a single
   cramped multi-line chart with a confusing legend. */
.mini-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.mini-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mini-card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.mini-card h4 {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text2);
}

.mini-card .mini-value {
    font-family: var(--mono);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
}

/* Fixed-height wrapper so every chart keeps the same proportions
   regardless of how many points it has. */
.chart-box {
    position: relative;
    height: 150px;
}

.chart-box.tall {
    height: 240px;
}

.chart-empty {
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.82rem;
    text-align: center;
}

/* Environment pill used in tables to keep the origin readable. */
.env-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(91, 141, 238, 0.12);
    border: 1px solid rgba(91, 141, 238, 0.25);
    color: var(--accent);
    white-space: nowrap;
}

.tag-yes {
    color: var(--warn);
    font-weight: 600;
}

.tag-muted {
    color: var(--muted);
}

/* Let wide detail tables scroll horizontally on small screens instead of
   overflowing the card. */
.table-scroll {
    overflow-x: auto;
}

/* Clickable KPI / mini cards that open a modal on click. */
.clickable {
    cursor: pointer;
}
.clickable:hover {
    border-color: var(--accent);
}

/* Sortable tables: clickable headers with an asc/desc indicator. */
.servers-table.sortable th {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.servers-table.sortable th:hover {
    color: var(--text);
}
.servers-table.sortable th.sort-asc::after {
    content: ' \25B2';
    color: var(--accent);
    font-size: 0.7em;
}
.servers-table.sortable th.sort-desc::after {
    content: ' \25BC';
    color: var(--accent);
    font-size: 0.7em;
}

/* Small inline chart-icon button inside table rows. */
.row-chart-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    line-height: 1;
}
.row-chart-btn svg {
    width: 16px;
    height: 16px;
    display: block;
}

/* Modal (drill-down time series and channel detail). */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(6, 8, 14, 0.72);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    z-index: 1000;
    overflow-y: auto;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: 12px;
    width: min(960px, 100%);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.modal-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}
.modal-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.modal-body {
    padding: 18px;
}
.modal-body h4 {
    margin: 18px 0 10px;
    font-size: 0.9rem;
    color: var(--text2);
}

/* Grafana-style chart + side legend. */
.modal-chart-row {
    display: flex;
    gap: 16px;
    align-items: stretch;
    flex-wrap: wrap;
}
.chart-box.modal-chart {
    position: relative;
    flex: 1 1 420px;
    height: 320px;
    min-width: 0;
}
.chart-legend {
    flex: 0 0 240px;
    max-width: 100%;
    overflow-y: auto;
    max-height: 320px;
}
.legend-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.legend-table th {
    text-align: right;
    color: var(--text2);
    font-weight: 600;
    font-size: 0.72rem;
    padding: 4px 6px;
    border-bottom: 1px solid var(--border);
}
.legend-table th:first-child {
    text-align: left;
}
.legend-table td {
    padding: 5px 6px;
    border-bottom: 1px solid var(--border);
    text-align: right;
    font-family: var(--mono);
}
.legend-table td:first-child {
    text-align: left;
    font-family: inherit;
    color: var(--text);
}
.legend-row {
    cursor: pointer;
}
.legend-row:hover {
    background: var(--surface2);
}
.legend-row.legend-off {
    opacity: 0.4;
}
.legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 8px;
    vertical-align: baseline;
}

/* Drag-to-select time range rectangle drawn over the chart. */
.chart-drag-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    display: none;
    background: rgba(91, 141, 238, 0.18);
    border-left: 1px solid var(--accent);
    border-right: 1px solid var(--accent);
    pointer-events: none;
}

/* Channel detail modal. */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}
.detail-item {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
}
.detail-item .detail-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text2);
}
.detail-item .detail-value {
    display: block;
    font-family: var(--mono);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin-top: 2px;
}
.plain-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.plain-list li {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.82rem;
}

/* ─────────────────────────────────────────────────────────────────────────
   "Visão Geral da Rede" only (body.page-global): richer visual polish.
   Scoped so the other dashboards keep the current, lighter look.
   ───────────────────────────────────────────────────────────────────────── */

/* Soft ambient depth behind the whole page. */
.page-global {
    background:
        radial-gradient(1200px 600px at 100% -10%, rgba(91, 141, 238, 0.10), transparent 60%),
        radial-gradient(1000px 500px at -10% 0, rgba(139, 109, 232, 0.08), transparent 55%),
        var(--bg);
    background-attachment: fixed;
}

/* Sticky, frosted header. */
.page-global #top-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(15, 17, 23, 0.82);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.page-global #title {
    background: linear-gradient(90deg, var(--text), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.page-global .kpi-grid {
    gap: 18px;
    margin-bottom: 4px;
}

.page-global .kpi-card {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    border-left: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 20px;
    /* Fallback first, then the tinted gradient for modern browsers. */
    background: var(--surface);
    background:
        radial-gradient(130% 150% at 100% 0,
            color-mix(in srgb, var(--kpi-color, var(--accent)) 16%, transparent) 0,
            transparent 55%),
        var(--surface);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

/* Accent bar on top instead of the flat left border. */
.page-global .kpi-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: var(--kpi-color, var(--accent));
    opacity: 0.9;
}

.page-global .kpi-card:hover {
    filter: none;
    transform: translateY(-3px);
    border-color: var(--border2);
    border-color: color-mix(in srgb, var(--kpi-color, var(--accent)) 50%, var(--border));
    box-shadow: 0 12px 26px -10px rgba(0, 0, 0, 0.6);
    box-shadow:
        0 12px 26px -10px color-mix(in srgb, var(--kpi-color, var(--accent)) 45%, transparent),
        0 2px 6px rgba(0, 0, 0, 0.35);
}

.page-global .kpi-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    color: var(--muted);
}

.page-global .kpi-value {
    font-size: 2.2rem;
    line-height: 1.1;
    color: var(--text);
    color: color-mix(in srgb, var(--kpi-color, var(--accent)) 55%, var(--text));
    text-shadow: 0 0 18px color-mix(in srgb, var(--kpi-color, var(--accent)) 28%, transparent);
}

/* Panels: rounder, with a soft lift. */
.page-global .chart-card {
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.page-global .chart-card h3 {
    font-size: 1rem;
    color: var(--text);
}

.page-global .stats-item span {
    color: var(--text2);
}

/* Confirmation dialog actions (e.g. logout). */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

/* Compact, screen-centered confirmation dialog. */
.modal-overlay.centered {
    align-items: center;
}
.modal.modal-confirm {
    width: min(380px, 100%);
}

/* Multi-series chart: on narrow screens stack the plot above its legend so
   the chart uses the full width instead of being squeezed to the left. */
@media (max-width: 700px) {
    .modal-chart-row { flex-direction: column; }
    .chart-box.modal-chart { flex: 1 1 auto; width: 100%; height: 260px; }
    .chart-legend { flex: 1 1 auto; width: 100%; max-width: 100%; max-height: none; }
}

/* "Visão Geral da Rede" mobile layout: keep the header tidy and center the
   KPI values so nothing looks off-center or lost. */
@media (max-width: 700px) {
    .page-global #top-header {
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
    }
    .page-global .brand { justify-content: center; }
    .page-global .toolbar { justify-content: center; gap: 8px; }
    .page-global .toolbar #user-info {
        flex-basis: 100%;
        text-align: center;
        margin: 0 0 2px;
    }
    .page-global .kpi-card { align-items: center; text-align: center; }
}

