:root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --text: #172033;
    --muted: #667085;
    --line: #d8dee8;
    --accent: #1769aa;
    --accent-dark: #105080;
    --ok: #087443;
    --danger: #b42318;
    --warn: #946200;
}

* {
    box-sizing: border-box;
}

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

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

button {
    height: 36px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    padding: 0 12px;
    font-weight: 650;
    cursor: pointer;
}

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

button.ghost {
    background: #fff;
    color: var(--accent);
}

button.small {
    height: 30px;
    padding: 0 9px;
    font-size: 12px;
}

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

.button-link {
    display: inline-flex;
    height: 36px;
    align-items: center;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    padding: 0 12px;
    font-weight: 650;
    text-decoration: none;
}

.button-link:hover {
    background: var(--accent-dark);
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    outline: none;
}

input,
select {
    height: 36px;
    padding: 0 9px;
}

textarea {
    min-height: 84px;
    padding: 9px;
    resize: vertical;
}

textarea.yaml {
    min-height: 520px;
    font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
}

label.check {
    display: flex;
    gap: 8px;
    align-items: center;
    color: var(--text);
    font-size: 14px;
}

label.check input {
    width: auto;
    height: auto;
}

label.setting-check {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 10px;
    align-items: start;
    color: var(--text);
    font-size: 14px;
}

label.setting-check .field-help {
    grid-column: 2;
}

.wide-field {
    margin-top: 12px;
}

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

.topbar div {
    display: flex;
    gap: 12px;
    align-items: baseline;
}

.topbar span {
    color: var(--muted);
}

.app {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    min-height: calc(100vh - 65px);
}

nav {
    border-right: 1px solid var(--line);
    background: #fff;
    padding: 16px;
}

nav a {
    display: block;
    border-radius: 6px;
    color: var(--text);
    padding: 9px 10px;
    text-decoration: none;
}

nav a.active,
nav a:hover {
    background: #eaf3fb;
    color: var(--accent-dark);
}

main {
    min-width: 0;
    padding: 22px;
}

.login-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 18px;
}

.login-panel {
    display: grid;
    width: min(420px, 100%);
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 20px;
}

h1,
h2 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    font-size: 24px;
}

h2 {
    font-size: 17px;
}

.section-head,
.hero {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: center;
    margin-bottom: 16px;
}

.section-head span {
    color: var(--muted);
    overflow-wrap: anywhere;
}

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

.panel h2 {
    margin-bottom: 14px;
}

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

.panel-head h2 {
    margin-bottom: 0;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(140px, 1fr));
    gap: 12px;
    width: min(560px, 100%);
}

.stats div {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 14px;
}

.stats span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.stats strong {
    display: block;
    margin-top: 4px;
    font-size: 26px;
}

.service-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(140px, 1fr));
    gap: 12px;
}

.service-grid div {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 12px;
}

.service-grid .wide {
    grid-column: span 2;
}

.service-grid.tunnel-grid {
    margin-top: 14px;
}

.service-grid.tunnel-grid code {
    display: block;
    max-width: none;
}

.service-grid span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.service-grid strong {
    display: block;
    margin-top: 4px;
    min-height: 20px;
    overflow-wrap: anywhere;
}

.service-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.logs-box {
    margin-top: 14px;
}

.logs-box pre {
    max-height: 360px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101828;
    color: #f2f4f7;
    padding: 12px;
    font: 12px/1.45 "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    white-space: pre-wrap;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 12px;
    align-items: end;
}

.api-form {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(320px, 2fr) minmax(260px, 1.5fr) auto;
    gap: 12px;
    align-items: end;
}

.api-response {
    max-height: 620px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101828;
    color: #f2f4f7;
    padding: 12px;
    font: 12px/1.5 "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    white-space: pre-wrap;
}

.api-meta {
    margin-bottom: 14px;
}

.settings-grid {
    display: grid;
    gap: 12px;
    align-items: start;
}

.settings-grid.one {
    grid-template-columns: 1fr;
}

.settings-grid.two {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.settings-grid.three {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.timing-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 12px;
    align-items: start;
}

textarea.proxies {
    min-height: 260px;
    font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    font-size: 13px;
    line-height: 1.45;
}

.hint {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.hint.no-margin {
    margin: 0;
}

.inline-hint {
    align-self: center;
    margin: 0;
}

.field-help {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.45;
}

.domain-check-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 12px;
}

.domain-check-results {
    margin-top: 14px;
    overflow-x: auto;
}

.domain-check-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 8px;
    color: var(--muted);
}

.domain-check-head strong {
    color: var(--text);
}

.mono {
    font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    font-size: 12px;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: 12px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    padding: 12px 16px;
    margin-bottom: 16px;
}

.sticky-actions span {
    color: var(--muted);
}

.collapsed-panel details {
    min-width: 0;
}

.form-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 12px;
}

.form-actions span {
    color: var(--muted);
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    color: var(--muted);
    font-size: 12px;
}

code {
    display: inline-block;
    max-width: 100%;
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
}

td code {
    display: block;
    max-width: 280px;
    margin-top: 4px;
}

.stack-table td {
    vertical-align: middle;
}

.stack-table td:first-child {
    min-width: 220px;
}

.badge {
    display: inline-flex;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 12px;
    font-weight: 700;
}

.badge.ok {
    background: #e6f6ee;
    color: var(--ok);
}

.badge.danger {
    background: #ffe9e7;
    color: var(--danger);
}

.badge.warn {
    background: #fff4d6;
    color: var(--warn);
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

details {
    min-width: 280px;
}

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

.edit-form {
    display: grid;
    gap: 10px;
    margin-top: 10px;
}

.alert {
    border: 1px solid #b7e4ce;
    border-radius: 8px;
    background: #ecfdf3;
    color: var(--ok);
    padding: 10px 12px;
    margin-bottom: 14px;
}

.alert.error {
    border-color: #f4b7b0;
    background: #fff1f0;
    color: var(--danger);
}

.package-modal {
    width: min(720px, calc(100vw - 32px));
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.22);
    padding: 18px;
    color: var(--text);
}

.package-modal::backdrop {
    background: rgba(15, 23, 42, 0.42);
}

.modal-head,
.modal-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.modal-head h2 {
    margin: 0;
    font-size: 20px;
}

#package-copy-text {
    width: 100%;
    min-height: 230px;
    border-color: #cbd5e1;
    background: #f8fafc;
    margin-top: 12px;
    font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    font-size: 13px;
    line-height: 1.45;
    resize: vertical;
}

.modal-form {
    margin-top: 14px;
}

.modal-form textarea {
    min-height: 120px;
}

.modal-actions {
    justify-content: flex-end;
    margin-top: 12px;
}

@media (max-width: 920px) {
    .app,
    .api-form,
    .form-grid,
    .settings-grid,
    .timing-grid,
    .service-grid,
    .stats {
        grid-template-columns: 1fr;
    }

    .service-grid .wide {
        grid-column: auto;
    }

    nav {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .topbar,
    .section-head,
    .hero {
        align-items: stretch;
        flex-direction: column;
    }
}
