:root {
    --bg: #f0f3f7;
    --panel: #ffffff;
    --panel-soft: #f7fafc;
    --line: #dfe7ee;
    --line-strong: #c5d2df;
    --text: #1f2a37;
    --muted: #536678;
    --primary: #1f5e86;
    --primary-soft: #edf5ff;
    --success: #1b7a33;
    --success-soft: #ebf8ef;
    --danger: #b42318;
    --danger-soft: #fff1f0;
    --shadow: 0 3px 12px rgba(15, 31, 48, 0.06);
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    min-height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

body {
    display: flex;
    min-height: 100vh;
}

.settings-shell {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 22px;
    background: #fff;
    color: var(--text);
    border-bottom: 1px solid var(--line);
    box-shadow: none;
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-icon {
    width: 150px;
    height: 50px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: #edf3fb;
    border: 1px solid var(--line);
    overflow: hidden;
    text-decoration: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.brand-logo {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 3px;
}

.brand-title {
    font-weight: 700;
    font-size: 1.02rem;
    white-space: nowrap;
    color: var(--primary);
}

.brand-sub {
    font-size: 0.72rem;
    opacity: 0.8;
    white-space: nowrap;
    color: var(--muted);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 999px;
    background: #f5f8ff;
    border: 1px solid var(--line);
    color: var(--text);
    font-size: 0.8rem;
    white-space: nowrap;
}

.nav-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 999px;
    background: var(--primary-soft);
    border: 1px solid #cfe1f8;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 700;
    transition: filter 0.15s ease, transform 0.15s ease;
}

.nav-back-btn:hover {
    filter: brightness(0.98);
    transform: translateY(-1px);
}

.primary-btn, .secondary-btn, .ghost-btn {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.15s ease;
}

.primary-btn {
    background: #0f6d52;
    border-color: #0f6d52;
    color: #fff;
}

.primary-btn:disabled,
.primary-btn.is-disabled {
    opacity: 0.42;
    cursor: not-allowed;
    filter: grayscale(0.18);
    transform: none;
    box-shadow: none;
    background: #8a99a4;
    border-color: #94a1ad;
}

.primary-btn.is-dirty:not(:disabled) {
    background: #0f6d52;
    border-color: #0f6d52;
    box-shadow: 0 0 0 3px rgba(31, 94, 134, 0.10);
}

.primary-btn.saved {
    background: #1b7a33;
    border-color: #1b7a33;
    box-shadow: 0 0 0 3px rgba(27, 122, 51, 0.14);
}

.secondary-btn {
    background: #edf5ff;
    border-color: #cfe0f9;
    color: var(--primary);
}

.ghost-btn {
    background: #fff;
    color: var(--text);
    border-color: var(--line);
}

.primary-btn:hover, .secondary-btn:hover, .ghost-btn:hover {
    filter: brightness(0.98);
    transform: translateY(-1px);
}

.layout {
    display: flex;
    flex: 1;
    min-height: 0;
}

.sidebar {
    width: 250px;
    background: #f8fafc;
    border-right: 1px solid var(--line);
    flex-shrink: 0;
}

.sidebar-header {
    padding: 16px 14px 12px;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    background: #f5f9fc;
    border-bottom: 1px solid var(--line);
}

.side-menu {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 10px;
}

.menu-item {
    width: 100%;
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    border-radius: 10px;
    padding: 10px 12px;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.menu-item:hover {
    background: #f2f7fb;
    border-color: var(--line);
}

.menu-item.active {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: #cfe1f8;
}

.content {
    flex: 1;
    padding: 22px;
    min-width: 0;
}

.settings-section {
    display: none;
}

.settings-section.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: linear-gradient(180deg, #f8fbff 0%, #f3f7fb 100%);
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
}

.panel-header h2 {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--primary);
}

.panel-body {
    padding: 18px 16px;
}

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

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.field label {
    font-size: 0.77rem;
    font-weight: 700;
    color: var(--muted);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    background: #fff;
    border-radius: 8px;
    padding: 9px 10px;
    font-size: 0.9rem;
    color: var(--text);
    outline: none;
    box-shadow: inset 0 1px 1px rgba(31, 42, 55, 0.02);
}

.password-input-wrap {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.password-input-wrap input {
    flex: 1 1 220px;
}

.password-toggle-btn,
.password-generate-btn {
    white-space: nowrap;
    padding: 8px 10px;
    min-width: 110px;
}

.password-hint {
    padding: 8px 10px;
    border-radius: 8px;
    background: #f7f9fc;
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.5;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: #7aa8d8;
    box-shadow: 0 0 0 3px rgba(113, 161, 214, 0.12);
}

.field textarea {
    min-height: 100px;
    resize: vertical;
}

.full-span {
    grid-column: 1 / -1;
}

.section-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.74rem;
    font-weight: 700;
    border: 1px solid transparent;
}

.status-badge.active {
    background: var(--success-soft);
    color: var(--success);
    border-color: #bddfc5;
}

.status-badge.disabled {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: #efc0b9;
}

.access-list {
    display: grid;
    gap: 12px;
}

.station-list {
    display: grid;
    gap: 10px;
}

.station-option {
    width: 100%;
    text-align: left;
    background: var(--panel-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    cursor: pointer;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    transition: all 0.15s ease;
}

.station-option:hover,
.station-option.active {
    background: var(--primary-soft);
    border-color: #cfe1f8;
    box-shadow: 0 0 0 2px rgba(31, 94, 134, 0.05);
}

.station-option .station-name {
    font-weight: 700;
    min-width: 180px;
}

.station-option .station-meta {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.access-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-soft);
    flex-wrap: wrap;
}

.station-name {
    font-weight: 700;
    min-width: 180px;
}

.check-group {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

.check-wrap {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 600;
}

.check-wrap input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.placeholder-box {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    padding: 24px;
    border: 1px dashed var(--line-strong);
    border-radius: 12px;
    background: linear-gradient(135deg, #fafcff, #f4f7fb);
    color: var(--muted);
    text-align: center;
    font-weight: 600;
}

.mini-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 16px;
}

.mini-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-soft);
    padding: 14px 12px;
}

.mini-card .kicker {
    display: block;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 800;
    margin-bottom: 8px;
}

.mini-card strong {
    font-size: 1.1rem;
    color: var(--primary);
}

@media (max-width: 900px) {
    .layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }

    .side-menu {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        white-space: nowrap;
        padding: 12px 10px;
    }

    .menu-item {
        min-width: 150px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .mini-grid {
        grid-template-columns: 1fr;
    }

    .content {
        padding: 16px;
    }
}

@media (max-width: 560px) {
    .topbar {
        padding: 12px 14px;
    }

    .brand-sub {
        display: none;
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .access-row {
        align-items: flex-start;
        flex-direction: column;
    }
}