@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;700&display=swap');

:root {
    --bg: #0d1117;
    --sidebar-bg: #161b22;
    --card-bg: #161b22;
    --primary: #2f81f7;
    --primary-hover: #58a6ff;
    --success: #238636;
    --danger: #da3633;
    --warning: #d29922;
    --border: #30363d;
    --text: #c9d1d9;
    --text-muted: #8b949e;
    --sidebar-w: 260px;
    --vip-gold: #f1c40f;
    --vip-text: #000;
    --admin-blue: #2f81f7;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.011em;
}

.dash-layout {
    display: flex;
    height: 100vh;
}

/* SIDEBAR */
.dash-sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 12px;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 32px;
    padding: 0 12px;
}

.menu-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 6px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    margin-bottom: 4px;
}

.menu-item:hover,
.menu-item.active {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}


.menu-item.active {
    background: var(--primary);
    color: white;
}

.sub-header {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    margin: 20px 12px 8px;
    letter-spacing: 0.05em;
}

/* MAIN */
.dash-main {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.section-title h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

/* STATS GRID */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: transform 0.2s, border-color 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at center, var(--primary) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.4s;
    pointer-events: none;
    z-index: 0;
}

.stat-card:hover::before {
    opacity: 0.1;
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.stat-label,
.stat-val {
    position: relative;
    z-index: 1;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.stat-val {
    font-size: 2rem;
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
}

/* TABLES (Shared) */
.table-scroll-wrapper {
    width: 100%;
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    white-space: nowrap;
}

th {
    background: rgba(255, 255, 255, 0.05);
    text-align: left;
    padding: 12px 16px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    position: relative;
    word-break: break-all;
    max-width: 280px;
    white-space: normal;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* BUTTONS */
.action-btn {
    padding: 6px 12px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: #21262d;
    color: var(--text);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: 0.2s;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-primary {
    background: var(--primary);
    border: none;
    color: white;
}

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

/* STATUS */
.status-badge {
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-online {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.status-offline {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* ФЛАГИ СТАТУСОВ (ПЕРЕЧЕРКИВАНИЕ) */
.status-flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    font-size: 0.9rem;
    position: relative;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.2s;
}

.status-flag.disabled {
    opacity: 0.2;
    filter: grayscale(1);
}

.status-flag.disabled::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 4px;
    right: 4px;
    height: 2px;
    background: var(--danger);
    transform: rotate(-45deg);
    border-radius: 2px;
}

/* LOADING PROGRESS BAR */
#top-loader {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), #a855f7);
    box-shadow: 0 0 10px var(--primary);
    z-index: 9999;
    transition: width 0.3s ease;
}

/* LOADING ANIMATION */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.spinning {
    animation: spin 0.8s linear infinite !important;
    display: inline-block;
}

.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.section-loader {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 100px;
    color: var(--primary);
    font-size: 2.5rem;
}

/* LOGS & EXPLORER */
.log-view,
.db-table-container {
    height: calc(100vh - 160px);
    background: #000;
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: auto;
}

.log-view {
    padding: 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    line-height: 1.4;
}

.log-entry {
    padding: 8px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    display: flex;
    gap: 12px;
}

.log-entry:hover {
    background: rgba(255, 255, 255, 0.02);
}

.log-time {
    color: var(--text-muted);
    min-width: 140px;
    font-weight: 500;
}

.log-level {
    min-width: 60px;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    height: fit-content;
}

.level-info {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
}

.level-warn {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.level-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.log-msg {
    color: var(--text);
    word-break: break-all;
}



/* ROLE BADGE */
.role-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    min-width: 42px;
    height: 18px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.role-full {
    background: var(--admin-blue);
    color: white;
    border-color: rgba(47, 129, 247, 0.5);
}

.role-base {
    background: #3f3f46;
    color: white;
}

.role-vip {
    background: linear-gradient(135deg, #f1c40f, #f39c12);
    color: #000;
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 2px 8px rgba(241, 196, 15, 0.3);
}

/* ПЛАВНОСТЬ СПИСКОВ */
.animate-fade {
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

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

/* MODALS */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

/* MOBILE ADAPTATION */
@media (max-width: 1024px) {
    :root {
        --sidebar-w: 240px;
    }

    .dash-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
    }

    .dash-sidebar.active {
        transform: translateX(0);
    }

    .dash-main {
        padding: 16px;
    }

    /* Убираем карточный вид для таблиц в БД, оставляем скролл */
    .db-table-container table {
        display: table !important;
    }

    .db-table-container thead {
        display: table-header-group !important;
    }

    .db-table-container tr {
        display: table-row !important;
        margin-bottom: 0 !important;
        background: none !important;
        border: none !important;
    }

    .db-table-container td {
        display: table-cell !important;
        padding: 12px 16px !important;
        text-align: left !important;
        border-bottom: 1px solid var(--border) !important;
    }

    .db-table-container td:before {
        display: none !important;
    }

    .mobile-nav-toggle {
        display: block !important;
        position: fixed;
        bottom: 24px;
        right: 24px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--primary);
        color: white;
        border: none;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
        z-index: 1001;
        font-size: 1.5rem;
    }
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

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

    table thead {
        display: none;
    }

    table,
    table tbody,
    table tr,
    table td {
        display: block;
        width: 100%;
    }

    table tr {
        margin-bottom: 15px;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--card-bg);
    }

    table td {
        text-align: right;
        padding-left: 50%;
        position: relative;
        border-bottom: 1px solid var(--border);
        max-width: 100%;
    }

    table td::before {
        content: attr(data-label);
        position: absolute;
        left: 15px;
        width: 45%;
        text-align: left;
        font-weight: 600;
        color: var(--text-muted);
    }

    /* Исключение для базы данных: всегда таблица */
    .db-table-container table {
        display: table !important;
    }

    .db-table-container thead {
        display: table-header-group !important;
    }

    .db-table-container tr {
        display: table-row !important;
        border: none !important;
        margin: 0 !important;
        background: none !important;
    }

    .db-table-container td {
        display: table-cell !important;
        text-align: left !important;
        padding: 12px 16px !important;
        width: auto !important;
        border-bottom: 1px solid var(--border) !important;
    }

    .db-table-container td::before {
        display: none !important;
    }

    .modal-card {
        width: 95%;
        margin: 10px;
        padding: 15px;
    }
}

.modal-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 600px !important;
    max-width: 95vw;
    max-height: 90vh;
    padding: 20px;
    overflow-y: auto;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
    background: rgba(22, 27, 34, 0.98) !important;
    backdrop-filter: blur(25px);
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    animation: modalExplode 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* SLEEK SCROLLBAR FOR MODAL */
.modal-card::-webkit-scrollbar {
    width: 5px;
}
.modal-card::-webkit-scrollbar-track {
    background: transparent;
}
.modal-card::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
}
.modal-card::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

@keyframes modalExplode {
    0% { opacity: 0; transform: scale(0.3) translateY(40px); filter: blur(10px); }
    70% { transform: scale(1.05) translateY(-5px); }
    100% { opacity: 1; transform: scale(1) translateY(0); filter: blur(0); }
}

.dash-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.dash-card:hover {
    border-color: rgba(255, 255, 255, 0.1);
}

/* FORCE TABLE VIEW FOR DATABASE EXPLORER */
.db-table-container[class*="db-table-container"] table,
.db-table-container[class*="db-table-container"] thead,
.db-table-container[class*="db-table-container"] tbody,
.db-table-container[class*="db-table-container"] tr,
.db-table-container[class*="db-table-container"] td {
    display: revert !important;
}

.db-table-container table {
    display: table !important;
    white-space: nowrap !important;
}

.db-table-container thead {
    display: table-header-group !important;
}

.db-table-container tbody {
    display: table-row-group !important;
}

.db-table-container tr {
    display: table-row !important;
}

.db-table-container td {
    display: table-cell !important;
    text-align: left !important;
    padding: 12px 16px !important;
    width: auto !important;
    border-bottom: 1px solid var(--border) !important;
}

.db-table-container td::before {
    display: none !important;
}

.field {
    margin-bottom: 16px;
}

.field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: white;
}

/* DEVICE DETAIL IMPROVEMENTS */
.clickable-row {
    cursor: pointer;
    transition: background 0.2s;
}

.clickable-row:hover {
    background: rgba(47, 129, 247, 0.05) !important;
}

.device-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    font-size: 0.85rem;
}

.detail-item {
    overflow: hidden;
}

.detail-item b {
    color: #fff;
    opacity: 0.6;
    font-size: 0.7rem;
    display: block;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

.detail-value {
    color: #ffffff;
    word-break: break-all;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    background: rgba(0, 0, 0, 0.4);
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
    line-height: 1.4;
}

.detail-item input.field {
    background: rgba(0, 0, 0, 0.4) !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    font-family: 'JetBrains Mono', monospace;
    padding: 10px !important;
}

.settings-toggles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    background: rgba(0, 0, 0, 0.4);
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.toggle-control {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.04);
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: #eee;
}

.toggle-control:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(47, 129, 247, 0.5);
    color: #fff;
    transform: translateY(-1px);
}

.toggle-control input {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

.modal-card h3 {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 20px;
    background: linear-gradient(90deg, #fff, var(--text-muted));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}