:root {
    --bg: #081633;
    --panel: #0d1d3d;
    --panel-2: #10254d;
    --text: #eef4ff;
    --muted: #9fb2d4;
    --accent: #22c55e;
    --accent-dark: #16a34a;
    --warn: #92400e;
    --danger: #b91c1c;
    --blue: #2563eb;
    --border: rgba(255, 255, 255, 0.08);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, sans-serif;
}

body {
    min-height: 100vh;
}

body.drawer-open {
    overflow: hidden;
}

.page {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 12px;
}

.topbar {
    margin-bottom: 12px;
}

.topbar-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.brand-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}

.brand {
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    padding: 10px 0 4px;
}

.menu-toggle-btn,
.back-nav-btn,
.drawer-close-btn,
.topbar-icon-link {
    height: 48px;
    margin-bottom: 0;
    padding: 0;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
}

.menu-toggle-btn,
.drawer-close-btn,
.topbar-icon-link {
    width: 48px;
    min-width: 48px;
}

.topbar-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    text-decoration: none;
    font-size: 22px;
    font-weight: 800;
}

.back-nav-btn {
    width: auto;
    min-width: 78px;
    padding: 0 14px;
    font-size: 14px;
}

.menu-toggle-btn {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
}

.menu-toggle-btn span {
    display: block;
    width: 20px;
    height: 2px;
    margin: 0 auto;
    border-radius: 999px;
    background: currentColor;
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(1, 7, 19, 0.62);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 180;
}

.drawer-backdrop-visible {
    opacity: 1;
    pointer-events: auto;
}

.side-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: min(320px, calc(100vw - 32px));
    height: 100vh;
    padding: 18px 16px 20px;
    background:
        linear-gradient(180deg, rgba(16, 37, 77, 0.98), rgba(8, 22, 51, 0.98)),
        var(--panel);
    border-right: 1px solid var(--border);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
    transform: translateX(calc(-100% - 16px));
    -webkit-transform: translate3d(calc(-100% - 16px), 0, 0);
    transition: transform 0.24s ease;
    will-change: transform;
    z-index: 200;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.side-drawer-open {
    transform: translateX(0);
    -webkit-transform: translate3d(0, 0, 0);
}

.drawer-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.drawer-title {
    font-size: 20px;
    font-weight: 700;
}

.drawer-subtitle {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
}

.drawer-close-btn {
    font-size: 28px;
    line-height: 1;
}

.drawer-nav {
    display: grid;
    gap: 10px;
}

.drawer-group {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.035);
    overflow: hidden;
}

.drawer-group-title {
    cursor: pointer;
    list-style: none;
    padding: 12px 14px;
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
}

.drawer-group-title::-webkit-details-marker {
    display: none;
}

.drawer-group-title::after {
    content: "▾";
    float: right;
    color: var(--muted);
    transition: transform 0.18s ease;
}

.drawer-group[open] .drawer-group-title::after {
    transform: rotate(180deg);
}

.drawer-group-links {
    display: grid;
    gap: 8px;
    padding: 0 8px 8px;
}

.drawer-link {
    display: block;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    text-decoration: none;
    font-size: 15px;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.drawer-link-nested {
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 14px;
}

.drawer-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 22px;
    margin-left: 8px;
    padding: 0 7px;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}

.drawer-link:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.16);
    transform: translateX(2px);
}

.drawer-link-active {
    background: rgba(37, 99, 235, 0.18);
    border-color: rgba(96, 165, 250, 0.45);
    color: #dbeafe;
}

.drawer-link-danger {
    margin-top: 8px;
    background: rgba(185, 28, 28, 0.16);
    border-color: rgba(248, 113, 113, 0.28);
    color: #fee2e2;
}

.install-btn {
    width: 100%;
    flex-basis: 100%;
    margin-bottom: 0;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 15px;
    cursor: pointer;
}

.ios-hint {
    background: rgba(37, 99, 235, 0.18);
    border: 1px solid rgba(37, 99, 235, 0.35);
    color: #dbeafe;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 14px;
    line-height: 1.5;
    font-size: 14px;
}

.hidden {
    display: none !important;
}

.auth-hint {
    margin: 16px 0 0;
    text-align: center;
}

.inline-link {
    color: #bfdbfe;
    font-weight: 700;
}

.flash-wrap {
    margin-bottom: 16px;
}

.flash {
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    font-size: 15px;
}

.flash-error {
    background: var(--warn);
    color: #fff7ed;
}

.flash-success {
    background: #14532d;
    color: #ecfdf5;
}

.announcement-banner,
.announcement-preview {
    border: 1px solid rgba(248, 113, 113, 0.48);
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(153, 27, 27, 0.96), rgba(127, 29, 29, 0.9));
    color: #fff1f2;
    padding: 14px;
    margin: 0 0 14px;
    line-height: 1.45;
    font-weight: 700;
    box-shadow: 0 12px 28px rgba(127, 29, 29, 0.25);
}

.announcement-preview {
    margin-top: 12px;
}

.content {
    display: block;
}

.mobile-stack {
    display: grid;
    gap: 16px;
}

.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.hero-card {
    background: linear-gradient(135deg, #10254d, #163164);
}

.card h2 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 22px;
}

.card h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 18px;
}

.collapsible-card {
    padding: 0;
    overflow: hidden;
}

.collapsible-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    cursor: pointer;
    font-size: 22px;
    font-weight: 700;
    list-style: none;
}

.collapsible-summary::-webkit-details-marker {
    display: none;
}

.collapsible-summary::after {
    content: "Развернуть";
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
}

.collapsible-card[open] .collapsible-summary::after {
    content: "Свернуть";
}

.collapsible-card .info-list {
    padding: 0 16px 16px;
}

.collapsible-empty {
    padding: 0 16px 16px;
    margin: 0;
}

.muted {
    color: var(--muted);
    line-height: 1.5;
}

label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 14px;
}

input,
button,
textarea,
select {
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 12px 14px;
    font-size: 16px;
    margin-bottom: 12px;
}

input,
textarea,
select {
    background: #071127;
    color: var(--text);
}

button {
    background: var(--accent);
    color: #04110a;
    font-weight: 700;
    cursor: pointer;
}

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

.menu-toggle-btn:hover,
.back-nav-btn:hover,
.drawer-close-btn:hover,
.install-btn:hover,
.topbar-icon-link:hover {
    background: #132a55;
    color: var(--text);
}

.big-actions {
    display: grid;
    gap: 12px;
}

.big-btn {
    min-height: 56px;
    font-size: 17px;
}

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

.info-list span {
    color: var(--muted);
    display: inline-block;
    min-width: 140px;
}

.simple-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.simple-list li {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    line-height: 1.5;
}

.passage-list {
    display: grid;
    gap: 12px;
    list-style: none;
    padding: 0;
    margin: 0;
}

.passage-item {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.04);
}

.passage-main {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.passage-plate {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.passage-chip {
    display: inline-block;
    margin-left: 8px;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(34, 197, 94, 0.16);
    color: #bbf7d0;
    font-size: 12px;
    font-weight: 800;
}

.passage-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.passage-meta span {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 8px;
    background: rgba(0, 0, 0, 0.12);
}

.list-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.action-link {
    display: inline-block;
    background: var(--blue);
    color: white;
    text-decoration: none;
    padding: 10px 14px;
    border-radius: 12px;
    text-align: center;
}

.link-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

.full-link {
    width: 100%;
}

.admin-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

textarea {
    resize: vertical;
    min-height: 120px;
}

.danger-btn {
    background: #dc2626;
    color: white;
}

.metric {
    font-size: 34px;
    font-weight: 700;
    margin-bottom: 14px;
}

.compact-card {
    text-align: center;
}

.user-cards {
    display: grid;
    gap: 12px;
}

.user-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
}

.user-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 10px;
}

.user-name {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
}

.user-meta {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 14px;
}

.user-list {
    display: grid;
    gap: 10px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.compact-user-list {
    padding: 0 16px 16px;
}

.user-list-item {
    display: grid;
    gap: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
}

.user-list-main {
    min-width: 0;
}

.user-list-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
    margin-top: 6px;
}

.user-list-action {
    align-self: start;
}

.filter-form {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.search-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin: 0;
}

.search-fields legend {
    color: var(--muted);
    font-size: 14px;
    padding: 0 6px;
}

.search-fields label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    color: var(--text);
}

.search-fields input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.strict-search-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--text);
}

.strict-search-toggle input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.checkbox-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    color: var(--text);
}

.checkbox-row input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.chat-card {
    display: grid;
    gap: 14px;
}

.chat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.chat-header-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.chat-header h2 {
    margin-bottom: 6px;
}

.action-link-button {
    width: auto;
    min-height: 0;
    margin: 0;
    cursor: pointer;
    font: inherit;
}

.chat-status {
    flex: 0 0 auto;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 10px;
    color: var(--muted);
    font-size: 13px;
}

.chat-messages {
    display: grid;
    gap: 10px;
    min-height: 360px;
    max-height: 58vh;
    overflow-y: auto;
    padding: 12px;
    background: rgba(0, 0, 0, 0.16);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.chat-message {
    max-width: 86%;
    justify-self: start;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px 12px;
}

.chat-message-mine {
    justify-self: end;
    background: rgba(34, 197, 94, 0.14);
    border-color: rgba(34, 197, 94, 0.34);
}

.chat-message-top {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 6px;
}

.chat-message-top strong {
    color: var(--text);
}

.chat-message-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.45;
}

.chat-delete-btn {
    width: auto;
    min-height: 0;
    margin: 10px 0 0;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(220, 38, 38, 0.18);
    color: #fecaca;
    border-color: rgba(220, 38, 38, 0.35);
    font-size: 12px;
}

.chat-new-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #bfdbfe;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.chat-new-divider::before,
.chat-new-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: rgba(191, 219, 254, 0.28);
}

.chat-dialogs-status {
    margin-bottom: 12px;
    font-size: 13px;
}

.dialog-has-unread {
    border-color: rgba(59, 130, 246, 0.45);
    background: rgba(59, 130, 246, 0.08);
}

.chat-form {
    display: grid;
    gap: 10px;
}

.camera-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.camera-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.camera-card-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.camera-card h3 {
    margin: 0 0 6px;
    font-size: 18px;
}

.camera-meta {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.camera-view {
    position: relative;
}

.camera-placeholder {
    display: grid;
    place-items: center;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: linear-gradient(135deg, #020617, #0f172a);
    border: 1px dashed var(--border);
    border-radius: 12px;
    color: var(--text);
    font-weight: 700;
    text-align: center;
    padding: 18px;
}

.camera-placeholder span {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.camera-stream {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: #030712;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.camera-view-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.camera-stop-btn {
    background: rgba(15, 23, 42, 0.92);
    color: var(--text);
    border: 1px solid var(--border);
}

.camera-action-form {
    margin-top: 12px;
}

@media (min-width: 768px) {
    .page {
        padding: 20px;
    }

    .topbar {
        margin-bottom: 18px;
    }

    .brand {
        font-size: 26px;
    }

    .install-btn {
        width: auto;
        flex-basis: auto;
        min-width: 220px;
    }

    .grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .admin-actions {
        grid-template-columns: repeat(3, 1fr);
    }

    .list-row {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .big-actions {
        grid-template-columns: repeat(2, 1fr);
    }

    .user-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .user-list-item {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
    }

    .filter-form {
        grid-template-columns: 2fr 1fr;
        align-items: end;
    }

    .strict-search-toggle {
        grid-column: 1 / -1;
    }

    .search-fields {
        grid-column: 1 / -1;
    }

    .filter-form button {
        grid-column: 1 / -1;
    }

    .camera-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1100px) {
    .user-cards {
        grid-template-columns: repeat(3, 1fr);
    }

    .side-drawer {
        width: 340px;
    }
}
