body {
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: var(--font-family);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(18, 18, 18, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding: 14px 30px;
    box-shadow: 0 1px 0 rgba(255,255,255,0.03), var(--shadow-md);
    flex: 0 0 auto;
    z-index: 1000;
}

.nav-brand {
    font-size: 1.35em;
    font-weight: 700;
    background: linear-gradient(135deg, #bb86fc, var(--accent-teal));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-decoration: none;
    letter-spacing: -0.02em;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-info {
    color: var(--text-secondary);
    font-size: 0.875em;
    border-right: 1px solid rgba(255,255,255,0.1);
    padding-right: 16px;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 28px;
    width: 100%;
    box-sizing: border-box;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.container.connections-page {
    overflow: hidden;
}

/* App Layout (sidebar + container) */
.app-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: rgba(18, 18, 18, 0.5);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    padding: 16px 0;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-header {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-tertiary);
    padding: 16px 20px 6px 20px;
    font-weight: 700;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    margin: 0 8px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition-base) var(--ease-out);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    position: relative;
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--brand-purple-subtle);
    color: #fff;
    font-weight: 600;
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--brand-purple);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.sidebar-link .icon {
    margin-right: 12px;
    font-size: 1rem;
    width: 22px;
    text-align: center;
    opacity: 0.8;
}

.sidebar-link.active .icon {
    opacity: 1;
}

.app-layout .container {
    margin: 0;
    max-width: none;
    width: 100%;
    border-radius: 0;
    padding: 24px 32px;
}

/* Mobile drawer */
.side-drawer {
    position: fixed;
    top: 0;
    right: -300px;
    width: 280px;
    height: 100%;
    background: rgba(18, 18, 18, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 999;
    box-shadow: -4px 0 24px rgba(0,0,0,0.5);
    transition: right var(--transition-slow) var(--ease-out);
    display: flex;
    flex-direction: column;
}

.side-drawer.open { right: 0; }

.drawer-header {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.1rem;
    font-weight: 700;
}

.drawer-content { padding: 16px 20px; }

.drawer-user {
    margin-bottom: 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.drawer-link {
    display: block;
    padding: 12px 0;
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    transition: color var(--transition-base);
}

.drawer-link:hover {
    color: var(--accent-teal);
    text-decoration: none;
}

.menu-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 998;
    display: none;
}

/* Dashboard */
.dashboard-container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-top: 0;
}

@media (max-width: 900px) {
    .dashboard-container { grid-template-columns: 1fr; }
}

/* Connections Page */
.connections-wrapper {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    height: 100%;
    overflow: hidden;
}

.scrollable-column {
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

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

.inventory-item {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    cursor: pointer;
    transition: all var(--transition-base) var(--ease-out);
    display: flex;
    align-items: center;
}

.inventory-item:hover {
    background-color: rgba(255,255,255,0.04);
    padding-left: 22px;
}

.inventory-item.selected {
    background: var(--brand-purple-subtle);
    border-left: 3px solid var(--brand-purple);
}

.inv-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.inv-name { font-weight: 600; color: #fff; font-size: 0.95em; }
.inv-meta { font-size: 0.8em; color: var(--text-tertiary); }

.connection-header {
    border-bottom: 1px solid rgba(255,255,255,0.06);
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.connection-meta {
    margin-top: 6px;
}

.connection-images {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.img-box {
    width: 150px;
    height: 150px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-md);
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

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

.img-box span {
    position: absolute;
    top: 6px;
    left: 6px;
    background: rgba(0,0,0,0.75);
    padding: 2px 8px;
    font-size: 0.65em;
    border-radius: var(--radius-sm);
    color: white;
    backdrop-filter: blur(4px);
}

.mappings-table {
    width: 100%;
    border-collapse: collapse;
}

.mappings-table th, .mappings-table td {
    padding: 10px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    text-align: left;
}

/* Logs Page */
.logs-page .charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    margin-top: 0;
}

.logs-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    justify-content: space-between;
}

.logs-filter-form {
    display: flex;
    gap: 10px;
    flex: 1;
    margin: 0;
    min-width: 300px;
}

.logs-actions {
    display: flex;
    gap: 10px;
}

@media (max-width: 900px) {
    .logs-page .charts-grid {
        grid-template-columns: 1fr;
    }
}

/* Auth Pages */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
    background: var(--bg-color);
    font-family: var(--font-family);
    position: relative;
    overflow: hidden;
}

.auth-container::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(124, 77, 255, 0.08) 0%, transparent 70%);
    top: -200px;
    right: -200px;
    pointer-events: none;
}

.auth-container::after {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(3, 218, 198, 0.06) 0%, transparent 70%);
    bottom: -150px;
    left: -150px;
    pointer-events: none;
}

/* Mobile */
@media (max-width: 768px) {
    .app-layout {
        display: block;
        overflow-y: auto;
    }

    .app-layout .container {
        padding: 16px;
        overflow-y: visible;
        height: auto;
    }

    .dashboard-container { grid-template-columns: 1fr; }

    .connections-wrapper {
        display: block;
    }

    .connections-wrapper .scrollable-column:first-child {
        display: flex;
        width: 100%;
        height: 100%;
    }

    .connections-wrapper #right-panel {
        display: none !important;
    }

    .connections-wrapper.mobile-details-open .scrollable-column:first-child {
        display: none !important;
    }

    .connections-wrapper.mobile-details-open #right-panel {
        display: flex !important;
        width: 100%;
        height: 100%;
    }

    .connections-header-controls {
        flex-wrap: wrap;
    }

    .connections-header-controls > button {
        flex: 1 1 100%;
        margin-bottom: 5px;
    }

    .header-actions-right {
        margin-left: 0 !important;
        width: 100%;
        gap: 10px;
        justify-content: space-between;
    }

    .header-actions-right button {
        flex: 1;
        white-space: nowrap;
        padding: 10px 5px;
        font-size: 0.9em;
        text-overflow: ellipsis;
        overflow: hidden;
    }

    .logs-filter-form {
        flex-direction: column;
        width: 100%;
        min-width: 0;
    }

    .logs-controls {
        flex-direction: column;
    }

    .logs-actions {
        width: 100%;
    }

    .logs-actions a, .logs-actions button {
        flex: 1;
        width: 100%;
    }

    .logs-actions a button {
        width: 100%;
    }

    .range-select {
        width: 100% !important;
    }
}
