:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --line: #e3e6ea;
    --text: #16191d;
    --muted: #6b7280;
    --up: #16a34a;
    --down: #dc2626;
    --warn: #d97706;
    --accent: #2563eb;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1117;
        --card: #161b22;
        --line: #2b313a;
        --text: #e6edf3;
        --muted: #9aa4b2;
    }
}

* { box-sizing: border-box; }

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

.top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}

.brand { font-weight: 600; text-decoration: none; color: var(--text); }
.top nav a { margin-left: 16px; color: var(--muted); text-decoration: none; }
.top nav a:hover { color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 24px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 20px;
}

.narrow { max-width: 380px; margin: 60px auto; }
.narrow h1 { margin: 0 0 12px; font-size: 20px; }

.add { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.add input[type=text] { flex: 1 1 200px; }
.add button { flex: 0 0 auto; }

input[type=text], input[type=password], input[type=number], select {
    width: 100%;
    height: 40px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

select { appearance: none; padding-right: 30px;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                      linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 17px) 17px, calc(100% - 12px) 17px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

/* Высота кнопки совпадает с высотой поля — иначе в одной строке
   с полем ввода кнопка оказывается выше и строка «плывёт». */
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
}

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

.actions button {
    height: 30px;
    padding: 0 10px;
    background: var(--card);
    color: var(--text);
    font-size: 13px;
}
.actions button.danger:hover { border-color: var(--down); color: var(--down); }
.actions form { display: flex; gap: 6px; justify-content: flex-end; }

.flash { padding: 11px 14px; border-radius: 8px; margin: 0 0 18px; }
.flash-ok { background: rgba(22, 163, 74, .12); color: var(--up); }
.flash-error { background: rgba(220, 38, 38, .12); color: var(--down); }

.summary { margin: 0 0 14px; color: var(--muted); }
.summary .up { color: var(--up); }
.summary .down { color: var(--down); }

table.sites { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.sites th, table.sites td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.sites th { font-size: 13px; color: var(--muted); font-weight: 500; }
table.sites tr:last-child td { border-bottom: none; }
table.sites td.actions { text-align: right; width: 1%; }

/* Числа и даты не должны ломаться на две строки: «143 мс» и
   «23 ч 30 мин назад» читаются только целиком. */
table.sites th, table.sites td { white-space: nowrap; }
table.sites th:first-child, table.sites td:first-child { white-space: normal; }

/* Название сайта забирает свободное место, остальные колонки — по содержимому. */
table.sites.list td:first-child, table.sites.list th:first-child { width: 34%; }
table.sites.list td:nth-child(2), table.sites.list th:nth-child(2) { min-width: 200px; }
table.sites tr.down { background: rgba(220, 38, 38, .05); }
table.sites tr.paused { opacity: .6; }
table.sites a { color: var(--text); text-decoration: none; font-weight: 500; }
table.sites a:hover { color: var(--accent); }

.url { display: block; font-size: 12px; color: var(--muted); }
/* Причина падения в одну строку с многоточием: полный текст в подсказке
   и на странице сайта. Иначе длинная причина раздувает строку таблицы. */
.why {
    display: block;
    max-width: 230px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    color: var(--muted);
}

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; }
.badge-up { background: rgba(22, 163, 74, .15); color: var(--up); }
.badge-down { background: rgba(220, 38, 38, .15); color: var(--down); }
.badge-paused { background: rgba(107, 114, 128, .15); color: var(--muted); }
.badge-unknown { background: rgba(217, 119, 6, .15); color: var(--warn); }

.hint { color: var(--muted); font-size: 13px; }
.hint a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line); }
.hint a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* Второстепенное действие не должно кричать так же, как основное. */
button.secondary { background: var(--card); color: var(--text); }
button.secondary:hover { border-color: var(--accent); color: var(--accent); filter: none; }
.last-run { margin-top: 18px; }

.field { margin-bottom: 16px; }

.field label {
    display: flex;
    align-items: flex-end;
    min-height: 2.4em;
    margin-bottom: 6px;
    font-size: 13px;
    line-height: 1.25;
    color: var(--muted);
}

.row {
    display: grid;
    /* auto-fill, а не auto-fit: пустые колонки сохраняются, поэтому ширина
       поля одинакова во всех разделах, сколько бы их в строке ни было. */
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    align-items: end;
}

.row .field { margin-bottom: 0; }

/* Заголовки разделов внутри карточки отбиваются линией. */
.card > .page-title {
    margin: 26px 0 14px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}

.card > .page-title:first-of-type { margin-top: 6px; }

.card > .row + button, .card > .field + button { margin-top: 20px; }

/* Ряд кнопок без подписей — выравниваем по левому краю с общим отступом. */
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.button-row + .hint { margin-top: 12px; }

/* Карточка под одиночное узкое поле — пароль во всю ширину экрана не нужен. */
.card.compact { max-width: 440px; }
.page-title { font-size: 19px; margin: 24px 0 8px; }
.page-title:first-child { margin-top: 0; }
