* {
    box-sizing: border-box;
}

:root {
    --bg-main: #f3f4f6;
    --bg-surface: #ffffff;
    --bg-surface-soft: #f8fafc;
    --border: #e5e7eb;
    --text-main: #111827;
    --text-muted: #6b7280;
    --accent: #1d4ed8;
    --accent-soft: #eff6ff;
    --ok: #166534;
    --warn: #b45309;
    --danger: #b91c1c;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
}

::selection {
    background: rgba(37, 99, 235, 0.24);
}

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

a:hover {
    color: #1e40af;
}

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

.container {
    max-width: 1160px;
    margin: 0 auto;
    padding: 20px 16px 30px;
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 18px;
    padding: 10px 4px;
    border-bottom: 1px solid #e5e7eb;
}

.topbar h1 {
    margin: 0 0 4px 0;
    font-size: 1.55rem;
    letter-spacing: -0.01em;
}

.topbar p {
    margin: 0;
}

.topbar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.topbar nav a {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #ffffff;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    color: #374151;
    font-size: 0.85rem;
    font-weight: 600;
}

.topbar nav a:hover {
    border-color: #cbd5e1;
    background: #f9fafb;
    color: #111827;
}

.topbar nav a.active {
    border-color: #111827;
    background: #111827;
    color: #f9fafb;
}

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: 0 3px 14px rgba(17, 24, 39, 0.06);
}

.card h2,
.card h3 {
    margin-top: 0;
    margin-bottom: 10px;
}

.card.narrow {
    max-width: 430px;
}

.page-intro {
    margin-bottom: 16px;
}

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

.kpi-grid .card {
    margin-bottom: 0;
    background: var(--bg-surface-soft);
}

.kpi-grid .card p {
    font-size: 1.8rem;
    margin: 4px 0 0 0;
    font-weight: 650;
}

.kpi-grid .card h3 {
    margin-bottom: 4px;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: #d1d5db #f3f4f6;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 980px;
}

th, td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    text-align: left;
    font-size: 0.92rem;
}

th {
    color: #374151;
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.84rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f9fafb;
}

tbody tr:hover {
    background: #f8fafc;
}

input, select, button, textarea {
    width: 100%;
    padding: 9px 10px;
    border-radius: 10px;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: var(--text-main);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
    font-size: 0.9rem;
}

input:focus, select:focus, button:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.16);
}

button {
    margin-top: 8px;
    font-weight: 600;
    cursor: pointer;
    width: auto;
    min-width: 140px;
    background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
    border-color: #2563eb;
    color: #eff6ff;
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.22);
}

button:hover {
    filter: brightness(1.04);
}

button.danger {
    background: linear-gradient(180deg, #dc2626 0%, #b91c1c 100%);
    border-color: #b91c1c;
}

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

.grid-form.compact {
    margin-top: 8px;
}

.grid-form label {
    display: grid;
    gap: 6px;
    font-size: 0.85rem;
    color: #4b5563;
    font-weight: 600;
}

select {
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, #6b7280 50%),
        linear-gradient(135deg, #6b7280 50%, transparent 50%);
    background-position:
        calc(100% - 18px) calc(50% - 2px),
        calc(100% - 12px) calc(50% - 2px);
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    padding-right: 30px;
}

.actions-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
}

.checkbox input {
    width: auto;
}

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge.ok {
    background: #ecfdf3;
    border-color: #bbf7d0;
    color: #166534;
}

.badge.error {
    background: #fff7ed;
    border-color: #fed7aa;
    color: #b45309;
}

.badge.critical {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

.badge.muted {
    background: #f3f4f6;
    border-color: #d1d5db;
    color: #6b7280;
}

.error {
    color: #991b1b;
    background: #fef2f2;
    border: 1px solid #fecaca;
    padding: 9px 10px;
    border-radius: 8px;
}

.success {
    color: #166534;
    background: #ecfdf3;
    border: 1px solid #bbf7d0;
    padding: 9px 10px;
    border-radius: 8px;
}

pre {
    margin: 8px 0 0 0;
    white-space: pre-wrap;
    color: #374151;
}

.message-cell {
    min-width: 300px;
    max-width: 560px;
}

.message-cell-main {
    width: 50%;
}

.message-cell pre {
    margin: 0;
    max-height: 14em;
    overflow: auto;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #f9fafb;
}

.stacked-cell {
    min-width: 220px;
}

.stacked-cell p {
    margin: 0 0 6px 0;
    color: #374151;
    font-size: 0.86rem;
}

.stacked-cell p:last-child {
    margin-bottom: 0;
}

.stacked-title {
    font-weight: 700;
    color: #111827;
    margin-bottom: 8px;
}

details summary {
    cursor: pointer;
    color: var(--accent);
    font-weight: 500;
}

details[open] summary {
    margin-bottom: 6px;
}

.table-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}

@media (max-width: 760px) {
    .container {
        padding: 14px 12px 22px;
    }

    .topbar h1 {
        font-size: 1.4rem;
    }

    table {
        min-width: 960px;
    }
}
