:root {
    --bg: #f2f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --ink: #14212b;
    --muted: #66788a;
    --line: #dbe4ee;
    --navy: #0f2f4a;
    --navy-soft: #163d5f;
    --blue: #1b74c9;
    --blue-strong: #155fa8;
    --green: #15803d;
    --green-soft: #e8f7ee;
    --amber: #b45309;
    --amber-soft: #fff7e6;
    --red: #b91c1c;
    --red-soft: #fdecec;
    --shadow: 0 12px 34px rgba(15, 47, 74, 0.08);
    --radius: 16px;
    --radius-sm: 10px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--bg);
    font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.55;
}

a {
    color: var(--blue);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

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

h1 {
    margin-bottom: 8px;
    font-size: clamp(24px, 3vw, 34px);
    line-height: 1.15;
    letter-spacing: -0.02em;
}

h2 {
    margin-bottom: 14px;
    font-size: 18px;
}

code {
    padding: 2px 6px;
    border-radius: 6px;
    background: #eef3f8;
    color: #24445f;
    font-size: 0.92em;
}

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

.nowrap {
    white-space: nowrap;
}

[hidden] {
    display: none !important;
}

/* Topbar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    color: #eaf4ff;
    background: linear-gradient(120deg, var(--navy), var(--navy-soft));
    box-shadow: 0 8px 24px rgba(15, 47, 74, 0.2);
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 24px;
    width: min(1400px, calc(100% - 32px));
    min-height: 66px;
    margin: 0 auto;
}

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

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    color: #0f2f4a;
    background: linear-gradient(135deg, #a9e0ff, #5cc0ff);
    font-weight: 800;
    letter-spacing: -0.03em;
}

.brand-text {
    display: grid;
    line-height: 1.2;
}

.brand-text strong {
    font-size: 15px;
}

.brand-text small {
    color: #a9c7df;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
}

.nav a {
    padding: 9px 12px;
    border-radius: 9px;
    color: #c6dced;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
}

.nav a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.nav a.active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.14);
}

.userbox {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.user-name {
    color: #d9e9f6;
    font-size: 13px;
    font-weight: 600;
}

.logout-form {
    margin: 0;
}

/* Layout */

.container {
    width: min(1400px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 56px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.page-head h1 {
    margin-bottom: 4px;
}

.eyebrow {
    margin-bottom: 6px;
    color: var(--blue);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

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

.head-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.last-updated {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

/* Summary */

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

.summary-card {
    display: grid;
    gap: 4px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.summary-card span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.summary-card strong {
    font-size: 28px;
    line-height: 1;
    letter-spacing: -0.04em;
}

.summary-card small {
    color: var(--muted);
    font-size: 11px;
}

.summary-online {
    border-top: 4px solid var(--green);
}

.summary-stale {
    border-top: 4px solid var(--amber);
}

.summary-offline {
    border-top: 4px solid #94a3b8;
}

.summary-danger {
    border-top: 4px solid var(--red);
}

/* Panel */

.panel {
    margin-bottom: 20px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.panel-head h2 {
    margin: 0;
}

/* Toolbar and forms */

.toolbar {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.field {
    display: grid;
    gap: 6px;
    min-width: 150px;
}

.field-search {
    flex: 1 1 260px;
}

.field-small {
    min-width: 90px;
}

.field-wide {
    grid-column: 1 / -1;
}

.field-action {
    margin-left: auto;
}

.field label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

input,
select,
textarea {
    width: 100%;
    min-height: 40px;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--ink);
    background: var(--surface);
    font: inherit;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(27, 116, 201, 0.14);
}

input:disabled,
select:disabled {
    color: var(--muted);
    background: var(--surface-2);
}

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

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
}

.inline-form select {
    min-height: 34px;
    padding: 5px 8px;
    font-size: 12px;
}

.password-form input {
    width: 130px;
    min-height: 34px;
    padding: 5px 8px;
    font-size: 12px;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

/* Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--ink);
    background: var(--surface-2);
    font: inherit;
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:hover {
    text-decoration: none;
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    color: #ffffff;
    background: var(--blue);
    border-color: var(--blue);
}

.btn-primary:hover {
    background: var(--blue-strong);
    border-color: var(--blue-strong);
}

.btn-danger {
    color: #ffffff;
    background: var(--red);
    border-color: var(--red);
}

.btn-danger:hover {
    background: #991b1b;
    border-color: #991b1b;
}

.btn-ghost {
    color: var(--ink);
    background: var(--surface);
    border-color: var(--line);
}

.btn-ghost:hover {
    background: var(--surface-2);
}

.btn-sm {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

/* Alerts */

.alert {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

.alert-success {
    color: #14532d;
    border-color: #b7e4c7;
    background: var(--green-soft);
}

.alert-error {
    color: #7f1d1d;
    border-color: #f3c0c0;
    background: var(--red-soft);
}

.alert-warning {
    color: #78350f;
    border-color: #f5d9a8;
    background: var(--amber-soft);
}

.alert-info {
    color: #164e63;
    border-color: #bae6fd;
    background: #eef9ff;
}

.exit-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

/* Bulk bar */

.bulkbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding: 10px 14px;
    border: 1px solid #bcd7f2;
    border-radius: var(--radius-sm);
    background: #eef7ff;
    font-weight: 700;
}

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

/* Table */

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

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

.data-table th,
.data-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: var(--muted);
    background: var(--surface-2);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: #f9fcff;
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.col-check {
    width: 36px;
}

.col-check input {
    width: 16px;
    min-height: 16px;
}

.col-number {
    width: 110px;
    text-align: center;
}

.col-actions {
    width: 170px;
}

.data-table .empty {
    padding: 28px 16px;
    color: var(--muted);
    text-align: center;
}

.metadata {
    max-width: 320px;
    max-height: 180px;
    margin: 6px 0 0;
    padding: 8px;
    overflow: auto;
    border-radius: 8px;
    background: #0f2f4a;
    color: #dbeafe;
    font-size: 11px;
    white-space: pre-wrap;
}

/* Badges */

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.badge-success {
    color: #14532d;
    background: #dcfce7;
}

.badge-info {
    color: #164e63;
    background: #e0f2fe;
}

.badge-warning {
    color: #78350f;
    background: #fef3c7;
}

.badge-danger {
    color: #7f1d1d;
    background: #fee2e2;
}

.badge-muted {
    color: #475569;
    background: #e2e8f0;
}

.badge-neutral {
    color: #334155;
    background: #f1f5f9;
}

/* Pagination */

.pagination {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.page-link {
    display: inline-grid;
    place-items: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: var(--surface);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.page-link:hover {
    background: var(--surface-2);
    text-decoration: none;
}

.page-link.active {
    color: #ffffff;
    background: var(--blue);
    border-color: var(--blue);
}

/* Detail */

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

.detail-card h2 {
    margin-bottom: 14px;
}

.detail-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 9px 0;
    border-bottom: 1px dashed var(--line);
}

.detail-row:last-child {
    border-bottom: 0;
}

.detail-row > span:first-child {
    color: var(--muted);
    font-size: 12px;
}

.detail-row-stack {
    display: grid;
    align-items: start;
}

.code-block {
    display: block;
    max-width: 100%;
    padding: 8px;
    overflow-wrap: anywhere;
    background: #eef3f8;
    color: #24445f;
    font-size: 11px;
}

/* Timeline */

.timeline {
    margin: 0;
    padding: 0 0 0 8px;
    list-style: none;
}

.timeline-item {
    position: relative;
    display: flex;
    gap: 12px;
    padding: 0 0 18px 22px;
    border-left: 2px solid var(--line);
}

.timeline-item:last-child {
    padding-bottom: 0;
    border-left-color: transparent;
}

.timeline-dot {
    position: absolute;
    top: 4px;
    left: -7px;
    width: 12px;
    height: 12px;
    border: 2px solid var(--surface);
    border-radius: 50%;
    background: #94a3b8;
    box-shadow: 0 0 0 2px var(--line);
}

.timeline-item.event-success .timeline-dot {
    background: var(--green);
}

.timeline-item.event-info .timeline-dot {
    background: var(--blue);
}

.timeline-item.event-danger .timeline-dot {
    background: var(--red);
}

.timeline-item.event-muted .timeline-dot {
    background: #94a3b8;
}

.timeline-body {
    min-width: 0;
}

.timeline-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}

/* Modal */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(3px);
}

.modal {
    width: min(520px, 100%);
    padding: 24px;
    border-radius: 20px;
    background: var(--surface);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);
}

.modal h2 {
    margin-bottom: 8px;
}

.modal label {
    display: block;
    margin: 14px 0 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* Toast */

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 60;
    max-width: min(420px, calc(100% - 40px));
    padding: 12px 16px;
    border-radius: 12px;
    color: #ffffff;
    background: #0f2f4a;
    box-shadow: 0 20px 50px rgba(15, 47, 74, 0.3);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.toast-error {
    background: #991b1b;
}

.toast.toast-success {
    background: #166534;
}

/* Empty state */

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

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

/* Login */

.auth-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
    background:
        radial-gradient(circle at 15% 15%, rgba(92, 192, 255, 0.24), transparent 30rem),
        linear-gradient(135deg, #0b2236, #123d5c 55%, #1b5f8a);
}

.auth-shell {
    width: min(440px, 100%);
}

.auth-card {
    padding: clamp(26px, 5vw, 42px);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.35);
}

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

.auth-brand strong {
    display: block;
    font-size: 15px;
}

.auth-brand small {
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.auth-card h1 {
    margin-bottom: 8px;
    font-size: 28px;
}

.auth-lead {
    margin-bottom: 22px;
    color: var(--muted);
}

.auth-form {
    display: grid;
    gap: 8px;
}

.auth-form label {
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

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

.auth-note {
    margin: 18px 0 0;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.6;
}

/* Responsive */

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

    .topbar-inner {
        flex-wrap: wrap;
        padding: 10px 0;
        gap: 10px 18px;
    }

    .nav {
        order: 3;
        width: 100%;
        margin-left: 0;
        overflow-x: auto;
    }

    .userbox {
        margin-left: auto;
    }
}

@media (max-width: 760px) {
    .container {
        width: min(100% - 20px, 1400px);
        padding-top: 18px;
    }

    .page-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .head-actions {
        justify-content: flex-start;
    }

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

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

    .field-action {
        margin-left: 0;
    }

    .toolbar {
        align-items: stretch;
    }

    .field,
    .field-search,
    .field-small {
        flex: 1 1 100%;
    }

    .panel {
        padding: 16px;
    }

    .exit-banner {
        align-items: flex-start;
        flex-direction: column;
    }

    .user-name {
        display: none;
    }
}

@media (max-width: 460px) {
    .summary-grid {
        grid-template-columns: 1fr;
    }

    .brand-text small {
        display: none;
    }
}
