:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --surface: #fff;
    --border: #dfe3e8;
    --border-strong: #c9d0d8;
    --text: #20252b;
    --muted: #68727d;
    --accent: #1677ff;
    --accent-hover: #0868e2;
    --accent-soft: #eaf3ff;
    --success: #1f8b4c;
    --danger: #c73535;
    --shadow: 0 1px 2px rgba(26, 38, 54, .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    min-width: 320px;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 Arial, Helvetica, sans-serif;
    letter-spacing: 0;
}
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 64px;
    padding: 10px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    background: #17202a;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
}
.brand h1 { margin: 0; font-size: 18px; line-height: 1.2; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.topbar-spacer { flex: 1; }
.connection { display: flex; align-items: center; gap: 7px; color: var(--muted); white-space: nowrap; font-size: 12px; }
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: #aab2bb; }
.connection.ready .connection-dot { background: var(--success); }
.connection.error .connection-dot { background: var(--danger); }
.primary {
    min-height: 38px;
    padding: 0 18px;
    border: 1px solid var(--accent);
    border-radius: 5px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}
.primary:hover { background: var(--accent-hover); }
.primary:disabled { cursor: default; opacity: .55; }

.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 64px); }
.sidebar {
    position: sticky;
    top: 64px;
    align-self: start;
    height: calc(100vh - 64px);
    overflow: auto;
    padding: 20px 12px;
    background: var(--surface);
    border-right: 1px solid var(--border);
}
.nav-button {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 40px;
    margin: 2px 0;
    padding: 8px 12px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #414a54;
    text-align: left;
}
.nav-button:hover { background: #f2f4f6; }
.nav-button.active { background: var(--accent-soft); color: #075ec8; font-weight: 600; }
.content { width: 100%; max-width: 1180px; padding: 28px 36px 80px; }
.section {
    margin: 0 0 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow);
    scroll-margin-top: 84px;
}
.section-title { margin: 0; padding: 18px 22px; border-bottom: 1px solid var(--border); font-size: 16px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { min-width: 0; padding: 16px 22px 18px; border-bottom: 1px solid #edf0f2; }
.field:nth-child(odd) { border-right: 1px solid #edf0f2; }
.field:last-child, .field:nth-last-child(2):nth-child(odd) { border-bottom: 0; }
.field-wide { grid-column: 1 / -1; border-right: 0 !important; }
.field label { display: block; margin-bottom: 7px; color: #404954; font-size: 13px; font-weight: 600; }
.control {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: #fff;
    color: var(--text);
    outline: none;
}
.control:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(22,119,255,.12); }
textarea.control { min-height: 112px; resize: vertical; }
.password-row { display: flex; gap: 8px; }
.password-row .control { flex: 1; }
.secondary {
    min-width: 84px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: #fff;
    color: #3e4751;
}
.secret-state { display: block; min-height: 17px; margin-top: 5px; color: var(--success); font-size: 12px; }
.toggle-row { display: flex; align-items: center; min-height: 38px; }
.toggle { position: relative; width: 42px; height: 24px; flex: 0 0 auto; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { position: absolute; inset: 0; border-radius: 12px; background: #b9c1c9; transition: .18s; }
.toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .22);
    transition: .18s;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); }
.loading {
    position: fixed;
    inset: 64px 0 0;
    z-index: 30;
    display: grid;
    place-items: center;
    background: rgba(244, 246, 248, .9);
    color: var(--muted);
}
.loading.hidden { display: none; }
.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 40;
    max-width: min(430px, calc(100vw - 44px));
    padding: 13px 16px;
    border-radius: 5px;
    background: #202a35;
    color: #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.toast.error { background: #9f2828; }
.toast.hidden { display: none; }

@media (max-width: 850px) {
    .topbar { padding: 10px 14px; }
    .brand { min-width: 0; }
    .brand small, .connection { display: none; }
    .layout { display: block; }
    .sidebar {
        position: sticky;
        top: 64px;
        z-index: 15;
        display: flex;
        height: auto;
        padding: 8px;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }
    .nav-button { width: auto; flex: 0 0 auto; white-space: nowrap; }
    .content { padding: 16px 12px 60px; }
    .fields { grid-template-columns: 1fr; }
    .field { border-right: 0 !important; }
    .field:last-child { border-bottom: 0; }
}
