/* ============================================================
   Dashboard — minimal neutral design system (Linear/Vercel style)
   Light + dark via [data-theme] CSS variables.
   ============================================================ */

/* ---------- Tokens: light ---------- */
:root[data-theme="light"] {
    --bg:            #fafafa;
    --surface:       #ffffff;
    --surface-2:     #f4f4f5;
    --surface-3:     #e4e4e7;
    --border:        #e4e4e7;
    --border-strong: #d4d4d8;
    --text:          #18181b;
    --text-secondary:#52525b;
    --text-muted:    #71717a;
    --accent:        #2563eb;
    --accent-hover:  #1d4ed8;
    --accent-soft:   #dbeafe;
    --accent-text:   #1e40af;
    --success:       #16a34a;
    --success-soft:  #dcfce7;
    --success-text:  #166534;
    --warning:       #ca8a04;
    --warning-soft:  #fef3c7;
    --warning-text:  #854d0e;
    --danger:        #dc2626;
    --danger-soft:   #fee2e2;
    --danger-text:   #991b1b;
    --shadow-xs:     0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-sm:     0 1px 3px 0 rgba(0, 0, 0, 0.06), 0 1px 2px -1px rgba(0, 0, 0, 0.06);
    --shadow-md:     0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
    --shadow-lg:     0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.08);
    --radius-sm:     6px;
    --radius:        8px;
    --radius-lg:     12px;
}

/* ---------- Tokens: dark ---------- */
:root[data-theme="dark"] {
    --bg:            #09090b;
    --surface:       #18181b;
    --surface-2:     #27272a;
    --surface-3:     #3f3f46;
    --border:        #27272a;
    --border-strong: #3f3f46;
    --text:          #fafafa;
    --text-secondary:#a1a1aa;
    --text-muted:    #71717a;
    --accent:        #3b82f6;
    --accent-hover:  #60a5fa;
    --accent-soft:   rgba(59, 130, 246, 0.15);
    --accent-text:   #93c5fd;
    --success:       #22c55e;
    --success-soft:  rgba(34, 197, 94, 0.15);
    --success-text:  #86efac;
    --warning:       #eab308;
    --warning-soft:  rgba(234, 179, 8, 0.15);
    --warning-text:  #fde047;
    --danger:        #ef4444;
    --danger-soft:   rgba(239, 68, 68, 0.15);
    --danger-text:   #fca5a5;
    --shadow-xs:     0 1px 2px 0 rgba(0, 0, 0, 0.30);
    --shadow-sm:     0 1px 3px 0 rgba(0, 0, 0, 0.35);
    --shadow-md:     0 4px 6px -1px rgba(0, 0, 0, 0.40);
    --shadow-lg:     0 10px 15px -3px rgba(0, 0, 0, 0.50);
    --radius-sm:     6px;
    --radius:        8px;
    --radius-lg:     12px;
}

/* ============================================================
   Reset / base
   ============================================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

html {
    background: var(--bg);
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    font-feature-settings: 'cv11', 'ss01';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

::selection {
    background: var(--accent-soft);
    color: var(--accent-text);
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
}

/* ============================================================
   Layout shell
   ============================================================ */
.app-shell {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-main {
    flex: 1;
}

.page {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

.page-narrow {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 32px 24px;
}

.page-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.page-header {
    margin-bottom: 28px;
}

.page-header h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.page-header p {
    margin: 6px 0 0;
    font-size: 14px;
    color: var(--text-secondary);
}

/* ============================================================
   Header / navigation
   ============================================================ */
.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: 56px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
    flex-shrink: 0;
}

.app-brand img {
    width: 24px;
    height: 24px;
    border-radius: 6px;
}

.app-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    margin-left: 16px;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14px;
    line-height: 1.4;
    transition: background-color 120ms ease, color 120ms ease;
}

.nav-link:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-link.router-link-active {
    background: var(--surface-2);
    color: var(--text);
}

.app-user {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.burger {
    display: none;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 120ms ease;
}

.burger:hover {
    background: var(--surface-2);
}

.burger:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
}

.burger svg {
    width: 18px;
    height: 18px;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.card-compact {
    padding: 16px;
}

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

.card-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.005em;
    color: var(--text);
}

.card-subtitle {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.card-section + .card-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 36px;
    padding: 0 14px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, opacity 120ms ease;
    white-space: nowrap;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
}

.btn-danger {
    background: var(--danger);
    color: #ffffff;
    border-color: var(--danger);
}

.btn-danger:hover {
    filter: brightness(0.92);
}

.btn-sm {
    height: 30px;
    padding: 0 10px;
    font-size: 13px;
    border-radius: var(--radius-sm);
}

.btn-lg {
    height: 44px;
    padding: 0 18px;
    font-size: 15px;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--radius-sm);
}

.btn-icon.btn-ghost {
    border: 1px solid transparent;
}

.btn-icon svg {
    width: 16px;
    height: 16px;
}

/* ============================================================
   Inputs
   ============================================================ */
.input {
    display: block;
    width: 100%;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

textarea.input {
    height: auto;
    min-height: 80px;
    padding: 10px 12px;
    resize: vertical;
    line-height: 1.5;
}

select.input {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2371717a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='4 6 8 10 12 6'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px 14px;
    padding-right: 32px;
}

.input::placeholder {
    color: var(--text-muted);
}

.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.input:disabled {
    background: var(--surface-2);
    color: var(--text-muted);
    cursor: not-allowed;
}

.label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

/* ============================================================
   Badges
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.5;
    white-space: nowrap;
}

.badge-neutral {
    background: var(--surface-2);
    color: var(--text-secondary);
}

.badge-info {
    background: var(--accent-soft);
    color: var(--accent-text);
}

.badge-success {
    background: var(--success-soft);
    color: var(--success-text);
}

.badge-warning {
    background: var(--warning-soft);
    color: var(--warning-text);
}

.badge-danger {
    background: var(--danger-soft);
    color: var(--danger-text);
}

/* ============================================================
   Avatar
   ============================================================ */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid var(--border);
    padding: 0;                       /* убираем дефолтный <button> padding (1px 6px) */
    cursor: default;
    box-sizing: border-box;
}

button.avatar {
    cursor: pointer;
    transition: border-color 120ms ease;
}

button.avatar:hover {
    border-color: var(--border-strong);
}

button.avatar:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-lg {
    width: 64px;
    height: 64px;
    font-size: 22px;
}

/* ============================================================
   Tables
   ============================================================ */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table thead th {
    text-align: left;
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: transparent;
    white-space: nowrap;
}

.table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text);
}

.table tbody tr {
    transition: background-color 120ms ease;
}

.table tbody tr:hover {
    background: var(--surface-2);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table-card {
    /* table inside .card without extra padding */
    margin: 0 -24px;
    width: calc(100% + 48px);
}

.table-card thead th:first-child,
.table-card tbody td:first-child {
    padding-left: 24px;
}

.table-card thead th:last-child,
.table-card tbody td:last-child {
    padding-right: 24px;
}

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

.user-cell .avatar {
    flex-shrink: 0;
}

.user-cell-text {
    min-width: 0;
}

.user-cell-name {
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.user-cell-uname {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

@media (max-width: 760px) {
    .table thead { display: none; }
    .table,
    .table tbody,
    .table tr,
    .table td {
        display: block;
        width: 100%;
    }
    .table-card { margin: 0; width: 100%; }
    .table tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 8px;
        padding: 12px;
    }
    .table tbody td {
        border-bottom: none;
        padding: 6px 0;
        display: flex;
        justify-content: space-between;
        gap: 12px;
        align-items: center;
    }
    .table tbody td::before {
        content: attr(data-label);
        font-size: 12px;
        font-weight: 500;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }
    .table tbody td:first-child::before {
        display: none;
    }
}

/* ============================================================
   Pagination & toolbar
   ============================================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.pagination-info {
    font-size: 13px;
    color: var(--text-secondary);
}

.users-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
}

.users-toolbar .grow {
    flex: 1 1 220px;
    min-width: 0;
}

.pill-group {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2px;
    gap: 0;
}

.pill-group button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
    line-height: 1.4;
}

.pill-group button:hover {
    color: var(--text);
}

.pill-group button.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-xs);
}

/* ============================================================
   Empty state
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ============================================================
   Spinner
   ============================================================ */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}

.spinner-sm {
    width: 12px;
    height: 12px;
    border-width: 2px;
}

.spinner-lg {
    width: 20px;
    height: 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   Skeleton placeholders — серые блоки с pulse'ом для loading-state
   ============================================================ */
.skeleton {
    display: block;
    background: linear-gradient(
        90deg,
        var(--surface-2) 0%,
        var(--surface-3) 50%,
        var(--surface-2) 100%
    );
    background-size: 200% 100%;
    border-radius: var(--radius-sm);
    animation: skeleton-shimmer 1.4s ease infinite;
}

@keyframes skeleton-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text   { height: 12px; margin: 4px 0; }
.skeleton-line   { height: 14px; }
.skeleton-block  { height: 60px; }
.skeleton-circle { border-radius: 50%; }

/* Container helpers */
.users-skeleton,
.audit-skeleton,
.sessions-skeleton {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.users-row-skeleton,
.audit-row-skeleton {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.users-row-skeleton:last-child,
.audit-row-skeleton:last-child {
    border-bottom: none;
}

.session-row-skeleton {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.stat-tile-skeleton {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.stat-tile-skeleton.compact {
    padding: 12px;
    gap: 6px;
}

@media (max-width: 760px) {
    .users-row-skeleton,
    .audit-row-skeleton {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: none;
        background: var(--surface-2);
    }
}

/* ============================================================
   Banners (kept for in-card status hints; lighter than toast)
   ============================================================ */
.banner {
    padding: 10px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 13px;
    line-height: 1.5;
    background: var(--surface-2);
    color: var(--text);
}

.banner-error {
    background: var(--danger-soft);
    border-color: transparent;
    color: var(--danger-text);
}

.banner-warning {
    background: var(--warning-soft);
    border-color: transparent;
    color: var(--warning-text);
}

.banner-info {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--accent-text);
}

.banner-success {
    background: var(--success-soft);
    border-color: transparent;
    color: var(--success-text);
}

/* ============================================================
   Toggle (form)
   ============================================================ */
.toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}

.toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

.toggle-track {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--surface-3);
    border-radius: 999px;
    transition: background-color 120ms ease;
    flex: 0 0 36px;
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--surface);
    border-radius: 50%;
    transition: transform 120ms ease;
    box-shadow: var(--shadow-xs);
}

.toggle input:checked + .toggle-track {
    background: var(--accent);
}

.toggle input:checked + .toggle-track::after {
    transform: translateX(16px);
}

.toggle input:focus-visible + .toggle-track {
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
}

.toggle input:disabled + .toggle-track {
    opacity: 0.45;
    cursor: not-allowed;
}

.toggle-label {
    font-size: 14px;
    color: var(--text);
    line-height: 1.4;
}

/* ============================================================
   Toast
   ============================================================ */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 380px;
    width: calc(100% - 32px);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.4;
    pointer-events: auto;
}

.toast-icon {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    margin-top: 1px;
}

.toast-success .toast-icon { color: var(--success); }
.toast-error   .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info    .toast-icon { color: var(--accent); }

.toast-body {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 500;
    color: var(--text);
}

.toast-message {
    color: var(--text-secondary);
    margin-top: 2px;
    word-break: break-word;
}

.toast-title + .toast-message { margin-top: 4px; }

.toast-close {
    flex-shrink: 0;
    background: transparent;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 120ms ease, color 120ms ease;
}

.toast-close:hover {
    background: var(--surface-2);
    color: var(--text);
}

.toast-close svg {
    width: 14px;
    height: 14px;
}

/* TransitionGroup for toasts */
.toast-enter-active,
.toast-leave-active {
    transition: transform 200ms ease, opacity 200ms ease;
}

.toast-enter-from {
    opacity: 0;
    transform: translateX(16px);
}

.toast-leave-to {
    opacity: 0;
    transform: translateX(16px);
}

.toast-leave-active {
    position: absolute;
    right: 0;
    left: 0;
}

/* ============================================================
   Modal
   ============================================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    color: var(--text);
}

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

.modal-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.modal-subtitle {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ============================================================
   Page transition: fade only
   ============================================================ */
.fade-enter-active,
.fade-leave-active {
    transition: opacity 120ms ease;
}

.fade-enter-from,
.fade-leave-to {
    opacity: 0;
}

/* ============================================================
   Stat tiles
   ============================================================ */
.stat-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.stat-grid-compact {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
}

.stat-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-tile-value {
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

.stat-tile-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.stat-tile-sub {
    font-size: 12px;
    color: var(--text-muted);
}

.stat-tile-compact {
    padding: 12px;
}

.stat-tile-compact .stat-tile-value {
    font-size: 20px;
}

.stat-tile-compact .stat-tile-label {
    font-size: 12px;
}

/* ============================================================
   Sessions
   ============================================================ */
.session-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: background-color 120ms ease, border-color 120ms ease;
}

.session-row:hover {
    background: var(--surface-2);
}

.session-row-icon {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-secondary);
}

.session-row-icon svg {
    width: 16px;
    height: 16px;
}

.session-row-meta {
    flex: 1 1 auto;
    min-width: 0;
}

.session-row-title {
    font-weight: 500;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    color: var(--text);
}

.session-row-action {
    flex: 0 0 auto;
}

.relative-time {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

@media (max-width: 640px) {
    .session-row { flex-wrap: wrap; }
    .session-row-action {
        flex-basis: 100%;
        display: flex;
        justify-content: flex-end;
    }
}

/* ============================================================
   Audit
   ============================================================ */
.audit-row td {
    vertical-align: top;
}

.audit-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
    word-break: break-word;
}

.audit-details-line {
    white-space: pre-wrap;
}

/* ============================================================
   Profile / admin grids
   ============================================================ */
.profile-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

.profile-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;                       /* чтобы grid-ячейка не «расширяла» родителя */
}

@media (min-width: 960px) {
    .profile-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: start;
    }
}

.dashboard-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.metric {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.metric-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric-value {
    font-size: 14px;
    color: var(--text);
    font-weight: 500;
}

.metric-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 14px;
}

.metric-row .key {
    color: var(--text-muted);
    flex: 0 0 auto;
}

.metric-row .val {
    color: var(--text);
    font-weight: 500;
}

/* ============================================================
   Mobile
   ============================================================ */
@media (max-width: 640px) {
    .app-header {
        padding: 0 16px;
        gap: 8px;
    }

    .app-nav {
        display: none;
    }

    .app-nav.is-open {
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        margin: 0;
        padding: 8px;
        box-shadow: var(--shadow-md);
        display: flex;
    }

    .nav-link {
        padding: 8px 12px;
    }

    .burger {
        display: inline-flex;
    }

    .page,
    .page-narrow {
        padding: 20px 16px;
    }

    .toast-container {
        top: 8px;
        right: 8px;
        left: 8px;
        max-width: none;
        width: auto;
    }
}

/* ============================================================
   Reduce-motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

/* ============================================================
   Login screen helpers
   ============================================================ */
.login-card {
    width: 100%;
    max-width: 400px;
    padding: 32px;
}

.login-logo {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    margin: 0 auto 16px;
    display: block;
}

.login-title {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
    text-align: center;
}

.login-subtitle {
    margin: 0 0 24px;
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
}

.login-help {
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

.login-waiting {
    text-align: center;
    padding: 8px 0 4px;
}

.login-waiting .spinner {
    width: 24px;
    height: 24px;
    border-width: 2px;
}

/* QR-фолбэк на login: на десктопе если у юзера нет TG Desktop, можно отсканить с телефона */
.login-qr {
    margin-top: 20px;
    text-align: center;
}

.login-qr-divider {
    position: relative;
    text-align: center;
    margin: 0 0 14px;
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.login-qr-divider::before,
.login-qr-divider::after {
    content: "";
    position: absolute;
    top: 50%;
    width: calc(50% - 78px);
    height: 1px;
    background: var(--border);
}
.login-qr-divider::before { left: 0; }
.login-qr-divider::after  { right: 0; }
.login-qr-divider span     { padding: 0 8px; }

.login-qr-frame {
    display: inline-block;
    background: #ffffff;          /* всегда белый — для лучшей сканируемости QR */
    padding: 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.login-qr-frame img {
    display: block;
    width: 200px;
    height: 200px;
}

/* На мобильном QR не нужен (TG откроется напрямую), занимает место — скрываем */
@media (max-width: 640px) {
    .login-qr { display: none; }
}

/* ============================================================
   Theme toggle button
   ============================================================ */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
}

.theme-toggle:hover {
    background: var(--surface-2);
    color: var(--text);
}

.theme-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
}

.theme-toggle svg {
    width: 16px;
    height: 16px;
}

/* ============================================================
   Language toggle (dropdown)
   ============================================================ */
.lang-toggle {
    position: relative;
    display: inline-flex;
}

.lang-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 32px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
    font-family: inherit;
}

.lang-toggle-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.lang-toggle-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
}

.lang-toggle-btn svg {
    opacity: 0.7;
}

.lang-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 80px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 4px;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.lang-dropdown button {
    background: transparent;
    border: none;
    padding: 6px 12px;
    text-align: left;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.04em;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 120ms ease, color 120ms ease;
    font-family: inherit;
}

.lang-dropdown button:hover {
    background: var(--surface-2);
    color: var(--text);
}

.lang-dropdown button.active {
    background: var(--surface-2);
    color: var(--text);
}

@media (max-width: 640px) {
    .lang-toggle-btn {
        padding: 0 6px;
    }
}
