/* ============================================================
   NetTrack styles
   Colors are at the top: change one here and every page updates.
   ============================================================ */

:root {
    --bg: #e5edec;
    --surface: #ffffff;
    --surface-muted: #f4f6f7;
    --border: #dfe5e8;
    --row-line: #eef1f3;
    --row-hover: #eef5f8;
    --text: #15191e;
    --text-muted: #5d6670;
    --label: #4a525b;

    --navy: #2c4a6e;
    --navy-dark: #213a58;
    --sky: #9cc3da;
    --sky-soft: #bad2de;
    --logo-ink: #1d4766;

    /* Status colors: strong for bars and charts, soft + text for badges */
    --online: #98d89a;
    --offline: #d99a9a;
    --maintenance: #dcd597;
    --total: #9cc3da;
    --online-soft: #dcf2dd;
    --online-text: #1f6a2c;
    --offline-soft: #f6dddd;
    --offline-text: #962f2f;
    --maintenance-soft: #f3efcf;
    --maintenance-text: #6f6012;

    /* The lines on the Reports chart ("Device status over time") */
    --chart-online: #00ff00;
    --chart-offline: #ff0000;
    --chart-maintenance: #ff7f00;

    --danger: #b93a35;
    --danger-dark: #9c2f2b;
    --chart-line: #4a7fef;

    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(20, 40, 60, .04);
    --shadow-pop: 0 12px 32px rgba(20, 40, 60, .16);

    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

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

[hidden] {
    display: none !important;
}

/* Restored by Back/Forward: hidden until the session is checked (layout.js) */
.is-checking {
    visibility: hidden;
}

/* Viewers only look: Add, Edit and Delete buttons are hidden (the server refuses them too) */
.is-viewer [data-admin-only] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
}

h1, h2, h3, p {
    margin: 0;
}

a {
    color: var(--navy);
}

:focus-visible {
    outline: 2px solid var(--navy);
    outline-offset: 2px;
}

.icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- Page layout ---------- */

/* Fills the whole window at every screen size */
.app {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 40px;
    width: 100%;
    min-height: 100vh;
    padding: 32px 40px;
}

.main {
    grid-column: 2; /* keeps its place while layout.js adds the sidebar */
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

/* ---------- Sidebar ---------- */

.sidebar {
    position: sticky;
    top: 32px;
    height: calc(100vh - 64px);
    min-height: 420px;
    padding: 24px 20px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.sidebar-top {
    padding-bottom: 22px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: inherit;
    text-decoration: none;
}

.brand-logo {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: var(--sky);
    color: var(--logo-ink);
}

.brand-logo .logo {
    width: 38px;
    height: 38px;
}

.logo-node {
    fill: var(--sky);
}

.brand-text strong {
    display: block;
    font-size: 20px;
    line-height: 1.15;
}

.brand-text small {
    font-size: 11px;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
    border-radius: 10px;
    color: var(--label);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .06em;
    text-decoration: none;
    text-transform: uppercase;
}

.nav-link:hover {
    background: var(--surface-muted);
    color: var(--text);
}

.nav-link.is-active {
    background: var(--sky-soft);
    color: var(--navy-dark);
}

.sidebar .nav-toggle {
    display: none;
}

/* ---------- Top bar ---------- */

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px 24px;
}

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

.page-heading h1 {
    font-size: 26px;
    line-height: 1.2;
}

.page-heading p {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 13px;
}

.heading-icon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--navy);
    color: #fff;
}

.heading-icon .icon {
    width: 26px;
    height: 26px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.search {
    position: relative;
}

.search .icon {
    position: absolute;
    top: 50%;
    left: 14px;
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transform: translateY(-50%);
    pointer-events: none;
}

.search input {
    width: 260px;
    height: 44px;
    padding: 0 14px 0 40px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.search input:focus {
    border-color: var(--navy);
    outline: none;
    box-shadow: 0 0 0 3px rgba(44, 74, 110, .15);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 4px 4px;
    border: 0;
    border-radius: 999px;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.user-chip:hover {
    background: rgba(255, 255, 255, .6);
}

.user-chip-text strong {
    display: block;
    font-size: 13px;
}

.user-chip-text small {
    color: var(--text-muted);
    font-size: 11px;
}

/* Alerts bell, with the number of new alerts in a red circle */

.bell {
    position: relative;
    flex: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    color: var(--text);
}

.bell:hover {
    background: rgba(255, 255, 255, .6);
}

.bell > .icon {
    width: 21px;
    height: 21px;
}

.bell-count {
    position: absolute;
    top: 3px;
    right: 1px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border: 2px solid var(--bg);
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 15px;
    text-align: center;
}

.avatar {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #7a909c;
    color: #fff;
    font-size: 20px;
    flex-shrink: 0;
}

.avatar-lg {
    width: 72px;
    height: 72px;
    font-size: 32px;
}

/* ---------- Cards ---------- */

.card {
    padding: 24px 28px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.card-head h2 {
    font-size: 18px;
}

.card-head p {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 12.5px;
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

/* ---------- Summary cards ---------- */

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 22px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 20px 28px 22px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: inherit;
    text-decoration: none;
    transition: transform .15s, box-shadow .15s;
}

.stat:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(20, 40, 60, .08);
}

.stat-label {
    color: var(--label);
    font-size: 12px;
    font-weight: 700;
}

.stat-value {
    font-size: 44px;
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.stat-bar {
    height: 4px;
    border-radius: 4px;
    background: var(--total);
}

.stat-online .stat-bar { background: var(--online); }
.stat-offline .stat-bar { background: var(--offline); }
.stat-maintenance .stat-bar { background: var(--maintenance); }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.btn .icon {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: var(--navy);
    color: #fff;
}

.btn-primary:hover {
    background: var(--navy-dark);
}

.btn-secondary {
    background: #e8ebee;
    color: var(--text);
}

.btn-secondary:hover {
    background: #dce0e4;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: var(--danger-dark);
}

.btn-block {
    width: 100%;
    height: 46px;
    font-size: 15px;
}

/* While saving (see setBusy() in components/form.js) */
.btn:disabled {
    opacity: .7;
    cursor: wait;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.icon-btn:hover {
    background: var(--surface-muted);
    color: var(--text);
}

/* ---------- Status badges ---------- */

.badge {
    display: inline-block;
    min-width: 104px;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.badge-online { background: var(--online-soft); color: var(--online-text); }
.badge-offline { background: var(--offline-soft); color: var(--offline-text); }
.badge-maintenance { background: var(--maintenance-soft); color: var(--maintenance-text); }

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--sky);
}

.dot-online { background: var(--online); }
.dot-offline,
.dot-deleted { background: var(--offline); }
.dot-maintenance { background: var(--maintenance); }
.dot-added { background: var(--sky); }
.dot-updated { background: var(--navy); }

/* ---------- Device table ---------- */

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    margin-bottom: 8px;
}

.filters label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--label);
    font-size: 12.5px;
    font-weight: 700;
}

.filters-count {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 12.5px;
}

.table-wrap {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table th {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--label);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .05em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}

.table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--row-line);
    white-space: nowrap;
}

.table tbody tr {
    cursor: pointer;
}

.table tbody tr:hover td {
    background: var(--row-hover);
}

.table .col-actions {
    width: 64px;
    text-align: right;
}

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

.mono {
    font-variant-numeric: tabular-nums;
}

/* Actions menu (⋯), placed by components/menu.js so the table can't cut it off */
.menu {
    position: fixed;
    z-index: 30;
    min-width: 150px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-pop);
    text-align: left;
}

.menu a,
.menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
}

.menu .icon {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

.menu a:hover,
.menu button:hover {
    background: var(--surface-muted);
}

.menu .danger,
.menu .danger .icon {
    color: var(--danger);
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 18px;
}

.page-link {
    display: inline-grid;
    place-items: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border-radius: 8px;
    color: var(--text);
    font-weight: 700;
    text-decoration: none;
}

a.page-link:hover {
    background: var(--surface-muted);
}

.page-link.is-current {
    background: var(--navy);
    color: #fff;
}

.page-link.is-disabled {
    color: #b7bdc3;
}

.page-gap {
    display: inline-grid;
    place-items: center;
    width: 24px;
    color: var(--text-muted);
}

.empty {
    padding: 48px 16px;
    text-align: center;
}

.empty .icon {
    width: 40px;
    height: 40px;
    color: var(--sky);
}

.empty h3 {
    margin-top: 12px;
    font-size: 17px;
}

.empty p {
    margin: 6px 0 18px;
    color: var(--text-muted);
}

/* ---------- Forms ---------- */

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

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label,
.field .label {
    font-size: 12.5px;
    font-weight: 700;
}

.req {
    color: var(--danger);
}

.input,
.field input,
.field select,
.field textarea,
.filters select {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-muted);
    color: var(--text);
    font: inherit;
    font-size: 13px;
}

.filters select {
    width: auto;
    height: 38px;
    padding-right: 34px;
    background-color: var(--surface);
    font-weight: 400;
}

.field select,
.filters select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235d6670' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-position: right 10px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 34px;
}

.field textarea {
    height: auto;
    min-height: 42px;
    padding: 10px 12px;
    resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.filters select:focus {
    border-color: var(--navy);
    outline: none;
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(44, 74, 110, .15);
}

.field input[readonly] {
    color: var(--text-muted);
    cursor: not-allowed;
}

.field.has-error input,
.field.has-error select,
.field.has-error textarea {
    border-color: var(--danger);
}

.field-error {
    color: var(--danger);
    font-size: 12px;
}

.field-hint {
    color: var(--text-muted);
    font-size: 12px;
}

.password-field {
    position: relative;
}

.password-field input {
    padding-right: 44px;
}

.password-field .icon-btn {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
}

.password-field .icon-btn.is-on {
    color: var(--navy);
}

.alert {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--offline-soft);
    color: var(--offline-text);
    font-size: 13px;
}

.alert-info {
    background: var(--online-soft);
    color: var(--online-text);
}

.alert-warning {
    background: var(--maintenance-soft);
    color: var(--maintenance-text);
}

/* "Checks paused" under the header (components/checks-notice.js) */
.checks-notice {
    align-items: flex-start;
    line-height: 1.5;
}

.checks-notice svg {
    flex-shrink: 0;
    margin-top: 1px;
}

.checks-notice p {
    margin: 0;
}

.checks-since {
    opacity: .8;
}

/* ---------- Popups ---------- */

.modal {
    width: min(460px, calc(100vw - 32px));
    padding: 30px 32px 28px;
    border: 0;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .25);
    color: var(--text);
}

.modal::backdrop {
    background: rgba(30, 40, 50, .45);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
}

.modal-icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin: 0 auto 10px;
    border-radius: 50%;
}

.modal-icon-view { background: var(--online-soft); color: var(--online-text); }
.modal-icon-delete { background: var(--offline-soft); color: var(--danger); }
.modal-icon-alert { background: var(--maintenance-soft); color: var(--maintenance-text); }

.modal h2 {
    font-size: 22px;
    text-align: center;
}

.modal-sub {
    margin: 6px 0 0;
    color: var(--text-muted);
    text-align: center;
}

.details {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 9px 16px;
    margin: 22px 0 0;
    font-size: 13.5px;
}

.details dt {
    font-weight: 700;
}

.details dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 26px;
}

.modal-actions-split > * {
    flex: 1;
}

/* View popup: details on the left, status history on the right */

.modal-wide {
    width: min(800px, calc(100vw - 32px));
}

.view-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 28px;
    margin-top: 22px;
}

.view-grid .details {
    align-content: start;
    margin: 0;
}

.history {
    min-width: 0;
    padding-left: 28px;
    border-left: 1px solid var(--border);
    font-size: 13.5px;
}

.history h3 {
    margin: 0 0 12px;
    font-size: 15px;
}

.history-now {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin: 0 0 18px;
}

.uptime-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    color: var(--label);
}

.uptime-value {
    font-size: 22px;
    color: var(--text);
}

.uptime-good { color: var(--online-text); }
.uptime-fair { color: var(--maintenance-text); }
.uptime-poor { color: var(--offline-text); }

.timeline {
    display: flex;
    height: 14px;
    margin-top: 8px;
    overflow: hidden;
    border-radius: 7px;
    background: var(--surface-muted);
}

.timeline-part { min-width: 2px; } /* so a 5-minute outage still shows */
.timeline-online { background: var(--online); }
.timeline-offline { background: var(--offline); }
.timeline-maintenance { background: var(--maintenance); }
.timeline-none { background: var(--surface-muted); }

.timeline-scale {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 11.5px;
    color: var(--text-muted);
}

.history .field-hint {
    margin: 8px 0 0;
}

.history-subtitle {
    margin: 20px 0 6px;
    font-size: 13px;
}

.changes {
    margin: 0;
    padding: 0;
    list-style: none;
}

.changes li {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    border-top: 1px solid var(--row-line);
}

.profile-head {
    display: flex;
    align-items: center;
    gap: 16px;
}

.profile-head h2 {
    font-size: 22px;
    text-align: left;
}

.profile-head p {
    color: var(--text-muted);
}

/* ---------- Toast message ---------- */

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: min(440px, calc(100vw - 40px));
    padding: 10px 8px 10px 16px;
    border-left: 4px solid var(--online);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow-pop);
    animation: toast-in .25s ease-out;
    transition: opacity .3s, transform .3s;
}

.toast > .icon {
    color: var(--online-text);
}

.toast-error {
    border-left-color: var(--danger);
}

.toast-error > .icon {
    color: var(--danger);
}

.toast.is-hiding {
    opacity: 0;
    transform: translateY(-8px);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
}

/* ---------- Dashboard ---------- */

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 28px;
    align-items: start;
}

.donut-wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 32px 56px;
    padding: 8px 0 12px;
}

.donut {
    display: grid;
    place-items: center;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    flex-shrink: 0;
}

.donut-hole {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--surface);
}

.donut-hole strong {
    font-size: 24px;
}

.donut-hole span {
    color: var(--text-muted);
    font-size: 12px;
}

.legend {
    display: grid;
    gap: 16px;
    min-width: 210px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.legend li {
    display: grid;
    grid-template-columns: 12px 1fr auto 44px;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.legend-pct {
    color: var(--text-muted);
    font-size: 12px;
    text-align: right;
}

.activity {
    display: grid;
    gap: 16px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.activity li {
    display: grid;
    grid-template-columns: 8px 1fr;
    gap: 12px;
}

.activity .dot {
    width: 8px;
    height: 8px;
    margin-top: 6px;
}

.activity-msg {
    font-size: 13px;
}

.activity-meta {
    color: var(--text-muted);
    font-size: 11.5px;
}

.empty-small {
    color: var(--text-muted);
}

/* The alerts popup: the Recent Activity list, each alert linking to its device */

.alerts {
    gap: 4px;
    margin-top: 20px;
    max-height: min(420px, 55vh);
    overflow-y: auto;
}

.alerts li {
    display: block;
}

.alert-row {
    display: grid;
    grid-template-columns: 8px 1fr;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 10px;
    color: inherit;
    text-decoration: none;
}

.alerts .is-new .alert-row {
    background: var(--surface-muted);
}

.alerts a.alert-row:hover {
    background: var(--row-hover);
}

/* ---------- Devices list: sorting and Delete selected ---------- */

/* A header you can click to sort by; the sorted one shows an arrow */
.sort-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
}

.sort-btn::after {
    content: '↕';
    opacity: .35;
}

.sort-btn:hover {
    color: var(--text);
}

th[aria-sort="ascending"] .sort-btn::after { content: '↑'; opacity: 1; }
th[aria-sort="descending"] .sort-btn::after { content: '↓'; opacity: 1; }

.col-select {
    width: 36px;
}

.col-select input {
    width: 16px;
    height: 16px;
    accent-color: var(--navy);
    cursor: pointer;
}

.bulk-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--surface-muted);
    font-size: 13px;
}

.bulk-list {
    max-height: 200px;
    margin: 14px 0 0;
    padding-left: 20px;
    overflow-y: auto;
    font-size: 13.5px;
}

/* ---------- Import CSV popup (Devices page) ---------- */

.import-links {
    margin: 12px 0 0;
    font-size: 13px;
}

.import-problems {
    max-height: 220px;
    margin: 14px 0 0;
    padding: 12px 14px 12px 32px;
    border-radius: 10px;
    background: var(--offline-soft);
    color: var(--offline-text);
    overflow-y: auto;
    font-size: 13px;
}

/* ---------- Scan network popup (Devices page) ---------- */

.scan-form {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-top: 22px;
}

.scan-form .field {
    flex: 1;
}

.scan-form .btn {
    margin-top: 24px; /* in line with the input, under its label */
}

.scan-results {
    margin-top: 18px;
}

.scan-summary {
    margin: 0 0 8px;
}

.btn-small {
    height: 32px;
    padding: 0 12px;
    font-size: 12.5px;
}

/* ---------- Activity page ---------- */

.activity-what {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: normal;
}

.activity-what .dot {
    flex: none;
    width: 8px;
    height: 8px;
}

/* "View all" in a card's header, and device names in tables that link somewhere */
.card-link {
    color: var(--navy);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.table-link {
    color: inherit;
    text-decoration: none;
}

.card-link:hover,
.table-link:hover {
    text-decoration: underline;
}

/* ---------- Reports ---------- */

.reports {
    display: grid;
    gap: 22px;
}

/* The cards may be narrower than the chart; on a phone the chart scrolls inside its card
   instead of making the whole page wider than the screen */
.reports > * {
    min-width: 0;
}

.chart-scroll {
    overflow-x: auto;
}

/* "Last 7 days" box on the Reports page, like the filter boxes */
.range-select {
    height: 40px;
    padding: 0 34px 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235d6670' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 16px;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    appearance: none;
    cursor: pointer;
}

.range-select:focus {
    border-color: var(--navy);
    outline: none;
    box-shadow: 0 0 0 3px rgba(44, 74, 110, .15);
}

.chart {
    display: block;
    width: 100%;
    min-width: 560px;
    height: auto;
    max-height: 380px; /* on wide screens the chart stays this tall, centered */
}

.chart text {
    fill: var(--text-muted);
    font-family: inherit;
    font-size: 12px;
}

.chart .day {
    fill: var(--text);
    font-size: 13px;
}

.chart .grid { stroke: #e6eaed; }
.chart .axis { stroke: #b9c0c6; }

.chart .line {
    fill: none;
    stroke-width: 2.5;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.chart .point {
    stroke: #fff;
    stroke-width: 1.5;
}

/* A light fill under the Online line */
.chart .area-online {
    fill: var(--chart-online);
    opacity: .1;
}

/* Days before NetTrack saved any numbers */
.chart .no-history { fill: #f3f5f7; }
.chart .no-history-text { font-size: 13px; }

/* Today's numbers at the end of the lines. Dark text, because bright green
   letters on white are hard to read; each number sits at the end of its line. */
.chart .end-value {
    fill: var(--text);
    font-size: 12.5px;
    font-weight: 700;
}

/* Point at a day: it lights up and shows that day's numbers */
.chart .day-hover {
    fill: transparent;
    cursor: default;
}

.chart .day-hover:hover { fill: rgba(44, 74, 110, .06); }

/* Only the day areas react to the mouse, so the whole day can be pointed at */
.chart .line, .chart .point, .chart .area-online, .chart .end-value, .chart .no-history, .chart .no-history-text {
    pointer-events: none;
}

/* One colour per status (--chart-online, ... at the top): the lines, their dots and the legend */
.chart .line-online { stroke: var(--chart-online); }
.chart .line-offline { stroke: var(--chart-offline); }
.chart .line-maintenance { stroke: var(--chart-maintenance); }
.chart .point-online, .swatch-online { fill: var(--chart-online); background: var(--chart-online); }
.chart .point-offline, .swatch-offline { fill: var(--chart-offline); background: var(--chart-offline); }
.chart .point-maintenance, .swatch-maintenance { fill: var(--chart-maintenance); background: var(--chart-maintenance); }

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    margin: 0 0 6px;
    padding: 0;
    color: var(--label);
    font-size: 13px;
    list-style: none;
}

.chart-legend li {
    display: flex;
    align-items: center;
    gap: 8px;
}

.swatch {
    width: 18px;
    height: 3px;
    border-radius: 2px;
}

.bars {
    display: grid;
    gap: 14px;
}

.bar-row {
    display: grid;
    grid-template-columns: 110px 1fr 72px;
    align-items: center;
    gap: 16px;
    font-size: 13px;
}

.bar-label {
    color: var(--label);
    font-weight: 700;
    text-decoration: none;
}

.bar-label:hover {
    color: var(--navy);
    text-decoration: underline;
}

/* "75%" after the count */
.bar-share {
    margin-left: 8px;
    color: var(--text-muted);
    font-weight: 400;
}

/* "None yet: Switches, Servers, ..." under the bars */
.bar-none {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 12.5px;
}

.bar-track {
    height: 18px;
    overflow: hidden;
    border-radius: 5px;
    background: var(--surface-muted);
}

.bar-fill {
    display: block;
    height: 100%;
    min-width: 4px;
    border-radius: 5px;
}

.bar-count {
    text-align: right;
}

/* ---------- Settings ---------- */

.settings-grid {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    gap: 22px;
    align-items: start;
}

.settings-nav {
    padding: 20px 14px;
}

.settings-nav .search {
    padding-bottom: 16px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.settings-nav .search .icon {
    top: 21px;
}

.settings-nav .search input {
    width: 100%;
    height: 40px;
    border-color: var(--border);
    background: var(--surface-muted);
}

.settings-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
}

.settings-link:hover {
    background: var(--surface-muted);
}

.settings-link.is-active {
    background: var(--sky-soft);
}

.settings-title {
    margin-bottom: 18px;
    color: var(--navy);
    font-size: 22px;
}

.settings-subtitle {
    margin: -12px 0 18px;
    color: var(--text-muted);
    font-size: 13px;
}

/* Settings -> Accounts: Email alerts and its on/off switch */

.email-alerts {
    margin-top: 20px;
}

.email-alerts h3 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.email-alerts-text {
    margin: 10px 0 14px;
    font-size: 13px;
}

.switch-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    cursor: pointer;
}

.switch {
    position: relative;
    flex: none;
    width: 42px;
    height: 24px;
    margin: 0;
    border-radius: 999px;
    background: var(--border);
    appearance: none;
    cursor: pointer;
    transition: background .2s;
}

.switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    transition: transform .2s;
}

.switch:checked {
    background: var(--online-text);
}

.switch:checked::after {
    transform: translateX(18px);
}

.switch:focus-visible {
    outline: 2px solid var(--navy);
    outline-offset: 2px;
}

.switch:disabled {
    cursor: wait;
    opacity: .6;
}

/* Settings -> Users: the accounts table and its Add / Edit popup */

.users-table td {
    vertical-align: middle;
}

.user-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-cell small {
    display: block;
    color: var(--text-muted);
    font-size: 11.5px;
}

/* The settings panel is narrow: emails wrap after the @, badges are only as wide as the word */
.users-table .user-email {
    white-space: normal;
}

.users-table .badge {
    min-width: 0;
    padding: 5px 9px;
}

.users-table th,
.users-table td {
    padding-right: 8px;
    padding-left: 8px;
}

.avatar-sm {
    flex: none;
    width: 32px;
    height: 32px;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
}

.tag {
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--sky-soft);
    color: var(--navy-dark);
    font-size: 11px;
    font-weight: 700;
}

.badge-admin { background: var(--sky-soft); color: var(--navy-dark); }
.badge-viewer { background: var(--surface-muted); color: var(--text-muted); }

.icon-btn-danger:hover {
    background: var(--offline-soft);
    color: var(--danger);
}

.icon-btn:disabled {
    opacity: .35;
    cursor: not-allowed;
}

.modal-fields {
    display: grid;
    gap: 14px;
    margin-top: 22px;
}

.panel {
    padding: 20px 22px;
    border-radius: 12px;
    background: var(--surface-muted);
}

.panel h3 {
    margin-bottom: 14px;
    color: var(--navy);
    font-size: 15px;
}

.about-grid,
.account-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    gap: 18px;
}

.account-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.about-brand {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-bottom: 16px;
}

.about-logo {
    display: grid;
    place-items: center;
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: var(--sky);
    color: var(--logo-ink);
    flex-shrink: 0;
}

.about-logo .logo {
    width: 64px;
    height: 64px;
}

.about-brand strong {
    display: block;
    font-size: 24px;
}

.about-brand small {
    color: var(--label);
    font-size: 12px;
    font-weight: 700;
}

.about-text {
    color: var(--label);
    font-size: 13px;
}

.info-list {
    display: grid;
    grid-template-columns: 100px 1fr;
    align-content: center;
    gap: 16px;
    margin: 0;
    font-size: 13px;
}

.info-list dt {
    color: var(--label);
    font-weight: 700;
}

.info-list dd {
    margin: 0;
    font-weight: 700;
}

.banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 18px;
}

.banner h3 {
    margin-bottom: 4px;
    color: var(--text);
    font-size: 17px;
}

.banner p {
    color: var(--text-muted);
    font-size: 13px;
}

.banner .network-art {
    width: 200px;
    height: auto;
}

.account-grid form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.account-grid h3 {
    margin-bottom: 0;
}

.account-grid .profile-head {
    margin-bottom: 4px;
}

.account-grid .btn {
    align-self: flex-start;
    margin-top: 6px;
}

.note {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 18px;
    padding: 14px 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #eef3f3;
    color: #3f4850;
    font-size: 12.5px;
}

.credits-head {
    margin-bottom: 20px;
    text-align: center;
}

.credits-head .icon {
    width: 40px;
    height: 40px;
}

.credits-head strong {
    display: block;
    color: var(--navy);
    font-size: 16px;
}

.credits-head small {
    color: var(--text-muted);
    font-weight: 700;
}

.credits-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.person {
    padding: 20px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    text-align: center;
}

.person .avatar {
    margin: 0 auto 10px;
    background: #5d6670;
}

.person .avatar .icon {
    width: 24px;
    height: 24px;
}

.person strong {
    display: block;
    color: var(--navy);
    font-size: 13px;
}

.person span {
    display: block;
    color: var(--label);
    font-size: 12px;
}

.credits-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-top: 22px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: #b06464;
    font-style: italic;
    font-weight: 700;
}

.credits-footer .icon {
    color: var(--navy);
    fill: var(--navy);
}

/* ---------- Login ---------- */

.auth {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    gap: 48px;
    max-width: 1200px;
    min-height: 100vh;
    margin: 0 auto;
    padding: 48px 56px;
}

.auth-form {
    width: 100%;
    max-width: 360px;
}

.auth-form .brand {
    margin-bottom: 40px;
}

.auth-form .brand-logo {
    width: 62px;
    height: 62px;
    border-radius: 14px;
}

.auth-form .brand-logo .logo {
    width: 46px;
    height: 46px;
}

.auth-form .brand strong {
    font-size: 28px;
}

.auth h1 {
    font-size: 42px;
    line-height: 1.1;
}

.auth .lead {
    margin: 6px 0 36px;
    font-size: 15px;
}

.auth form {
    display: grid;
    gap: 16px;
}

.auth .field input {
    height: 48px;
    border-color: transparent;
    background: var(--surface);
}

.auth .field label {
    font-size: 15px;
}

.auth .btn-block {
    margin-top: 16px;
}

.auth-panel {
    min-height: 600px;
    padding: 72px 52px;
    border-radius: 36px;
    background: var(--navy);
    color: #fff;
}

.auth-panel .eyebrow {
    color: #d6e2ee;
    font-size: 12px;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.auth-panel h2 {
    margin: 10px 0 8px;
    font-size: 30px;
    letter-spacing: .02em;
}

.auth-panel p {
    color: #d6e2ee;
    font-size: 13px;
}

.auth-panel .network-art {
    display: block;
    width: 100%;
    max-width: 320px;
    margin: 40px auto 0;
}

.network-art .node {
    transform-box: fill-box;
    transform-origin: center;
    animation: node-pulse 3s ease-in-out infinite;
}

.network-art .node-2 { animation-delay: .6s; }
.network-art .node-4 { animation-delay: 1.2s; }
.network-art .node-5 { animation-delay: 1.8s; }

@keyframes node-pulse {
    50% { transform: scale(1.15); }
}

@media (prefers-reduced-motion: reduce) {
    .network-art .node { animation: none; }
}

/* ---------- Smaller screens ---------- */

@media (max-width: 1150px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid,
    .about-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 16px;
    }

    .main { grid-column: 1; }

    .sidebar {
        position: static;
        height: auto;
        min-height: 0;
        padding: 12px 16px;
    }

    .sidebar-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0;
        margin: 0;
        border: 0;
    }

    .brand-logo { width: 42px; height: 42px; }
    .brand-logo .logo { width: 30px; height: 30px; }
    .sidebar .nav-toggle { display: inline-grid; }
    .nav { display: none; margin-top: 12px; }
    .sidebar.is-open .nav { display: flex; }

    .topbar-actions { width: 100%; }
    .search { flex: 1; }
    .search input { width: 100%; }

    .settings-grid,
    .account-grid { grid-template-columns: 1fr; }

    .auth {
        grid-template-columns: 1fr;
        padding: 40px 16px;
    }

    .auth-form { margin: 0 auto; }
    .auth-panel { display: none; }

    /* View popup: history below the details */
    .modal-wide { width: min(480px, calc(100vw - 32px)); }
    .view-grid { grid-template-columns: 1fr; }
    .history {
        padding: 20px 0 0;
        border-top: 1px solid var(--border);
        border-left: 0;
    }
}

@media (max-width: 600px) {
    .stats { gap: 12px; }
    .stat { padding: 16px; }
    .stat-value { font-size: 32px; }
    .card { padding: 18px 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .credits-grid { grid-template-columns: 1fr; }
    .user-chip-text { display: none; }
    .page-heading h1 { font-size: 22px; }
    .donut-wrap { justify-content: center; }
    .legend { min-width: 0; width: 100%; }
    .filters-count { width: 100%; margin-left: 0; }
    .bar-row { grid-template-columns: 90px 1fr 64px; gap: 10px; }
    .details { grid-template-columns: 105px minmax(0, 1fr); }
    /* Latest changes: "how long" goes under the time */
    .changes li { grid-template-columns: auto minmax(0, 1fr); row-gap: 0; }
    .changes li > .badge { grid-row: span 2; }
    .changes li > :last-child { font-size: 12.5px; }
    /* Scan network: the button goes under the network box */
    .scan-form { flex-direction: column; align-items: stretch; }
    .scan-form .btn { margin-top: 0; }
}

/* ---------- Printing (Reports page) ---------- */

@media print {
    body { background: #fff; }
    .app { display: block; padding: 0; }
    .sidebar,
    .topbar-actions,
    .no-print,
    .toast { display: none !important; }
    .card { box-shadow: none; border: 1px solid var(--border); break-inside: avoid; }
    .reports { gap: 16px; }
}
