:root {
    --ink: #17232b;
    --muted: #63717a;
    --line: #dce3e6;
    --bg: #f4f7f6;
    --card: #ffffff;
    --brand: #176b5b;
    --brand-dark: #0f5145;
    --header: #102d2a;
    --danger: #a72f2f;
    --warning: #fff3cf;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(26, 42, 47, 0.04);
    color: var(--ink);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    line-height: 1.5;
}

[hidden] {
    display: none !important;
}

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

a:hover {
    text-decoration: underline;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    outline: 3px solid rgba(23, 107, 91, 0.28);
    outline-offset: 2px;
}

img,
svg {
    max-width: 100%;
}

h1,
h2,
h3,
p {
    overflow-wrap: anywhere;
}

h2 {
    margin-top: 0;
    font-size: 1.25rem;
}

h3 {
    margin-top: 0;
}

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

.topbar {
    position: sticky;
    z-index: 100;
    top: 0;
    display: flex;
    min-height: 68px;
    align-items: center;
    gap: 32px;
    padding: 0 max(20px, calc((100vw - 1200px) / 2));
    color: #ffffff;
    background: var(--header);
    box-shadow: 0 2px 10px rgba(6, 25, 22, 0.14);
}

.brand {
    flex: 0 0 auto;
    color: #ffffff;
    font-size: 1.08rem;
    font-weight: 750;
    white-space: nowrap;
}

.topbar nav {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 8px;
}

.topbar nav a {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    padding: 0 10px;
    border-radius: 7px;
    color: #d9e9e6;
    white-space: nowrap;
}

.topbar nav a:hover,
.topbar nav a[aria-current="page"] {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
    text-decoration: none;
}

.account {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 15px;
    font-size: 0.9rem;
}

.account small {
    display: block;
    color: #afc9c4;
}

.account form {
    margin: 0;
}

.nav-toggle {
    display: none;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: transparent;
}

.nav-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.nav-toggle-icon {
    display: flex;
    width: 20px;
    flex-direction: column;
    gap: 4px;
}

.nav-toggle-icon span {
    display: block;
    height: 2px;
    border-radius: 2px;
    background: #ffffff;
}

.container {
    width: min(100%, 1240px);
    margin: 0 auto;
    padding: 36px 20px 70px;
}

.page-heading,
.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 22px;
}

.page-heading > div,
.section-heading > div {
    min-width: 0;
}

.page-heading h1 {
    margin: 0.1em 0;
    font-size: clamp(1.65rem, 4vw, 2rem);
    line-height: 1.18;
}

.page-heading p,
.section-heading p {
    margin: 0.25em 0;
    color: var(--muted);
}

.eyebrow {
    color: var(--brand) !important;
    font-size: 0.72rem;
    font-weight: 750;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.card {
    min-width: 0;
    padding: 22px;
    margin-bottom: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
}

.card-link {
    display: block;
    color: inherit;
}

.card-link:hover {
    border-color: #9bc4bc;
    text-decoration: none;
}

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

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

.fields-inline,
.user-row {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    flex-wrap: wrap;
}

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(138px, 1fr));
    align-items: end;
    gap: 14px;
}

.filters label:first-of-type {
    grid-column: span 2;
}

.grow {
    flex: 1;
    min-width: 210px;
}

label {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 5px;
    color: #40515a;
    font-size: 0.87rem;
    font-weight: 650;
}

input,
select,
textarea,
button {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    padding: 9px 10px;
    border: 1px solid #b9c6cb;
    border-radius: 7px;
    color: var(--ink);
    background: #ffffff;
}

input[type="checkbox"],
input[type="radio"] {
    min-height: auto;
}

button {
    min-height: 42px;
    padding: 10px 15px;
    border: 0;
    border-radius: 7px;
    color: #ffffff;
    background: var(--brand);
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

button:hover {
    background: var(--brand-dark);
}

button.secondary {
    color: var(--ink);
    background: #e8efed;
}

button.danger,
.danger {
    background: var(--danger);
}

button.danger-link {
    padding: 7px;
    color: var(--danger);
    background: none;
}

.link-button {
    min-height: 38px;
    padding: 0;
    border: 0;
    color: #ffffff;
    background: none;
    text-decoration: underline;
}

.check {
    flex-direction: row;
    align-items: center;
    gap: 9px;
}

.check input {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
}

.table-wrap {
    max-width: 100%;
    overflow: auto;
    padding: 0;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.91rem;
}

th,
td {
    padding: 14px 15px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: #5a6870;
    background: #f9fbfa;
    font-size: 0.76rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

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

.strong {
    font-weight: 720;
}

.subtle {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.8rem;
}

.status,
.count {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 750;
    white-space: nowrap;
}

.status-unmanaged {
    color: #725308;
    background: #fff0c9;
}

.status-managed {
    color: #17643b;
    background: #d9f4e4;
}

.status-disabled {
    color: #535960;
    background: #e8e9eb;
}

.count {
    color: #31554e;
    background: #e5efed;
}

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

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

.metrics {
    display: flex;
    gap: 10px 20px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 0.88rem;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 22px;
}

.details-grid div {
    min-width: 0;
}

.details-grid dt {
    color: var(--muted);
    font-size: 0.78rem;
}

.details-grid dd {
    margin: 3px 0;
    overflow-wrap: anywhere;
    font-weight: 650;
}

.list-item {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.list-item > :first-child {
    min-width: 0;
}

.list-item:last-child {
    border-bottom: 0;
}

.list-item form {
    flex: 0 0 auto;
    margin: 0;
}

.rule-summary {
    margin: 0;
    overflow-wrap: anywhere;
}

.top-gap {
    margin-top: 18px;
}

.warning,
.notice {
    padding: 12px 14px;
    border-radius: 8px;
    color: #674c08;
    background: var(--warning);
}

.notice {
    color: #31515e;
    background: #e9f1f5;
}

.danger-zone {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px;
    margin-top: 28px;
    border: 1px solid #e6b6b6;
    border-radius: var(--radius);
}

.danger-zone p {
    margin: 0;
}

.management-panel {
    max-width: 650px;
    margin-top: 30px;
}

.login-page {
    display: grid;
    min-height: 100vh;
    padding: 16px;
    place-items: center;
    background: #e9f0ee;
}

.login-card {
    width: min(430px, 100%);
    padding: 38px;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 15px 45px rgba(15, 49, 44, 0.12);
}

.login-card h1 {
    margin: 0.2em 0;
    font-size: 2rem;
}

.audit-event {
    display: grid;
    grid-template-columns: minmax(150px, 180px) minmax(0, 1fr);
    gap: 20px;
}

.audit-event h2 {
    margin: 0;
}

.audit-event p {
    margin: 0.25em 0;
}

.audit-event details {
    margin-top: 12px;
}

.audit-event summary {
    min-height: 40px;
    padding: 8px 0;
    cursor: pointer;
}

.audit-event pre {
    max-width: 100%;
    overflow: auto;
    padding: 12px;
    border-radius: 7px;
    background: #f3f5f5;
    font-size: 0.78rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 15px;
    color: var(--muted);
}

.pagination a {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #ffffff;
}

.rule-builder {
    max-width: 720px;
    margin-top: 20px;
}

.user-row > label {
    flex: 1 1 150px;
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    overflow-wrap: anywhere;
}

@media (max-width: 900px) {
    .topbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0 12px;
        padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
    }

    .brand {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-toggle {
        display: inline-flex;
    }

    .topbar nav {
        display: none;
        grid-column: 1 / -1;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        padding: 10px 0;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
        margin-top: 10px;
    }

    .topbar nav.is-open {
        display: flex;
    }

    .topbar nav a {
        min-height: 46px;
        padding: 0 12px;
    }

    .account {
        grid-column: 1 / -1;
        justify-content: space-between;
        padding-top: 9px;
        margin-top: 8px;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
    }

    .cards-grid,
    .two-column {
        grid-template-columns: minmax(0, 1fr);
    }

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

@media (max-width: 700px) {
    .container {
        padding: 26px 14px max(50px, env(safe-area-inset-bottom));
    }

    .page-heading,
    .section-heading {
        flex-direction: column;
        gap: 12px;
    }

    .card {
        padding: 17px;
        margin-bottom: 16px;
    }

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

    .filters label:first-of-type {
        grid-column: 1 / -1;
    }

    .filters button {
        width: 100%;
    }

    input,
    select,
    textarea {
        min-height: 44px;
        font-size: 16px;
    }

    button {
        min-height: 44px;
    }

    .server-table {
        overflow: visible;
        padding: 0;
        border: 0;
        background: transparent;
        box-shadow: none;
    }

    .server-table table,
    .server-table tbody,
    .server-table tr,
    .server-table td {
        display: block;
        width: 100%;
    }

    .server-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
    }

    .server-table tr {
        padding: 5px 15px;
        margin-bottom: 14px;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: #ffffff;
        box-shadow: var(--shadow);
    }

    .server-table td {
        display: grid;
        grid-template-columns: minmax(82px, 0.38fr) minmax(0, 1fr);
        gap: 10px;
        align-items: start;
        padding: 10px 0;
        border-bottom: 1px solid var(--line);
        overflow-wrap: anywhere;
    }

    .server-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 0.75rem;
        font-weight: 750;
        letter-spacing: 0.03em;
        text-transform: uppercase;
    }

    .server-table td:first-child {
        grid-template-columns: 1fr;
        padding-top: 13px;
        font-size: 1rem;
    }

    .server-table td:first-child::before {
        display: none;
    }

    .server-table td:last-child {
        border-bottom: 0;
    }

    .server-table td.empty {
        display: block;
        text-align: center;
    }

    .server-table td.empty::before {
        display: none;
    }

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

    .audit-event {
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
    }

    .danger-zone {
        flex-direction: column;
        align-items: stretch;
    }

    .pagination {
        justify-content: space-between;
        gap: 8px;
    }

    .pagination span {
        text-align: center;
        font-size: 0.82rem;
    }
}

@media (max-width: 520px) {
    .filters {
        grid-template-columns: minmax(0, 1fr);
    }

    .filters label:first-of-type {
        grid-column: auto;
    }

    .fields-inline,
    .user-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch;
        width: 100%;
    }

    .fields-inline > *,
    .user-row > * {
        width: 100%;
        min-width: 0;
    }

    .fields-inline .check,
    .user-row .check {
        min-height: 44px;
    }

    .details-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 13px;
    }

    .details-grid div {
        padding-bottom: 10px;
        border-bottom: 1px solid var(--line);
    }

    .details-grid div:last-child {
        border-bottom: 0;
    }

    .list-item {
        align-items: flex-start;
    }

    .rule-builder {
        max-width: none;
    }

    .login-card {
        padding: 26px 20px;
    }

    .login-card button,
    .management-panel button {
        width: 100%;
    }

    .pagination a {
        padding: 8px 10px;
        font-size: 0.86rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
