:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1f2933;
    --muted: #5f6b7a;
    --border: #d9dee5;
    --primary: #1d4ed8;
    --primary-text: #ffffff;
    --ok-bg: #e7f6ec;
    --ok-text: #14532d;
    --error-bg: #fdecec;
    --error-text: #8a1c1c;
    --wait-bg: #fff6db;
    --wait-text: #7a5a00;
    --focus: #f59e0b;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12161c;
        --surface: #1c222b;
        --text: #e6e9ee;
        --muted: #a3adbb;
        --border: #313a46;
        --primary: #6c9cff;
        --primary-text: #0b1020;
        --ok-bg: #12301d;
        --ok-text: #b7ebc8;
        --error-bg: #3a1717;
        --error-text: #ffc9c9;
        --wait-bg: #3a3011;
        --wait-text: #ffe39a;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

.top { background: var(--surface); border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.top__inner { display: flex; align-items: center; justify-content: space-between; min-height: 56px; gap: 16px; flex-wrap: wrap; }
.top__nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--primary); }

h1 { font-size: 1.5rem; margin: 0 0 12px; }
a { color: var(--primary); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 16px; }
.narrow { max-width: 480px; margin-left: auto; margin-right: auto; }
.muted { color: var(--muted); }

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

.form { display: flex; flex-direction: column; gap: 6px; }
.form label { font-weight: 600; margin-top: 10px; }
.form input {
    font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg); color: var(--text);
}
.form textarea, .form select, .filters input, .filters select {
    font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg); color: var(--text);
}
.form textarea { min-height: 140px; resize: vertical; }
.form input[type="file"] { padding: 8px; }
.form input[aria-invalid="true"], .form textarea[aria-invalid="true"], .form select[aria-invalid="true"] { border-color: var(--error-text); }
.form .check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-top: 10px; }
.form .check input { width: 18px; height: 18px; }
.form fieldset { border: 0; padding: 0; margin: 10px 0 0; }
.form legend { font-weight: 600; padding: 0; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 16px; }
.hint { font-size: 0.9rem; color: var(--muted); margin: 0; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters .button { margin-top: 0; }
.button--secondary { background: var(--surface); color: var(--primary); border: 1px solid var(--border); }
.button-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.button-row .button { margin-top: 0; }
.contacts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.message-body { white-space: pre-wrap; margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
pre.example { background: var(--bg); padding: 12px; border-radius: 6px; overflow-x: auto; font-size: 0.9rem; margin: 8px 0 0; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.form__actions { display: flex; align-items: center; gap: 16px; margin-top: 16px; }
.field-error { color: var(--error-text); margin: 0; font-size: 0.9rem; }

.button {
    display: inline-block; font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 6px; border: 0;
    background: var(--primary); color: var(--primary-text); text-decoration: none; cursor: pointer; margin-top: 12px;
}
.page-head .button { margin-top: 0; }
.link { font: inherit; background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; text-decoration: underline; }
.link--danger { color: var(--error-text); }
.inline { display: inline; }

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

.alert { padding: 12px 16px; border-radius: 6px; margin: 0 0 16px; }
.alert--ok { background: var(--ok-bg); color: var(--ok-text); }
.alert--error { background: var(--error-bg); color: var(--error-text); }

.table-wrap { overflow-x: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; display: flex; gap: 16px; }

.badge { font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.status { font-size: 0.85rem; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.status--on { background: var(--ok-bg); color: var(--ok-text); }
.status--off { background: var(--error-bg); color: var(--error-text); }
.status--wait { background: var(--wait-bg); color: var(--wait-text); }

.debug { white-space: pre-wrap; font-size: 0.85rem; background: var(--bg); padding: 12px; border-radius: 6px; }

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

@media (max-width: 640px) {
    td.actions { flex-direction: column; gap: 8px; }
    .grid-2 { grid-template-columns: 1fr; }
}
