:root {
    --ink: #18212b;
    --muted: #66727f;
    --line: #dfe4e8;
    --surface: #ffffff;
    --canvas: #f4f6f7;
    --nav: #172126;
    --accent: #087f5b;
}

* {
    letter-spacing: 0;
}

body {
    margin: 0;
    background: var(--canvas);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
}

.sidebar {
    background: var(--nav);
    color: #fff;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    text-decoration: none;
    font-weight: 700;
    font-size: 17px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    background: #21a179;
    color: #fff;
    border-radius: 6px;
}

.sidebar .nav {
    margin-top: 30px;
}

.sidebar .nav-link {
    color: #cbd3d7;
    display: flex;
    gap: 11px;
    align-items: center;
    padding: 10px 11px;
    border-radius: 6px;
    font-size: 14px;
}

.sidebar .nav-link:hover {
    color: #fff;
    background: #253239;
}

.sidebar .btn i,
.btn i {
    margin-right: 7px;
}

.main-content {
    padding: 28px 32px 48px;
    min-width: 0;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.eyebrow {
    color: var(--muted);
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 700;
}

h1 {
    margin: 2px 0 0;
    font-size: 25px;
    line-height: 1.25;
}

.admin-chip {
    display: flex;
    gap: 8px;
    align-items: center;
    color: var(--muted);
    font-size: 14px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.metric {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 17px;
    display: flex;
    align-items: center;
    gap: 13px;
    min-width: 0;
}

.metric>i {
    font-size: 20px;
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: #edf1f3;
}

.metric strong,
.metric span {
    display: block;
}

.metric strong {
    font-size: 23px;
    line-height: 1;
}

.metric span {
    color: var(--muted);
    font-size: 12px;
    margin-top: 5px;
}

.metric-success>i {
    background: #dff4ea;
    color: #087f5b;
}

.metric-danger>i {
    background: #fde5e5;
    color: #c92a2a;
}

.metric-warning>i {
    background: #fff1d6;
    color: #a45b00;
}

.metric-info>i {
    background: #e3f2fd;
    color: #1971c2;
}

.content-section,
.form-surface {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 20px;
}

.section-heading,
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.section-heading h2 {
    font-size: 16px;
    margin: 0;
}

.table {
    margin: 0;
    font-size: 13px;
}

.table thead th {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    border-bottom-width: 1px;
    white-space: nowrap;
}

.table td {
    padding-top: 13px;
    padding-bottom: 13px;
}

.empty-state {
    text-align: center;
    color: var(--muted) !important;
    padding: 42px !important;
}

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #21a179;
    margin-right: 7px;
}

.toolbar {
    margin-bottom: 14px;
}

.filter-row {
    display: flex;
    gap: 8px;
    flex: 1;
}

.search-control {
    max-width: 360px;
}

.status-filter {
    max-width: 155px;
}

.actions {
    white-space: nowrap;
}

.actions form,
td form {
    display: inline-block;
}

.key-cell {
    min-width: 245px;
}

.serial-cell {
    min-width: 470px;
    font-size: 12px;
}

.form-surface {
    max-width: 920px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.field-span-2 {
    grid-column: 1 / -1;
}

fieldset legend {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.segmented-control {
    display: inline-flex;
}

.segmented-control .btn {
    min-width: 110px;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
}

.form-actions {
    border-top: 1px solid var(--line);
    margin-top: 24px;
    padding-top: 18px;
    display: flex;
    justify-content: flex-end;
    gap: 9px;
}

.settings-form {
    display: grid;
    gap: 20px;
    max-width: 760px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    gap: 30px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 16px;
}

.setting-row p {
    color: var(--muted);
    font-size: 13px;
    margin: 2px 0 0;
}

.form-switch .form-check-input {
    width: 42px;
    height: 22px;
}

.password-form {
    margin-top: 18px;
}

.password-form h2 {
    font-size: 16px;
    margin: 0 0 4px;
}

.key-heading {
    font-size: 15px;
    font-weight: 700;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: #eef2f3;
}

.login-panel {
    width: min(400px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 30px;
    box-shadow: 0 18px 45px rgba(20, 32, 38, .08);
}

.login-brand {
    color: var(--ink);
    margin-bottom: 30px;
}

.login-panel h1 {
    font-size: 21px;
    margin-bottom: 22px;
}

.btn,
.form-control,
.form-select,
.input-group-text,
.alert {
    border-radius: 6px;
}

.btn-primary {
    --bs-btn-bg: #087f5b;
    --bs-btn-border-color: #087f5b;
    --bs-btn-hover-bg: #066b4c;
    --bs-btn-hover-border-color: #066b4c;
}

@media (max-width: 980px) {
    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        min-height: auto;
    }

    .sidebar .nav {
        margin: 18px 0;
    }

    .main-content {
        padding: 20px 14px 36px;
    }

    .page-header {
        align-items: flex-start;
    }

    .admin-chip {
        display: none;
    }

    .metric-grid {
        grid-template-columns: 1fr 1fr;
    }

    .toolbar,
    .filter-row {
        align-items: stretch;
        flex-direction: column;
    }

    .search-control,
    .status-filter {
        max-width: none;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .field-span-2 {
        grid-column: auto;
    }

    .segmented-control {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .segmented-control .btn {
        min-width: 0;
    }

    .serial-cell {
        min-width: 340px;
    }
}

.connect-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #11181c;
    color: #f7f9fa;
}

.connect-content {
    width: min(560px, 100%);
    text-align: center;
}

.connect-brand {
    width: 78px;
    height: 78px;
    margin: 0 auto 22px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #e03131;
    color: #fff;
    font-size: 27px;
    font-weight: 800;
}

.connect-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    color: #b9c4ca;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
}

.connect-status span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2f9e44;
    box-shadow: 0 0 0 4px rgba(47, 158, 68, .16);
}

.connect-content h1 {
    margin: 0;
    font-size: clamp(34px, 8vw, 58px);
    line-height: 1.08;
}

.connect-handle {
    margin: 12px 0 28px;
    color: #9eabb2;
    font-size: 17px;
}

.telegram-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 48px;
    padding: 0 22px;
    border-radius: 7px;
    background: #229ed9;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    transition: background-color .18s ease, transform .18s ease;
}

.telegram-button:hover {
    background: #168ac1;
    color: #fff;
    transform: translateY(-1px);
}

.telegram-button i {
    font-size: 20px;
}