:root {
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI",
        sans-serif;
    color: #1f2937;
    background: #f5f7fb;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 320px;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

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

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 5%;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
}

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

.brand-icon {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border-radius: 12px;
    background: #1d4ed8;
    color: #ffffff;
    font-weight: 800;
    letter-spacing: -1px;
}

.brand h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.brand p {
    margin: 4px 0 0;
    color: #6b7280;
    font-size: 12px;
}

.device-status {
    display: flex;
    align-items: center;
    gap: 9px;
    color: #4b5563;
    font-size: 13px;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #9ca3af;
}

.container {
    width: min(1400px, 92%);
    margin: 32px auto;
}

.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.page-heading h2 {
    margin: 0;
    font-size: 27px;
    letter-spacing: -0.7px;
}

.page-heading p,
.panel-heading p {
    margin: 7px 0 0;
    color: #6b7280;
    font-size: 14px;
}

.button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 10px 15px;
    border: 1px solid transparent;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s ease;
}

.button-primary {
    background: #1d4ed8;
    color: #ffffff;
}

.button-primary:hover:not(:disabled) {
    background: #1e40af;
}

.button-secondary {
    border-color: #d1d5db;
    background: #ffffff;
    color: #374151;
}

.button-secondary:hover:not(:disabled) {
    background: #f3f4f6;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.summary-card {
    padding: 23px;
    border: 1px solid #e5e7eb;
    border-radius: 11px;
    background: #ffffff;
}

.summary-label {
    color: #6b7280;
    font-size: 13px;
    font-weight: 500;
}

.summary-value {
    margin-top: 15px;
    color: #111827;
    font-size: 32px;
    font-weight: 750;
    letter-spacing: -1px;
}

.device-address {
    font-size: 23px;
    letter-spacing: -0.5px;
}

.summary-description {
    margin-top: 8px;
    color: #9ca3af;
    font-size: 12px;
}

.panel {
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 11px;
    background: #ffffff;
}

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

.panel-heading h3 {
    margin: 0;
    font-size: 17px;
}

.result-count {
    color: #6b7280;
    font-size: 12px;
}

.filter-form {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
    gap: 15px;
    padding: 0 23px 23px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    color: #4b5563;
    font-size: 12px;
    font-weight: 600;
}

.form-group input,
.form-group select {
    width: 100%;
    min-height: 40px;
    padding: 9px 11px;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    background: #ffffff;
    color: #1f2937;
    outline: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgb(37 99 235 / 10%);
}

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

.table-wrapper {
    overflow-x: auto;
    border-top: 1px solid #e5e7eb;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    white-space: nowrap;
}

thead {
    background: #f9fafb;
}

th {
    padding: 14px 18px;
    color: #6b7280;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

td {
    padding: 15px 18px;
    border-top: 1px solid #f0f1f4;
    color: #374151;
    font-size: 13px;
}

tbody tr:hover {
    background: #fafbff;
}

.empty-state {
    padding: 42px 20px;
    color: #9ca3af;
    text-align: center;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 23px;
    border-top: 1px solid #e5e7eb;
    color: #6b7280;
    font-size: 12px;
}

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

.message {
    margin-bottom: 20px;
    padding: 13px 15px;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    background: #ffffff;
    color: #374151;
    font-size: 13px;
    overflow-wrap: anywhere;
}

.message.error {
    border-color: #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.message.success {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.hidden {
    display: none;
}

footer {
    padding: 24px 0 8px;
    color: #9ca3af;
    font-size: 12px;
    text-align: center;
}

@media (max-width: 1000px) {
    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

    .filter-actions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 650px) {
    .topbar,
    .page-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar {
        padding: 16px 4%;
    }

    .container {
        width: 94%;
        margin-top: 24px;
    }

    .page-heading h2 {
        font-size: 23px;
    }

    .summary-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .summary-card {
        padding: 18px;
    }

    .summary-value {
        font-size: 28px;
    }

    .filter-form {
        grid-template-columns: 1fr;
        padding: 0 16px 18px;
    }

    .filter-actions {
        grid-column: auto;
        flex-wrap: wrap;
    }

    .panel-heading {
        align-items: flex-start;
        flex-direction: column;
        padding: 18px 16px;
    }

    .pagination {
        align-items: flex-start;
        flex-direction: column;
        padding: 16px;
    }
}

/* Live synchronization overview */

.sync-overview {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.sync-item {
    display: flex;
    flex-direction: column;
    gap: 9px;
    min-width: 0;
    padding: 20px 23px;
    border: 1px solid #e5e7eb;
    border-radius: 11px;
    background: #ffffff;
}

.sync-label {
    color: #6b7280;
    font-size: 12px;
    font-weight: 600;
}

.sync-value {
    overflow-wrap: anywhere;
    color: #111827;
    font-size: 16px;
    font-weight: 700;
}

.sync-description {
    overflow-wrap: anywhere;
    color: #6b7280;
    font-size: 12px;
    line-height: 1.5;
}

.sync-value.sync-running {
    color: #b45309;
}

.sync-value.sync-success {
    color: #15803d;
}

.sync-value.sync-failed {
    color: #b91c1c;
}

.sync-value.sync-skipped {
    color: #6b7280;
}

.status-dot.status-success {
    background: #16a34a;
}

.status-dot.status-failed {
    background: #dc2626;
}

.status-dot.status-unknown {
    background: #9ca3af;
}

.status-dot.status-running {
    background: #d97706;
}

@media (max-width: 900px) {
    .sync-overview {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .sync-overview {
        grid-template-columns: 1fr;
    }
}

/* Real-time connection and live event feed */

.topbar-status {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 18px;
}

.live-indicator {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 11px;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    color: #4b5563;
    font-size: 12px;
    font-weight: 600;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
}

.live-dot.live-live {
    background: #16a34a;
    animation: live-pulse 2s ease-out infinite;
}

.live-dot.live-reconnecting {
    background: #d97706;
}

.live-dot.live-offline {
    background: #dc2626;
}

@keyframes live-pulse {
    0% {
        box-shadow: 0 0 0 0 rgb(22 163 74 / 45%);
    }

    100% {
        box-shadow: 0 0 0 8px rgb(22 163 74 / 0%);
    }
}

.live-panel {
    margin-bottom: 24px;
}

.live-feed {
    max-height: 320px;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    border-top: 1px solid #e5e7eb;
    list-style: none;
}

.feed-item {
    display: grid;
    grid-template-columns: 90px minmax(90px, 1fr) 110px 100px 110px 60px 90px;
    align-items: center;
    gap: 12px;
    padding: 11px 23px;
    border-top: 1px solid #f0f1f4;
    font-size: 13px;
}

.feed-item:first-child {
    border-top: 0;
}

.feed-time {
    color: #111827;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    white-space: nowrap;
}

.feed-user {
    overflow: hidden;
    color: #374151;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.feed-verify,
.feed-device,
.feed-received {
    overflow: hidden;
    color: #6b7280;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.feed-received {
    text-align: right;
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    background: #f3f4f6;
    color: #4b5563;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
}

.badge-in {
    background: #dcfce7;
    color: #166534;
}

.badge-out {
    background: #fee2e2;
    color: #991b1b;
}

.badge-adms {
    background: #dbeafe;
    color: #1e40af;
}

.badge-pull {
    background: #ede9fe;
    color: #5b21b6;
}

/* New rows flash, then fade back once the class is removed. */
.feed-item,
tbody tr {
    transition: background-color 1.5s ease;
}

.feed-item.is-new,
tbody tr.is-new {
    background: #fef9c3;
}

.result-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.button-new {
    min-height: 30px;
    padding: 5px 11px;
    background: #fef9c3;
    color: #854d0e;
    font-size: 12px;
}

.button-new:hover {
    background: #fef08a;
}

@media (max-width: 650px) {
    .feed-item {
        grid-template-columns: auto 1fr auto auto;
        gap: 8px;
        padding: 11px 16px;
    }

    /* With several devices, which one matters more than the source. */
    .feed-verify,
    .feed-item .badge-adms,
    .feed-item .badge-pull,
    .feed-item .badge-unknown,
    .feed-received {
        display: none;
    }
}

/* One card per configured device */

.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.device-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    padding: 20px 23px;
    border: 1px solid #e5e7eb;
    border-radius: 11px;
    background: #ffffff;
}

.device-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.device-name {
    flex: 1;
    overflow: hidden;
    color: #111827;
    font-size: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-meta {
    overflow-wrap: anywhere;
    color: #9ca3af;
    font-size: 12px;
}

.device-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
}

.device-row {
    display: grid;
    grid-template-columns: 80px 1fr;
    align-items: baseline;
    gap: 10px;
}

.device-row dt {
    color: #6b7280;
    font-size: 12px;
    font-weight: 600;
}

.device-row dd {
    min-width: 0;
    margin: 0;
}

.device-row .sync-value {
    font-size: 14px;
}

.device-error {
    padding: 8px 10px;
    border-radius: 7px;
    background: #fef2f2;
    color: #991b1b;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.button-small {
    min-height: 30px;
    padding: 5px 11px;
    font-size: 12px;
}

@media (max-width: 650px) {
    .device-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .device-card {
        padding: 18px;
    }
}


/* Sites, each with its own grid of device cards */

.site-list {
    display: flex;
    flex-direction: column;
    gap: 22px;
    margin-bottom: 24px;
}

.site-list > .device-card {
    max-width: 480px;
}

.site-group .device-grid {
    margin-bottom: 0;
}

.site-head {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin-bottom: 12px;
}

.site-head h3 {
    margin: 0;
    color: #111827;
    font-size: 16px;
}

.site-agent .sync-value {
    font-size: 12px;
}

.pending-banner {
    display: block;
    border-color: #fde68a;
    background: #fffbeb;
    color: #92400e;
    font-weight: 600;
    text-decoration: none;
}

.pending-banner:hover {
    background: #fef3c7;
}

.pending-banner.hidden {
    display: none;
}

/* Signed-in user */

.user-menu {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.user-menu a {
    text-decoration: none;
}

.user-name {
    padding: 0 4px;
    color: #4b5563;
    font-size: 12px;
    font-weight: 600;
}

.button-danger {
    border-color: #fecaca;
    background: #ffffff;
    color: #b91c1c;
}

.button-danger:hover:not(:disabled) {
    background: #fef2f2;
}

/* Sign-in page */

.login-body {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 16px;
}

.login-card {
    display: flex;
    flex-direction: column;
    gap: 22px;
    width: min(400px, 100%);
    padding: 30px;
    border: 1px solid #e5e7eb;
    border-radius: 11px;
    background: #ffffff;
}

.login-card .message {
    margin: 0;
}

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.stack-form h3 {
    margin: 0;
    font-size: 17px;
}

.stack-form .message {
    margin: 0;
}

/* Dialogs */

.dialog {
    width: min(460px, calc(100% - 32px));
    max-height: calc(100vh - 32px);
    padding: 24px;
    border: 1px solid #e5e7eb;
    border-radius: 11px;
    color: #1f2937;
    box-shadow: 0 20px 50px rgb(15 23 42 / 18%);
}

.dialog-wide {
    width: min(760px, calc(100% - 32px));
}

.dialog::backdrop {
    background: rgb(15 23 42 / 40%);
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

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

.form-row.hidden {
    display: none;
}

.form-row-actions {
    grid-template-columns: 1fr 1fr auto;
    align-items: end;
}

.code-block {
    margin: 0;
    padding: 12px 14px;
    overflow-x: auto;
    border-radius: 7px;
    background: #f3f4f6;
    color: #111827;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-all;
}

code {
    font-size: 12px;
}

/* Admin page */

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

.admin-nav a {
    padding: 8px 12px;
    border-radius: 7px;
    color: #1d4ed8;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.admin-nav a:hover {
    background: #eff6ff;
}

.panel-gap {
    margin-bottom: 24px;
    scroll-margin-top: 16px;
}

.panel.hidden {
    display: none;
}

.row-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

a.button {
    text-decoration: none;
}

.heading-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.panel-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 0 23px 18px;
}

.panel-toolbar .inline-input {
    flex: 0 1 380px;
    min-width: 0;
}

.panel-toolbar .sync-description {
    flex: 1 1 300px;
}

tr.unregistered td {
    color: #9ca3af;
}

.inline-input {
    min-height: 32px;
    padding: 5px 9px;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    background: #ffffff;
    font-size: 13px;
}

.command-result {
    max-width: 280px;
    overflow: hidden;
    color: #6b7280;
    font-size: 12px;
    text-overflow: ellipsis;
}

@media (max-width: 650px) {
    .login-card,
    .dialog {
        padding: 20px;
    }

    .form-row,
    .form-row-actions {
        grid-template-columns: 1fr;
    }

    .user-menu {
        width: 100%;
    }
}

.problems-banner ul {
    margin: 6px 0 0;
    padding-left: 18px;
}

.problems-banner li {
    margin-top: 2px;
}
